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

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

#include <ODPCMAliasBlockFile.h>

Inheritance diagram for ODPCMAliasBlockFile:
PCMAliasBlockFile AliasBlockFile BlockFile

Public Member Functions

 ODPCMAliasBlockFile (wxFileNameWrapper &&baseFileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel)
 Constructs a PCMAliasBlockFile, writing the summary to disk. More...
 
 ODPCMAliasBlockFile (wxFileNameWrapper &&existingSummaryFileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel, float min, float max, float rms, bool summaryAvailable)
 summaryAvailable should be true if the file has been written already. More...
 
virtual ~ODPCMAliasBlockFile ()
 
bool IsSummaryAvailable () const override
 Returns TRUE if this block's complete summary has been computed and is ready (for OD) 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 ODPCMAliasBlockFile or PCMAliasBlockFile depending on summary availability. More...
 
void SaveXML (XMLWriter &xmlFile) override
 Saves as xml ODPCMAliasBlockFile or PCMAliasBlockFile depending on summary availability. More...
 
void Recover (void) override
 Writes the summary file if summary data is available. More...
 
void DoWriteSummary ()
 A public interface to WriteSummary. More...
 
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...
 
void Lock () override
 Locks the blockfile only if it has a file that exists. More...
 
void Unlock () override
 Unlocks the blockfile only if it has a file that exists. 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...
 
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...
 
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 CloseLock () override
 
void LockRead () const override
 Prevents a read on other threads. More...
 
void UnlockRead () const override
 Allows reading on other threads. More...
 
- Public Member Functions inherited from PCMAliasBlockFile
 PCMAliasBlockFile (wxFileNameWrapper &&baseFileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel)
 Constructs a PCMAliasBlockFile, writing the summary to disk. More...
 
 PCMAliasBlockFile (wxFileNameWrapper &&fileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel, bool writeSummary)
 Constructs a PCMAliasBlockFile with the option of not writing to disk. More...
 
 PCMAliasBlockFile (wxFileNameWrapper &&existingSummaryFileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel, float min, float max, float rms)
 
virtual ~PCMAliasBlockFile ()
 
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...
 
void SaveXML (XMLWriter &xmlFile) override
 Stores a representation of this file in XML. More...
 
BlockFilePtr Copy (wxFileNameWrapper &&fileName) override
 
void Recover () override
 if the on-disk state disappeared, either recover it (if it was More...
 
- Public Member Functions inherited from AliasBlockFile
 AliasBlockFile (wxFileNameWrapper &&baseFileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel)
 Constructs an AliasBlockFile. More...
 
 AliasBlockFile (wxFileNameWrapper &&existingSummaryFileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel, float min, float max, float RMS)
 
virtual ~AliasBlockFile ()
 
DiskByteCount GetSpaceUsage () const override
 
void SilenceAliasLog () const
 as SilentLog (which would affect Summary data access), but More...
 
const wxFileName & GetAliasedFileName () const
 
void ChangeAliasedFileName (wxFileNameWrapper &&newAliasedFile)
 
bool IsAlias () const override
 Returns TRUE if this block references another disk file. More...
 
- Public Member Functions inherited from BlockFile
 BlockFile (wxFileNameWrapper &&fileName, size_t samples)
 Construct a BlockFile. More...
 
virtual ~BlockFile ()
 
virtual bool GetNeedWriteCacheToDisk ()
 
virtual void WriteCacheToDisk ()
 
virtual bool GetNeedFillCache ()
 
virtual void FillCache ()
 
size_t GetLength () const
 
void SetLength (size_t newLen)
 
virtual bool IsLocked ()
 Returns TRUE if this BlockFile is locked. More...
 
virtual bool IsDataAvailable () const
 Returns TRUE if this block's complete data is ready to be accessed by Read() More...
 
void SilenceLog () const
 if we've detected an on-disk problem, the user opted to More...
 
ReadLock LockForRead () const
 

Static Public Member Functions

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

Protected Member Functions

void WriteSummary () override
 Write the summary to disk, using the derived ReadData() to get the data. More...
 
void * CalcSummary (samplePtr buffer, size_t len, sampleFormat format, ArrayOf< char > &cleanup) override
 
- Protected Member Functions inherited from AliasBlockFile
bool ReadSummary (ArrayOf< char > &data) override
 Read the summary into a buffer. More...
 
- Protected Member Functions inherited from BlockFile
void CalcSummaryFromBuffer (const float *fbuffer, size_t len, float *summary256, float *summary64K)
 
virtual void FixSummary (void *data)
 

Private Attributes

ODLock mWriteSummaryMutex
 
ODLock mFileNameMutex
 
ODLock mAliasedFileNameMutex
 Also need to protect the aliased file name. More...
 
ODLock mReadDataMutex
 
ODLock mSummaryAvailableMutex
 
bool mSummaryAvailable
 
bool mSummaryBeingComputed
 
bool mHasBeenSaved
 
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...
 

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 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)
 
- Protected Attributes inherited from AliasBlockFile
wxFileNameWrapper mAliasedFileName
 
sampleCount mAliasStart
 
const int mAliasChannel
 
bool mSilentAliasLog
 
- Protected Attributes inherited from BlockFile
wxFileNameWrapper mFileName
 
size_t mLen
 
SummaryInfo mSummaryInfo
 
float mMin
 
float mMax
 
float mRMS
 
bool mSilentLog
 

Detailed Description

An AliasBlockFile that references uncompressed data in an existing file.

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

Load On-Demand implementation of the AliasBlockFile for PCM files.

to load large files more quickly, we skip computing the summary data and put ODPCMAliasBlockFiles in the sequence as place holders. A background thread loads and computes the summary data into these classes. ODPCMAliasBlockFiles unlike all other BlockFiles are not immutable (for the most part,) because when NEW summary data is computed for an existing ODPCMAliasBlockFile we save the buffer then and write the Summary File.

All BlockFile methods that treat the summary data as a buffer that exists in its BlockFile are implemented here to behave when the data is not available yet.

Some of these methods have been overridden only because they used the unsafe wxLog calls in the base class.

Definition at line 46 of file ODPCMAliasBlockFile.h.

Constructor & Destructor Documentation

ODPCMAliasBlockFile::ODPCMAliasBlockFile ( wxFileNameWrapper &&  baseFileName,
wxFileNameWrapper &&  aliasedFileName,
sampleCount  aliasStart,
size_t  aliasLen,
int  aliasChannel 
)

Constructs a PCMAliasBlockFile, writing the summary to disk.

Definition at line 49 of file ODPCMAliasBlockFile.cpp.

54 : PCMAliasBlockFile { std::move(fileName), std::move(aliasedFileName),
55  aliasStart, aliasLen, aliasChannel, false }
56 {
58 }
An AliasBlockFile that references uncompressed data in an existing file.
ODPCMAliasBlockFile::ODPCMAliasBlockFile ( wxFileNameWrapper &&  existingSummaryFileName,
wxFileNameWrapper &&  aliasedFileName,
sampleCount  aliasStart,
size_t  aliasLen,
int  aliasChannel,
float  min,
float  max,
float  rms,
bool  summaryAvailable 
)

summaryAvailable should be true if the file has been written already.

Definition at line 61 of file ODPCMAliasBlockFile.cpp.

References mHasBeenSaved, mSummaryAvailable, and mSummaryBeingComputed.

67 : PCMAliasBlockFile(std::move(existingSummaryFileName), std::move(aliasedFileName),
68  aliasStart, aliasLen,
69  aliasChannel, min, max, rms)
70 {
71  mSummaryAvailable=summaryAvailable;
73  }
int min(int a, int b)
PCMAliasBlockFile(wxFileNameWrapper &&baseFileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel)
Constructs a PCMAliasBlockFile, writing the summary to disk.
ODPCMAliasBlockFile::~ODPCMAliasBlockFile ( )
virtual

Definition at line 75 of file ODPCMAliasBlockFile.cpp.

76 {
77 }

Member Function Documentation

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

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

Constructs a ODPCMAliasBlockFile from the xml output of WriteXML. Does not schedule the ODPCMAliasBlockFile for OD loading. Client code must do this.

Definition at line 277 of file ODPCMAliasBlockFile.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().

278 {
279  wxFileNameWrapper summaryFileName;
280  wxFileNameWrapper aliasFileName;
281  sampleCount aliasStart = 0;
282  size_t aliasLen = 0;
283  int aliasChannel=0;
284  long nValue;
285  long long nnValue;
286 
287  while(*attrs)
288  {
289  const wxChar *attr = *attrs++;
290  const wxChar *value = *attrs++;
291  if (!value)
292  break;
293 
294  const wxString strValue = value;
295  if (!wxStricmp(attr, wxT("summaryfile")) &&
296  // Can't use XMLValueChecker::IsGoodFileName here, but do part of its test.
298  (strValue.Length() + 1 + dm.GetProjectDataDir().Length() <= PLATFORM_MAX_PATH))
299  {
300  if (!dm.AssignFile(summaryFileName, strValue, false))
301  // Make sure summaryFileName is back to uninitialized state so we can detect problem later.
302  summaryFileName.Clear();
303  }
304  else if( !wxStricmp(attr, wxT("aliasfile")) )
305  {
306  if (XMLValueChecker::IsGoodPathName(strValue))
307  aliasFileName.Assign(strValue);
308  else if (XMLValueChecker::IsGoodFileName(strValue, dm.GetProjectDataDir()))
309  // Allow fallback of looking for the file name, located in the data directory.
310  aliasFileName.Assign(dm.GetProjectDataDir(), strValue);
311  else if (XMLValueChecker::IsGoodPathString(strValue))
312  // If the aliased file is missing, we failed XMLValueChecker::IsGoodPathName()
313  // and XMLValueChecker::IsGoodFileName, because both do existence tests,
314  // but we want to keep the reference to the missing file because it's a good path string.
315  aliasFileName.Assign(strValue);
316  }
317  else if ( !wxStricmp(attr, wxT("aliasstart")) )
318  {
319  if (XMLValueChecker::IsGoodInt64(strValue) &&
320  strValue.ToLongLong(&nnValue) && (nnValue >= 0))
321  aliasStart = nnValue;
322  }
323  else if (XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
324  { // integer parameters
325  if (!wxStricmp(attr, wxT("aliaslen")) && (nValue >= 0))
326  aliasLen = nValue;
327  else if (!wxStricmp(attr, wxT("aliaschannel")) && XMLValueChecker::IsValidChannel(aliasChannel))
328  aliasChannel = nValue;
329  }
330  }
331 
332  return make_blockfile<ODPCMAliasBlockFile>
333  (std::move(summaryFileName), std::move(aliasFileName),
334  aliasStart, aliasLen, aliasChannel, 0, 0, 0, false);
335 }
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 * ODPCMAliasBlockFile::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 455 of file ODPCMAliasBlockFile.cpp.

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

Referenced by WriteSummary().

457 {
459  char* localFullSummary = cleanup.get();
460 
461  memcpy(localFullSummary, aheaderTag, aheaderTagLen);
462 
463  float *summary64K = (float *)(localFullSummary + mSummaryInfo.offset64K);
464  float *summary256 = (float *)(localFullSummary + mSummaryInfo.offset256);
465 
466  Floats floats;
467  float *fbuffer;
468 
469  //mchinen: think we can hack this - don't allocate and copy if we don't need to.,
470  if(format==floatSample)
471  {
472  fbuffer = (float*)buffer;
473  }
474  else
475  {
476  floats.reinit(len);
477  fbuffer = floats.get();
478  CopySamples(buffer, format,
479  (samplePtr)fbuffer, floatSample, len);
480  }
481 
482  BlockFile::CalcSummaryFromBuffer(fbuffer, len, summary256, summary64K);
483 
484  return localFullSummary;
485 }
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
int format
Definition: ExportPCM.cpp:56
char * samplePtr
Definition: Types.h:203
size_t totalSummaryBytes
Definition: BlockFile.h:41
char aheaderTag[aheaderTagLen+1]
int offset256
Definition: BlockFile.h:40
const int aheaderTagLen
void ODPCMAliasBlockFile::CloseLock ( )
overridevirtual

when the project closes, it locks the blockfiles. Override this in case it needs special treatment.

Reimplemented from BlockFile.

Definition at line 109 of file ODPCMAliasBlockFile.cpp.

References BlockFile::Lock(), and mHasBeenSaved.

110 {
111  if(mHasBeenSaved)
113 }
virtual void Lock()
Locks this BlockFile, to prevent it from being moved.
Definition: BlockFile.cpp:148
BlockFilePtr ODPCMAliasBlockFile::Copy ( wxFileNameWrapper &&  newFileName)
overridevirtual

Makes NEW ODPCMAliasBlockFile or PCMAliasBlockFile depending on summary availability.

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

Parameters
newFileNameThe filename to copy the summary data to.

Implements BlockFile.

Definition at line 206 of file ODPCMAliasBlockFile.cpp.

References IsSummaryAvailable(), BlockFile::LockForRead(), AliasBlockFile::mAliasChannel, AliasBlockFile::mAliasedFileName, AliasBlockFile::mAliasStart, mHasBeenSaved, BlockFile::mLen, BlockFile::mMax, BlockFile::mMin, and BlockFile::mRMS.

207 {
208  BlockFilePtr newBlockFile;
209 
210  //mAliasedFile can change so we lock readdatamutex, which is responsible for it.
211  auto locker = LockForRead();
212  //If the file has been written AND it has been saved, we create a PCM alias blockfile because for
213  //all intents and purposes, it is the same.
214  //However, if it hasn't been saved yet, we shouldn't create one because the default behavior of the
215  //PCMAliasBlockFile is to lock on exit, and this will cause orphaned blockfiles..
217  {
218  newBlockFile = make_blockfile<PCMAliasBlockFile>
219  (std::move(newFileName), wxFileNameWrapper{mAliasedFileName},
221 
222  }
223  else
224  {
225  //Summary File might exist in this case, but it might not.
226  newBlockFile = make_blockfile<ODPCMAliasBlockFile>
227  (std::move(newFileName), wxFileNameWrapper{mAliasedFileName},
230  //The client code will need to schedule this blockfile for OD summarizing if it is going to a NEW track.
231  }
232 
233  return newBlockFile;
234 }
ReadLock LockForRead() const
Definition: BlockFile.h:200
const int mAliasChannel
Definition: BlockFile.h:291
float mMin
Definition: BlockFile.h:238
wxFileNameWrapper mAliasedFileName
Definition: BlockFile.h:289
std::shared_ptr< BlockFile > BlockFilePtr
Definition: BlockFile.h:48
float mRMS
Definition: BlockFile.h:238
bool IsSummaryAvailable() const override
Returns TRUE if this block's complete summary has been computed and is ready (for OD) ...
sampleCount mAliasStart
Definition: BlockFile.h:290
size_t mLen
Definition: BlockFile.h:236
float mMax
Definition: BlockFile.h:238
void ODPCMAliasBlockFile::DoWriteSummary ( )

A public interface to WriteSummary.

Calls write summary, and makes sure it is only done once in a thread-safe fashion.

Definition at line 357 of file ODPCMAliasBlockFile.cpp.

References IsSummaryAvailable(), mWriteSummaryMutex, and WriteSummary().

358 {
359  ODLocker locker { &mWriteSummaryMutex };
360  if(!IsSummaryAvailable())
361  WriteSummary();
362 }
bool IsSummaryAvailable() const override
Returns TRUE if this block's complete summary has been computed and is ready (for OD) ...
void WriteSummary() override
Write the summary to disk, using the derived ReadData() to get the data.
sampleCount ODPCMAliasBlockFile::GetClipOffset ( ) const
inline

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

Definition at line 108 of file ODPCMAliasBlockFile.h.

References mClipOffset.

108 {return mClipOffset;}
sampleCount mClipOffset
the ODTask needs to know where this blockfile lies in the track, so for convenience, we have this here.
auto ODPCMAliasBlockFile::GetFileName ( ) const
overridevirtual

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

Reimplemented from BlockFile.

Definition at line 373 of file ODPCMAliasBlockFile.cpp.

References BlockFile::mFileName, and mFileNameMutex.

374 {
375  return { mFileName, ODLocker{ &mFileNameMutex } };
376 }
wxFileNameWrapper mFileName
Definition: BlockFile.h:235
sampleCount ODPCMAliasBlockFile::GetGlobalEnd ( ) const
inline

Definition at line 114 of file ODPCMAliasBlockFile.h.

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

114 {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 ODPCMAliasBlockFile::GetGlobalStart ( ) const
inline

Definition at line 111 of file ODPCMAliasBlockFile.h.

References mClipOffset, and mStart.

111 {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 ODPCMAliasBlockFile::GetMinMaxRMS ( size_t  start,
size_t  len,
bool  mayThrow 
) const
overridevirtual

Gets extreme values for the specified region.

Reimplemented from BlockFile.

Definition at line 126 of file ODPCMAliasBlockFile.cpp.

References BlockFile::GetMinMaxRMS(), and JUST_BELOW_MAX_AUDIO.

128 {
129  if(IsSummaryAvailable())
130  {
131  return PCMAliasBlockFile::GetMinMaxRMS(start, len, mayThrow);
132  }
133  else
134  {
135  if (mayThrow)
137 
138  //fake values. These values are used usually for normalization and amplifying, so we want
139  //the max to be maximal and the min to be minimal
140  return {
143  0.707f //sin with amp of 1 rms
144  };
145  }
146 }
#define JUST_BELOW_MAX_AUDIO
Definition: Audacity.h:220
const wxFileName & GetAliasedFileName() const
Definition: BlockFile.h:278
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
auto ODPCMAliasBlockFile::GetMinMaxRMS ( bool  mayThrow) const
overridevirtual

Gets extreme values for the entire block.

Reimplemented from BlockFile.

Definition at line 149 of file ODPCMAliasBlockFile.cpp.

References BlockFile::GetMinMaxRMS(), and JUST_BELOW_MAX_AUDIO.

150 {
151  if(IsSummaryAvailable())
152  {
153  return PCMAliasBlockFile::GetMinMaxRMS(mayThrow);
154  }
155  else
156  {
157  if (mayThrow)
159 
160  //fake values. These values are used usually for normalization and amplifying, so we want
161  //the max to be maximal and the min to be minimal
162  return {
165  0.707f //sin with amp of 1 rms
166  };
167  }
168 }
#define JUST_BELOW_MAX_AUDIO
Definition: Audacity.h:220
const wxFileName & GetAliasedFileName() const
Definition: BlockFile.h:278
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
auto ODPCMAliasBlockFile::GetSpaceUsage ( ) const
overridevirtual

Implements BlockFile.

Definition at line 82 of file ODPCMAliasBlockFile.cpp.

References IsSummaryAvailable(), BlockFile::mFileName, and mFileNameMutex.

83 {
84  if(IsSummaryAvailable())
85  {
86  DiskByteCount ret;
87  mFileNameMutex.Lock();
88  wxFFile summaryFile(mFileName.GetFullPath());
89  ret= summaryFile.Length();
90  mFileNameMutex.Unlock();
91  return ret;
92  }
93  else
94  {
95  return 0;
96  }
97 }
wxFileNameWrapper mFileName
Definition: BlockFile.h:235
unsigned long long DiskByteCount
Definition: BlockFile.h:152
bool IsSummaryAvailable() const override
Returns TRUE if this block's complete summary has been computed and is ready (for OD) ...
sampleCount ODPCMAliasBlockFile::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 96 of file ODPCMAliasBlockFile.h.

References mStart.

96 {return mStart;}
sampleCount mStart
for reporting after task is complete. Only for display use.
bool ODPCMAliasBlockFile::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 347 of file ODPCMAliasBlockFile.cpp.

References mSummaryAvailable, and mSummaryAvailableMutex.

Referenced by Copy(), DoWriteSummary(), GetSpaceUsage(), Lock(), Read256(), Read64K(), Recover(), SaveXML(), and Unlock().

348 {
349  bool retval;
350  mSummaryAvailableMutex.Lock();
351  retval= mSummaryAvailable;
352  mSummaryAvailableMutex.Unlock();
353  return retval;
354 }
bool ODPCMAliasBlockFile::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 63 of file ODPCMAliasBlockFile.h.

References mSummaryBeingComputed.

void ODPCMAliasBlockFile::Lock ( )
overridevirtual

Locks the blockfile only if it has a file that exists.

Locks the blockfile only if it has a file that exists. This needs to be done so that the unsaved ODPCMAliasBlockfiles are deleted upon exit

Reimplemented from BlockFile.

Definition at line 101 of file ODPCMAliasBlockFile.cpp.

References IsSummaryAvailable(), BlockFile::Lock(), and mHasBeenSaved.

102 {
105 }
virtual void Lock()
Locks this BlockFile, to prevent it from being moved.
Definition: BlockFile.cpp:148
bool IsSummaryAvailable() const override
Returns TRUE if this block's complete summary has been computed and is ready (for OD) ...
void ODPCMAliasBlockFile::LockRead ( ) const
overridevirtual

Prevents a read on other threads.

Reimplemented from BlockFile.

Definition at line 556 of file ODPCMAliasBlockFile.cpp.

References mReadDataMutex.

557 {
558  mReadDataMutex.Lock();
559 }
bool ODPCMAliasBlockFile::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 172 of file ODPCMAliasBlockFile.cpp.

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

173 {
174  if(IsSummaryAvailable())
175  {
176  return PCMAliasBlockFile::Read256(buffer,start,len);
177  }
178  else
179  {
180  //return nothing.
181  ClearSamples((samplePtr)buffer, floatSample, 0, len);
182  return false;
183  }
184 }
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
bool IsSummaryAvailable() const override
Returns TRUE if this block's complete summary has been computed and is ready (for OD) ...
void ClearSamples(samplePtr dst, sampleFormat format, size_t start, size_t len)
bool ODPCMAliasBlockFile::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 188 of file ODPCMAliasBlockFile.cpp.

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

189 {
190  if(IsSummaryAvailable())
191  {
192  return PCMAliasBlockFile::Read64K(buffer,start,len);
193  }
194  else
195  {
196  //return nothing - it hasn't been calculated yet
197  ClearSamples((samplePtr)buffer, floatSample, 0, len);
198  return false;
199  }
200 }
char * samplePtr
Definition: Types.h:203
bool IsSummaryAvailable() const override
Returns TRUE if this block's complete summary has been computed and is ready (for OD) ...
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 ODPCMAliasBlockFile::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. Copied from PCMAliasBlockFIle but wxLog calls taken out for thread safety

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 498 of file ODPCMAliasBlockFile.cpp.

References BlockFile::CommonReadData(), BlockFile::LockForRead(), AliasBlockFile::mAliasChannel, AliasBlockFile::mAliasedFileName, AliasBlockFile::mAliasStart, AliasBlockFile::mSilentAliasLog, and SAMPLE_SIZE.

Referenced by WriteSummary().

500 {
501 
502  auto locker = LockForRead();
503 
504  if(!mAliasedFileName.IsOk()){ // intentionally silenced
505  memset(data,0,SAMPLE_SIZE(format)*len);
506  return len;
507  }
508 
509  return CommonReadData( mayThrow,
511  data, format, start, len);
512 }
ReadLock LockForRead() const
Definition: BlockFile.h:200
const int mAliasChannel
Definition: BlockFile.h:291
#define SAMPLE_SIZE(SampleFormat)
Definition: Types.h:198
wxFileNameWrapper mAliasedFileName
Definition: BlockFile.h:289
int format
Definition: ExportPCM.cpp:56
bool mSilentAliasLog
Definition: BlockFile.h:292
sampleCount mAliasStart
Definition: BlockFile.h:290
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)
Definition: BlockFile.cpp:483
bool ODPCMAliasBlockFile::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 520 of file ODPCMAliasBlockFile.cpp.

References BlockFile::FixSummary(), BlockFile::mFileName, mFileNameMutex, BlockFile::mSilentLog, BlockFile::mSummaryInfo, ArrayOf< X >::reinit(), and SummaryInfo::totalSummaryBytes.

521 {
523 
524  ODLocker locker{ &mFileNameMutex };
525  wxFFile summaryFile(mFileName.GetFullPath(), wxT("rb"));
526 
527  if( !summaryFile.IsOpened() ) {
528 
529  // NEW model; we need to return valid data
530  memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
531 
532  // we silence the logging for this operation in this object
533  // after first occurrence of error; it's already reported and
534  // spewing at the user will complicate the user's ability to
535  // deal
536  mSilentLog = TRUE;
537 
538  return false;
539  }
540  else
541  mSilentLog = FALSE; // worked properly, any future error is NEW
542 
543  auto read = summaryFile.Read(data.get(), mSummaryInfo.totalSummaryBytes);
544 
545  if (read != mSummaryInfo.totalSummaryBytes) {
546  memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
547  return false;
548  }
549 
550  FixSummary(data.get());
551 
552  return true;
553 }
wxFileNameWrapper mFileName
Definition: BlockFile.h:235
void reinit(Integral count, bool initialize=false)
Definition: MemoryX.h:117
bool mSilentLog
Definition: BlockFile.h:239
SummaryInfo mSummaryInfo
Definition: BlockFile.h:237
size_t totalSummaryBytes
Definition: BlockFile.h:41
virtual void FixSummary(void *data)
Definition: BlockFile.cpp:331
void ODPCMAliasBlockFile::Recover ( void  )
overridevirtual

Writes the summary file if summary data is available.

Implements BlockFile.

Definition at line 339 of file ODPCMAliasBlockFile.cpp.

References IsSummaryAvailable(), and WriteSummary().

340 {
341  if(IsSummaryAvailable())
342  {
343  WriteSummary();
344  }
345 }
bool IsSummaryAvailable() const override
Returns TRUE if this block's complete summary has been computed and is ready (for OD) ...
void WriteSummary() override
Write the summary to disk, using the derived ReadData() to get the data.
void ODPCMAliasBlockFile::SaveXML ( XMLWriter xmlFile)
overridevirtual

Saves as xml ODPCMAliasBlockFile or PCMAliasBlockFile depending on summary availability.

Writes the xml as a PCMAliasBlockFile 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 exist, 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 241 of file ODPCMAliasBlockFile.cpp.

References sampleCount::as_long_long(), XMLWriter::EndTag(), IsSummaryAvailable(), BlockFile::LockForRead(), AliasBlockFile::mAliasChannel, AliasBlockFile::mAliasedFileName, AliasBlockFile::mAliasStart, BlockFile::mFileName, mFileNameMutex, mHasBeenSaved, BlockFile::mLen, PCMAliasBlockFile::SaveXML(), XMLWriter::StartTag(), and XMLWriter::WriteAttr().

243 {
244  //we lock this so that mAliasedFileName doesn't change.
245  auto locker = LockForRead();
246  if(IsSummaryAvailable())
247  {
249  mHasBeenSaved = true;
250  }
251  else
252  {
253  xmlFile.StartTag(wxT("odpcmaliasblockfile"));
254 
255  //unlock to prevent deadlock and resume lock after.
256  {
257  auto suspension = locker.Suspend();
258  ODLocker locker2 { &mFileNameMutex };
259  xmlFile.WriteAttr(wxT("summaryfile"), mFileName.GetFullName());
260  }
261 
262  xmlFile.WriteAttr(wxT("aliasfile"), mAliasedFileName.GetFullPath());
263  xmlFile.WriteAttr(wxT("aliasstart"),
265  xmlFile.WriteAttr(wxT("aliaslen"), mLen);
266  xmlFile.WriteAttr(wxT("aliaschannel"), mAliasChannel);
267 
268  xmlFile.EndTag(wxT("odpcmaliasblockfile"));
269  }
270 }
ReadLock LockForRead() const
Definition: BlockFile.h:200
const int mAliasChannel
Definition: BlockFile.h:291
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:78
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
void SaveXML(XMLWriter &xmlFile) override
Stores a representation of this file in XML.
wxFileNameWrapper mAliasedFileName
Definition: BlockFile.h:289
bool IsSummaryAvailable() const override
Returns TRUE if this block's complete summary has been computed and is ready (for OD) ...
sampleCount mAliasStart
Definition: BlockFile.h:290
size_t mLen
Definition: BlockFile.h:236
long long as_long_long() const
Definition: Types.h:90
void ODPCMAliasBlockFile::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 105 of file ODPCMAliasBlockFile.h.

References mClipOffset.

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

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

Reimplemented from BlockFile.

Definition at line 365 of file ODPCMAliasBlockFile.cpp.

References BlockFile::mFileName, mFileNameMutex, and name.

366 {
367  mFileNameMutex.Lock();
368  mFileName = std::move(name);
369  mFileNameMutex.Unlock();
370 }
wxFileNameWrapper mFileName
Definition: BlockFile.h:235
void ODPCMAliasBlockFile::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 93 of file ODPCMAliasBlockFile.h.

References mStart.

Referenced by ODComputeSummaryTask::Update().

93 {mStart = startSample;}
sampleCount mStart
for reporting after task is complete. Only for display use.
void ODPCMAliasBlockFile::Unlock ( )
overridevirtual

Unlocks the blockfile only if it has a file that exists.

unlocks the blockfile only if it has a file that exists. This needs to be done so that the unsaved ODPCMAliasBlockfiles are deleted upon exit

Reimplemented from BlockFile.

Definition at line 118 of file ODPCMAliasBlockFile.cpp.

References BlockFile::IsLocked(), IsSummaryAvailable(), and BlockFile::Unlock().

119 {
120  if(IsSummaryAvailable() && IsLocked())
122 }
virtual bool IsLocked()
Returns TRUE if this BlockFile is locked.
Definition: BlockFile.cpp:162
bool IsSummaryAvailable() const override
Returns TRUE if this block's complete summary has been computed and is ready (for OD) ...
virtual void Unlock()
Unlock this BlockFile, allowing it to be moved.
Definition: BlockFile.cpp:155
void ODPCMAliasBlockFile::UnlockRead ( ) const
overridevirtual

Allows reading on other threads.

Reimplemented from BlockFile.

Definition at line 561 of file ODPCMAliasBlockFile.cpp.

References mReadDataMutex.

562 {
563  mReadDataMutex.Unlock();
564 }
void ODPCMAliasBlockFile::WriteSummary ( )
overrideprotectedvirtual

Write the summary to disk, using the derived ReadData() to get the data.

Reimplemented from AliasBlockFile.

Definition at line 379 of file ODPCMAliasBlockFile.cpp.

References CalcSummary(), floatSample, BlockFile::mFileName, mFileNameMutex, BlockFile::mLen, mSummaryAvailable, mSummaryAvailableMutex, BlockFile::mSummaryInfo, SampleBuffer::ptr(), FileException::Read, ReadData(), and SummaryInfo::totalSummaryBytes.

Referenced by DoWriteSummary(), and Recover().

380 {
381  // To build the summary data, call ReadData (implemented by the
382  // derived classes) to get the sample data
383  // Call this first, so that in case of exceptions from ReadData, there is
384  // no NEW output file
385  SampleBuffer sampleData(mLen, floatSample);
386  this->ReadData(sampleData.ptr(), floatSample, 0, mLen, true);
387 
388  ArrayOf< char > fileNameChar;
389  FILE *summaryFile{};
390  {
391  //the mFileName path may change, for example, when the project is saved.
392  //(it moves from /tmp/ to wherever it is saved to.
393  ODLocker locker { &mFileNameMutex };
394 
395  //wxFFile is not thread-safe - if any error occurs in opening the file,
396  // it posts a wxlog message which WILL crash
397  // Audacity because it goes into the wx GUI.
398  // For this reason I left the wxFFile method commented out. (mchinen)
399  // wxFFile summaryFile(mFileName.GetFullPath(), wxT("wb"));
400 
401  // ...and we use fopen instead.
402  wxString sFullPath = mFileName.GetFullPath();
403  fileNameChar.reinit( strlen(sFullPath.mb_str(wxConvFile)) + 1 );
404  strcpy(fileNameChar.get(), sFullPath.mb_str(wxConvFile));
405  summaryFile = fopen(fileNameChar.get(), "wb");
406  }
407 
408  // JKC ANSWER-ME: Whay is IsOpened() commented out?
409  if (!summaryFile){//.IsOpened() ){
410 
411  // Never silence the Log w.r.t write errors; they always count
412  //however, this is going to be called from a non-main thread,
413  //and wxLog calls are not thread safe.
414  wxPrintf("Unable to write summary data to file: %s", fileNameChar.get());
415 
416  throw FileException{
417  FileException::Cause::Read, wxFileName{ fileNameChar.get() } };
418  }
419 
420  ArrayOf<char> cleanup;
421  void *summaryData = CalcSummary(sampleData.ptr(), mLen,
422  floatSample, cleanup);
423 
424  //summaryFile.Write(summaryData, mSummaryInfo.totalSummaryBytes);
425  fwrite(summaryData, 1, mSummaryInfo.totalSummaryBytes, summaryFile);
426  fclose(summaryFile);
427 
428 
429  // wxPrintf("write successful. filename: %s\n", fileNameChar);
430 
431  mSummaryAvailableMutex.Lock();
432  mSummaryAvailable=true;
433  mSummaryAvailableMutex.Unlock();
434 }
wxFileNameWrapper mFileName
Definition: BlockFile.h:235
SummaryInfo mSummaryInfo
Definition: BlockFile.h:237
size_t totalSummaryBytes
Definition: BlockFile.h:41
void * CalcSummary(samplePtr buffer, size_t len, sampleFormat format, ArrayOf< char > &cleanup) override
size_t mLen
Definition: BlockFile.h:236
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.

Member Data Documentation

ODLock ODPCMAliasBlockFile::mAliasedFileNameMutex
private

Also need to protect the aliased file name.

Definition at line 153 of file ODPCMAliasBlockFile.h.

sampleCount ODPCMAliasBlockFile::mClipOffset
private

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

Definition at line 167 of file ODPCMAliasBlockFile.h.

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

ODLock ODPCMAliasBlockFile::mFileNameMutex
mutableprivate
bool ODPCMAliasBlockFile::mHasBeenSaved
private

Definition at line 161 of file ODPCMAliasBlockFile.h.

Referenced by CloseLock(), Copy(), Lock(), ODPCMAliasBlockFile(), and SaveXML().

ODLock ODPCMAliasBlockFile::mReadDataMutex
mutableprivate

Definition at line 156 of file ODPCMAliasBlockFile.h.

Referenced by LockRead(), and UnlockRead().

sampleCount ODPCMAliasBlockFile::mStart
private

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

Definition at line 164 of file ODPCMAliasBlockFile.h.

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

bool ODPCMAliasBlockFile::mSummaryAvailable
private

Definition at line 159 of file ODPCMAliasBlockFile.h.

Referenced by IsSummaryAvailable(), ODPCMAliasBlockFile(), and WriteSummary().

ODLock ODPCMAliasBlockFile::mSummaryAvailableMutex
mutableprivate

Definition at line 158 of file ODPCMAliasBlockFile.h.

Referenced by IsSummaryAvailable(), and WriteSummary().

bool ODPCMAliasBlockFile::mSummaryBeingComputed
private

Definition at line 160 of file ODPCMAliasBlockFile.h.

Referenced by IsSummaryBeingComputed(), and ODPCMAliasBlockFile().

ODLock ODPCMAliasBlockFile::mWriteSummaryMutex
private

Definition at line 147 of file ODPCMAliasBlockFile.h.

Referenced by DoWriteSummary().


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