1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-29 22:58:39 +02:00

Remove Sequence::CopyWrite and needless file reads in Sequence::Set

This commit is contained in:
Paul Licameli 2017-03-20 12:45:06 -04:00
parent c6b4e2fffe
commit 7b7ad75a49
2 changed files with 39 additions and 48 deletions

View File

@ -1134,29 +1134,6 @@ bool Sequence::Read(samplePtr buffer, sampleFormat format,
return true;
}
bool Sequence::CopyWrite(SampleBuffer &scratch,
samplePtr buffer, SeqBlock &b,
size_t blockRelativeStart, size_t len)
{
// We don't ever write to an existing block; to support Undo,
// we copy the old block entirely into memory, dereference it,
// make the change, and then write the NEW block to disk.
const auto length = b.f->GetLength();
wxASSERT(length <= mMaxSamples);
wxASSERT(blockRelativeStart + len <= length);
auto sampleSize = SAMPLE_SIZE(mSampleFormat);
Read(scratch.ptr(), mSampleFormat, b, 0, length);
memcpy(scratch.ptr() +
blockRelativeStart * sampleSize, buffer, len*sampleSize);
b.f = mDirManager->NewSimpleBlockFile(scratch.ptr(), length, mSampleFormat);
return true;
}
bool Sequence::Get(samplePtr buffer, sampleFormat format,
sampleCount start, size_t len) const
{
@ -1218,32 +1195,50 @@ bool Sequence::Set(samplePtr buffer, sampleFormat format,
const auto fileLength = block.f->GetLength();
const auto blen = limitSampleBufferSize( fileLength - bstart, len );
if (buffer) {
if (format == mSampleFormat)
CopyWrite(scratch, buffer, block, bstart, blen);
else {
// To do: remove the extra movement. Can we copy-samples within CopyWrite?
CopySamples(buffer, format, temp.ptr(), mSampleFormat, blen);
CopyWrite(scratch, temp.ptr(), block, bstart, blen);
samplePtr useBuffer = buffer;
if (buffer && format != mSampleFormat)
{
// To do: remove the extra movement.
CopySamples(buffer, format, temp.ptr(), mSampleFormat, blen);
useBuffer = temp.ptr();
}
// We don't ever write to an existing block; to support Undo,
// we copy the old block entirely into memory, dereference it,
// make the change, and then write the NEW block to disk.
if (!(fileLength <= mMaxSamples &&
bstart + blen <= fileLength))
//THROW_INCONSISTENCY_EXCEPTION
wxASSERT(false)
;
if ( bstart > 0 || blen < fileLength ) {
Read(scratch.ptr(), mSampleFormat, block, 0, fileLength);
if (useBuffer) {
auto sampleSize = SAMPLE_SIZE(mSampleFormat);
memcpy(scratch.ptr() +
bstart * sampleSize, useBuffer, blen * sampleSize);
}
buffer += (blen * SAMPLE_SIZE(format));
else
ClearSamples(scratch.ptr(), mSampleFormat, bstart, blen);
block.f = mDirManager->NewSimpleBlockFile(
scratch.ptr(), fileLength, mSampleFormat);
}
else {
// If it's a full block of silence
if (start == block.start &&
blen == fileLength) {
block.f = make_blockfile<SilentBlockFile>(blen);
}
else {
// Odd partial blocks of silence at start or end.
temp.Allocate(blen, format);
ClearSamples(temp.ptr(), format, 0, blen);
// Otherwise write silence just to the portion of the block
CopyWrite(scratch, temp.ptr(), block, bstart, blen);
}
// Avoid reading the disk when the replacement is total
if (useBuffer)
block.f = mDirManager->NewSimpleBlockFile(
useBuffer, fileLength, mSampleFormat);
else
block.f = make_blockfile<SilentBlockFile>(fileLength);
}
if( buffer )
buffer += (blen * SAMPLE_SIZE(format));
len -= blen;
start += blen;
b++;

View File

@ -252,10 +252,6 @@ class PROFILE_DLL_API Sequence final : public XMLTagHandler{
const SeqBlock &b,
size_t blockRelativeStart, size_t len) const;
bool CopyWrite(SampleBuffer &scratch,
samplePtr buffer, SeqBlock &b,
size_t blockRelativeStart, size_t len);
void Blockify(BlockArray &list, sampleCount start, samplePtr buffer, size_t len);
bool Get(int b, samplePtr buffer, sampleFormat format,