Audacity  3.0.3
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 <wx/atomic.h> // member variable
32 
33 class ODFileDecoder;
34 
36 class ODDecodeBlockFile final : public SimpleBlockFile
37 {
38  public:
39 
40  // Constructor / Destructor
41 
43  ODDecodeBlockFile(wxFileNameWrapper &&baseFileName, wxFileNameWrapper &&audioFileName, sampleCount aliasStart,
44  size_t aliasLen, int aliasChannel, unsigned int decodeType);
46  ODDecodeBlockFile(wxFileNameWrapper &&existingFile, wxFileNameWrapper &&audioFileName, sampleCount aliasStart,
47  size_t aliasLen, int aliasChannel, unsigned int decodeType,
48  float min, float max, float rms, bool dataAvailable);
49 
50  virtual ~ODDecodeBlockFile();
51  //checks to see if summary data has been computed and written to disk yet. Thread safe. Blocks if we are writing summary data.
52  bool IsSummaryAvailable() const override;
53 
55  bool IsDataAvailable() const override;
56 
58  bool IsSummaryBeingComputed() override { return false; }
59 
60  const wxFileNameWrapper &GetExternalFileName() const override;
61  void SetExternalFileName( wxFileNameWrapper &&newName ) override;
62 
63  //Calls that rely on summary files need to be overridden
64  DiskByteCount GetSpaceUsage() const override;
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
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 overridden 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 
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 
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 
181 
184 
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 
193 class ODFileDecoder /* not final */
194 {
195 public:
197  ODFileDecoder(const wxString& fName);
198  virtual ~ODFileDecoder();
199 
202  virtual bool ReadHeader()=0;
203  virtual bool Init(){return ReadHeader();}
204 
205  virtual bool SeekingAllowed(){return true;}
206 
214  virtual int Decode(SampleBuffer & data, sampleFormat & format, sampleCount start, size_t len, unsigned int channel) = 0;
215 
216  const wxString &GetFileName(){return mFName;}
217 
218  bool IsInitialized();
219 
220 protected:
222  void MarkInitialized();
223 
224  bool mInited;
226 
227  const wxString mFName;
228 
229  unsigned int mSampleRate;
230  unsigned int mNumSamples;//this may depend on the channel - so TODO: we should probably let the decoder create/modify the track info directly.
231  unsigned int mNumChannels;
232 };
233 
234 #endif
235 
XMLWriter
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:23
ODDecodeBlockFile::SetFileName
void SetFileName(wxFileNameWrapper &&name) override
sets the file name the summary info will be saved in. threadsafe.
Definition: ODDecodeBlockFile.cpp:372
ODDecodeBlockFile::~ODDecodeBlockFile
virtual ~ODDecodeBlockFile()
Definition: ODDecodeBlockFile.cpp:83
wxFileNameWrapper
Definition: wxFileNameWrapper.h:21
ODDecodeBlockFile::UnlockRead
void UnlockRead() const override
Allows reading of encoded file on other threads.
Definition: ODDecodeBlockFile.cpp:501
ODDecodeBlockFile::CalcSummary
void * CalcSummary(samplePtr buffer, size_t len, sampleFormat format, ArrayOf< char > &cleanup) override
Definition: ODDecodeBlockFile.cpp:406
ODFileDecoder::SeekingAllowed
virtual bool SeekingAllowed()
Definition: ODDecodeBlockFile.h:205
ODFileDecoder::mInited
bool mInited
Definition: ODDecodeBlockFile.h:224
ODDecodeBlockFile::SetExternalFileName
void SetExternalFileName(wxFileNameWrapper &&newName) override
Definition: ODDecodeBlockFile.cpp:513
ODFileDecoder::Init
virtual bool Init()
Definition: ODDecodeBlockFile.h:203
ODFileDecoder::GetFileName
const wxString & GetFileName()
Definition: ODDecodeBlockFile.h:216
ODFileDecoder::mSampleRate
unsigned int mSampleRate
Definition: ODDecodeBlockFile.h:229
ODDecodeBlockFile
An AliasBlockFile that references uncompressed data in an existing file.
Definition: ODDecodeBlockFile.h:37
ODDecodeBlockFile::GetEncodedAudioFilename
const wxFileNameWrapper & GetEncodedAudioFilename() const
Definition: ODDecodeBlockFile.h:145
ODDecodeBlockFile::SetStart
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
MinMaxRMS
Definition: SampleBlock.h:32
ODDecodeBlockFile::GetFileName
GetFileNameResult GetFileName() const override
sets the file name the summary info will be saved in. threadsafe.
Definition: ODDecodeBlockFile.cpp:384
ODDecodeBlockFile::GetGlobalStart
sampleCount GetGlobalStart() const
Definition: ODDecodeBlockFile.h:103
ODDecodeBlockFile::mFileNameMutex
ODLock mFileNameMutex
Definition: ODDecodeBlockFile.h:165
ODDecodeBlockFile::mAliasStart
sampleCount mAliasStart
Definition: ODDecodeBlockFile.h:187
ODDecodeBlockFile::mAudioFileName
wxFileNameWrapper mAudioFileName
The original file the audio came from.
Definition: ODDecodeBlockFile.h:168
ODDecodeBlockFile::Read64K
bool Read64K(float *buffer, size_t start, size_t len) override
Returns the 64K summary data block.
Definition: ODDecodeBlockFile.cpp:162
ODDecodeBlockFile::SetClipOffset
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
ODDecodeBlockFile::mDataAvailable
wxAtomicInt mDataAvailable
Definition: ODDecodeBlockFile.h:170
ODDecodeBlockFile::mClipOffset
sampleCount mClipOffset
the ODTask needs to know where this blockfile lies in the track, so for convenience,...
Definition: ODDecodeBlockFile.h:183
ODFileDecoder::MarkInitialized
void MarkInitialized()
Derived classes should call this after they have parsed the header.
Definition: ODDecodeBlockFile.cpp:558
ODFileDecoder::IsInitialized
bool IsInitialized()
Definition: ODDecodeBlockFile.cpp:548
ODDecodeBlockFile::GetSpaceUsage
DiskByteCount GetSpaceUsage() const override
Definition: ODDecodeBlockFile.cpp:90
ODDecodeBlockFile::mAliasChannel
const int mAliasChannel
Definition: ODDecodeBlockFile.h:188
SimpleBlockFile
A BlockFile that reads and writes uncompressed data using libsndfile.
Definition: SimpleBlockFile.h:34
ODDecodeBlockFile::mType
unsigned int mType
Definition: ODDecodeBlockFile.h:161
ODDecodeBlockFile::mDataBeingComputed
bool mDataBeingComputed
Definition: ODDecodeBlockFile.h:171
ODDecodeBlockFile::LockRead
void LockRead() const override
Prevents a read on other threads of the encoded audio file.
Definition: ODDecodeBlockFile.cpp:496
ODDecodeBlockFile::mDecoderMutex
ODLock mDecoderMutex
Definition: ODDecodeBlockFile.h:174
ODDecodeBlockFile::GetDecodeType
unsigned int GetDecodeType() const
Returns the type of audiofile this blockfile is loaded from.
Definition: ODDecodeBlockFile.h:118
ODDecodeBlockFile::BuildFromXML
static BlockFilePtr BuildFromXML(DirManager &dm, const wxChar **attrs)
Reconstructs from XML a ODDecodeBlockFile and reschedules it for OD loading.
Definition: ODDecodeBlockFile.cpp:242
ODFileDecoder::mNumChannels
unsigned int mNumChannels
Definition: ODDecodeBlockFile.h:231
ODDecodeBlockFile::GetMinMaxRMS
MinMaxRMS GetMinMaxRMS(size_t start, size_t len, bool mayThrow) const override
Gets extreme values for the specified region.
Definition: ODDecodeBlockFile.cpp:105
ODDecodeBlockFile::mReadDataMutex
ODLock mReadDataMutex
For accessing the audio file that will be decoded. Used by dir manager;.
Definition: ODDecodeBlockFile.h:177
name
const TranslatableString name
Definition: Distortion.cpp:98
ODFileDecoder::ODFileDecoder
ODFileDecoder(const wxString &fName)
This should handle unicode converted to UTF-8 on mac/linux, but OD TODO:check on windows.
Definition: ODDecodeBlockFile.cpp:538
format
int format
Definition: ExportPCM.cpp:56
ODFileDecoder::Decode
virtual int Decode(SampleBuffer &data, sampleFormat &format, sampleCount start, size_t len, unsigned int channel)=0
ODFileDecoder::~ODFileDecoder
virtual ~ODFileDecoder()
Definition: ODDecodeBlockFile.cpp:544
ODDecodeBlockFile::GetGlobalEnd
sampleCount GetGlobalEnd() const
Definition: ODDecodeBlockFile.h:106
ODDecodeBlockFile::ChangeAudioFile
void ChangeAudioFile(wxFileNameWrapper &&newAudioFile)
Definition: ODDecodeBlockFile.cpp:521
ODDecodeBlockFile::ODDecodeBlockFile
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
ODFileDecoder::mInitedLock
ODLock mInitedLock
Definition: ODDecodeBlockFile.h:225
ODDecodeBlockFile::IsSummaryAvailable
bool IsSummaryAvailable() const override
Definition: ODDecodeBlockFile.cpp:315
SimpleBlockFile.h
ODDecodeBlockFile::GetStart
sampleCount GetStart() const
Gets the value that indicates where the first sample in this block corresponds to the global sequence...
Definition: ODDecodeBlockFile.h:100
SampleBuffer
Definition: SampleFormat.h:69
ODDecodeBlockFile::IsDataAvailable
bool IsDataAvailable() const override
Returns TRUE if this block's complete data is ready to be accessed by Read()
Definition: ODDecodeBlockFile.cpp:320
ODDecodeBlockFile::DoWriteBlockFile
int DoWriteBlockFile()
Definition: ODDecodeBlockFile.h:92
sampleFormat
sampleFormat
Definition: SampleFormat.h:29
samplePtr
char * samplePtr
Definition: SampleFormat.h:49
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
ODLock
Definition: ODTaskThread.h:89
ODFileDecoder
class to decode a particular file (one per file). Saves info such as filename and length (after the h...
Definition: ODDecodeBlockFile.h:194
ODDecodeBlockFile::ReadSummary
bool ReadSummary(ArrayOf< char > &data) override
Read the summary into a buffer.
Definition: ODDecodeBlockFile.cpp:472
ODDecodeBlockFile::mStart
sampleCount mStart
for reporting after task is complete. Only for display use.
Definition: ODDecodeBlockFile.h:180
sampleCount
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:18
ODDecodeBlockFile::SaveXML
void SaveXML(XMLWriter &xmlFile) override
Saves as xml ODDecodeBlockFile or SimpleBlockFile depending on summary availability.
Definition: ODDecodeBlockFile.cpp:209
ODFileDecoder::ReadHeader
virtual bool ReadHeader()=0
ODDecodeBlockFile::Read256
bool Read256(float *buffer, size_t start, size_t len) override
Returns the 256 byte summary data block.
Definition: ODDecodeBlockFile.cpp:147
ODDecodeBlockFile::ReadData
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
ODDecodeBlockFile::GetAudioFileName
const wxFileName & GetAudioFileName()
Definition: ODDecodeBlockFile.h:132
ODDecodeBlockFile::Copy
BlockFilePtr Copy(wxFileNameWrapper &&fileName) override
Makes NEW ODDecodeBlockFile or SimpleBlockFile depending on summary availability.
Definition: ODDecodeBlockFile.cpp:179
ODDecodeBlockFile::SetODFileDecoder
void SetODFileDecoder(ODFileDecoder *decoder)
set the decoder,
Definition: ODDecodeBlockFile.cpp:484
ODFileDecoder::mFName
const wxString mFName
Definition: ODDecodeBlockFile.h:227
ODDecodeBlockFile::Recover
void Recover(void) override
Writes the summary file if summary data is available.
Definition: ODDecodeBlockFile.cpp:307
ODDecodeBlockFile::mDecoder
ODFileDecoder * mDecoder
Definition: ODDecodeBlockFile.h:173
ODDecodeBlockFile::IsSummaryBeingComputed
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:58
ODDecodeBlockFile::GetClipOffset
sampleCount GetClipOffset() const
Gets the number of samples the clip associated with this blockfile is offset by.
Definition: ODDecodeBlockFile.h:125
ArrayOf< char >
ODFileDecoder::mNumSamples
unsigned int mNumSamples
Definition: ODDecodeBlockFile.h:230
ODDecodeBlockFile::GetExternalFileName
const wxFileNameWrapper & GetExternalFileName() const override
Definition: ODDecodeBlockFile.cpp:506
ODDecodeBlockFile::WriteODDecodeBlockFile
int WriteODDecodeBlockFile()
Definition: ODDecodeBlockFile.cpp:328
ODDecodeBlockFile::mFormat
sampleFormat mFormat
Definition: ODDecodeBlockFile.h:185