Audacity  3.0.3
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:
[legend]
Collaboration diagram for ODDecodeBlockFile:
[legend]

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
 
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...
 
const wxFileNameWrapperGetExternalFileName () const override
 
void SetExternalFileName (wxFileNameWrapper &&newName) override
 
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 wxFileNameWrapperGetEncodedAudioFilename () const
 
void ChangeAudioFile (wxFileNameWrapper &&newAudioFile)
 
- Public Member Functions inherited from SimpleBlockFile
 SimpleBlockFile (wxFileNameWrapper &&baseFileName, samplePtr sampleData, size_t sampleLen, sampleFormat format)
 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
 

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)
 

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
 

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 36 of file ODDecodeBlockFile.h.

Constructor & Destructor Documentation

◆ ODDecodeBlockFile() [1/2]

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.

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 }

References floatSample.

◆ ODDecodeBlockFile() [2/2]

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.

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 }

References min().

Here is the call graph for this function:

◆ ~ODDecodeBlockFile()

ODDecodeBlockFile::~ODDecodeBlockFile ( )
virtual

Definition at line 83 of file ODDecodeBlockFile.cpp.

84 {
85 
86 }

Member Function Documentation

◆ BuildFromXML()

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.

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 }

References XMLValueChecker::IsGoodFileName(), XMLValueChecker::IsGoodFileString(), XMLValueChecker::IsGoodInt(), XMLValueChecker::IsGoodInt64(), XMLValueChecker::IsGoodPathName(), XMLValueChecker::IsGoodPathString(), anonymous_namespace{WaveTrack.cpp}::IsValidChannel(), and PLATFORM_MAX_PATH.

Here is the call graph for this function:

◆ CalcSummary()

void * ODDecodeBlockFile::CalcSummary ( samplePtr  buffer,
size_t  len,
sampleFormat  format,
ArrayOf< char > &  cleanup 
)
overrideprotected

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.

Definition at line 406 of file ODDecodeBlockFile.cpp.

408 {
409  cleanup.reinit(mSummaryInfo.totalSummaryBytes);
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 }

References bheaderTag, bheaderTagLen, CopySamples(), floatSample, format, and ArrayOf< X >::reinit().

Here is the call graph for this function:

◆ ChangeAudioFile()

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 521 of file ODDecodeBlockFile.cpp.

522 {
523  mAudioFileName = std::move(newAudioFile);
524 }

References mAudioFileName.

Referenced by SetExternalFileName().

Here is the caller graph for this function:

◆ Copy()

BlockFilePtr ODDecodeBlockFile::Copy ( wxFileNameWrapper &&  newFileName)
override

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.

Definition at line 179 of file ODDecodeBlockFile.cpp.

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},
196  mMin, mMax, mRMS, IsSummaryAvailable());
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 }

References SimpleBlockFile::Copy(), IsSummaryAvailable(), mAliasChannel, mAliasStart, mAudioFileName, and mType.

Here is the call graph for this function:

◆ DoWriteBlockFile()

int ODDecodeBlockFile::DoWriteBlockFile ( )
inline

Definition at line 92 of file ODDecodeBlockFile.h.

92 {return WriteODDecodeBlockFile();}

References WriteODDecodeBlockFile().

Here is the call graph for this function:

◆ GetAudioFileName()

const wxFileName& ODDecodeBlockFile::GetAudioFileName ( )
inline

Definition at line 132 of file ODDecodeBlockFile.h.

132 {return mAudioFileName;}

References mAudioFileName.

Referenced by ODDecodeTask::GetOrCreateMatchingFileDecoder().

Here is the caller graph for this function:

◆ GetClipOffset()

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.

125 {return mClipOffset;}

References mClipOffset.

Referenced by ODDecodeTask::Update().

Here is the caller graph for this function:

◆ GetDecodeType()

unsigned int ODDecodeBlockFile::GetDecodeType ( ) const
inline

Returns the type of audiofile this blockfile is loaded from.

Definition at line 118 of file ODDecodeBlockFile.h.

118 { return mType; }

References mType.

Referenced by ODDecodeTask::GetOrCreateMatchingFileDecoder().

Here is the caller graph for this function:

◆ GetEncodedAudioFilename()

const wxFileNameWrapper& ODDecodeBlockFile::GetEncodedAudioFilename ( ) const
inline

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

Definition at line 145 of file ODDecodeBlockFile.h.

146  {
147  return mAudioFileName;
148  }

References mAudioFileName.

Referenced by GetExternalFileName().

Here is the caller graph for this function:

◆ GetExternalFileName()

const wxFileNameWrapper & ODDecodeBlockFile::GetExternalFileName ( ) const
override

Definition at line 506 of file ODDecodeBlockFile.cpp.

507 {
508  if ( !IsDataAvailable() )
509  return GetEncodedAudioFilename();
510  return SimpleBlockFile::GetExternalFileName();
511 }

References GetEncodedAudioFilename(), and IsDataAvailable().

Here is the call graph for this function:

◆ GetFileName()

auto ODDecodeBlockFile::GetFileName ( ) const
override

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

Definition at line 384 of file ODDecodeBlockFile.cpp.

385 {
386  return { mFileName, ODLocker{ &mFileNameMutex } };
387 }

References mFileNameMutex.

◆ GetGlobalEnd()

sampleCount ODDecodeBlockFile::GetGlobalEnd ( ) const
inline

Definition at line 106 of file ODDecodeBlockFile.h.

106 {return mClipOffset+mStart+GetLength();}

References mClipOffset, and mStart.

Referenced by ODDecodeTask::OrderBlockFiles().

Here is the caller graph for this function:

◆ GetGlobalStart()

sampleCount ODDecodeBlockFile::GetGlobalStart ( ) const
inline

Definition at line 103 of file ODDecodeBlockFile.h.

103 {return mClipOffset+mStart;}

References mClipOffset, and mStart.

Referenced by ODDecodeTask::OrderBlockFiles().

Here is the caller graph for this function:

◆ GetMinMaxRMS() [1/2]

auto ODDecodeBlockFile::GetMinMaxRMS ( bool  mayThrow) const
override

Gets extreme values for the entire block.

Definition at line 126 of file ODDecodeBlockFile.cpp.

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 }

◆ GetMinMaxRMS() [2/2]

auto ODDecodeBlockFile::GetMinMaxRMS ( size_t  start,
size_t  len,
bool  mayThrow 
) const
override

Gets extreme values for the specified region.

Definition at line 105 of file ODDecodeBlockFile.cpp.

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 }

◆ GetSpaceUsage()

auto ODDecodeBlockFile::GetSpaceUsage ( ) const
override

Definition at line 90 of file ODDecodeBlockFile.cpp.

91 {
92  if(IsSummaryAvailable())
93  {
94  wxFFile summaryFile(mFileName.GetFullPath());
95  return summaryFile.Length();
96  }
97  else
98  {
99  return 0;
100  }
101 }

References IsSummaryAvailable().

Here is the call graph for this function:

◆ GetStart()

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.

100 {return mStart;}

References mStart.

Referenced by ODDecodeTask::Update().

Here is the caller graph for this function:

◆ IsDataAvailable()

bool ODDecodeBlockFile::IsDataAvailable ( ) const
override

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

Definition at line 320 of file ODDecodeBlockFile.cpp.

321 {
322  return mDataAvailable != 0;
323 }

References mDataAvailable.

Referenced by GetExternalFileName(), and IsSummaryAvailable().

Here is the caller graph for this function:

◆ IsSummaryAvailable()

bool ODDecodeBlockFile::IsSummaryAvailable ( ) const
override

Definition at line 315 of file ODDecodeBlockFile.cpp.

316 {
317  return IsDataAvailable();
318 }

References IsDataAvailable().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsSummaryBeingComputed()

bool ODDecodeBlockFile::IsSummaryBeingComputed ( )
inlineoverride

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

Definition at line 58 of file ODDecodeBlockFile.h.

58 { return false; }

◆ LockRead()

void ODDecodeBlockFile::LockRead ( ) const
override

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

Prevents a read on other threads.

Definition at line 496 of file ODDecodeBlockFile.cpp.

497 {
498  mReadDataMutex.Lock();
499 }

References mReadDataMutex.

◆ Read256()

bool ODDecodeBlockFile::Read256 ( float *  buffer,
size_t  start,
size_t  len 
)
override

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.

Definition at line 147 of file ODDecodeBlockFile.cpp.

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 }

References ClearSamples(), floatSample, and IsSummaryAvailable().

Here is the call graph for this function:

◆ Read64K()

bool ODDecodeBlockFile::Read64K ( float *  buffer,
size_t  start,
size_t  len 
)
override

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.

Definition at line 162 of file ODDecodeBlockFile.cpp.

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 }

References ClearSamples(), floatSample, and IsSummaryAvailable().

Here is the call graph for this function:

◆ ReadData()

size_t ODDecodeBlockFile::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.

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

Definition at line 448 of file ODDecodeBlockFile.cpp.

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 }

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

Here is the call graph for this function:

◆ ReadSummary()

bool ODDecodeBlockFile::ReadSummary ( ArrayOf< char > &  data)
override

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.

Definition at line 472 of file ODDecodeBlockFile.cpp.

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 
478  data.reinit( mSummaryInfo.totalSummaryBytes );
479  memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
480  return false;
481 }

References IsSummaryAvailable(), SimpleBlockFile::ReadSummary(), and ArrayOf< X >::reinit().

Here is the call graph for this function:

◆ Recover()

void ODDecodeBlockFile::Recover ( void  )
override

Writes the summary file if summary data is available.

Definition at line 307 of file ODDecodeBlockFile.cpp.

308 {
309  if(IsSummaryAvailable())
310  {
312  }
313 }

References IsSummaryAvailable(), and WriteODDecodeBlockFile().

Here is the call graph for this function:

◆ SaveXML()

void ODDecodeBlockFile::SaveXML ( XMLWriter xmlFile)
override

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

Definition at line 209 of file ODDecodeBlockFile.cpp.

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 }

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

Here is the call graph for this function:

◆ SetClipOffset()

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.

122 {mClipOffset= numSamples;}

References mClipOffset.

Referenced by ODDecodeTask::Update().

Here is the caller graph for this function:

◆ SetExternalFileName()

void ODDecodeBlockFile::SetExternalFileName ( wxFileNameWrapper &&  newName)
override

Definition at line 513 of file ODDecodeBlockFile.cpp.

514 {
515  ChangeAudioFile( std::move( newName ) );
516 }

References ChangeAudioFile().

Here is the call graph for this function:

◆ SetFileName()

void ODDecodeBlockFile::SetFileName ( wxFileNameWrapper &&  name)
override

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

Definition at line 372 of file ODDecodeBlockFile.cpp.

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 }

References mFileNameMutex, and name.

◆ SetODFileDecoder()

void ODDecodeBlockFile::SetODFileDecoder ( ODFileDecoder decoder)

set the decoder,

Definition at line 484 of file ODDecodeBlockFile.cpp.

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 }

References mDecoder, and mDecoderMutex.

◆ SetStart()

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.

97 {mStart = startSample;}

References mStart.

Referenced by ODDecodeTask::Update().

Here is the caller graph for this function:

◆ UnlockRead()

void ODDecodeBlockFile::UnlockRead ( ) const
override

Allows reading of encoded file on other threads.

Definition at line 501 of file ODDecodeBlockFile.cpp.

502 {
503  mReadDataMutex.Unlock();
504 }

References mReadDataMutex.

◆ WriteODDecodeBlockFile()

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.

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 }

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

Referenced by DoWriteBlockFile(), and Recover().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mAliasChannel

const int ODDecodeBlockFile::mAliasChannel
protected

Definition at line 188 of file ODDecodeBlockFile.h.

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

◆ mAliasStart

sampleCount ODDecodeBlockFile::mAliasStart
protected

Definition at line 187 of file ODDecodeBlockFile.h.

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

◆ mAudioFileName

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().

◆ mClipOffset

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().

◆ mDataAvailable

wxAtomicInt ODDecodeBlockFile::mDataAvailable { 0 }
protected

Definition at line 170 of file ODDecodeBlockFile.h.

Referenced by IsDataAvailable(), and WriteODDecodeBlockFile().

◆ mDataBeingComputed

bool ODDecodeBlockFile::mDataBeingComputed
protected

Definition at line 171 of file ODDecodeBlockFile.h.

◆ mDecoder

ODFileDecoder* ODDecodeBlockFile::mDecoder
protected

Definition at line 173 of file ODDecodeBlockFile.h.

Referenced by SetODFileDecoder(), and WriteODDecodeBlockFile().

◆ mDecoderMutex

ODLock ODDecodeBlockFile::mDecoderMutex
protected

Definition at line 174 of file ODDecodeBlockFile.h.

Referenced by SetODFileDecoder(), and WriteODDecodeBlockFile().

◆ mFileNameMutex

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().

◆ mFormat

sampleFormat ODDecodeBlockFile::mFormat
protected

Definition at line 185 of file ODDecodeBlockFile.h.

Referenced by WriteODDecodeBlockFile().

◆ mReadDataMutex

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().

◆ mStart

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().

◆ mType

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:
XMLWriter::EndTag
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:99
ClearSamples
void ClearSamples(samplePtr dst, sampleFormat format, size_t start, size_t len)
Definition: SampleFormat.cpp:77
wxFileNameWrapper
Definition: wxFileNameWrapper.h:21
XMLValueChecker::IsGoodInt
static bool IsGoodInt(const wxString &strInt)
Check that the supplied string can be converted to a long (32bit) integer.
Definition: XMLTagHandler.cpp:157
XMLValueChecker::IsGoodPathName
static bool IsGoodPathName(const FilePath &strPathName)
Definition: XMLTagHandler.cpp:98
NotYetAvailableException
Definition: NotYetAvailableException.h:17
SimpleBlockFile::SaveXML
void SaveXML(XMLWriter &xmlFile) override
Write an XML representation of this file.
Definition: SimpleBlockFile.cpp:274
ArrayOf::reinit
void reinit(Integral count, bool initialize=false)
Definition: MemoryX.h:57
FileException
Thrown for failure of file or database operations in deeply nested places.
Definition: FileException.h:19
ODDecodeBlockFile::GetEncodedAudioFilename
const wxFileNameWrapper & GetEncodedAudioFilename() const
Definition: ODDecodeBlockFile.h:145
XMLValueChecker::IsGoodInt64
static bool IsGoodInt64(const wxString &strInt)
Check that the supplied string can be converted to a 64bit integer.
Definition: XMLTagHandler.cpp:163
SimpleBlockFile::Copy
BlockFilePtr Copy(wxFileNameWrapper &&newFileName) override
Create a NEW block file identical to this one.
Definition: SimpleBlockFile.cpp:339
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::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
floatSample
@ floatSample
Definition: SampleFormat.h:34
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::mDecoderMutex
ODLock mDecoderMutex
Definition: ODDecodeBlockFile.h:174
CopySamples
void CopySamples(constSamplePtr src, sampleFormat srcFormat, samplePtr dst, sampleFormat dstFormat, size_t len, DitherType ditherType, unsigned int srcStride, unsigned int dstStride)
Copy samples from any format to any other format; apply dithering only if narrowing the format.
Definition: SampleFormat.cpp:111
sampleCount::as_long_long
long long as_long_long() const
Definition: SampleCount.h:47
int16Sample
@ int16Sample
Definition: SampleFormat.h:32
SimpleBlockFile::ReadSummary
bool ReadSummary(ArrayOf< char > &data) override
Read the summary section of the disk file.
Definition: SimpleBlockFile.cpp:226
ODDecodeBlockFile::mReadDataMutex
ODLock mReadDataMutex
For accessing the audio file that will be decoded. Used by dir manager;.
Definition: ODDecodeBlockFile.h:177
SimpleBlockFile::ReadData
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.
Definition: SimpleBlockFile.cpp:267
name
const TranslatableString name
Definition: Distortion.cpp:98
XMLValueChecker::IsGoodFileName
static bool IsGoodFileName(const FilePath &strFileName, const FilePath &strDirName={})
Definition: XMLTagHandler.cpp:58
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
bheaderTag
char bheaderTag[bheaderTagLen+1]
Definition: ODDecodeBlockFile.cpp:36
ODLocker
Definition: ODTaskThread.h:120
XMLValueChecker::IsGoodFileString
static bool IsGoodFileString(const FilePath &str)
Definition: XMLTagHandler.cpp:70
ODDecodeBlockFile::ChangeAudioFile
void ChangeAudioFile(wxFileNameWrapper &&newAudioFile)
Definition: ODDecodeBlockFile.cpp:521
ODDecodeBlockFile::IsSummaryAvailable
bool IsSummaryAvailable() const override
Definition: ODDecodeBlockFile.cpp:315
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
samplePtr
char * samplePtr
Definition: SampleFormat.h:49
SimpleBlockFile::WriteSimpleBlockFile
bool WriteSimpleBlockFile(samplePtr sampleData, size_t sampleLen, sampleFormat format, void *summaryData)
Definition: SimpleBlockFile.cpp:113
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
bheaderTagLen
const int bheaderTagLen
Definition: ODDecodeBlockFile.cpp:35
anonymous_namespace{WaveTrack.cpp}::IsValidChannel
bool IsValidChannel(const int nValue)
Definition: WaveTrack.cpp:1706
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
XMLWriter::WriteAttr
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:34
PLATFORM_MAX_PATH
#define PLATFORM_MAX_PATH
Definition: FileNames.h:22
XMLValueChecker::IsGoodPathString
static bool IsGoodPathString(const FilePath &str)
Definition: XMLTagHandler.cpp:105
ODDecodeBlockFile::mDecoder
ODFileDecoder * mDecoder
Definition: ODDecodeBlockFile.h:173
ArrayOf< float >
XMLWriter::StartTag
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:76
ODDecodeBlockFile::WriteODDecodeBlockFile
int WriteODDecodeBlockFile()
Definition: ODDecodeBlockFile.cpp:328
ODDecodeBlockFile::mFormat
sampleFormat mFormat
Definition: ODDecodeBlockFile.h:185
SampleBuffer::ptr
samplePtr ptr() const
Definition: SampleFormat.h:98