Audacity  2.2.2
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ODDecodeBlockFile Class Referencefinal

An AliasBlockFile that references uncompressed data in an existing file. More...

#include <ODDecodeBlockFile.h>

Inheritance diagram for ODDecodeBlockFile:
SimpleBlockFile BlockFile

Public Member Functions

 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. More...
 
 ODDecodeBlockFile (wxFileNameWrapper &&existingFile, wxFileNameWrapper &&audioFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel, unsigned int decodeType, float min, float max, float rms, bool dataAvailable)
 Create the memory structure to refer to the given block file. More...
 
virtual ~ODDecodeBlockFile ()
 
bool IsSummaryAvailable () const override
 Returns TRUE if this block's complete summary has been computed and is ready (for OD) More...
 
bool IsDataAvailable () const override
 Returns TRUE if this block's complete data is ready to be accessed by Read() More...
 
bool IsSummaryBeingComputed () override
 Returns TRUE if the summary has not yet been written, but is actively being computed and written to disk. More...
 
DiskByteCount GetSpaceUsage () const override
 
MinMaxRMS GetMinMaxRMS (size_t start, size_t len, bool mayThrow) const override
 Gets extreme values for the specified region. More...
 
MinMaxRMS GetMinMaxRMS (bool mayThrow) const override
 Gets extreme values for the entire block. More...
 
bool Read256 (float *buffer, size_t start, size_t len) override
 Returns the 256 byte summary data block. More...
 
bool Read64K (float *buffer, size_t start, size_t len) override
 Returns the 64K summary data block. More...
 
BlockFilePtr Copy (wxFileNameWrapper &&fileName) override
 Makes NEW ODDecodeBlockFile or SimpleBlockFile depending on summary availability. More...
 
void SaveXML (XMLWriter &xmlFile) override
 Saves as xml ODDecodeBlockFile or SimpleBlockFile depending on summary availability. More...
 
void Recover (void) override
 Writes the summary file if summary data is available. More...
 
int DoWriteBlockFile ()
 
int WriteODDecodeBlockFile ()
 
void SetStart (sampleCount startSample)
 Sets the value that indicates where the first sample in this block corresponds to the global sequence/clip. Only for display use. More...
 
sampleCount GetStart () const
 Gets the value that indicates where the first sample in this block corresponds to the global sequence/clip. Only for display use. More...
 
sampleCount GetGlobalStart () const
 
sampleCount GetGlobalEnd () const
 
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. More...
 
bool ReadSummary (ArrayOf< char > &data) override
 Read the summary into a buffer. More...
 
unsigned int GetDecodeType () const
 Returns the type of audiofile this blockfile is loaded from. More...
 
void SetClipOffset (sampleCount numSamples)
 sets the amount of samples the clip associated with this blockfile is offset in the wavetrack (non effecting) More...
 
sampleCount GetClipOffset () const
 Gets the number of samples the clip associated with this blockfile is offset by. More...
 
void SetODFileDecoder (ODFileDecoder *decoder)
 set the decoder, More...
 
const wxFileName & GetAudioFileName ()
 
void SetFileName (wxFileNameWrapper &&name) override
 sets the file name the summary info will be saved in. threadsafe. More...
 
GetFileNameResult GetFileName () const override
 sets the file name the summary info will be saved in. threadsafe. More...
 
void LockRead () const override
 Prevents a read on other threads of the encoded audio file. More...
 
void UnlockRead () const override
 Allows reading of encoded file on other threads. More...
 
const wxFileName & GetEncodedAudioFilename ()
 
void ChangeAudioFile (wxFileNameWrapper &&newAudioFile)
 
- Public Member Functions inherited from SimpleBlockFile
 SimpleBlockFile (wxFileNameWrapper &&baseFileName, samplePtr sampleData, size_t sampleLen, sampleFormat format, bool allowDeferredWrite=false, bool bypassCache=false)
 Create a disk file and write summary and sample data to it. More...
 
 SimpleBlockFile (wxFileNameWrapper &&existingFile, size_t len, float min, float max, float rms)
 Create the memory structure to refer to the given block file. More...
 
virtual ~SimpleBlockFile ()
 
bool ReadSummary (ArrayOf< char > &data) override
 Read the summary section of the disk file. More...
 
size_t ReadData (samplePtr data, sampleFormat format, size_t start, size_t len, bool mayThrow) const override
 Read the data section of the disk file. More...
 
BlockFilePtr Copy (wxFileNameWrapper &&newFileName) override
 Create a NEW block file identical to this one. More...
 
void SaveXML (XMLWriter &xmlFile) override
 Write an XML representation of this file. More...
 
DiskByteCount GetSpaceUsage () const override
 
void Recover () override
 if the on-disk state disappeared, either recover it (if it was More...
 
bool GetNeedWriteCacheToDisk () override
 
void WriteCacheToDisk () override
 
bool GetNeedFillCache () override
 
void FillCache () override
 
- Public Member Functions inherited from BlockFile
 BlockFile (wxFileNameWrapper &&fileName, size_t samples)
 Construct a BlockFile. More...
 
virtual ~BlockFile ()
 
size_t GetLength () const
 
void SetLength (size_t newLen)
 
virtual void Lock ()
 Locks this BlockFile, to prevent it from being moved. More...
 
virtual void Unlock ()
 Unlock this BlockFile, allowing it to be moved. More...
 
virtual bool IsLocked ()
 Returns TRUE if this BlockFile is locked. More...
 
virtual bool IsAlias () const
 Returns TRUE if this block references another disk file. More...
 
void SilenceLog () const
 if we've detected an on-disk problem, the user opted to More...
 
virtual void CloseLock ()
 
ReadLock LockForRead () const
 

Static Public Member Functions

static BlockFilePtr BuildFromXML (DirManager &dm, const wxChar **attrs)
 Reconstructs from XML a ODDecodeBlockFile and reschedules it for OD loading. More...
 
- Static Public Member Functions inherited from SimpleBlockFile
static BlockFilePtr BuildFromXML (DirManager &dm, const wxChar **attrs)
 static More...
 

Protected Member Functions

void * CalcSummary (samplePtr buffer, size_t len, sampleFormat format, ArrayOf< char > &cleanup) override
 
- Protected Member Functions inherited from SimpleBlockFile
bool WriteSimpleBlockFile (samplePtr sampleData, size_t sampleLen, sampleFormat format, void *summaryData)
 
void ReadIntoCache ()
 
- Protected Member Functions inherited from BlockFile
void CalcSummaryFromBuffer (const float *fbuffer, size_t len, float *summary256, float *summary64K)
 
virtual void FixSummary (void *data)
 

Protected Attributes

unsigned int mType
 
ODLock mFileNameMutex
 
wxFileNameWrapper mAudioFileName
 The original file the audio came from. More...
 
wxAtomicInt mDataAvailable { 0 }
 
bool mDataBeingComputed
 
ODFileDecodermDecoder
 
ODLock mDecoderMutex
 
ODLock mReadDataMutex
 For accessing the audio file that will be decoded. Used by dir manager;. More...
 
sampleCount mStart
 for reporting after task is complete. Only for display use. More...
 
sampleCount mClipOffset
 the ODTask needs to know where this blockfile lies in the track, so for convenience, we have this here. More...
 
sampleFormat mFormat
 
sampleCount mAliasStart
 
const int mAliasChannel
 
- Protected Attributes inherited from SimpleBlockFile
SimpleBlockFileCache mCache
 
- Protected Attributes inherited from BlockFile
wxFileNameWrapper mFileName
 
size_t mLen
 
SummaryInfo mSummaryInfo
 
float mMin
 
float mMax
 
float mRMS
 
bool mSilentLog
 

Additional Inherited Members

- Public Types inherited from BlockFile
using DiskByteCount = unsigned long long
 
- Static Public Attributes inherited from BlockFile
static unsigned long gBlockFileDestructionCount { 0 }
 
- Protected Types inherited from BlockFile
using ReadLockBase = std::unique_ptr< const BlockFile, ReadUnlocker >
 
- Static Protected Member Functions inherited from SimpleBlockFile
static bool GetCache ()
 
- Static Protected Member Functions inherited from BlockFile
static size_t CommonReadData (bool mayThrow, const wxFileName &fileName, bool &mSilentLog, const AliasBlockFile *pAliasFile, sampleCount origin, unsigned channel, samplePtr data, sampleFormat format, size_t start, size_t len, const sampleFormat *pLegacyFormat=nullptr, size_t legacyLen=0)
 

Detailed Description

An AliasBlockFile that references uncompressed data in an existing file.

ODDecodeBlockFile is a special type of SimpleBlockFile that does not necessarily have summary OR audio data available The summary and audio is eventually computed and written to a file in a background thread.

ODDecodeBlockFile is a special type of SimpleBlockFile that does not necessarily have summary OR audio data available The summary is eventually computed and written to a file in a background thread. See ODPCMAliasBlockFile for a similar class.

Load On-Demand implementation of the SimpleBlockFile for audio files that need to be decoded (mp3,flac,etc..).

Also, see ODPCMAliasBlockFile for a similar file.

Definition at line 39 of file ODDecodeBlockFile.h.

Constructor & Destructor Documentation

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 at line 41 of file ODDecodeBlockFile.cpp.

References floatSample.

44  : SimpleBlockFile{ std::move(baseFileName),
45  NULL, aliasLen, floatSample, true, true },
46  //floatSample has no effect. last two bools - bypass writing of blockfile and cache
47 
48  mType(decodeType),
49  mAliasStart(aliasStart),
50  mAliasChannel(aliasChannel)
51 {
52  mDecoder = NULL;
53  mAudioFileName = std::move(audioFileName);
55 }
56 catch ( const FileException & WXUNUSED(e) )
57 {
58  // The constructor SimpleBlockFile sometimes throws this,
59  // but it never will for the arguments that were passed to it here.
60  // So add a catch for completeness, but just assert that this won't happen.
61  wxASSERT(false);
62  throw;
63 }
A BlockFile that reads and writes uncompressed data using libsndfile.
ODFileDecoder * mDecoder
wxFileNameWrapper mAudioFileName
The original file the audio came from.
ODDecodeBlockFile::ODDecodeBlockFile ( wxFileNameWrapper &&  existingFile,
wxFileNameWrapper &&  audioFileName,
sampleCount  aliasStart,
size_t  aliasLen,
int  aliasChannel,
unsigned int  decodeType,
float  min,
float  max,
float  rms,
bool  dataAvailable 
)

Create the memory structure to refer to the given block file.

Definition at line 66 of file ODDecodeBlockFile.cpp.

References min().

68  :
69  SimpleBlockFile{ std::move(existingFile), aliasLen, min, max, rms },
70 
71  mType(decodeType),
72  mDataAvailable( dataAvailable ),
73  mAliasStart(aliasStart),
74  mAliasChannel(aliasChannel)
75 {
76  mDecoder = NULL;
77  mAudioFileName = std::move(audioFileName);
79 }
wxAtomicInt mDataAvailable
A BlockFile that reads and writes uncompressed data using libsndfile.
ODFileDecoder * mDecoder
int min(int a, int b)
wxFileNameWrapper mAudioFileName
The original file the audio came from.
ODDecodeBlockFile::~ODDecodeBlockFile ( )
virtual

Definition at line 83 of file ODDecodeBlockFile.cpp.

84 {
85 
86 }

Member Function Documentation

BlockFilePtr ODDecodeBlockFile::BuildFromXML ( DirManager dm,
const wxChar **  attrs 
)
static

Reconstructs from XML a ODDecodeBlockFile and reschedules it for OD loading.

Constructs a ODDecodeBlockFile from the xml output of WriteXML. Also schedules the ODDecodeBlockFile for OD loading.

Definition at line 242 of file ODDecodeBlockFile.cpp.

References DirManager::AssignFile(), DirManager::GetProjectDataDir(), XMLValueChecker::IsGoodFileName(), XMLValueChecker::IsGoodFileString(), XMLValueChecker::IsGoodInt(), XMLValueChecker::IsGoodInt64(), XMLValueChecker::IsGoodPathName(), XMLValueChecker::IsGoodPathString(), XMLValueChecker::IsValidChannel(), and PLATFORM_MAX_PATH.

Referenced by DirManager::HandleXMLTag().

243 {
244  wxFileNameWrapper summaryFileName;
245  wxFileNameWrapper audioFileName;
246  sampleCount aliasStart = 0;
247  size_t aliasLen = 0;
248  int aliasChannel=0;
249  long nValue;
250  long long nnValue;
251  unsigned int decodeType=0;
252 
253  while(*attrs)
254  {
255  const wxChar *attr = *attrs++;
256  const wxChar *value = *attrs++;
257  if (!value)
258  break;
259 
260  const wxString strValue = value;
261  if (!wxStricmp(attr, wxT("summaryfile")) &&
262  // Can't use XMLValueChecker::IsGoodFileName here, but do part of its test.
264  (strValue.Length() + 1 + dm.GetProjectDataDir().Length() <= PLATFORM_MAX_PATH))
265  {
266  if (!dm.AssignFile(summaryFileName, strValue, false))
267  // Make sure summaryFileName is back to uninitialized state so we can detect problem later.
268  summaryFileName.Clear();
269  }
270  else if( !wxStricmp(attr, wxT("audiofile")) )
271  {
272  if (XMLValueChecker::IsGoodPathName(strValue))
273  audioFileName.Assign(strValue);
274  else if (XMLValueChecker::IsGoodFileName(strValue, dm.GetProjectDataDir()))
275  // Allow fallback of looking for the file name, located in the data directory.
276  audioFileName.Assign(dm.GetProjectDataDir(), strValue);
277  else if (XMLValueChecker::IsGoodPathString(strValue))
278  // If the file is missing, we failed XMLValueChecker::IsGoodPathName()
279  // and XMLValueChecker::IsGoodFileName, because both do existence tests,
280  // but we want to keep the reference to the file because it's a good path string.
281  audioFileName.Assign(strValue);
282  }
283  else if ( !wxStricmp(attr, wxT("aliasstart")) )
284  {
285  if (XMLValueChecker::IsGoodInt64(strValue) &&
286  strValue.ToLongLong(&nnValue) && (nnValue >= 0))
287  aliasStart = nnValue;
288  }
289  else if (XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
290  { // integer parameters
291  if (!wxStricmp(attr, wxT("aliaslen")) && (nValue >= 0))
292  aliasLen = nValue;
293  else if (!wxStricmp(attr, wxT("aliaschannel")) && XMLValueChecker::IsValidChannel(aliasChannel))
294  aliasChannel = nValue;
295  else if( !wxStricmp(attr, wxT("decodetype")) )
296  decodeType = nValue;
297  }
298  }
299 
300  return make_blockfile<ODDecodeBlockFile>
301  (std::move(summaryFileName), std::move(audioFileName),
302  aliasStart, aliasLen, aliasChannel, decodeType, 0, 0, 0, false);
303 }
static bool IsValidChannel(const int nValue)
static bool IsGoodInt64(const wxString &strInt)
Check that the supplied string can be converted to a 64bit integer.
static bool IsGoodPathName(const wxString &strPathName)
static bool IsGoodPathString(const wxString &str)
static bool IsGoodInt(const wxString &strInt)
Check that the supplied string can be converted to a long (32bit) integer.
#define PLATFORM_MAX_PATH
Definition: Audacity.h:118
wxString GetProjectDataDir()
Definition: DirManager.cpp:679
static bool IsGoodFileString(const wxString &str)
static bool IsGoodFileName(const wxString &strFileName, const wxString &strDirName=wxEmptyString)
bool AssignFile(wxFileNameWrapper &filename, const wxString &value, bool check)
Definition: DirManager.cpp:752
void * ODDecodeBlockFile::CalcSummary ( samplePtr  buffer,
size_t  len,
sampleFormat  format,
ArrayOf< char > &  cleanup 
)
overrideprotectedvirtual

A thread-safe version of CalcSummary. BlockFile::CalcSummary uses a static summary array across the class, which we can't use. Get a buffer containing a summary block describing this sample data. This must be called by derived classes when they are constructed, to allow them to construct their summary data, after which they should write that data to their disk file.

This method also has the side effect of setting the mMin, mMax, and mRMS members of this class.

Unlike BlockFile's implementation You SHOULD DELETE the returned buffer. this is protected so it shouldn't be hard to deal with - just override all BlockFile methods that use this method.

Parameters
bufferA buffer containing the sample data to be analyzed
lenThe length of the sample data
formatThe format of the sample data.

Reimplemented from BlockFile.

Definition at line 406 of file ODDecodeBlockFile.cpp.

References bheaderTag, bheaderTagLen, BlockFile::CalcSummaryFromBuffer(), CopySamples(), floatSample, BlockFile::mSummaryInfo, SummaryInfo::offset256, SummaryInfo::offset64K, ArrayOf< X >::reinit(), and SummaryInfo::totalSummaryBytes.

408 {
410  char* localFullSummary = cleanup.get();
411 
412  memcpy(localFullSummary, bheaderTag, bheaderTagLen);
413 
414  float *summary64K = (float *)(localFullSummary + mSummaryInfo.offset64K);
415  float *summary256 = (float *)(localFullSummary + mSummaryInfo.offset256);
416 
417  Floats floats;
418  float *fbuffer;
419 
420  //mchinen: think we can hack this - don't allocate and copy if we don't need to.,
421  if(format==floatSample)
422  {
423  fbuffer = (float*)buffer;
424  }
425  else
426  {
427  floats.reinit(len);
428  fbuffer = floats.get();
429  CopySamples(buffer, format,
430  (samplePtr)fbuffer, floatSample, len);
431  }
432 
433  BlockFile::CalcSummaryFromBuffer(fbuffer, len, summary256, summary64K);
434 
435  return localFullSummary;
436 }
char bheaderTag[bheaderTagLen+1]
void CalcSummaryFromBuffer(const float *fbuffer, size_t len, float *summary256, float *summary64K)
Definition: BlockFile.cpp:203
void reinit(Integral count, bool initialize=false)
Definition: MemoryX.h:117
int offset64K
Definition: BlockFile.h:38
void CopySamples(samplePtr src, sampleFormat srcFormat, samplePtr dst, sampleFormat dstFormat, unsigned int len, bool highQuality, unsigned int srcStride, unsigned int dstStride)
SummaryInfo mSummaryInfo
Definition: BlockFile.h:237
const int bheaderTagLen
int format
Definition: ExportPCM.cpp:56
char * samplePtr
Definition: Types.h:203
size_t totalSummaryBytes
Definition: BlockFile.h:41
int offset256
Definition: BlockFile.h:40
void ODDecodeBlockFile::ChangeAudioFile ( wxFileNameWrapper &&  newAudioFile)

Modify this block to point at a different file. This is generally looked down on, but it is necessary in one case: see DirManager::EnsureSafeFilename().

Definition at line 509 of file ODDecodeBlockFile.cpp.

References mAudioFileName.

Referenced by DirManager::EnsureSafeFilename().

510 {
511  mAudioFileName = std::move(newAudioFile);
512 }
wxFileNameWrapper mAudioFileName
The original file the audio came from.
BlockFilePtr ODDecodeBlockFile::Copy ( wxFileNameWrapper &&  newFileName)
overridevirtual

Makes NEW ODDecodeBlockFile or SimpleBlockFile depending on summary availability.

returns true before decoding is complete, because it is linked to the encoded file until then. returns false afterwards.

If the summary has been computed, Construct a NEW SimpleBlockFile based on this one. otherwise construct an ODDecodeBlockFile that still needs to be computed.

Parameters
newFileNameThe filename to copy the summary data to.

Implements BlockFile.

Definition at line 179 of file ODDecodeBlockFile.cpp.

References SimpleBlockFile::Copy(), IsSummaryAvailable(), BlockFile::LockForRead(), mAliasChannel, mAliasStart, mAudioFileName, BlockFile::mLen, BlockFile::mMax, BlockFile::mMin, BlockFile::mRMS, and mType.

180 {
181  BlockFilePtr newBlockFile;
182 
183  //mAliasedFile can change so we lock readdatamutex, which is responsible for it.
184  auto locker = LockForRead();
185  if(IsSummaryAvailable())
186  {
187  //create a simpleblockfile, because once it has the summary it is a simpleblockfile for all intents an purposes
188  newBlockFile = SimpleBlockFile::Copy(std::move(newFileName)) ;
189  }
190  else
191  {
192  //Summary File might exist in this case, but it probably (99.999% of the time) won't.
193  newBlockFile = make_blockfile<ODDecodeBlockFile>
194  (std::move(newFileName), wxFileNameWrapper{mAudioFileName},
197  //The client code will need to schedule this blockfile for OD decoding if it is going to a NEW track.
198  //It can do this by checking for IsDataAvailable()==false.
199  }
200 
201  return newBlockFile;
202 }
ReadLock LockForRead() const
Definition: BlockFile.h:200
bool IsSummaryAvailable() const override
Returns TRUE if this block's complete summary has been computed and is ready (for OD) ...
BlockFilePtr Copy(wxFileNameWrapper &&newFileName) override
Create a NEW block file identical to this one.
float mMin
Definition: BlockFile.h:238
std::shared_ptr< BlockFile > BlockFilePtr
Definition: BlockFile.h:48
float mRMS
Definition: BlockFile.h:238
size_t mLen
Definition: BlockFile.h:236
wxFileNameWrapper mAudioFileName
The original file the audio came from.
float mMax
Definition: BlockFile.h:238
int ODDecodeBlockFile::DoWriteBlockFile ( )
inline

Definition at line 92 of file ODDecodeBlockFile.h.

References WriteODDecodeBlockFile().

92 {return WriteODDecodeBlockFile();}
const wxFileName& ODDecodeBlockFile::GetAudioFileName ( )
inline

Definition at line 132 of file ODDecodeBlockFile.h.

References mAudioFileName.

Referenced by ODDecodeTask::GetOrCreateMatchingFileDecoder().

132 {return mAudioFileName;}
wxFileNameWrapper mAudioFileName
The original file the audio came from.
sampleCount ODDecodeBlockFile::GetClipOffset ( ) const
inline

Gets the number of samples the clip associated with this blockfile is offset by.

Definition at line 125 of file ODDecodeBlockFile.h.

References mClipOffset.

125 {return mClipOffset;}
sampleCount mClipOffset
the ODTask needs to know where this blockfile lies in the track, so for convenience, we have this here.
unsigned int ODDecodeBlockFile::GetDecodeType ( ) const
inline

Returns the type of audiofile this blockfile is loaded from.

Definition at line 118 of file ODDecodeBlockFile.h.

References mType.

Referenced by ODDecodeTask::GetOrCreateMatchingFileDecoder().

118 { return mType; }
const wxFileName& ODDecodeBlockFile::GetEncodedAudioFilename ( )
inline

Get the name of the file where the audio data for this block is stored.

Definition at line 145 of file ODDecodeBlockFile.h.

References mAudioFileName.

146  {
147  return mAudioFileName;
148  }
wxFileNameWrapper mAudioFileName
The original file the audio came from.
auto ODDecodeBlockFile::GetFileName ( ) const
overridevirtual

sets the file name the summary info will be saved in. threadsafe.

Reimplemented from BlockFile.

Definition at line 384 of file ODDecodeBlockFile.cpp.

References BlockFile::mFileName, and mFileNameMutex.

385 {
386  return { mFileName, ODLocker{ &mFileNameMutex } };
387 }
wxFileNameWrapper mFileName
Definition: BlockFile.h:235
sampleCount ODDecodeBlockFile::GetGlobalEnd ( ) const
inline

Definition at line 106 of file ODDecodeBlockFile.h.

References BlockFile::GetLength(), mClipOffset, and mStart.

106 {return mClipOffset+mStart+GetLength();}
sampleCount mStart
for reporting after task is complete. Only for display use.
size_t GetLength() const
Definition: BlockFile.h:114
sampleCount mClipOffset
the ODTask needs to know where this blockfile lies in the track, so for convenience, we have this here.
sampleCount ODDecodeBlockFile::GetGlobalStart ( ) const
inline

Definition at line 103 of file ODDecodeBlockFile.h.

References mClipOffset, and mStart.

103 {return mClipOffset+mStart;}
sampleCount mStart
for reporting after task is complete. Only for display use.
sampleCount mClipOffset
the ODTask needs to know where this blockfile lies in the track, so for convenience, we have this here.
auto ODDecodeBlockFile::GetMinMaxRMS ( size_t  start,
size_t  len,
bool  mayThrow 
) const
overridevirtual

Gets extreme values for the specified region.

Reimplemented from BlockFile.

Definition at line 105 of file ODDecodeBlockFile.cpp.

References BlockFile::GetMinMaxRMS().

107 {
108  if(IsSummaryAvailable())
109  {
110  return SimpleBlockFile::GetMinMaxRMS(start, len, mayThrow);
111  }
112  else
113  {
114  if (mayThrow)
116 
117  //fake values. These values are used usually for normalization and amplifying, so we want
118  //the max to be maximal and the min to be minimal
119  return {
120  -1.0f, 1.0f, 0.707f //sin with amp of 1 rms
121  };
122  }
123 }
bool IsSummaryAvailable() const override
Returns TRUE if this block's complete summary has been computed and is ready (for OD) ...
virtual MinMaxRMS GetMinMaxRMS(size_t start, size_t len, bool mayThrow=true) const
Gets extreme values for the specified region.
Definition: BlockFile.cpp:369
wxFileNameWrapper mAudioFileName
The original file the audio came from.
auto ODDecodeBlockFile::GetMinMaxRMS ( bool  mayThrow) const
overridevirtual

Gets extreme values for the entire block.

Reimplemented from BlockFile.

Definition at line 126 of file ODDecodeBlockFile.cpp.

References BlockFile::GetMinMaxRMS().

127 {
128  if(IsSummaryAvailable())
129  {
130  return SimpleBlockFile::GetMinMaxRMS(mayThrow);
131  }
132  else
133  {
134  if (mayThrow)
136 
137  //fake values. These values are used usually for normalization and amplifying, so we want
138  //the max to be maximal and the min to be minimal
139  return {
140  -1.0f, 1.0f, 0.707f //sin with amp of 1 rms
141  };
142  }
143 }
bool IsSummaryAvailable() const override
Returns TRUE if this block's complete summary has been computed and is ready (for OD) ...
virtual MinMaxRMS GetMinMaxRMS(size_t start, size_t len, bool mayThrow=true) const
Gets extreme values for the specified region.
Definition: BlockFile.cpp:369
wxFileNameWrapper mAudioFileName
The original file the audio came from.
auto ODDecodeBlockFile::GetSpaceUsage ( ) const
overridevirtual

Implements BlockFile.

Definition at line 90 of file ODDecodeBlockFile.cpp.

References IsSummaryAvailable(), and BlockFile::mFileName.

91 {
92  if(IsSummaryAvailable())
93  {
94  wxFFile summaryFile(mFileName.GetFullPath());
95  return summaryFile.Length();
96  }
97  else
98  {
99  return 0;
100  }
101 }
wxFileNameWrapper mFileName
Definition: BlockFile.h:235
bool IsSummaryAvailable() const override
Returns TRUE if this block's complete summary has been computed and is ready (for OD) ...
sampleCount ODDecodeBlockFile::GetStart ( ) const
inline

Gets the value that indicates where the first sample in this block corresponds to the global sequence/clip. Only for display use.

Definition at line 100 of file ODDecodeBlockFile.h.

References mStart.

100 {return mStart;}
sampleCount mStart
for reporting after task is complete. Only for display use.
bool ODDecodeBlockFile::IsDataAvailable ( ) const
overridevirtual

Returns TRUE if this block's complete data is ready to be accessed by Read()

Reimplemented from BlockFile.

Definition at line 320 of file ODDecodeBlockFile.cpp.

References mDataAvailable.

Referenced by IsSummaryAvailable().

321 {
322  return mDataAvailable != 0;
323 }
wxAtomicInt mDataAvailable
bool ODDecodeBlockFile::IsSummaryAvailable ( ) const
overridevirtual

Returns TRUE if this block's complete summary has been computed and is ready (for OD)

Reimplemented from BlockFile.

Definition at line 315 of file ODDecodeBlockFile.cpp.

References IsDataAvailable().

Referenced by Copy(), GetSpaceUsage(), Read256(), Read64K(), ReadData(), ReadSummary(), Recover(), and SaveXML().

316 {
317  return IsDataAvailable();
318 }
bool IsDataAvailable() const override
Returns TRUE if this block's complete data is ready to be accessed by Read()
bool ODDecodeBlockFile::IsSummaryBeingComputed ( )
inlineoverridevirtual

Returns TRUE if the summary has not yet been written, but is actively being computed and written to disk.

Reimplemented from BlockFile.

Definition at line 61 of file ODDecodeBlockFile.h.

61 { return false; }
void ODDecodeBlockFile::LockRead ( ) const
overridevirtual

Prevents a read on other threads of the encoded audio file.

Prevents a read on other threads.

Reimplemented from BlockFile.

Definition at line 496 of file ODDecodeBlockFile.cpp.

References mReadDataMutex.

497 {
498  mReadDataMutex.Lock();
499 }
ODLock mReadDataMutex
For accessing the audio file that will be decoded. Used by dir manager;.
bool ODDecodeBlockFile::Read256 ( float *  buffer,
size_t  start,
size_t  len 
)
overridevirtual

Returns the 256 byte summary data block.

Returns the 256 byte summary data block Fill with zeroes and return false if data are unavailable for any reason.

Reimplemented from BlockFile.

Definition at line 147 of file ODDecodeBlockFile.cpp.

References ClearSamples(), floatSample, IsSummaryAvailable(), and BlockFile::Read256().

148 {
149  if(IsSummaryAvailable())
150  {
151  return SimpleBlockFile::Read256(buffer,start,len);
152  }
153  else
154  {
155  ClearSamples((samplePtr)buffer, floatSample, 0, len);
156  return false;
157  }
158 }
bool IsSummaryAvailable() const override
Returns TRUE if this block's complete summary has been computed and is ready (for OD) ...
virtual bool Read256(float *buffer, size_t start, size_t len)
Returns the 256 byte summary data block.
Definition: BlockFile.cpp:415
char * samplePtr
Definition: Types.h:203
void ClearSamples(samplePtr dst, sampleFormat format, size_t start, size_t len)
bool ODDecodeBlockFile::Read64K ( float *  buffer,
size_t  start,
size_t  len 
)
overridevirtual

Returns the 64K summary data block.

Returns the 64K summary data block Fill with zeroes and return false if data are unavailable for any reason.

Reimplemented from BlockFile.

Definition at line 162 of file ODDecodeBlockFile.cpp.

References ClearSamples(), floatSample, IsSummaryAvailable(), and BlockFile::Read64K().

163 {
164  if(IsSummaryAvailable())
165  {
166  return SimpleBlockFile::Read64K(buffer,start,len);
167  }
168  else
169  {
170  ClearSamples((samplePtr)buffer, floatSample, 0, len);
171  return false;
172  }
173 }
bool IsSummaryAvailable() const override
Returns TRUE if this block's complete summary has been computed and is ready (for OD) ...
char * samplePtr
Definition: Types.h:203
void ClearSamples(samplePtr dst, sampleFormat format, size_t start, size_t len)
virtual bool Read64K(float *buffer, size_t start, size_t len)
Returns the 64K summary data block.
Definition: BlockFile.cpp:454
size_t ODDecodeBlockFile::ReadData ( samplePtr  data,
sampleFormat  format,
size_t  start,
size_t  len,
bool  mayThrow 
) const
overridevirtual

Reads the specified data from the aliased file using libsndfile.

Reads the specified data from the aliased file, using libsndfile, and converts it to the given sample format.

Parameters
dataThe buffer to read the sample data into.
formatThe format to convert the data into
startThe offset within the block to begin reading
lenThe number of samples to read

Implements BlockFile.

Definition at line 448 of file ODDecodeBlockFile.cpp.

References ClearSamples(), IsSummaryAvailable(), BlockFile::LockForRead(), mAudioFileName, and SimpleBlockFile::ReadData().

450 {
451  auto locker = LockForRead();
452  if(IsSummaryAvailable())
453  return SimpleBlockFile::ReadData(data, format, start, len, mayThrow);
454  else
455  {
456  if (mayThrow)
458 
459  //we should do an ODRequest to start processing the data here, and wait till it finishes. and just do a SimpleBlockFile
460  //ReadData.
461  ClearSamples(data, format, 0, len);
462  return 0;
463  }
464 }
ReadLock LockForRead() const
Definition: BlockFile.h:200
bool IsSummaryAvailable() const override
Returns TRUE if this block's complete summary has been computed and is ready (for OD) ...
int format
Definition: ExportPCM.cpp:56
size_t ReadData(samplePtr data, sampleFormat format, size_t start, size_t len, bool mayThrow) const override
Read the data section of the disk file.
void ClearSamples(samplePtr dst, sampleFormat format, size_t start, size_t len)
wxFileNameWrapper mAudioFileName
The original file the audio came from.
bool ODDecodeBlockFile::ReadSummary ( ArrayOf< char > &  data)
overridevirtual

Read the summary into a buffer.

Read the summary of this alias block from disk. Since the audio data is elsewhere, this consists of reading the entire summary file. Fill with zeroes and return false if data are unavailable for any reason.

Parameters
*dataThe buffer where the summary data will be stored. It must be at least mSummaryInfo.totalSummaryBytes long.

Implements BlockFile.

Definition at line 472 of file ODDecodeBlockFile.cpp.

References IsSummaryAvailable(), BlockFile::mSummaryInfo, SimpleBlockFile::ReadSummary(), ArrayOf< X >::reinit(), and SummaryInfo::totalSummaryBytes.

473 {
474  //I dont think we need to add a mutex here because only the main thread changes filenames and calls ReadSummary
475  if(IsSummaryAvailable())
476  return SimpleBlockFile::ReadSummary(data);
477 
479  memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
480  return false;
481 }
void reinit(Integral count, bool initialize=false)
Definition: MemoryX.h:117
bool IsSummaryAvailable() const override
Returns TRUE if this block's complete summary has been computed and is ready (for OD) ...
SummaryInfo mSummaryInfo
Definition: BlockFile.h:237
bool ReadSummary(ArrayOf< char > &data) override
Read the summary section of the disk file.
size_t totalSummaryBytes
Definition: BlockFile.h:41
void ODDecodeBlockFile::Recover ( void  )
overridevirtual

Writes the summary file if summary data is available.

Implements BlockFile.

Definition at line 307 of file ODDecodeBlockFile.cpp.

References IsSummaryAvailable(), and WriteODDecodeBlockFile().

308 {
309  if(IsSummaryAvailable())
310  {
312  }
313 }
bool IsSummaryAvailable() const override
Returns TRUE if this block's complete summary has been computed and is ready (for OD) ...
void ODDecodeBlockFile::SaveXML ( XMLWriter xmlFile)
overridevirtual

Saves as xml ODDecodeBlockFile or SimpleBlockFile depending on summary availability.

Writes the xml as a SimpleBlockFile if we can (if we have a summary file) Otherwise writes XML as a subset of attributes with 'odpcmaliasblockfile as the start tag. Most notably, the summaryfile attribute refers to a file that does not yet, so when the project file is read back in and this object reconstructed, it needs to avoid trying to open it as well as schedule itself for OD loading

Implements BlockFile.

Definition at line 209 of file ODDecodeBlockFile.cpp.

References sampleCount::as_long_long(), XMLWriter::EndTag(), IsSummaryAvailable(), BlockFile::LockForRead(), mAliasChannel, mAliasStart, mAudioFileName, BlockFile::mFileName, mFileNameMutex, BlockFile::mLen, mType, SimpleBlockFile::SaveXML(), XMLWriter::StartTag(), and XMLWriter::WriteAttr().

211 {
212  auto locker = LockForRead();
213  if(IsSummaryAvailable())
214  {
215  SimpleBlockFile::SaveXML(xmlFile);
216  }
217  else
218  {
219  xmlFile.StartTag(wxT("oddecodeblockfile"));
220  {
221  //unlock to prevent deadlock and resume lock after.
222  auto suspension = locker.Suspend();
223  ODLocker locker2{ &mFileNameMutex };
224  xmlFile.WriteAttr(wxT("summaryfile"), mFileName.GetFullName());
225  }
226  xmlFile.WriteAttr(wxT("audiofile"), mAudioFileName.GetFullPath());
227  xmlFile.WriteAttr(wxT("aliasstart"),
229  xmlFile.WriteAttr(wxT("aliaslen"), mLen);
230  xmlFile.WriteAttr(wxT("aliaschannel"), mAliasChannel);
231  xmlFile.WriteAttr(wxT("decodetype"), (size_t)mType);
232 
233  xmlFile.EndTag(wxT("oddecodeblockfile"));
234  }
235 }
ReadLock LockForRead() const
Definition: BlockFile.h:200
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:78
void SaveXML(XMLWriter &xmlFile) override
Write an XML representation of this file.
wxFileNameWrapper mFileName
Definition: BlockFile.h:235
virtual void WriteAttr(const wxString &name, const wxString &value)
Definition: XMLWriter.cpp:131
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:101
bool IsSummaryAvailable() const override
Returns TRUE if this block's complete summary has been computed and is ready (for OD) ...
size_t mLen
Definition: BlockFile.h:236
long long as_long_long() const
Definition: Types.h:90
wxFileNameWrapper mAudioFileName
The original file the audio came from.
void ODDecodeBlockFile::SetClipOffset ( sampleCount  numSamples)
inline

sets the amount of samples the clip associated with this blockfile is offset in the wavetrack (non effecting)

Definition at line 122 of file ODDecodeBlockFile.h.

References mClipOffset.

122 {mClipOffset= numSamples;}
sampleCount mClipOffset
the ODTask needs to know where this blockfile lies in the track, so for convenience, we have this here.
void ODDecodeBlockFile::SetFileName ( wxFileNameWrapper &&  name)
overridevirtual

sets the file name the summary info will be saved in. threadsafe.

Reimplemented from BlockFile.

Definition at line 372 of file ODDecodeBlockFile.cpp.

References BlockFile::mFileName, mFileNameMutex, and name.

373 {
374  mFileNameMutex.Lock();
375  mFileName=std::move(name);
376 /* mchinen oct 9 2009 don't think we need the char* but leaving it in for now just as a reminder that we might
377  if wxFileName isn't threadsafe.
378  mFileNameChar.reinit(strlen(mFileName.GetFullPath().mb_str(wxConvUTF8))+1);
379  strcpy(mFileNameChar.get(), mFileName.GetFullPath().mb_str(wxConvUTF8)); */
380  mFileNameMutex.Unlock();
381 }
wxFileNameWrapper mFileName
Definition: BlockFile.h:235
void ODDecodeBlockFile::SetODFileDecoder ( ODFileDecoder decoder)

set the decoder,

Definition at line 484 of file ODDecodeBlockFile.cpp.

References mDecoder, and mDecoderMutex.

485 {
486  //since this is the only place that writes to mdecoder, it is totally thread-safe to read check without the mutex
487  if(decoder == mDecoder)
488  return;
489  mDecoderMutex.Lock();
490  mDecoder = decoder;
491  mDecoderMutex.Unlock();
492 }
ODFileDecoder * mDecoder
void ODDecodeBlockFile::SetStart ( sampleCount  startSample)
inline

Sets the value that indicates where the first sample in this block corresponds to the global sequence/clip. Only for display use.

Definition at line 97 of file ODDecodeBlockFile.h.

References mStart.

97 {mStart = startSample;}
sampleCount mStart
for reporting after task is complete. Only for display use.
void ODDecodeBlockFile::UnlockRead ( ) const
overridevirtual

Allows reading of encoded file on other threads.

Reimplemented from BlockFile.

Definition at line 501 of file ODDecodeBlockFile.cpp.

References mReadDataMutex.

502 {
503  mReadDataMutex.Unlock();
504 }
ODLock mReadDataMutex
For accessing the audio file that will be decoded. Used by dir manager;.
int ODDecodeBlockFile::WriteODDecodeBlockFile ( )

Write the summary to disk, using the derived ReadData() to get the data Here, the decoder ODTask associated with this file must fetch the samples with the ODDecodeTask::Decode() method.

Definition at line 328 of file ODDecodeBlockFile.cpp.

References ODFileDecoder::Decode(), mAliasChannel, mAliasStart, mDataAvailable, mDecoder, mDecoderMutex, mFileNameMutex, mFormat, BlockFile::mLen, SampleBuffer::ptr(), and SimpleBlockFile::WriteSimpleBlockFile().

Referenced by DoWriteBlockFile(), and Recover().

329 {
330 
331  // To build the summary data, call ReadData (implemented by the
332  // derived classes) to get the sample data
333  SampleBuffer sampleData;// = NewSamples(mLen, floatSample);
334  int ret;
335 
336  {
337  //use the decoder here.
338  ODLocker locker{ &mDecoderMutex };
339 
340  if(!mDecoder)
341  return -1;
342 
343  //sampleData and mFormat are set by the decoder.
344  ret = mDecoder->Decode(sampleData, mFormat, mAliasStart, mLen, mAliasChannel);
345 
346  if(ret < 0) {
347  wxPrintf("ODDecodeBlockFile Decode failure\n");
348  return ret; //failure
349  }
350  }
351 
352  {
353  //the summary is also calculated here.
354  ODLocker locker{ &mFileNameMutex };
355  //TODO: we may need to write a version of WriteSimpleBlockFile that uses threadsafe FILE vs wxFile
356  bool bSuccess =
358  sampleData.ptr(),
359  mLen,
360  mFormat,
361  NULL);
362  if ( !bSuccess )
363  return -1;
364  }
365 
366  wxAtomicInc( mDataAvailable );
367 
368  return ret;
369 }
wxAtomicInt mDataAvailable
ODFileDecoder * mDecoder
virtual int Decode(SampleBuffer &data, sampleFormat &format, sampleCount start, size_t len, unsigned int channel)=0
samplePtr ptr() const
Definition: SampleFormat.h:81
size_t mLen
Definition: BlockFile.h:236
bool WriteSimpleBlockFile(samplePtr sampleData, size_t sampleLen, sampleFormat format, void *summaryData)

Member Data Documentation

const int ODDecodeBlockFile::mAliasChannel
protected

Definition at line 188 of file ODDecodeBlockFile.h.

Referenced by Copy(), SaveXML(), and WriteODDecodeBlockFile().

sampleCount ODDecodeBlockFile::mAliasStart
protected

Definition at line 187 of file ODDecodeBlockFile.h.

Referenced by Copy(), SaveXML(), and WriteODDecodeBlockFile().

wxFileNameWrapper ODDecodeBlockFile::mAudioFileName
protected

The original file the audio came from.

Definition at line 168 of file ODDecodeBlockFile.h.

Referenced by ChangeAudioFile(), Copy(), GetAudioFileName(), GetEncodedAudioFilename(), ReadData(), and SaveXML().

sampleCount ODDecodeBlockFile::mClipOffset
protected

the ODTask needs to know where this blockfile lies in the track, so for convenience, we have this here.

Definition at line 183 of file ODDecodeBlockFile.h.

Referenced by GetClipOffset(), GetGlobalEnd(), GetGlobalStart(), and SetClipOffset().

wxAtomicInt ODDecodeBlockFile::mDataAvailable { 0 }
protected

Definition at line 170 of file ODDecodeBlockFile.h.

Referenced by IsDataAvailable(), and WriteODDecodeBlockFile().

bool ODDecodeBlockFile::mDataBeingComputed
protected

Definition at line 171 of file ODDecodeBlockFile.h.

ODFileDecoder* ODDecodeBlockFile::mDecoder
protected

Definition at line 173 of file ODDecodeBlockFile.h.

Referenced by SetODFileDecoder(), and WriteODDecodeBlockFile().

ODLock ODDecodeBlockFile::mDecoderMutex
protected

Definition at line 174 of file ODDecodeBlockFile.h.

Referenced by SetODFileDecoder(), and WriteODDecodeBlockFile().

ODLock ODDecodeBlockFile::mFileNameMutex
mutableprotected

This lock is for the filename (string) of the blockfile that contains summary/audio data after decoding

Definition at line 165 of file ODDecodeBlockFile.h.

Referenced by GetFileName(), SaveXML(), SetFileName(), and WriteODDecodeBlockFile().

sampleFormat ODDecodeBlockFile::mFormat
protected

Definition at line 185 of file ODDecodeBlockFile.h.

Referenced by WriteODDecodeBlockFile().

ODLock ODDecodeBlockFile::mReadDataMutex
mutableprotected

For accessing the audio file that will be decoded. Used by dir manager;.

Definition at line 177 of file ODDecodeBlockFile.h.

Referenced by LockRead(), and UnlockRead().

sampleCount ODDecodeBlockFile::mStart
protected

for reporting after task is complete. Only for display use.

Definition at line 180 of file ODDecodeBlockFile.h.

Referenced by GetGlobalEnd(), GetGlobalStart(), GetStart(), and SetStart().

unsigned int ODDecodeBlockFile::mType
protected

Definition at line 161 of file ODDecodeBlockFile.h.

Referenced by Copy(), GetDecodeType(), and SaveXML().


The documentation for this class was generated from the following files: