mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-16 15:41:11 +02:00
Move memory allocation to where it's needed, at the request of Ed. No functional changes.
This commit is contained in:
@@ -1286,12 +1286,6 @@ bool Sequence::Append(samplePtr buffer, sampleFormat format,
|
|||||||
if (((double)mNumSamples) + ((double)len) > wxLL(9223372036854775807))
|
if (((double)mNumSamples) + ((double)len) > wxLL(9223372036854775807))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
samplePtr temp = NULL;
|
|
||||||
if (format != mSampleFormat) {
|
|
||||||
temp = NewSamples(mMaxSamples, mSampleFormat);
|
|
||||||
wxASSERT(temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the last block is not full, we need to add samples to it
|
// If the last block is not full, we need to add samples to it
|
||||||
int numBlocks = mBlock->Count();
|
int numBlocks = mBlock->Count();
|
||||||
if (numBlocks > 0 && mBlock->Item(numBlocks - 1)->f->GetLength() < mMinSamples) {
|
if (numBlocks > 0 && mBlock->Item(numBlocks - 1)->f->GetLength() < mMinSamples) {
|
||||||
@@ -1333,6 +1327,15 @@ bool Sequence::Append(samplePtr buffer, sampleFormat format,
|
|||||||
buffer += addLen * SAMPLE_SIZE(format);
|
buffer += addLen * SAMPLE_SIZE(format);
|
||||||
}
|
}
|
||||||
// Append the rest as new blocks
|
// Append the rest as new blocks
|
||||||
|
samplePtr temp = NULL;
|
||||||
|
if (format != mSampleFormat) {
|
||||||
|
temp = NewSamples(mMaxSamples, mSampleFormat);
|
||||||
|
wxASSERT(temp);
|
||||||
|
if (!temp) {
|
||||||
|
wxMessageBox(_("Memory allocation failed -- NewSamples"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
while (len) {
|
while (len) {
|
||||||
sampleCount idealSamples = GetIdealBlockSize();
|
sampleCount idealSamples = GetIdealBlockSize();
|
||||||
sampleCount l = (len > idealSamples ? idealSamples : len);
|
sampleCount l = (len > idealSamples ? idealSamples : len);
|
||||||
@@ -1358,8 +1361,7 @@ bool Sequence::Append(samplePtr buffer, sampleFormat format,
|
|||||||
mNumSamples += l;
|
mNumSamples += l;
|
||||||
len -= l;
|
len -= l;
|
||||||
}
|
}
|
||||||
|
if (temp)
|
||||||
if (format != mSampleFormat)
|
|
||||||
DeleteSamples(temp);
|
DeleteSamples(temp);
|
||||||
|
|
||||||
// JKC: During generate we use Append again and again.
|
// JKC: During generate we use Append again and again.
|
||||||
@@ -1691,16 +1693,3 @@ void Sequence::AppendBlockFile(BlockFile* blockFile)
|
|||||||
ConsistencyCheck(wxT("AppendBlockFile"));
|
ConsistencyCheck(wxT("AppendBlockFile"));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Indentation settings for Vim and Emacs and unique identifier for Arch, a
|
|
||||||
// version control system. Please do not modify past this point.
|
|
||||||
//
|
|
||||||
// Local Variables:
|
|
||||||
// c-basic-offset: 3
|
|
||||||
// indent-tabs-mode: nil
|
|
||||||
// End:
|
|
||||||
//
|
|
||||||
// vim: et sts=3 sw=3
|
|
||||||
// arch-tag: db4a8822-8419-4e37-869e-957151956fb7
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user