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

Audacity 1.1.0 block file format: More...

#include <LegacyBlockFile.h>

Inheritance diagram for LegacyBlockFile:
BlockFile

Public Member Functions

 LegacyBlockFile (wxFileNameWrapper &&existingFile, sampleFormat format, size_t summaryLen, size_t len, bool noRMS)
 Create the memory structure to refer to the given block file. More...
 
virtual ~LegacyBlockFile ()
 
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...
 
- 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 ()
 
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 (const wxString &dir, const wxChar **attrs, size_t len, sampleFormat format)
 static More...
 

Protected Attributes

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

Additional Inherited Members

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

Detailed Description

Audacity 1.1.0 block file format:

Definition at line 35 of file LegacyBlockFile.h.

Constructor & Destructor Documentation

LegacyBlockFile::LegacyBlockFile ( wxFileNameWrapper &&  existingFile,
sampleFormat  format,
size_t  summaryLen,
size_t  len,
bool  noRMS 
)

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

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

Parameters
existingFileThe disk file this LegacyBlockFile should use.

Definition at line 127 of file LegacyBlockFile.cpp.

131  :
132  BlockFile{ std::move(existingFile), len },
133  mFormat(format)
134 {
135 
136  sampleFormat summaryFormat;
137 
138  if (noRMS)
139  summaryFormat = int16Sample;
140  else
141  summaryFormat = floatSample;
142 
144  summaryLen, summaryFormat,
145  &mSummaryInfo, noRMS, FALSE,
146  &mMin, &mMax, &mRMS);
147 }
A BlockFile is a chunk of immutable audio data.
Definition: BlockFile.h:56
wxFileNameWrapper mFileName
Definition: BlockFile.h:235
void ComputeLegacySummaryInfo(const wxFileName &fileName, size_t summaryLen, sampleFormat format, SummaryInfo *info, bool noRMS, bool Silent, float *min, float *max, float *rms)
sampleFormat mFormat
SummaryInfo mSummaryInfo
Definition: BlockFile.h:237
float mMin
Definition: BlockFile.h:238
int format
Definition: ExportPCM.cpp:56
sampleFormat
Definition: Types.h:188
float mRMS
Definition: BlockFile.h:238
float mMax
Definition: BlockFile.h:238
LegacyBlockFile::~LegacyBlockFile ( )
virtual

Definition at line 149 of file LegacyBlockFile.cpp.

150 {
151 }

Member Function Documentation

BlockFilePtr LegacyBlockFile::BuildFromXML ( const wxString &  dir,
const wxChar **  attrs,
size_t  len,
sampleFormat  format 
)
static

static

Definition at line 224 of file LegacyBlockFile.cpp.

References format, XMLValueChecker::IsGoodFileName(), XMLValueChecker::IsGoodInt(), and XMLValueChecker::IsValidSampleFormat().

Referenced by DirManager::HandleXMLTag().

226 {
227  wxFileNameWrapper fileName;
228  size_t summaryLen = 0;
229  bool noRMS = false;
230  long nValue;
231 
232  while(*attrs)
233  {
234  const wxChar *attr = *attrs++;
235  const wxChar *value = *attrs++;
236  if (!value)
237  break;
238 
239  const wxString strValue = value;
240  if (!wxStricmp(attr, wxT("name")) && XMLValueChecker::IsGoodFileName(strValue, projDir))
241  //v Should this be
242  // dm.AssignFile(fileName, strValue, false);
243  // as in PCMAliasBlockFile::BuildFromXML? Test with an old project.
244  fileName.Assign(projDir, strValue);
245  else if (XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
246  { // integer parameters
247  if (!wxStrcmp(attr, wxT("len")) && (nValue >= 0))
248  len = nValue;
249  else if (!wxStrcmp(attr, wxT("norms")))
250  noRMS = (nValue != 0);
251  else if (!wxStrcmp(attr, wxT("format")) && XMLValueChecker::IsValidSampleFormat(nValue))
252  format = (sampleFormat)nValue;
253  else if (!wxStrcmp(attr, wxT("summarylen")) && (nValue > 0))
254  // Note attribute "summarylen" was written as int, no need for 64 bits
255  summaryLen = nValue;
256  }
257  }
258 
259  return make_blockfile<LegacyBlockFile>
260  (std::move(fileName), format, summaryLen, len, noRMS);
261 }
static bool IsGoodInt(const wxString &strInt)
Check that the supplied string can be converted to a long (32bit) integer.
int format
Definition: ExportPCM.cpp:56
sampleFormat
Definition: Types.h:188
static bool IsValidSampleFormat(const int nValue)
static bool IsGoodFileName(const wxString &strFileName, const wxString &strDirName=wxEmptyString)
BlockFilePtr LegacyBlockFile::Copy ( wxFileNameWrapper &&  newFileName)
overridevirtual

Create a NEW block file identical to this one.

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

Parameters
newFileNameThe name of the NEW file to use.

Implements BlockFile.

Definition at line 266 of file LegacyBlockFile.cpp.

References SummaryInfo::fields, mFormat, BlockFile::mLen, BlockFile::mSummaryInfo, and SummaryInfo::totalSummaryBytes.

267 {
268  return make_blockfile<LegacyBlockFile>
269  (std::move(newFileName),
271  mLen, mSummaryInfo.fields < 3);
272 }
sampleFormat mFormat
SummaryInfo mSummaryInfo
Definition: BlockFile.h:237
size_t totalSummaryBytes
Definition: BlockFile.h:41
size_t mLen
Definition: BlockFile.h:236
int fields
Definition: BlockFile.h:34
auto LegacyBlockFile::GetSpaceUsage ( ) const
overridevirtual

Implements BlockFile.

Definition at line 274 of file LegacyBlockFile.cpp.

References BlockFile::mFileName.

275 {
276  wxFFile dataFile(mFileName.GetFullPath());
277  return dataFile.Length();
278 }
wxFileNameWrapper mFileName
Definition: BlockFile.h:235
size_t LegacyBlockFile::ReadData ( samplePtr  data,
sampleFormat  format,
size_t  start,
size_t  len,
bool  mayThrow 
) const
overridevirtual

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.

Parameters
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.

Definition at line 196 of file LegacyBlockFile.cpp.

References BlockFile::CommonReadData(), BlockFile::mFileName, mFormat, BlockFile::mLen, BlockFile::mSilentLog, BlockFile::mSummaryInfo, SAMPLE_SIZE, and SummaryInfo::totalSummaryBytes.

198 {
199  sf_count_t origin = (mSummaryInfo.totalSummaryBytes / SAMPLE_SIZE(mFormat));
200  return CommonReadData( mayThrow,
201  mFileName, mSilentLog, nullptr, origin, 0, data, format, start, len,
202  &mFormat, mLen
203  );
204 }
wxFileNameWrapper mFileName
Definition: BlockFile.h:235
#define SAMPLE_SIZE(SampleFormat)
Definition: Types.h:198
bool mSilentLog
Definition: BlockFile.h:239
sampleFormat mFormat
SummaryInfo mSummaryInfo
Definition: BlockFile.h:237
int format
Definition: ExportPCM.cpp:56
size_t totalSummaryBytes
Definition: BlockFile.h:41
size_t mLen
Definition: BlockFile.h:236
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 LegacyBlockFile::ReadSummary ( ArrayOf< char > &  data)
overridevirtual

Read the summary section of the disk file.

Read the summary section of the disk file. Fill with zeroes and return false if data are unavailable for any reason.

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

Implements BlockFile.

Definition at line 158 of file LegacyBlockFile.cpp.

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

159 {
161  wxFFile summaryFile(mFileName.GetFullPath(), wxT("rb"));
162  size_t read;
163  {
164  Maybe<wxLogNull> silence{};
165  if (mSilentLog)
166  silence.create();
167 
168  if (!summaryFile.IsOpened()) {
169 
170  memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
171 
172  mSilentLog = TRUE;
173 
174  return false;
175  }
176 
177  read = summaryFile.Read(data.get(), mSummaryInfo.totalSummaryBytes);
178  }
179  mSilentLog = FALSE;
180 
181  if (read != mSummaryInfo.totalSummaryBytes) {
182  memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
183  return false;
184  }
185 
186  return true;
187 }
wxFileNameWrapper mFileName
Definition: BlockFile.h:235
void reinit(Integral count, bool initialize=false)
Definition: MemoryX.h:117
bool mSilentLog
Definition: BlockFile.h:239
Definition: MemoryX.h:204
SummaryInfo mSummaryInfo
Definition: BlockFile.h:237
size_t totalSummaryBytes
Definition: BlockFile.h:41
void create(Args &&...args)
Definition: MemoryX.h:251
void LegacyBlockFile::Recover ( )
overridevirtual

if the on-disk state disappeared, either recover it (if it was

Implements BlockFile.

Definition at line 280 of file LegacyBlockFile.cpp.

281 {
282 
283 
284 }
void LegacyBlockFile::SaveXML ( XMLWriter xmlFile)
overridevirtual

Write an XML representation of this file.

Implements BlockFile.

Definition at line 206 of file LegacyBlockFile.cpp.

References XMLWriter::EndTag(), SummaryInfo::fields, BlockFile::mFileName, BlockFile::mLen, BlockFile::mSummaryInfo, XMLWriter::StartTag(), SummaryInfo::totalSummaryBytes, and XMLWriter::WriteAttr().

208 {
209  xmlFile.StartTag(wxT("legacyblockfile"));
210 
211  xmlFile.WriteAttr(wxT("name"), mFileName.GetFullName());
212  xmlFile.WriteAttr(wxT("len"), mLen);
213  if (mSummaryInfo.fields < 3)
214  xmlFile.WriteAttr(wxT("norms"), 1);
215  xmlFile.WriteAttr(wxT("summarylen"), mSummaryInfo.totalSummaryBytes);
216 
217  xmlFile.EndTag(wxT("legacyblockfile"));
218 }
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
SummaryInfo mSummaryInfo
Definition: BlockFile.h:237
size_t totalSummaryBytes
Definition: BlockFile.h:41
size_t mLen
Definition: BlockFile.h:236
int fields
Definition: BlockFile.h:34

Member Data Documentation

sampleFormat LegacyBlockFile::mFormat
protected

Definition at line 68 of file LegacyBlockFile.h.

Referenced by Copy(), and ReadData().


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