mirror of
https://github.com/cookiengineer/audacity
synced 2025-08-02 17:09:26 +02:00
Zero and return false for all failures to read block file summary...
... Though in the only place where these summaries are used, which is Sequence::GetWaveDisplay, we ignore the correctly reported error code anyway. Also RAII in management of relevant memory buffers and mutexes.
This commit is contained in:
parent
7b7ad75a49
commit
2677796b0c
@ -424,6 +424,8 @@ void BlockFile::GetMinMax(float *outMin, float *outMax, float *outRMS) const
|
|||||||
/// data provides information about the minimum value, the maximum
|
/// data provides information about the minimum value, the maximum
|
||||||
/// value, and the maximum RMS value for every group of 256 samples in the
|
/// value, and the maximum RMS value for every group of 256 samples in the
|
||||||
/// file.
|
/// file.
|
||||||
|
/// Fill with zeroes and return false if data are unavailable for any reason.
|
||||||
|
///
|
||||||
///
|
///
|
||||||
/// @param *buffer The area where the summary information will be
|
/// @param *buffer The area where the summary information will be
|
||||||
/// written. It must be at least len*3 long.
|
/// written. It must be at least len*3 long.
|
||||||
@ -434,54 +436,17 @@ bool BlockFile::Read256(float *buffer,
|
|||||||
{
|
{
|
||||||
wxASSERT(start >= 0);
|
wxASSERT(start >= 0);
|
||||||
|
|
||||||
ArrayOf<char> summary{ mSummaryInfo.totalSummaryBytes };
|
ArrayOf< char > summary;
|
||||||
// FIXME: TRAP_ERR ReadSummary() could return fail.
|
// In case of failure, summary is filled with zeroes
|
||||||
this->ReadSummary(summary.get());
|
auto result = this->ReadSummary(summary);
|
||||||
|
|
||||||
start = std::min( start, mSummaryInfo.frames256 );
|
start = std::min( start, mSummaryInfo.frames256 );
|
||||||
len = std::min( len, mSummaryInfo.frames256 - start );
|
len = std::min( len, mSummaryInfo.frames256 - start );
|
||||||
|
|
||||||
CopySamples(summary.get() + mSummaryInfo.offset256 + (start * mSummaryInfo.bytesPerFrame),
|
CopySamples(summary.get() + mSummaryInfo.offset256 +
|
||||||
mSummaryInfo.format,
|
|
||||||
(samplePtr)buffer, floatSample, len * mSummaryInfo.fields);
|
|
||||||
|
|
||||||
if (mSummaryInfo.fields == 2) {
|
|
||||||
// No RMS info
|
|
||||||
for(auto i = len; i--;) {
|
|
||||||
buffer[3*i+2] = (fabs(buffer[2*i]) + fabs(buffer[2*i+1]))/4.0;
|
|
||||||
buffer[3*i+1] = buffer[2*i+1];
|
|
||||||
buffer[3*i] = buffer[2*i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Retrieves a portion of the 64K summary buffer from this BlockFile. This
|
|
||||||
/// data provides information about the minimum value, the maximum
|
|
||||||
/// value, and the maximum RMS value for every group of 64K samples in the
|
|
||||||
/// file.
|
|
||||||
///
|
|
||||||
/// @param *buffer The area where the summary information will be
|
|
||||||
/// written. It must be at least len*3 long.
|
|
||||||
/// @param start The offset in 64K-sample increments
|
|
||||||
/// @param len The number of 64K-sample summary frames to read
|
|
||||||
bool BlockFile::Read64K(float *buffer,
|
|
||||||
size_t start, size_t len)
|
|
||||||
{
|
|
||||||
wxASSERT(start >= 0);
|
|
||||||
|
|
||||||
ArrayOf<char> summary{ mSummaryInfo.totalSummaryBytes };
|
|
||||||
// FIXME: TRAP_ERR ReadSummary() could return fail.
|
|
||||||
this->ReadSummary(summary.get());
|
|
||||||
|
|
||||||
start = std::min( start, mSummaryInfo.frames64K );
|
|
||||||
len = std::min( len, mSummaryInfo.frames64K - start );
|
|
||||||
|
|
||||||
CopySamples(summary.get() + mSummaryInfo.offset64K +
|
|
||||||
(start * mSummaryInfo.bytesPerFrame),
|
(start * mSummaryInfo.bytesPerFrame),
|
||||||
mSummaryInfo.format,
|
mSummaryInfo.format,
|
||||||
(samplePtr)buffer, floatSample, len*mSummaryInfo.fields);
|
(samplePtr)buffer, floatSample, len * mSummaryInfo.fields);
|
||||||
|
|
||||||
if (mSummaryInfo.fields == 2) {
|
if (mSummaryInfo.fields == 2) {
|
||||||
// No RMS info; make guess
|
// No RMS info; make guess
|
||||||
@ -492,7 +457,46 @@ bool BlockFile::Read64K(float *buffer,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Retrieves a portion of the 64K summary buffer from this BlockFile. This
|
||||||
|
/// data provides information about the minimum value, the maximum
|
||||||
|
/// value, and the maximum RMS value for every group of 64K samples in the
|
||||||
|
/// file.
|
||||||
|
/// Fill with zeroes and return false if data are unavailable for any reason.
|
||||||
|
///
|
||||||
|
/// @param *buffer The area where the summary information will be
|
||||||
|
/// written. It must be at least len*3 long.
|
||||||
|
/// @param start The offset in 64K-sample increments
|
||||||
|
/// @param len The number of 64K-sample summary frames to read
|
||||||
|
bool BlockFile::Read64K(float *buffer,
|
||||||
|
size_t start, size_t len)
|
||||||
|
{
|
||||||
|
wxASSERT(start >= 0);
|
||||||
|
|
||||||
|
ArrayOf< char > summary;
|
||||||
|
// In case of failure, summary is filled with zeroes
|
||||||
|
auto result = this->ReadSummary(summary);
|
||||||
|
|
||||||
|
start = std::min( start, mSummaryInfo.frames64K );
|
||||||
|
len = std::min( len, mSummaryInfo.frames64K - start );
|
||||||
|
|
||||||
|
CopySamples(summary.get() + mSummaryInfo.offset64K +
|
||||||
|
(start * mSummaryInfo.bytesPerFrame),
|
||||||
|
mSummaryInfo.format,
|
||||||
|
(samplePtr)buffer, floatSample, len * mSummaryInfo.fields);
|
||||||
|
|
||||||
|
if (mSummaryInfo.fields == 2) {
|
||||||
|
// No RMS info; make guess
|
||||||
|
for(auto i = len; i--;) {
|
||||||
|
buffer[3*i+2] = (fabs(buffer[2*i]) + fabs(buffer[2*i+1]))/4.0;
|
||||||
|
buffer[3*i+1] = buffer[2*i+1];
|
||||||
|
buffer[3*i] = buffer[2*i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t BlockFile::CommonReadData(
|
size_t BlockFile::CommonReadData(
|
||||||
@ -714,11 +718,13 @@ AliasBlockFile::~AliasBlockFile()
|
|||||||
|
|
||||||
/// Read the summary of this alias block from disk. Since the audio data
|
/// Read the summary of this alias block from disk. Since the audio data
|
||||||
/// is elsewhere, this consists of reading the entire summary file.
|
/// is elsewhere, this consists of reading the entire summary file.
|
||||||
|
/// Fill with zeroes and return false if data are unavailable for any reason.
|
||||||
///
|
///
|
||||||
/// @param *data The buffer where the summary data will be stored. It must
|
/// @param *data The buffer where the summary data will be stored. It must
|
||||||
/// be at least mSummaryInfo.totalSummaryBytes long.
|
/// be at least mSummaryInfo.totalSummaryBytes long.
|
||||||
bool AliasBlockFile::ReadSummary(void *data)
|
bool AliasBlockFile::ReadSummary(ArrayOf<char> &data)
|
||||||
{
|
{
|
||||||
|
data.reinit( mSummaryInfo.totalSummaryBytes );
|
||||||
wxFFile summaryFile(mFileName.GetFullPath(), wxT("rb"));
|
wxFFile summaryFile(mFileName.GetFullPath(), wxT("rb"));
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -729,24 +735,28 @@ bool AliasBlockFile::ReadSummary(void *data)
|
|||||||
if (!summaryFile.IsOpened()){
|
if (!summaryFile.IsOpened()){
|
||||||
|
|
||||||
// NEW model; we need to return valid data
|
// NEW model; we need to return valid data
|
||||||
memset(data, 0, mSummaryInfo.totalSummaryBytes);
|
memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
|
||||||
|
|
||||||
// we silence the logging for this operation in this object
|
// we silence the logging for this operation in this object
|
||||||
// after first occurrence of error; it's already reported and
|
// after first occurrence of error; it's already reported and
|
||||||
// spewing at the user will complicate the user's ability to
|
// spewing at the user will complicate the user's ability to
|
||||||
// deal
|
// deal
|
||||||
mSilentLog = TRUE;
|
mSilentLog = TRUE;
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
else mSilentLog = FALSE; // worked properly, any future error is NEW
|
else mSilentLog = FALSE; // worked properly, any future error is NEW
|
||||||
}
|
}
|
||||||
|
|
||||||
auto read = summaryFile.Read(data, mSummaryInfo.totalSummaryBytes);
|
auto read = summaryFile.Read(data.get(), mSummaryInfo.totalSummaryBytes);
|
||||||
|
if (read != mSummaryInfo.totalSummaryBytes) {
|
||||||
|
memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
FixSummary(data);
|
FixSummary(data.get());
|
||||||
|
|
||||||
return (read == mSummaryInfo.totalSummaryBytes);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Modify this block to point at a different file. This is generally
|
/// Modify this block to point at a different file. This is generally
|
||||||
|
@ -181,7 +181,7 @@ class PROFILE_DLL_API BlockFile /* not final, abstract */ {
|
|||||||
float *summary256, float *summary64K);
|
float *summary256, float *summary64K);
|
||||||
|
|
||||||
/// Read the summary section of the file. Derived classes implement.
|
/// Read the summary section of the file. Derived classes implement.
|
||||||
virtual bool ReadSummary(void *data) = 0;
|
virtual bool ReadSummary(ArrayOf<char> &data) = 0;
|
||||||
|
|
||||||
/// Byte-swap the summary data, in case it was saved by a system
|
/// Byte-swap the summary data, in case it was saved by a system
|
||||||
/// on a different platform
|
/// on a different platform
|
||||||
@ -251,7 +251,7 @@ class AliasBlockFile /* not final */ : public BlockFile
|
|||||||
/// Write the summary to disk, using the derived ReadData() to get the data
|
/// Write the summary to disk, using the derived ReadData() to get the data
|
||||||
virtual void WriteSummary();
|
virtual void WriteSummary();
|
||||||
/// Read the summary into a buffer
|
/// Read the summary into a buffer
|
||||||
bool ReadSummary(void *data) override;
|
bool ReadSummary(ArrayOf<char> &data) override;
|
||||||
|
|
||||||
wxFileNameWrapper mAliasedFileName;
|
wxFileNameWrapper mAliasedFileName;
|
||||||
sampleCount mAliasStart;
|
sampleCount mAliasStart;
|
||||||
|
@ -1402,6 +1402,8 @@ bool Sequence::GetWaveDisplay(float *min, float *max, float *rms, int* bl,
|
|||||||
// Read triples
|
// Read triples
|
||||||
//check to see if summary data has been computed
|
//check to see if summary data has been computed
|
||||||
if (seqBlock.f->IsSummaryAvailable())
|
if (seqBlock.f->IsSummaryAvailable())
|
||||||
|
// Ignore the return value.
|
||||||
|
// This function fills with zeroes if read fails
|
||||||
seqBlock.f->Read256(temp.get(), startPosition, num);
|
seqBlock.f->Read256(temp.get(), startPosition, num);
|
||||||
else
|
else
|
||||||
//otherwise, mark the display as not yet computed
|
//otherwise, mark the display as not yet computed
|
||||||
@ -1411,6 +1413,8 @@ bool Sequence::GetWaveDisplay(float *min, float *max, float *rms, int* bl,
|
|||||||
// Read triples
|
// Read triples
|
||||||
//check to see if summary data has been computed
|
//check to see if summary data has been computed
|
||||||
if (seqBlock.f->IsSummaryAvailable())
|
if (seqBlock.f->IsSummaryAvailable())
|
||||||
|
// Ignore the return value.
|
||||||
|
// This function fills with zeroes if read fails
|
||||||
seqBlock.f->Read64K(temp.get(), startPosition, num);
|
seqBlock.f->Read64K(temp.get(), startPosition, num);
|
||||||
else
|
else
|
||||||
//otherwise, mark the display as not yet computed
|
//otherwise, mark the display as not yet computed
|
||||||
|
@ -151,11 +151,13 @@ LegacyBlockFile::~LegacyBlockFile()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 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.
|
||||||
///
|
///
|
||||||
/// @param *data The buffer to write the data to. It must be at least
|
/// @param *data The buffer to write the data to. It must be at least
|
||||||
/// mSummaryinfo.totalSummaryBytes long.
|
/// mSummaryinfo.totalSummaryBytes long.
|
||||||
bool LegacyBlockFile::ReadSummary(void *data)
|
bool LegacyBlockFile::ReadSummary(ArrayOf<char> &data)
|
||||||
{
|
{
|
||||||
|
data.reinit( mSummaryInfo.totalSummaryBytes );
|
||||||
wxFFile summaryFile(mFileName.GetFullPath(), wxT("rb"));
|
wxFFile summaryFile(mFileName.GetFullPath(), wxT("rb"));
|
||||||
size_t read;
|
size_t read;
|
||||||
{
|
{
|
||||||
@ -163,20 +165,25 @@ bool LegacyBlockFile::ReadSummary(void *data)
|
|||||||
if (mSilentLog)
|
if (mSilentLog)
|
||||||
silence.create();
|
silence.create();
|
||||||
|
|
||||||
if (!summaryFile.IsOpened()){
|
if (!summaryFile.IsOpened()) {
|
||||||
|
|
||||||
memset(data, 0, mSummaryInfo.totalSummaryBytes);
|
memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
|
||||||
|
|
||||||
mSilentLog = TRUE;
|
mSilentLog = TRUE;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
read = summaryFile.Read(data.get(), mSummaryInfo.totalSummaryBytes);
|
||||||
|
}
|
||||||
|
mSilentLog = FALSE;
|
||||||
|
|
||||||
|
if (read != mSummaryInfo.totalSummaryBytes) {
|
||||||
|
memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
read = summaryFile.Read(data, mSummaryInfo.totalSummaryBytes);
|
|
||||||
}
|
|
||||||
mSilentLog=FALSE;
|
|
||||||
|
|
||||||
return (read == mSummaryInfo.totalSummaryBytes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read the data portion of the block file using libsndfile. Convert it
|
/// Read the data portion of the block file using libsndfile. Convert it
|
||||||
|
@ -48,7 +48,7 @@ class LegacyBlockFile final : public BlockFile {
|
|||||||
// Reading
|
// Reading
|
||||||
|
|
||||||
/// Read the summary section of the disk file
|
/// Read the summary section of the disk file
|
||||||
bool ReadSummary(void *data) override;
|
bool ReadSummary(ArrayOf<char> &data) override;
|
||||||
/// Read the data section of the disk file
|
/// Read the data section of the disk file
|
||||||
size_t ReadData(samplePtr data, sampleFormat format,
|
size_t ReadData(samplePtr data, sampleFormat format,
|
||||||
size_t start, size_t len) const override;
|
size_t start, size_t len) const override;
|
||||||
|
@ -126,6 +126,7 @@ void ODDecodeBlockFile::GetMinMax(float *outMin, float *outMax, float *outRMS) c
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 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.
|
||||||
bool ODDecodeBlockFile::Read256(float *buffer, size_t start, size_t len)
|
bool ODDecodeBlockFile::Read256(float *buffer, size_t start, size_t len)
|
||||||
{
|
{
|
||||||
if(IsSummaryAvailable())
|
if(IsSummaryAvailable())
|
||||||
@ -134,13 +135,13 @@ bool ODDecodeBlockFile::Read256(float *buffer, size_t start, size_t len)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//this should not be reached (client should check IsSummaryAvailable()==true before this.
|
ClearSamples((samplePtr)buffer, floatSample, 0, len);
|
||||||
buffer = NULL;
|
return false;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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.
|
||||||
bool ODDecodeBlockFile::Read64K(float *buffer, size_t start, size_t len)
|
bool ODDecodeBlockFile::Read64K(float *buffer, size_t start, size_t len)
|
||||||
{
|
{
|
||||||
if(IsSummaryAvailable())
|
if(IsSummaryAvailable())
|
||||||
@ -149,8 +150,8 @@ bool ODDecodeBlockFile::Read64K(float *buffer, size_t start, size_t len)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//this should not be reached (client should check IsSummaryAvailable()==true before this.
|
ClearSamples((samplePtr)buffer, floatSample, 0, len);
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,17 +451,19 @@ size_t ODDecodeBlockFile::ReadData(samplePtr data, sampleFormat format,
|
|||||||
|
|
||||||
/// Read the summary of this alias block from disk. Since the audio data
|
/// Read the summary of this alias block from disk. Since the audio data
|
||||||
/// is elsewhere, this consists of reading the entire summary file.
|
/// is elsewhere, this consists of reading the entire summary file.
|
||||||
|
/// Fill with zeroes and return false if data are unavailable for any reason.
|
||||||
///
|
///
|
||||||
/// @param *data The buffer where the summary data will be stored. It must
|
/// @param *data The buffer where the summary data will be stored. It must
|
||||||
/// be at least mSummaryInfo.totalSummaryBytes long.
|
/// be at least mSummaryInfo.totalSummaryBytes long.
|
||||||
bool ODDecodeBlockFile::ReadSummary(void *data)
|
bool ODDecodeBlockFile::ReadSummary(ArrayOf<char> &data)
|
||||||
{
|
{
|
||||||
//I dont think we need to add a mutex here because only the main thread changes filenames and calls ReadSummarz
|
//I dont think we need to add a mutex here because only the main thread changes filenames and calls ReadSummary
|
||||||
if(IsSummaryAvailable())
|
if(IsSummaryAvailable())
|
||||||
return SimpleBlockFile::ReadSummary(data);
|
return SimpleBlockFile::ReadSummary(data);
|
||||||
|
|
||||||
memset(data, 0, mSummaryInfo.totalSummaryBytes);
|
data.reinit( mSummaryInfo.totalSummaryBytes );
|
||||||
return true;
|
memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
///set the decoder,
|
///set the decoder,
|
||||||
|
@ -112,7 +112,7 @@ class ODDecodeBlockFile final : public SimpleBlockFile
|
|||||||
size_t start, size_t len) const override;
|
size_t start, size_t len) const override;
|
||||||
|
|
||||||
/// Read the summary into a buffer
|
/// Read the summary into a buffer
|
||||||
bool ReadSummary(void *data) override;
|
bool ReadSummary(ArrayOf<char> &data) override;
|
||||||
|
|
||||||
///Returns the type of audiofile this blockfile is loaded from.
|
///Returns the type of audiofile this blockfile is loaded from.
|
||||||
unsigned int GetDecodeType() /* not override */ const { return mType; }
|
unsigned int GetDecodeType() /* not override */ const { return mType; }
|
||||||
|
@ -155,7 +155,8 @@ void ODPCMAliasBlockFile::GetMinMax(float *outMin, float *outMax, float *outRMS)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the 256 byte summary data block. Clients should check to see if the summary is available before trying to read it with this call.
|
/// Returns the 256 byte summary data block.
|
||||||
|
/// Fill with zeroes and return false if data are unavailable for any reason.
|
||||||
bool ODPCMAliasBlockFile::Read256(float *buffer, size_t start, size_t len)
|
bool ODPCMAliasBlockFile::Read256(float *buffer, size_t start, size_t len)
|
||||||
{
|
{
|
||||||
if(IsSummaryAvailable())
|
if(IsSummaryAvailable())
|
||||||
@ -165,12 +166,13 @@ bool ODPCMAliasBlockFile::Read256(float *buffer, size_t start, size_t len)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
//return nothing.
|
//return nothing.
|
||||||
buffer = NULL;
|
ClearSamples((samplePtr)buffer, floatSample, 0, len);
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the 64K summary data block. Clients should check to see if the summary is available before trying to read it with this call.
|
/// Returns the 64K summary data block.
|
||||||
|
/// Fill with zeroes and return false if data are unavailable for any reason.
|
||||||
bool ODPCMAliasBlockFile::Read64K(float *buffer, size_t start, size_t len)
|
bool ODPCMAliasBlockFile::Read64K(float *buffer, size_t start, size_t len)
|
||||||
{
|
{
|
||||||
if(IsSummaryAvailable())
|
if(IsSummaryAvailable())
|
||||||
@ -180,8 +182,8 @@ bool ODPCMAliasBlockFile::Read64K(float *buffer, size_t start, size_t len)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
//return nothing - it hasn't been calculated yet
|
//return nothing - it hasn't been calculated yet
|
||||||
buffer = NULL;
|
ClearSamples((samplePtr)buffer, floatSample, 0, len);
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -505,40 +507,43 @@ size_t ODPCMAliasBlockFile::ReadData(samplePtr data, sampleFormat format,
|
|||||||
|
|
||||||
/// Read the summary of this alias block from disk. Since the audio data
|
/// Read the summary of this alias block from disk. Since the audio data
|
||||||
/// is elsewhere, this consists of reading the entire summary file.
|
/// is elsewhere, this consists of reading the entire summary file.
|
||||||
|
/// Fill with zeroes and return false if data are unavailable for any reason.
|
||||||
///
|
///
|
||||||
/// @param *data The buffer where the summary data will be stored. It must
|
/// @param *data The buffer where the summary data will be stored. It must
|
||||||
/// be at least mSummaryInfo.totalSummaryBytes long.
|
/// be at least mSummaryInfo.totalSummaryBytes long.
|
||||||
bool ODPCMAliasBlockFile::ReadSummary(void *data)
|
bool ODPCMAliasBlockFile::ReadSummary(ArrayOf<char> &data)
|
||||||
{
|
{
|
||||||
|
data.reinit( mSummaryInfo.totalSummaryBytes );
|
||||||
|
|
||||||
mFileNameMutex.Lock();
|
ODLocker locker{ &mFileNameMutex };
|
||||||
wxFFile summaryFile(mFileName.GetFullPath(), wxT("rb"));
|
wxFFile summaryFile(mFileName.GetFullPath(), wxT("rb"));
|
||||||
|
|
||||||
if( !summaryFile.IsOpened() ){
|
if( !summaryFile.IsOpened() ) {
|
||||||
|
|
||||||
// NEW model; we need to return valid data
|
// NEW model; we need to return valid data
|
||||||
memset(data, 0, mSummaryInfo.totalSummaryBytes);
|
memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
|
||||||
|
|
||||||
// we silence the logging for this operation in this object
|
// we silence the logging for this operation in this object
|
||||||
// after first occurrence of error; it's already reported and
|
// after first occurrence of error; it's already reported and
|
||||||
// spewing at the user will complicate the user's ability to
|
// spewing at the user will complicate the user's ability to
|
||||||
// deal
|
// deal
|
||||||
mSilentLog=TRUE;
|
mSilentLog = TRUE;
|
||||||
|
|
||||||
mFileNameMutex.Unlock();
|
|
||||||
return true;
|
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mSilentLog=FALSE; // worked properly, any future error is NEW
|
mSilentLog = FALSE; // worked properly, any future error is NEW
|
||||||
|
|
||||||
auto read = summaryFile.Read(data, mSummaryInfo.totalSummaryBytes);
|
auto read = summaryFile.Read(data.get(), mSummaryInfo.totalSummaryBytes);
|
||||||
|
|
||||||
FixSummary(data);
|
if (read != mSummaryInfo.totalSummaryBytes) {
|
||||||
|
memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
FixSummary(data.get());
|
||||||
|
|
||||||
mFileNameMutex.Unlock();
|
return true;
|
||||||
return (read == mSummaryInfo.totalSummaryBytes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prevents a read on other threads.
|
/// Prevents a read on other threads.
|
||||||
|
@ -121,7 +121,7 @@ class ODPCMAliasBlockFile final : public PCMAliasBlockFile
|
|||||||
size_t start, size_t len) const override;
|
size_t start, size_t len) const override;
|
||||||
|
|
||||||
/// Read the summary into a buffer
|
/// Read the summary into a buffer
|
||||||
bool ReadSummary(void *data) override;
|
bool ReadSummary(ArrayOf<char> &data) override;
|
||||||
|
|
||||||
///sets the file name the summary info will be saved in. threadsafe.
|
///sets the file name the summary info will be saved in. threadsafe.
|
||||||
void SetFileName(wxFileNameWrapper &&name) override;
|
void SetFileName(wxFileNameWrapper &&name) override;
|
||||||
|
@ -24,9 +24,10 @@ SilentBlockFile::~SilentBlockFile()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SilentBlockFile::ReadSummary(void *data)
|
bool SilentBlockFile::ReadSummary(ArrayOf<char> &data)
|
||||||
{
|
{
|
||||||
memset(data, 0, mSummaryInfo.totalSummaryBytes);
|
data.reinit( mSummaryInfo.totalSummaryBytes );
|
||||||
|
memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ class SilentBlockFile final : public BlockFile {
|
|||||||
// Reading
|
// Reading
|
||||||
|
|
||||||
/// Read the summary section of the disk file
|
/// Read the summary section of the disk file
|
||||||
bool ReadSummary(void *data) override;
|
bool ReadSummary(ArrayOf<char> &data) override;
|
||||||
/// Read the data section of the disk file
|
/// Read the data section of the disk file
|
||||||
size_t ReadData(samplePtr data, sampleFormat format,
|
size_t ReadData(samplePtr data, sampleFormat format,
|
||||||
size_t start, size_t len) const override;
|
size_t start, size_t len) const override;
|
||||||
|
@ -321,9 +321,8 @@ void SimpleBlockFile::FillCache()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read summary data into cache
|
// Read summary data into cache
|
||||||
mCache.summaryData.reinit(mSummaryInfo.totalSummaryBytes);
|
// Fills with zeroes in case of failure:
|
||||||
if (!ReadSummary(mCache.summaryData.get()))
|
ReadSummary(mCache.summaryData);
|
||||||
memset(mCache.summaryData.get(), 0, mSummaryInfo.totalSummaryBytes);
|
|
||||||
|
|
||||||
// Cache is active but already on disk
|
// Cache is active but already on disk
|
||||||
mCache.active = true;
|
mCache.active = true;
|
||||||
@ -336,12 +335,12 @@ void SimpleBlockFile::FillCache()
|
|||||||
///
|
///
|
||||||
/// @param *data The buffer to write the data to. It must be at least
|
/// @param *data The buffer to write the data to. It must be at least
|
||||||
/// mSummaryinfo.totalSummaryBytes long.
|
/// mSummaryinfo.totalSummaryBytes long.
|
||||||
bool SimpleBlockFile::ReadSummary(void *data)
|
bool SimpleBlockFile::ReadSummary(ArrayOf<char> &data)
|
||||||
{
|
{
|
||||||
if (mCache.active)
|
data.reinit( mSummaryInfo.totalSummaryBytes );
|
||||||
{
|
if (mCache.active) {
|
||||||
//wxLogDebug("SimpleBlockFile::ReadSummary(): Summary is already in cache.");
|
//wxLogDebug("SimpleBlockFile::ReadSummary(): Summary is already in cache.");
|
||||||
memcpy(data, mCache.summaryData.get(), mSummaryInfo.totalSummaryBytes);
|
memcpy(data.get(), mCache.summaryData.get(), mSummaryInfo.totalSummaryBytes);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -357,23 +356,24 @@ bool SimpleBlockFile::ReadSummary(void *data)
|
|||||||
// FIXME: TRAP_ERR no report to user of absent summary files?
|
// FIXME: TRAP_ERR no report to user of absent summary files?
|
||||||
// filled with zero instead.
|
// filled with zero instead.
|
||||||
if (!file.IsOpened()){
|
if (!file.IsOpened()){
|
||||||
memset(data, 0, mSummaryInfo.totalSummaryBytes);
|
memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
|
||||||
mSilentLog = TRUE;
|
mSilentLog = TRUE;
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mSilentLog=FALSE;
|
mSilentLog = FALSE;
|
||||||
|
|
||||||
// The offset is just past the au header
|
// The offset is just past the au header
|
||||||
// FIXME: Seek in summary file could fail.
|
if( !file.Seek(sizeof(auHeader)) ||
|
||||||
if( !file.Seek(sizeof(auHeader)) )
|
file.Read(data.get(), mSummaryInfo.totalSummaryBytes) !=
|
||||||
|
mSummaryInfo.totalSummaryBytes ) {
|
||||||
|
memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
auto read = file.Read(data, mSummaryInfo.totalSummaryBytes);
|
FixSummary(data.get());
|
||||||
|
|
||||||
FixSummary(data);
|
return true;
|
||||||
|
|
||||||
return (read == mSummaryInfo.totalSummaryBytes);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ class PROFILE_DLL_API SimpleBlockFile /* not final */ : public BlockFile {
|
|||||||
// Reading
|
// Reading
|
||||||
|
|
||||||
/// Read the summary section of the disk file
|
/// Read the summary section of the disk file
|
||||||
bool ReadSummary(void *data) override;
|
bool ReadSummary(ArrayOf<char> &data) override;
|
||||||
/// Read the data section of the disk file
|
/// Read the data section of the disk file
|
||||||
size_t ReadData(samplePtr data, sampleFormat format,
|
size_t ReadData(samplePtr data, sampleFormat format,
|
||||||
size_t start, size_t len) const override;
|
size_t start, size_t len) const override;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user