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:
parent
c6b4e2fffe
commit
7b7ad75a49
@ -1134,29 +1134,6 @@ bool Sequence::Read(samplePtr buffer, sampleFormat format,
|
|||||||
return true;
|
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,
|
bool Sequence::Get(samplePtr buffer, sampleFormat format,
|
||||||
sampleCount start, size_t len) const
|
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 fileLength = block.f->GetLength();
|
||||||
const auto blen = limitSampleBufferSize( fileLength - bstart, len );
|
const auto blen = limitSampleBufferSize( fileLength - bstart, len );
|
||||||
|
|
||||||
if (buffer) {
|
samplePtr useBuffer = buffer;
|
||||||
if (format == mSampleFormat)
|
if (buffer && format != mSampleFormat)
|
||||||
CopyWrite(scratch, buffer, block, bstart, blen);
|
{
|
||||||
else {
|
// To do: remove the extra movement.
|
||||||
// To do: remove the extra movement. Can we copy-samples within CopyWrite?
|
CopySamples(buffer, format, temp.ptr(), mSampleFormat, blen);
|
||||||
CopySamples(buffer, format, temp.ptr(), mSampleFormat, blen);
|
useBuffer = temp.ptr();
|
||||||
CopyWrite(scratch, temp.ptr(), block, bstart, blen);
|
}
|
||||||
|
|
||||||
|
// 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 {
|
else {
|
||||||
// If it's a full block of silence
|
// Avoid reading the disk when the replacement is total
|
||||||
if (start == block.start &&
|
if (useBuffer)
|
||||||
blen == fileLength) {
|
block.f = mDirManager->NewSimpleBlockFile(
|
||||||
|
useBuffer, fileLength, mSampleFormat);
|
||||||
block.f = make_blockfile<SilentBlockFile>(blen);
|
else
|
||||||
}
|
block.f = make_blockfile<SilentBlockFile>(fileLength);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( buffer )
|
||||||
|
buffer += (blen * SAMPLE_SIZE(format));
|
||||||
|
|
||||||
len -= blen;
|
len -= blen;
|
||||||
start += blen;
|
start += blen;
|
||||||
b++;
|
b++;
|
||||||
|
@ -252,10 +252,6 @@ class PROFILE_DLL_API Sequence final : public XMLTagHandler{
|
|||||||
const SeqBlock &b,
|
const SeqBlock &b,
|
||||||
size_t blockRelativeStart, size_t len) const;
|
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);
|
void Blockify(BlockArray &list, sampleCount start, samplePtr buffer, size_t len);
|
||||||
|
|
||||||
bool Get(int b, samplePtr buffer, sampleFormat format,
|
bool Get(int b, samplePtr buffer, sampleFormat format,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user