Audacity  2.2.0
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 ()
 Locks the blockfile only if it has a file that exists. More...
 
void Unlock ()
 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 = movable_ptr_with_deleter< 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.

Constructor & Destructor Documentation

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

Constructs a PCMAliasBlockFile, writing the summary to disk.

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.

References mHasBeenSaved, mSummaryAvailable, and mSummaryBeingComputed.

ODPCMAliasBlockFile::~ODPCMAliasBlockFile ( )
virtual

Member Function Documentation

BlockFilePtr ODPCMAliasBlockFile::BuildFromXML ( DirManager dm,
const wxChar **  attrs 
)
static
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.

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

Referenced by WriteSummary().

void ODPCMAliasBlockFile::CloseLock ( )
overridevirtual

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

Reimplemented from BlockFile.

References BlockFile::Lock(), and mHasBeenSaved.

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.

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

void ODPCMAliasBlockFile::DoWriteSummary ( )

A public interface to WriteSummary.

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

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

sampleCount ODPCMAliasBlockFile::GetClipOffset ( ) const
inline

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

References mClipOffset.

auto ODPCMAliasBlockFile::GetFileName ( ) const
overridevirtual

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

Reimplemented from BlockFile.

References BlockFile::mFileName, and mFileNameMutex.

sampleCount ODPCMAliasBlockFile::GetGlobalEnd ( ) const
inline
sampleCount ODPCMAliasBlockFile::GetGlobalStart ( ) const
inline

References mClipOffset, and mStart.

auto ODPCMAliasBlockFile::GetMinMaxRMS ( size_t  start,
size_t  len,
bool  mayThrow 
) const
overridevirtual

Gets extreme values for the specified region.

Reimplemented from BlockFile.

References BlockFile::GetMinMaxRMS(), and JUST_BELOW_MAX_AUDIO.

auto ODPCMAliasBlockFile::GetMinMaxRMS ( bool  mayThrow) const
overridevirtual

Gets extreme values for the entire block.

Reimplemented from BlockFile.

References BlockFile::GetMinMaxRMS(), and JUST_BELOW_MAX_AUDIO.

auto ODPCMAliasBlockFile::GetSpaceUsage ( ) const
overridevirtual
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.

References mStart.

bool ODPCMAliasBlockFile::IsSummaryAvailable ( ) const
overridevirtual

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

Reimplemented from BlockFile.

References mSummaryAvailable, and mSummaryAvailableMutex.

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

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.

References mSummaryBeingComputed.

void ODPCMAliasBlockFile::Lock ( )
virtual

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.

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

void ODPCMAliasBlockFile::LockRead ( ) const
overridevirtual

Prevents a read on other threads.

Reimplemented from BlockFile.

References mReadDataMutex.

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.

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

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.

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

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.

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

Referenced by WriteSummary().

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.

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

void ODPCMAliasBlockFile::Recover ( void  )
overridevirtual

Writes the summary file if summary data is available.

Implements BlockFile.

References IsSummaryAvailable(), and WriteSummary().

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.

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

void ODPCMAliasBlockFile::SetClipOffset ( sampleCount  numSamples)
inline

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

References mClipOffset.

void ODPCMAliasBlockFile::SetFileName ( wxFileNameWrapper &&  name)
overridevirtual

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

Reimplemented from BlockFile.

References BlockFile::mFileName, mFileNameMutex, and name.

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.

References mStart.

Referenced by ODComputeSummaryTask::Update().

void ODPCMAliasBlockFile::Unlock ( )
virtual

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.

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

void ODPCMAliasBlockFile::UnlockRead ( ) const
overridevirtual

Allows reading on other threads.

Reimplemented from BlockFile.

References mReadDataMutex.

void ODPCMAliasBlockFile::WriteSummary ( )
overrideprotectedvirtual

Member Data Documentation

ODLock ODPCMAliasBlockFile::mAliasedFileNameMutex
private

Also need to protect the aliased file name.

sampleCount ODPCMAliasBlockFile::mClipOffset
private

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

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

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

Referenced by LockRead(), and UnlockRead().

sampleCount ODPCMAliasBlockFile::mStart
private

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

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

bool ODPCMAliasBlockFile::mSummaryAvailable
private
ODLock ODPCMAliasBlockFile::mSummaryAvailableMutex
mutableprivate

Referenced by IsSummaryAvailable(), and WriteSummary().

bool ODPCMAliasBlockFile::mSummaryBeingComputed
private
ODLock ODPCMAliasBlockFile::mWriteSummaryMutex
private

Referenced by DoWriteSummary().


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