Audacity  2.2.2
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 
MinMaxRMS GetMinMaxRMS(size_t start, size_t len, bool mayThrow) const override
Gets extreme values for the specified region.
wxAtomicInt mDataAvailable
Creates and manages BlockFile objects.
Definition: DirManager.h:54
sampleCount GetStart() const
Gets the value that indicates where the first sample in this block corresponds to the global sequence...
const wxFileName & GetAudioFileName()
sampleCount GetGlobalStart() const
sampleCount mStart
for reporting after task is complete. Only for display use.
class to decode a particular file (one per file). Saves info such as filename and length (after the h...
Definition: ODDecodeTask.h:100
void SetFileName(wxFileNameWrapper &&name) override
sets the file name the summary info will be saved in. threadsafe.
An AliasBlockFile that references uncompressed data in an existing file.
sampleCount GetGlobalEnd() const
A BlockFile that reads and writes uncompressed data using libsndfile.
sampleCount GetClipOffset() const
Gets the number of samples the clip associated with this blockfile is offset by.
bool IsSummaryAvailable() const override
Returns TRUE if this block's complete summary has been computed and is ready (for OD) ...
bool IsDataAvailable() const override
Returns TRUE if this block's complete data is ready to be accessed by Read()
bool IsSummaryBeingComputed() override
Returns TRUE if the summary has not yet been written, but is actively being computed and written to d...
bool Read256(float *buffer, size_t start, size_t len) override
Returns the 256 byte summary data block.
void SaveXML(XMLWriter &xmlFile) override
Saves as xml ODDecodeBlockFile or SimpleBlockFile depending on summary availability.
unsigned long long DiskByteCount
Definition: BlockFile.h:152
GetFileNameResult GetFileName() const override
sets the file name the summary info will be saved in. threadsafe.
const wxFileName & GetEncodedAudioFilename()
std::shared_ptr< BlockFile > BlockFilePtr
Definition: BlockFile.h:48
size_t GetLength() const
Definition: BlockFile.h:114
void ChangeAudioFile(wxFileNameWrapper &&newAudioFile)
unsigned int GetDecodeType() const
Returns the type of audiofile this blockfile is loaded from.
void UnlockRead() const override
Allows reading of encoded file on other threads.
int format
Definition: ExportPCM.cpp:56
ODFileDecoder * mDecoder
void SetClipOffset(sampleCount numSamples)
sets the amount of samples the clip associated with this blockfile is offset in the wavetrack (non ef...
void SetStart(sampleCount startSample)
Sets the value that indicates where the first sample in this block corresponds to the global sequence...
BlockFilePtr Copy(wxFileNameWrapper &&fileName) override
Makes NEW ODDecodeBlockFile or SimpleBlockFile depending on summary availability. ...
void SetODFileDecoder(ODFileDecoder *decoder)
set the decoder,
bool ReadSummary(ArrayOf< char > &data) override
Read the summary into a buffer.
void Recover(void) override
Writes the summary file if summary data is available.
bool Read64K(float *buffer, size_t start, size_t len) override
Returns the 64K summary data block.
int min(int a, int b)
static BlockFilePtr BuildFromXML(DirManager &dm, const wxChar **attrs)
Reconstructs from XML a ODDecodeBlockFile and reschedules it for OD loading.
DiskByteCount GetSpaceUsage() const override
const wxChar * name
Definition: Distortion.cpp:94
void LockRead() const override
Prevents a read on other threads of the encoded audio file.
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.
wxFileNameWrapper mAudioFileName
The original file the audio came from.
void * CalcSummary(samplePtr buffer, size_t len, sampleFormat format, ArrayOf< char > &cleanup) override
sampleCount mClipOffset
the ODTask needs to know where this blockfile lies in the track, so for convenience, we have this here.
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;.
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.