Audacity  2.2.0
SimpleBlockFile Class Reference

A BlockFile that reads and writes uncompressed data using libsndfile. More...

#include <SimpleBlockFile.h>

Inheritance diagram for SimpleBlockFile:
BlockFile ODDecodeBlockFile

Public Member Functions

 SimpleBlockFile (wxFileNameWrapper &&baseFileName, samplePtr sampleData, size_t sampleLen, sampleFormat format, bool allowDeferredWrite=false, bool bypassCache=false)
 Create a disk file and write summary and sample data to it. More...
 SimpleBlockFile (wxFileNameWrapper &&existingFile, size_t len, float min, float max, float rms)
 Create the memory structure to refer to the given block file. More...
virtual ~SimpleBlockFile ()
bool ReadSummary (ArrayOf< char > &data) override
 Read the summary section of the disk file. More...
size_t ReadData (samplePtr data, sampleFormat format, size_t start, size_t len, bool mayThrow) const override
 Read the data section of the disk file. More...
BlockFilePtr Copy (wxFileNameWrapper &&newFileName) override
 Create a NEW block file identical to this one. More...
void SaveXML (XMLWriter &xmlFile) override
 Write an XML representation of this file. More...
DiskByteCount GetSpaceUsage () const override
void Recover () override
 if the on-disk state disappeared, either recover it (if it was More...
bool GetNeedWriteCacheToDisk () override
void WriteCacheToDisk () override
bool GetNeedFillCache () override
void FillCache () override
- Public Member Functions inherited from BlockFile
 BlockFile (wxFileNameWrapper &&fileName, size_t samples)
 Construct a BlockFile. More...
virtual ~BlockFile ()
virtual GetFileNameResult GetFileName () const
virtual void SetFileName (wxFileNameWrapper &&name)
 sets the file name the summary info will be saved in. threadsafe. More...
size_t GetLength () const
void SetLength (size_t newLen)
virtual void Lock ()
 Locks this BlockFile, to prevent it from being moved. More...
virtual void Unlock ()
 Unlock this BlockFile, allowing it to be moved. More...
virtual bool IsLocked ()
 Returns TRUE if this BlockFile is locked. More...
virtual MinMaxRMS GetMinMaxRMS (size_t start, size_t len, bool mayThrow=true) const
 Gets extreme values for the specified region. More...
virtual MinMaxRMS GetMinMaxRMS (bool mayThrow=true) const
 Gets extreme values for the entire block. More...
virtual bool Read256 (float *buffer, size_t start, size_t len)
 Returns the 256 byte summary data block. More...
virtual bool Read64K (float *buffer, size_t start, size_t len)
 Returns the 64K summary data block. More...
virtual bool IsAlias () const
 Returns TRUE if this block references another disk file. More...
virtual bool IsSummaryAvailable () const
 Returns TRUE if this block's complete summary has been computed and is ready (for OD) More...
virtual bool IsDataAvailable () const
 Returns TRUE if this block's complete data is ready to be accessed by Read() More...
virtual bool IsSummaryBeingComputed ()
 Returns TRUE if the summary has not yet been written, but is actively being computed and written to disk. More...
void SilenceLog () const
 if we've detected an on-disk problem, the user opted to More...
virtual void CloseLock ()
ReadLock LockForRead () const

Static Public Member Functions

static BlockFilePtr BuildFromXML (DirManager &dm, const wxChar **attrs)
 static More...

Protected Member Functions

bool WriteSimpleBlockFile (samplePtr sampleData, size_t sampleLen, sampleFormat format, void *summaryData)
void ReadIntoCache ()
- Protected Member Functions inherited from BlockFile
virtual void LockRead () const
 Prevents a read on other threads. The basic blockfile runs on only one thread, so does nothing. More...
virtual void UnlockRead () const
 Allows reading on other threads. More...
virtual void * CalcSummary (samplePtr buffer, size_t len, sampleFormat format, ArrayOf< char > &cleanup)
void CalcSummaryFromBuffer (const float *fbuffer, size_t len, float *summary256, float *summary64K)
virtual void FixSummary (void *data)

Static Protected Member Functions

static bool GetCache ()
- Static Protected Member Functions inherited from BlockFile
static size_t CommonReadData (bool mayThrow, const wxFileName &fileName, bool &mSilentLog, const AliasBlockFile *pAliasFile, sampleCount origin, unsigned channel, samplePtr data, sampleFormat format, size_t start, size_t len, const sampleFormat *pLegacyFormat=nullptr, size_t legacyLen=0)

Protected Attributes

SimpleBlockFileCache mCache
- Protected Attributes inherited from BlockFile
wxFileNameWrapper mFileName
size_t mLen
SummaryInfo mSummaryInfo
float mMin
float mMax
float mRMS
bool mSilentLog

Private Attributes

sampleFormat mFormat

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 >

Detailed Description

A BlockFile that reads and writes uncompressed data using libsndfile.

A block file that writes the audio data to an .au file and reads it back using libsndfile.

There are two ways to construct a simple block file. One is to supply data and have the constructor write the file. The other is for when the file already exists and we simply want to create the data structure to refer to it.

The block file can be cached in two ways. Caching is enabled if the preference "/Directories/CacheBlockFiles" is set, otherwise disabled. The default is to disable caching.

Read-caching: If caching is enabled, all block files will always be read-cached. Block files on disk will be read as soon as they are created and held in memory. New block files will be written to disk, but held in memory, so they are never read from disk in the current session.

Write-caching: If caching is enabled and the parameter allowDeferredWrite is enabled at the block file constructor, NEW block files are held in memory and written to disk only when WriteCacheToDisk() is called. This is used during recording to prevent disk access. After recording, WriteCacheToDisk() will be called on all block files and they will be written to disk. During normal editing, no write cache is active, that is, any block files will be written to disk instantly.

Even with write cache, auto recovery during normal editing will work as expected. However, auto recovery during recording will not work (not even manual auto recovery, because the files are never written physically to disk).

Constructor & Destructor Documentation

SimpleBlockFile::SimpleBlockFile ( wxFileNameWrapper &&  baseFileName,
samplePtr  sampleData,
size_t  sampleLen,
sampleFormat  format,
bool  allowDeferredWrite = false,
bool  bypassCache = false 

Create a disk file and write summary and sample data to it.

Constructs a SimpleBlockFile based on sample data and writes it to disk.

baseFileNameThe filename to use, but without an extension. This constructor will add the appropriate extension (.au in this case).
sampleDataThe sample data to be written to this block.
sampleLenThe number of samples to be written to this block.
formatThe format of the given samples.
allowDeferredWriteAllow deferred write-caching

References SimpleBlockFileCache::active, BlockFile::CalcSummary(), SimpleBlockFileCache::format, format, GetCache(), BlockFile::GetFileName(), mCache, mFormat, BlockFile::mSummaryInfo, BlockFile::GetFileNameResult::name, SimpleBlockFileCache::needWrite, ArrayOf< X >::reinit(), SimpleBlockFileCache::sampleData, SimpleBlockFileCache::summaryData, SummaryInfo::totalSummaryBytes, FileException::Write, and WriteSimpleBlockFile().

SimpleBlockFile::SimpleBlockFile ( wxFileNameWrapper &&  existingFile,
size_t  len,
float  min,
float  max,
float  rms 

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

Construct a SimpleBlockFile memory structure that will point to an existing block file. This file must exist and be a valid block file.

existingFileThe disk file this SimpleBlockFile should use.
SimpleBlockFile::~SimpleBlockFile ( )

Member Function Documentation

BlockFilePtr SimpleBlockFile::Copy ( wxFileNameWrapper &&  newFileName)

Create a NEW block file identical to this one.

Create a copy of this BlockFile, but using a different disk file.

newFileNameThe name of the NEW file to use.

Implements BlockFile.

References BlockFile::mLen, BlockFile::mMax, BlockFile::mMin, and BlockFile::mRMS.

Referenced by ODDecodeBlockFile::Copy().

bool SimpleBlockFile::GetCache ( )

References GetFreeMemory(), and gPrefs.

Referenced by SimpleBlockFile().

bool SimpleBlockFile::GetNeedFillCache ( )

Reimplemented from BlockFile.

bool SimpleBlockFile::GetNeedWriteCacheToDisk ( )
size_t SimpleBlockFile::ReadData ( samplePtr  data,
sampleFormat  format,
size_t  start,
size_t  len,
bool  mayThrow 
) const

Read the data section of the disk file.

Read the data portion of the block file using libsndfile. Convert it to the given format if it is not already.

dataThe buffer where the data will be stored
formatThe format the data will be stored in
startThe offset in this block file
lenThe number of samples to read

Implements BlockFile.

References SimpleBlockFileCache::active, ClearSamples(), BlockFile::CommonReadData(), CopySamples(), SimpleBlockFileCache::format, mCache, BlockFile::mFileName, min(), BlockFile::mLen, BlockFile::mSilentLog, FileException::Read, and SimpleBlockFileCache::sampleData.

Referenced by FillCache(), and ODDecodeBlockFile::ReadData().

void SimpleBlockFile::ReadIntoCache ( )
bool SimpleBlockFile::ReadSummary ( ArrayOf< char > &  data)

Read the summary section of the disk file.

Read the summary section of the disk file.

*dataThe buffer to write the data to. It must be at least mSummaryinfo.totalSummaryBytes long.

Implements BlockFile.

References SimpleBlockFileCache::active, Maybe< X >::create(), BlockFile::FixSummary(), mCache, BlockFile::mFileName, BlockFile::mSilentLog, BlockFile::mSummaryInfo, ArrayOf< X >::reinit(), SimpleBlockFileCache::summaryData, and SummaryInfo::totalSummaryBytes.

Referenced by FillCache(), and ODDecodeBlockFile::ReadSummary().

void SimpleBlockFile::Recover ( )
void SimpleBlockFile::SaveXML ( XMLWriter xmlFile)

Member Data Documentation

sampleFormat SimpleBlockFile::mFormat

Referenced by GetSpaceUsage(), and SimpleBlockFile().

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