1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-01 16:19:43 +02:00

Merge branch 'master' into refactor

This commit is contained in:
Paul Licameli 2015-06-02 22:35:08 -04:00
commit 74beaa3436

View File

@ -137,6 +137,9 @@ SimpleBlockFile::SimpleBlockFile(wxFileName existingFile, sampleCount len,
float min, float max, float rms): float min, float max, float rms):
BlockFile(existingFile, len) BlockFile(existingFile, len)
{ {
// Set an invalid format to force GetSpaceUsage() to read it from the file.
mFormat = (sampleFormat) 0;
mMin = min; mMin = min;
mMax = max; mMax = max;
mRMS = rms; mRMS = rms;
@ -543,10 +546,54 @@ wxLongLong SimpleBlockFile::GetSpaceUsage()
{ {
// We don't know space usage yet // We don't know space usage yet
return 0; return 0;
} else
{
return sizeof(auHeader) + mSummaryInfo.totalSummaryBytes + (GetLength() * SAMPLE_SIZE(mFormat));
} }
// Don't know the format, so it must be read from the file
if (mFormat == (sampleFormat) 0)
{
// Check sample format
wxFFile file(mFileName.GetFullPath(), wxT("rb"));
if (!file.IsOpened())
{
// Don't read into cache if file not available
return 0;
}
auHeader header;
if (file.Read(&header, sizeof(header)) != sizeof(header))
{
// Corrupt file
return 0;
}
wxUint32 encoding;
if (header.magic == 0x2e736e64)
encoding = header.encoding; // correct endianness
else
encoding = SwapUintEndianess(header.encoding);
switch (encoding)
{
case AU_SAMPLE_FORMAT_16:
mFormat = int16Sample;
break;
case AU_SAMPLE_FORMAT_24:
mFormat = int24Sample;
break;
default:
// floatSample is a safe default (we will never loose data)
mFormat = floatSample;
break;
}
file.Close();
}
return sizeof(auHeader) +
mSummaryInfo.totalSummaryBytes +
(GetLength() * SAMPLE_SIZE_DISK(mFormat));
} }
void SimpleBlockFile::Recover(){ void SimpleBlockFile::Recover(){