mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-26 07:13:49 +01:00
BlockFile::ReadData overrides: on failure, pad with 0s or throw...
... as the mayThrow argument directs.
This commit is contained in:
@@ -194,10 +194,10 @@ bool LegacyBlockFile::ReadSummary(ArrayOf<char> &data)
|
||||
/// @param start The offset in this block file
|
||||
/// @param len The number of samples to read
|
||||
size_t LegacyBlockFile::ReadData(samplePtr data, sampleFormat format,
|
||||
size_t start, size_t len) const
|
||||
size_t start, size_t len, bool mayThrow) const
|
||||
{
|
||||
sf_count_t origin = (mSummaryInfo.totalSummaryBytes / SAMPLE_SIZE(mFormat));
|
||||
return CommonReadData(
|
||||
return CommonReadData( mayThrow,
|
||||
mFileName, mSilentLog, nullptr, origin, 0, data, format, start, len,
|
||||
&mFormat, mLen
|
||||
);
|
||||
|
||||
@@ -51,7 +51,7 @@ class LegacyBlockFile final : public BlockFile {
|
||||
bool ReadSummary(ArrayOf<char> &data) override;
|
||||
/// Read the data section of the disk file
|
||||
size_t ReadData(samplePtr data, sampleFormat format,
|
||||
size_t start, size_t len) const override;
|
||||
size_t start, size_t len, bool mayThrow) const override;
|
||||
|
||||
/// Create a NEW block file identical to this one
|
||||
BlockFilePtr Copy(wxFileNameWrapper &&newFileName) override;
|
||||
|
||||
@@ -438,20 +438,22 @@ void *ODDecodeBlockFile::CalcSummary(samplePtr buffer, size_t len,
|
||||
/// @param start The offset within the block to begin reading
|
||||
/// @param len The number of samples to read
|
||||
size_t ODDecodeBlockFile::ReadData(samplePtr data, sampleFormat format,
|
||||
size_t start, size_t len) const
|
||||
size_t start, size_t len, bool mayThrow) const
|
||||
{
|
||||
size_t ret;
|
||||
auto locker = LockForRead();
|
||||
if(IsSummaryAvailable())
|
||||
ret = SimpleBlockFile::ReadData(data,format,start,len);
|
||||
return SimpleBlockFile::ReadData(data, format, start, len, mayThrow);
|
||||
else
|
||||
{
|
||||
if (mayThrow)
|
||||
//throw NotYetAvailableException{ mFileName }
|
||||
;
|
||||
|
||||
//we should do an ODRequest to start processing the data here, and wait till it finishes. and just do a SimpleBlockFile
|
||||
//ReadData.
|
||||
ClearSamples(data, format, 0, len);
|
||||
ret = len;
|
||||
return 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// Read the summary of this alias block from disk. Since the audio data
|
||||
|
||||
@@ -109,7 +109,7 @@ class ODDecodeBlockFile final : public SimpleBlockFile
|
||||
|
||||
/// Reads the specified data from the aliased file using libsndfile
|
||||
size_t ReadData(samplePtr data, sampleFormat format,
|
||||
size_t start, size_t len) const override;
|
||||
size_t start, size_t len, bool mayThrow) const override;
|
||||
|
||||
/// Read the summary into a buffer
|
||||
bool ReadSummary(ArrayOf<char> &data) override;
|
||||
|
||||
@@ -414,7 +414,7 @@ void ODPCMAliasBlockFile::WriteSummary()
|
||||
// To build the summary data, call ReadData (implemented by the
|
||||
// derived classes) to get the sample data
|
||||
SampleBuffer sampleData(mLen, floatSample);
|
||||
this->ReadData(sampleData.ptr(), floatSample, 0, mLen);
|
||||
this->ReadData(sampleData.ptr(), floatSample, 0, mLen, true);
|
||||
|
||||
ArrayOf<char> cleanup;
|
||||
void *summaryData = CalcSummary(sampleData.ptr(), mLen,
|
||||
@@ -495,7 +495,7 @@ void *ODPCMAliasBlockFile::CalcSummary(samplePtr buffer, size_t len,
|
||||
/// @param start The offset within the block to begin reading
|
||||
/// @param len The number of samples to read
|
||||
size_t ODPCMAliasBlockFile::ReadData(samplePtr data, sampleFormat format,
|
||||
size_t start, size_t len) const
|
||||
size_t start, size_t len, bool mayThrow) const
|
||||
{
|
||||
|
||||
auto locker = LockForRead();
|
||||
@@ -505,7 +505,7 @@ size_t ODPCMAliasBlockFile::ReadData(samplePtr data, sampleFormat format,
|
||||
return len;
|
||||
}
|
||||
|
||||
return CommonReadData(
|
||||
return CommonReadData( mayThrow,
|
||||
mAliasedFileName, mSilentAliasLog, this, mAliasStart, mAliasChannel,
|
||||
data, format, start, len);
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ class ODPCMAliasBlockFile final : public PCMAliasBlockFile
|
||||
|
||||
/// Reads the specified data from the aliased file using libsndfile
|
||||
size_t ReadData(samplePtr data, sampleFormat format,
|
||||
size_t start, size_t len) const override;
|
||||
size_t start, size_t len, bool mayThrow) const override;
|
||||
|
||||
/// Read the summary into a buffer
|
||||
bool ReadSummary(ArrayOf<char> &data) override;
|
||||
|
||||
@@ -75,14 +75,14 @@ PCMAliasBlockFile::~PCMAliasBlockFile()
|
||||
/// @param start The offset within the block to begin reading
|
||||
/// @param len The number of samples to read
|
||||
size_t PCMAliasBlockFile::ReadData(samplePtr data, sampleFormat format,
|
||||
size_t start, size_t len) const
|
||||
size_t start, size_t len, bool mayThrow) const
|
||||
{
|
||||
if(!mAliasedFileName.IsOk()){ // intentionally silenced
|
||||
memset(data, 0, SAMPLE_SIZE(format) * len);
|
||||
return len;
|
||||
}
|
||||
|
||||
return CommonReadData(
|
||||
return CommonReadData( mayThrow,
|
||||
mAliasedFileName, mSilentAliasLog, this, mAliasStart, mAliasChannel,
|
||||
data, format, start, len);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class PCMAliasBlockFile /* not final */ : public AliasBlockFile
|
||||
|
||||
/// Reads the specified data from the aliased file using libsndfile
|
||||
size_t ReadData(samplePtr data, sampleFormat format,
|
||||
size_t start, size_t len) const override;
|
||||
size_t start, size_t len, bool mayThrow) const override;
|
||||
|
||||
void SaveXML(XMLWriter &xmlFile) override;
|
||||
BlockFilePtr Copy(wxFileNameWrapper &&fileName) override;
|
||||
|
||||
@@ -32,7 +32,7 @@ bool SilentBlockFile::ReadSummary(ArrayOf<char> &data)
|
||||
}
|
||||
|
||||
size_t SilentBlockFile::ReadData(samplePtr data, sampleFormat format,
|
||||
size_t WXUNUSED(start), size_t len) const
|
||||
size_t WXUNUSED(start), size_t len, bool) const
|
||||
{
|
||||
ClearSamples(data, format, 0, len);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class SilentBlockFile final : public BlockFile {
|
||||
bool ReadSummary(ArrayOf<char> &data) override;
|
||||
/// Read the data section of the disk file
|
||||
size_t ReadData(samplePtr data, sampleFormat format,
|
||||
size_t start, size_t len) const override;
|
||||
size_t start, size_t len, bool mayThrow) const override;
|
||||
|
||||
/// Create a NEW block file identical to this one
|
||||
BlockFilePtr Copy(wxFileNameWrapper &&newFileName) override;
|
||||
|
||||
@@ -315,7 +315,9 @@ void SimpleBlockFile::FillCache()
|
||||
|
||||
// Read samples into cache
|
||||
mCache.sampleData.reinit(mLen * SAMPLE_SIZE(mCache.format));
|
||||
if (ReadData(mCache.sampleData.get(), mCache.format, 0, mLen) != mLen)
|
||||
if (ReadData(mCache.sampleData.get(), mCache.format, 0, mLen,
|
||||
// no exceptions!
|
||||
false) != mLen)
|
||||
{
|
||||
// Could not read all samples
|
||||
mCache.sampleData.reset();
|
||||
@@ -387,21 +389,30 @@ bool SimpleBlockFile::ReadSummary(ArrayOf<char> &data)
|
||||
/// @param start The offset in this block file
|
||||
/// @param len The number of samples to read
|
||||
size_t SimpleBlockFile::ReadData(samplePtr data, sampleFormat format,
|
||||
size_t start, size_t len) const
|
||||
size_t start, size_t len, bool mayThrow) const
|
||||
{
|
||||
if (mCache.active)
|
||||
{
|
||||
//wxLogDebug("SimpleBlockFile::ReadData(): Data are already in cache.");
|
||||
|
||||
len = std::min(len, std::max(start, mLen) - start);
|
||||
auto framesRead = std::min(len, std::max(start, mLen) - start);
|
||||
CopySamples(
|
||||
(samplePtr)(mCache.sampleData.get() +
|
||||
start * SAMPLE_SIZE(mCache.format)),
|
||||
mCache.format, data, format, len);
|
||||
return len;
|
||||
mCache.format, data, format, framesRead);
|
||||
|
||||
if ( framesRead < len ) {
|
||||
if (mayThrow)
|
||||
// Not the best exception class?
|
||||
//throw FileException{ FileException::Cause::Read, mFileName }
|
||||
;
|
||||
ClearSamples(data, format, framesRead, len - framesRead);
|
||||
}
|
||||
|
||||
return framesRead;
|
||||
}
|
||||
else
|
||||
return CommonReadData(
|
||||
return CommonReadData( mayThrow,
|
||||
mFileName, mSilentLog, nullptr, 0, 0, data, format, start, len);
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ class PROFILE_DLL_API SimpleBlockFile /* not final */ : public BlockFile {
|
||||
bool ReadSummary(ArrayOf<char> &data) override;
|
||||
/// Read the data section of the disk file
|
||||
size_t ReadData(samplePtr data, sampleFormat format,
|
||||
size_t start, size_t len) const override;
|
||||
size_t start, size_t len, bool mayThrow) const override;
|
||||
|
||||
/// Create a NEW block file identical to this one
|
||||
BlockFilePtr Copy(wxFileNameWrapper &&newFileName) override;
|
||||
|
||||
Reference in New Issue
Block a user