|
Audacity
3.0.3
|
Go to the documentation of this file.
19 #include "../Audacity.h"
25 #include <wx/wxcrtvararg.h>
27 #include <wx/thread.h>
30 #include "../DirManager.h"
31 #include "../FileFormats.h"
32 #include "../ondemand/ODManager.h"
42 size_t aliasLen,
int aliasChannel,
unsigned int decodeType)
49 mAliasStart(aliasStart),
50 mAliasChannel(aliasChannel)
53 mAudioFileName = std::move(audioFileName);
67 size_t aliasLen,
int aliasChannel,
unsigned int decodeType,
68 float min,
float max,
float rms,
bool dataAvailable):
72 mDataAvailable( dataAvailable ),
73 mAliasStart(aliasStart),
74 mAliasChannel(aliasChannel)
77 mAudioFileName = std::move(audioFileName);
94 wxFFile summaryFile(mFileName.GetFullPath());
95 return summaryFile.Length();
106 size_t start,
size_t len,
bool mayThrow)
const ->
MinMaxRMS
108 if(IsSummaryAvailable())
110 return SimpleBlockFile::GetMinMaxRMS(start, len, mayThrow);
128 if(IsSummaryAvailable())
130 return SimpleBlockFile::GetMinMaxRMS(mayThrow);
151 return SimpleBlockFile::Read256(buffer,start,len);
166 return SimpleBlockFile::Read64K(buffer,start,len);
181 BlockFilePtr newBlockFile;
184 auto locker = LockForRead();
193 newBlockFile = make_blockfile<ODDecodeBlockFile>
212 auto locker = LockForRead();
219 xmlFile.
StartTag(wxT(
"oddecodeblockfile"));
222 auto suspension = locker.Suspend();
224 xmlFile.
WriteAttr(wxT(
"summaryfile"), mFileName.GetFullName());
229 xmlFile.
WriteAttr(wxT(
"aliaslen"), mLen);
233 xmlFile.
EndTag(wxT(
"oddecodeblockfile"));
251 unsigned int decodeType=0;
255 const wxChar *attr = *attrs++;
256 const wxChar *value = *attrs++;
260 const wxString strValue = value;
261 if (!wxStricmp(attr, wxT(
"summaryfile")) &&
266 if (!dm.AssignFile(summaryFileName, strValue,
false))
268 summaryFileName.Clear();
270 else if( !wxStricmp(attr, wxT(
"audiofile")) )
273 audioFileName.Assign(strValue);
276 audioFileName.Assign(dm.GetProjectDataDir(), strValue);
281 audioFileName.Assign(strValue);
283 else if ( !wxStricmp(attr, wxT(
"aliasstart")) )
286 strValue.ToLongLong(&nnValue) && (nnValue >= 0))
287 aliasStart = nnValue;
291 if (!wxStricmp(attr, wxT(
"aliaslen")) && (nValue >= 0))
294 aliasChannel = nValue;
295 else if( !wxStricmp(attr, wxT(
"decodetype")) )
300 return make_blockfile<ODDecodeBlockFile>
301 (std::move(summaryFileName), std::move(audioFileName),
302 aliasStart, aliasLen, aliasChannel, decodeType, 0, 0, 0,
false);
347 wxPrintf(
"ODDecodeBlockFile Decode failure\n");
375 mFileName=std::move(
name);
409 cleanup.
reinit(mSummaryInfo.totalSummaryBytes);
410 char* localFullSummary = cleanup.get();
414 float *summary64K = (
float *)(localFullSummary + mSummaryInfo.offset64K);
415 float *summary256 = (
float *)(localFullSummary + mSummaryInfo.offset256);
423 fbuffer = (
float*)buffer;
428 fbuffer = floats.get();
433 BlockFile::CalcSummaryFromBuffer(fbuffer, len, summary256, summary64K);
435 return localFullSummary;
449 size_t start,
size_t len,
bool mayThrow)
const
451 auto locker = LockForRead();
478 data.
reinit( mSummaryInfo.totalSummaryBytes );
479 memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
510 return SimpleBlockFile::GetExternalFileName();
530 []( DirManager &dm,
const wxChar **attrs ){
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
virtual void EndTag(const wxString &name)
void SetFileName(wxFileNameWrapper &&name) override
sets the file name the summary info will be saved in. threadsafe.
virtual ~ODDecodeBlockFile()
void UnlockRead() const override
Allows reading of encoded file on other threads.
static bool IsGoodInt(const wxString &strInt)
Check that the supplied string can be converted to a long (32bit) integer.
void * CalcSummary(samplePtr buffer, size_t len, sampleFormat format, ArrayOf< char > &cleanup) override
static bool IsGoodPathName(const FilePath &strPathName)
void SetExternalFileName(wxFileNameWrapper &&newName) override
void SaveXML(XMLWriter &xmlFile) override
Write an XML representation of this file.
void reinit(Integral count, bool initialize=false)
Thrown for failure of file or database operations in deeply nested places.
const wxFileNameWrapper & GetEncodedAudioFilename() const
static bool IsGoodInt64(const wxString &strInt)
Check that the supplied string can be converted to a 64bit integer.
BlockFilePtr Copy(wxFileNameWrapper &&newFileName) override
Create a NEW block file identical to this one.
GetFileNameResult GetFileName() const override
sets the file name the summary info will be saved in. threadsafe.
wxFileNameWrapper mAudioFileName
The original file the audio came from.
bool Read64K(float *buffer, size_t start, size_t len) override
Returns the 64K summary data block.
wxAtomicInt mDataAvailable
void MarkInitialized()
Derived classes should call this after they have parsed the header.
DiskByteCount GetSpaceUsage() const override
static void MarkLoadedODFlag()
sets a flag that is set if we have loaded some OD blockfiles from PCM.
A BlockFile that reads and writes uncompressed data using libsndfile.
void LockRead() const override
Prevents a read on other threads of the encoded audio file.
long long as_long_long() const
static BlockFilePtr BuildFromXML(DirManager &dm, const wxChar **attrs)
Reconstructs from XML a ODDecodeBlockFile and reschedules it for OD loading.
MinMaxRMS GetMinMaxRMS(size_t start, size_t len, bool mayThrow) const override
Gets extreme values for the specified region.
bool ReadSummary(ArrayOf< char > &data) override
Read the summary section of the disk file.
ODLock mReadDataMutex
For accessing the audio file that will be decoded. Used by dir manager;.
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.
const TranslatableString name
static bool IsGoodFileName(const FilePath &strFileName, const FilePath &strDirName={})
ODFileDecoder(const wxString &fName)
This should handle unicode converted to UTF-8 on mac/linux, but OD TODO:check on windows.
virtual int Decode(SampleBuffer &data, sampleFormat &format, sampleCount start, size_t len, unsigned int channel)=0
char bheaderTag[bheaderTagLen+1]
static bool IsGoodFileString(const FilePath &str)
void ChangeAudioFile(wxFileNameWrapper &&newAudioFile)
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.
bool IsSummaryAvailable() const override
bool IsDataAvailable() const override
Returns TRUE if this block's complete data is ready to be accessed by Read()
bool WriteSimpleBlockFile(samplePtr sampleData, size_t sampleLen, sampleFormat format, void *summaryData)
class to decode a particular file (one per file). Saves info such as filename and length (after the h...
bool ReadSummary(ArrayOf< char > &data) override
Read the summary into a buffer.
bool IsValidChannel(const int nValue)
Positions or offsets within audio files need a wide type.
static DirManager::RegisteredBlockFileDeserializer sRegistration
void SaveXML(XMLWriter &xmlFile) override
Saves as xml ODDecodeBlockFile or SimpleBlockFile depending on summary availability.
void WriteAttr(const wxString &name, const Identifier &value)
#define PLATFORM_MAX_PATH
bool Read256(float *buffer, size_t start, size_t len) override
Returns the 256 byte summary data block.
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.
static bool IsGoodPathString(const FilePath &str)
BlockFilePtr Copy(wxFileNameWrapper &&fileName) override
Makes NEW ODDecodeBlockFile or SimpleBlockFile depending on summary availability.
void SetODFileDecoder(ODFileDecoder *decoder)
set the decoder,
void Recover(void) override
Writes the summary file if summary data is available.
virtual void StartTag(const wxString &name)
const wxFileNameWrapper & GetExternalFileName() const override
int WriteODDecodeBlockFile()