Audacity  2.2.0
ODDecodeBlockFile.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  ODDecodeBlockFile.h
6 
7  Created by Michael Chinen (mchinen)
8  Audacity(R) is copyright (c) 1999-2008 Audacity Team.
9  License: GPL v2. See License.txt.
10 
11 ******************************************************************//*******************************************************************/
21 
22 
23 
24 
25 
26 
27 #ifndef __AUDACITY_ODDecodeBlockFile__
28 #define __AUDACITY_ODDecodeBlockFile__
29 
30 #include "SimpleBlockFile.h"
31 #include "../BlockFile.h"
32 #include "../ondemand/ODTaskThread.h"
33 #include "../DirManager.h"
34 #include "../ondemand/ODDecodeTask.h"
35 #include <wx/atomic.h>
36 #include <wx/thread.h>
37 
39 class ODDecodeBlockFile final : public SimpleBlockFile
40 {
41  public:
42 
43  // Constructor / Destructor
44 
46  ODDecodeBlockFile(wxFileNameWrapper &&baseFileName, wxFileNameWrapper &&audioFileName, sampleCount aliasStart,
47  size_t aliasLen, int aliasChannel, unsigned int decodeType);
49  ODDecodeBlockFile(wxFileNameWrapper &&existingFile, wxFileNameWrapper &&audioFileName, sampleCount aliasStart,
50  size_t aliasLen, int aliasChannel, unsigned int decodeType,
51  float min, float max, float rms, bool dataAvailable);
52 
53  virtual ~ODDecodeBlockFile();
54  //checks to see if summary data has been computed and written to disk yet. Thread safe. Blocks if we are writing summary data.
55  bool IsSummaryAvailable() const override;
56 
58  bool IsDataAvailable() const override;
59 
61  bool IsSummaryBeingComputed() override { return false; }
62 
63  //Calls that rely on summary files need to be overidden
64  DiskByteCount GetSpaceUsage() const override;
66  MinMaxRMS GetMinMaxRMS(
67  size_t start, size_t len, bool mayThrow) const override;
69  MinMaxRMS GetMinMaxRMS(bool mayThrow) const override;
71  bool Read256(float *buffer, size_t start, size_t len) override;
73  bool Read64K(float *buffer, size_t start, size_t len) override;
74 
77 
78 
79 
81  BlockFilePtr Copy(wxFileNameWrapper &&fileName) override;
82 
84  void SaveXML(XMLWriter &xmlFile) override;
85 
87  static BlockFilePtr BuildFromXML(DirManager &dm, const wxChar **attrs);
88 
90  void Recover(void) override;
91 
93 
95 
97  void SetStart(sampleCount startSample){mStart = startSample;}
98 
100  sampleCount GetStart() const {return mStart;}
101 
102  //returns the number of samples from the beginning of the track that this blockfile starts at
103  sampleCount GetGlobalStart() const {return mClipOffset+mStart;}
104 
105  //returns the number of samples from the beginning of the track that this blockfile ends at
106  sampleCount GetGlobalEnd() const {return mClipOffset+mStart+GetLength();}
107 
108  //Below calls are overrided just so we can take wxlog calls out, which are not threadsafe.
109 
111  size_t ReadData(samplePtr data, sampleFormat format,
112  size_t start, size_t len, bool mayThrow) const override;
113 
115  bool ReadSummary(ArrayOf<char> &data) override;
116 
118  unsigned int GetDecodeType() /* not override */ const { return mType; }
119  // void SetDecodeType(unsigned int type) /* not override */ { mType = type; }
120 
122  void SetClipOffset(sampleCount numSamples){mClipOffset= numSamples;}
123 
125  sampleCount GetClipOffset() const {return mClipOffset;}
126 
127  //OD TODO:set ISAlias to true while we have no data?
128 
130  void SetODFileDecoder(ODFileDecoder* decoder);
131 
132  const wxFileName &GetAudioFileName(){return mAudioFileName;}
133 
135  void SetFileName(wxFileNameWrapper &&name) override;
136  GetFileNameResult GetFileName() const override;
137 
139  void LockRead() const override;
141  void UnlockRead() const override;
142 
145  const wxFileName &GetEncodedAudioFilename()
146  {
147  return mAudioFileName;
148  }
149 
153  void ChangeAudioFile(wxFileNameWrapper &&newAudioFile);
154 
155  protected:
156 
157 // void WriteSimpleBlockFile() override;
158  void *CalcSummary(samplePtr buffer, size_t len,
159  sampleFormat format, ArrayOf<char> &cleanup) override;
160  //The on demand type.
161  unsigned int mType;
162 
166 
169 
170  wxAtomicInt mDataAvailable{ 0 };
172 
175 
178 
180  sampleCount mStart;
181 
183  sampleCount mClipOffset;
184 
185  sampleFormat mFormat;
186 
187  sampleCount mAliasStart;//where in the encoded audio file this block corresponds to.
188  const int mAliasChannel;//The channel number in the encoded file..
189 
190 };
191 
192 #endif
193 
unsigned int mType
Definition: ODDecodeBlockFile.h:161
MinMaxRMS GetMinMaxRMS(size_t start, size_t len, bool mayThrow) const override
Gets extreme values for the specified region.
Definition: ODDecodeBlockFile.cpp:105
wxAtomicInt mDataAvailable
Definition: ODDecodeBlockFile.h:170
Creates and manages BlockFile objects.
Definition: DirManager.h:52
sampleCount GetStart() const
Gets the value that indicates where the first sample in this block corresponds to the global sequence...
Definition: ODDecodeBlockFile.h:100
const wxFileName & GetAudioFileName()
Definition: ODDecodeBlockFile.h:132
sampleCount GetGlobalStart() const
Definition: ODDecodeBlockFile.h:103
sampleCount mStart
for reporting after task is complete. Only for display use.
Definition: ODDecodeBlockFile.h:180
class to decode a particular file (one per file). Saves info such as filename and length (after the h...
Definition: ODDecodeTask.h:100
int DoWriteBlockFile()
Definition: ODDecodeBlockFile.h:92
void SetFileName(wxFileNameWrapper &&name) override
sets the file name the summary info will be saved in. threadsafe.
Definition: ODDecodeBlockFile.cpp:372
An AliasBlockFile that references uncompressed data in an existing file.
Definition: ODDecodeBlockFile.h:39
sampleCount GetGlobalEnd() const
Definition: ODDecodeBlockFile.h:106
A BlockFile that reads and writes uncompressed data using libsndfile.
Definition: SimpleBlockFile.h:46
sampleCount GetClipOffset() const
Gets the number of samples the clip associated with this blockfile is offset by.
Definition: ODDecodeBlockFile.h:125
bool IsSummaryAvailable() const override
Returns TRUE if this block's complete summary has been computed and is ready (for OD) ...
Definition: ODDecodeBlockFile.cpp:315
bool IsDataAvailable() const override
Returns TRUE if this block's complete data is ready to be accessed by Read()
Definition: ODDecodeBlockFile.cpp:320
bool IsSummaryBeingComputed() override
Returns TRUE if the summary has not yet been written, but is actively being computed and written to d...
Definition: ODDecodeBlockFile.h:61
bool Read256(float *buffer, size_t start, size_t len) override
Returns the 256 byte summary data block.
Definition: ODDecodeBlockFile.cpp:147
Definition: wxFileNameWrapper.h:16
void SaveXML(XMLWriter &xmlFile) override
Saves as xml ODDecodeBlockFile or SimpleBlockFile depending on summary availability.
Definition: ODDecodeBlockFile.cpp:209
unsigned long long DiskByteCount
Definition: BlockFile.h:152
GetFileNameResult GetFileName() const override
sets the file name the summary info will be saved in. threadsafe.
Definition: ODDecodeBlockFile.cpp:384
const wxFileName & GetEncodedAudioFilename()
Definition: ODDecodeBlockFile.h:145
std::shared_ptr< BlockFile > BlockFilePtr
Definition: BlockFile.h:48
sampleFormat mFormat
Definition: ODDecodeBlockFile.h:185
size_t GetLength() const
Definition: BlockFile.h:114
void ChangeAudioFile(wxFileNameWrapper &&newAudioFile)
Definition: ODDecodeBlockFile.cpp:509
unsigned int GetDecodeType() const
Returns the type of audiofile this blockfile is loaded from.
Definition: ODDecodeBlockFile.h:118
void UnlockRead() const override
Allows reading of encoded file on other threads.
Definition: ODDecodeBlockFile.cpp:501
int format
Definition: ExportPCM.cpp:56
ODFileDecoder * mDecoder
Definition: ODDecodeBlockFile.h:173
void SetClipOffset(sampleCount numSamples)
sets the amount of samples the clip associated with this blockfile is offset in the wavetrack (non ef...
Definition: ODDecodeBlockFile.h:122
void SetStart(sampleCount startSample)
Sets the value that indicates where the first sample in this block corresponds to the global sequence...
Definition: ODDecodeBlockFile.h:97
BlockFilePtr Copy(wxFileNameWrapper &&fileName) override
Makes NEW ODDecodeBlockFile or SimpleBlockFile depending on summary availability. ...
Definition: ODDecodeBlockFile.cpp:179
void SetODFileDecoder(ODFileDecoder *decoder)
set the decoder,
Definition: ODDecodeBlockFile.cpp:484
int WriteODDecodeBlockFile()
Definition: ODDecodeBlockFile.cpp:328
virtual ~ODDecodeBlockFile()
Definition: ODDecodeBlockFile.cpp:83
bool ReadSummary(ArrayOf< char > &data) override
Read the summary into a buffer.
Definition: ODDecodeBlockFile.cpp:472
void Recover(void) override
Writes the summary file if summary data is available.
Definition: ODDecodeBlockFile.cpp:307
bool Read64K(float *buffer, size_t start, size_t len) override
Returns the 64K summary data block.
Definition: ODDecodeBlockFile.cpp:162
bool mDataBeingComputed
Definition: ODDecodeBlockFile.h:171
int min(int a, int b)
Definition: CompareAudioCommand.cpp:80
sampleCount mAliasStart
Definition: ODDecodeBlockFile.h:187
static BlockFilePtr BuildFromXML(DirManager &dm, const wxChar **attrs)
Reconstructs from XML a ODDecodeBlockFile and reschedules it for OD loading.
Definition: ODDecodeBlockFile.cpp:242
ODLock mFileNameMutex
Definition: ODDecodeBlockFile.h:165
const int mAliasChannel
Definition: ODDecodeBlockFile.h:188
Definition: ODTaskThread.h:150
DiskByteCount GetSpaceUsage() const override
Definition: ODDecodeBlockFile.cpp:90
const wxChar * name
Definition: Distortion.cpp:93
void LockRead() const override
Prevents a read on other threads of the encoded audio file.
Definition: ODDecodeBlockFile.cpp:496
ODDecodeBlockFile(wxFileNameWrapper &&baseFileName, wxFileNameWrapper &&audioFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel, unsigned int decodeType)
Create a disk file and write summary and sample data to it.
Definition: ODDecodeBlockFile.cpp:41
wxFileNameWrapper mAudioFileName
The original file the audio came from.
Definition: ODDecodeBlockFile.h:168
void * CalcSummary(samplePtr buffer, size_t len, sampleFormat format, ArrayOf< char > &cleanup) override
Definition: ODDecodeBlockFile.cpp:406
sampleCount mClipOffset
the ODTask needs to know where this blockfile lies in the track, so for convenience, we have this here.
Definition: ODDecodeBlockFile.h:183
ODLock mDecoderMutex
Definition: ODDecodeBlockFile.h:174
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:22
ODLock mReadDataMutex
For accessing the audio file that will be decoded. Used by dir manager;.
Definition: ODDecodeBlockFile.h:177
size_t ReadData(samplePtr data, sampleFormat format, size_t start, size_t len, bool mayThrow) const override
Reads the specified data from the aliased file using libsndfile.
Definition: ODDecodeBlockFile.cpp:448