mirror of
https://github.com/cookiengineer/audacity
synced 2026-03-07 23:15:36 +01:00
Remove naked new[] in: builtin effects
This commit is contained in:
@@ -182,58 +182,55 @@ bool EffectSoundTouch::ProcessOne(WaveTrack *track,
|
||||
//to make it a double now than it is to do it later
|
||||
auto len = (end - start).as_double();
|
||||
|
||||
//Initiate a processing buffer. This buffer will (most likely)
|
||||
//be shorter than the length of the track being processed.
|
||||
float *buffer = new float[track->GetMaxBlockSize()];
|
||||
{
|
||||
//Initiate a processing buffer. This buffer will (most likely)
|
||||
//be shorter than the length of the track being processed.
|
||||
Floats buffer{ track->GetMaxBlockSize() };
|
||||
|
||||
//Go through the track one buffer at a time. s counts which
|
||||
//sample the current buffer starts at.
|
||||
auto s = start;
|
||||
while (s < end) {
|
||||
//Get a block of samples (smaller than the size of the buffer)
|
||||
const auto block =
|
||||
limitSampleBufferSize( track->GetBestBlockSize(s), end - s );
|
||||
//Go through the track one buffer at a time. s counts which
|
||||
//sample the current buffer starts at.
|
||||
auto s = start;
|
||||
while (s < end) {
|
||||
//Get a block of samples (smaller than the size of the buffer)
|
||||
const auto block =
|
||||
limitSampleBufferSize( track->GetBestBlockSize(s), end - s );
|
||||
|
||||
//Get the samples from the track and put them in the buffer
|
||||
track->Get((samplePtr) buffer, floatSample, s, block);
|
||||
//Get the samples from the track and put them in the buffer
|
||||
track->Get((samplePtr)buffer.get(), floatSample, s, block);
|
||||
|
||||
//Add samples to SoundTouch
|
||||
mSoundTouch->putSamples(buffer, block);
|
||||
//Add samples to SoundTouch
|
||||
mSoundTouch->putSamples(buffer.get(), block);
|
||||
|
||||
//Get back samples from SoundTouch
|
||||
unsigned int outputCount = mSoundTouch->numSamples();
|
||||
if (outputCount > 0) {
|
||||
float *buffer2 = new float[outputCount];
|
||||
mSoundTouch->receiveSamples(buffer2, outputCount);
|
||||
outputTrack->Append((samplePtr)buffer2, floatSample, outputCount);
|
||||
delete[] buffer2;
|
||||
//Get back samples from SoundTouch
|
||||
unsigned int outputCount = mSoundTouch->numSamples();
|
||||
if (outputCount > 0) {
|
||||
Floats buffer2{ outputCount };
|
||||
mSoundTouch->receiveSamples(buffer2.get(), outputCount);
|
||||
outputTrack->Append((samplePtr)buffer2.get(), floatSample, outputCount);
|
||||
}
|
||||
|
||||
//Increment s one blockfull of samples
|
||||
s += block;
|
||||
|
||||
//Update the Progress meter
|
||||
if (TrackProgress(mCurTrackNum, (s - start).as_double() / len))
|
||||
return false;
|
||||
}
|
||||
|
||||
//Increment s one blockfull of samples
|
||||
s += block;
|
||||
// Tell SoundTouch to finish processing any remaining samples
|
||||
mSoundTouch->flush(); // this should only be used for changeTempo - it dumps data otherwise with pRateTransposer->clear();
|
||||
|
||||
//Update the Progress meter
|
||||
if (TrackProgress(mCurTrackNum, (s - start).as_double() / len))
|
||||
return false;
|
||||
unsigned int outputCount = mSoundTouch->numSamples();
|
||||
if (outputCount > 0) {
|
||||
Floats buffer2{ outputCount };
|
||||
mSoundTouch->receiveSamples(buffer2.get(), outputCount);
|
||||
outputTrack->Append((samplePtr)buffer2.get(), floatSample, outputCount);
|
||||
}
|
||||
|
||||
// Flush the output WaveTrack (since it's buffered, too)
|
||||
outputTrack->Flush();
|
||||
}
|
||||
|
||||
// Tell SoundTouch to finish processing any remaining samples
|
||||
mSoundTouch->flush(); // this should only be used for changeTempo - it dumps data otherwise with pRateTransposer->clear();
|
||||
|
||||
unsigned int outputCount = mSoundTouch->numSamples();
|
||||
if (outputCount > 0) {
|
||||
float *buffer2 = new float[outputCount];
|
||||
mSoundTouch->receiveSamples(buffer2, outputCount);
|
||||
outputTrack->Append((samplePtr)buffer2, floatSample, outputCount);
|
||||
delete[] buffer2;
|
||||
}
|
||||
|
||||
// Flush the output WaveTrack (since it's buffered, too)
|
||||
outputTrack->Flush();
|
||||
|
||||
// Clean up the buffer
|
||||
delete[]buffer;
|
||||
|
||||
// Take the output track and insert it in place of the original
|
||||
// sample data
|
||||
track->ClearAndPaste(mCurT0, mCurT1, outputTrack.get(), true, false, &warper);
|
||||
@@ -249,7 +246,7 @@ bool EffectSoundTouch::ProcessStereo(
|
||||
WaveTrack* leftTrack, WaveTrack* rightTrack,
|
||||
sampleCount start, sampleCount end, const TimeWarper &warper)
|
||||
{
|
||||
mSoundTouch->setSampleRate((unsigned int)(leftTrack->GetRate()+0.5));
|
||||
mSoundTouch->setSampleRate((unsigned int)(leftTrack->GetRate() + 0.5));
|
||||
|
||||
auto outputLeftTrack = mFactory->NewWaveTrack(leftTrack->GetSampleFormat(),
|
||||
leftTrack->GetRate());
|
||||
@@ -267,75 +264,70 @@ bool EffectSoundTouch::ProcessStereo(
|
||||
// because Soundtouch wants them interleaved, i.e., each
|
||||
// Soundtouch sample is left-right pair.
|
||||
auto maxBlockSize = leftTrack->GetMaxBlockSize();
|
||||
float* leftBuffer = new float[maxBlockSize];
|
||||
float* rightBuffer = new float[maxBlockSize];
|
||||
float* soundTouchBuffer = new float[maxBlockSize * 2];
|
||||
{
|
||||
Floats leftBuffer{ maxBlockSize };
|
||||
Floats rightBuffer{ maxBlockSize };
|
||||
Floats soundTouchBuffer{ maxBlockSize * 2 };
|
||||
|
||||
// Go through the track one stereo buffer at a time.
|
||||
// sourceSampleCount counts the sample at which the current buffer starts,
|
||||
// per channel.
|
||||
auto sourceSampleCount = start;
|
||||
while (sourceSampleCount < end) {
|
||||
//Get a block of samples (smaller than the size of the buffer)
|
||||
//Adjust the block size if it is the final block in the track
|
||||
auto blockSize = limitSampleBufferSize(
|
||||
leftTrack->GetBestBlockSize(sourceSampleCount),
|
||||
end - sourceSampleCount
|
||||
);
|
||||
// Go through the track one stereo buffer at a time.
|
||||
// sourceSampleCount counts the sample at which the current buffer starts,
|
||||
// per channel.
|
||||
auto sourceSampleCount = start;
|
||||
while (sourceSampleCount < end) {
|
||||
auto blockSize = limitSampleBufferSize(
|
||||
leftTrack->GetBestBlockSize(sourceSampleCount),
|
||||
end - sourceSampleCount
|
||||
);
|
||||
|
||||
// Get the samples from the tracks and put them in the buffers.
|
||||
leftTrack->Get((samplePtr)(leftBuffer), floatSample, sourceSampleCount, blockSize);
|
||||
rightTrack->Get((samplePtr)(rightBuffer), floatSample, sourceSampleCount, blockSize);
|
||||
// Get the samples from the tracks and put them in the buffers.
|
||||
leftTrack->Get((samplePtr)(leftBuffer.get()), floatSample, sourceSampleCount, blockSize);
|
||||
rightTrack->Get((samplePtr)(rightBuffer.get()), floatSample, sourceSampleCount, blockSize);
|
||||
|
||||
// Interleave into soundTouchBuffer.
|
||||
for (decltype(blockSize) index = 0; index < blockSize; index++) {
|
||||
soundTouchBuffer[index*2] = leftBuffer[index];
|
||||
soundTouchBuffer[(index*2)+1] = rightBuffer[index];
|
||||
// Interleave into soundTouchBuffer.
|
||||
for (decltype(blockSize) index = 0; index < blockSize; index++) {
|
||||
soundTouchBuffer[index * 2] = leftBuffer[index];
|
||||
soundTouchBuffer[(index * 2) + 1] = rightBuffer[index];
|
||||
}
|
||||
|
||||
//Add samples to SoundTouch
|
||||
mSoundTouch->putSamples(soundTouchBuffer.get(), blockSize);
|
||||
|
||||
//Get back samples from SoundTouch
|
||||
unsigned int outputCount = mSoundTouch->numSamples();
|
||||
if (outputCount > 0)
|
||||
this->ProcessStereoResults(outputCount, outputLeftTrack.get(), outputRightTrack.get());
|
||||
|
||||
//Increment sourceSampleCount one blockfull of samples
|
||||
sourceSampleCount += blockSize;
|
||||
|
||||
//Update the Progress meter
|
||||
// mCurTrackNum is left track. Include right track.
|
||||
int nWhichTrack = mCurTrackNum;
|
||||
double frac = (sourceSampleCount - start).as_double() / len;
|
||||
if (frac < 0.5)
|
||||
frac *= 2.0; // Show twice as far for each track, because we're doing 2 at once.
|
||||
else
|
||||
{
|
||||
nWhichTrack++;
|
||||
frac -= 0.5;
|
||||
frac *= 2.0; // Show twice as far for each track, because we're doing 2 at once.
|
||||
}
|
||||
if (TrackProgress(nWhichTrack, frac))
|
||||
return false;
|
||||
}
|
||||
|
||||
//Add samples to SoundTouch
|
||||
mSoundTouch->putSamples(soundTouchBuffer, blockSize);
|
||||
// Tell SoundTouch to finish processing any remaining samples
|
||||
mSoundTouch->flush();
|
||||
|
||||
//Get back samples from SoundTouch
|
||||
unsigned int outputCount = mSoundTouch->numSamples();
|
||||
if (outputCount > 0)
|
||||
this->ProcessStereoResults(outputCount, outputLeftTrack.get(), outputRightTrack.get());
|
||||
|
||||
//Increment sourceSampleCount one blockfull of samples
|
||||
sourceSampleCount += blockSize;
|
||||
|
||||
//Update the Progress meter
|
||||
// mCurTrackNum is left track. Include right track.
|
||||
int nWhichTrack = mCurTrackNum;
|
||||
double frac = (sourceSampleCount - start).as_double() / len;
|
||||
if (frac < 0.5)
|
||||
frac *= 2.0; // Show twice as far for each track, because we're doing 2 at once.
|
||||
else
|
||||
{
|
||||
nWhichTrack++;
|
||||
frac -= 0.5;
|
||||
frac *= 2.0; // Show twice as far for each track, because we're doing 2 at once.
|
||||
}
|
||||
if (TrackProgress(nWhichTrack, frac))
|
||||
return false;
|
||||
// Flush the output WaveTracks (since they're buffered, too)
|
||||
outputLeftTrack->Flush();
|
||||
outputRightTrack->Flush();
|
||||
}
|
||||
|
||||
// Tell SoundTouch to finish processing any remaining samples
|
||||
mSoundTouch->flush();
|
||||
|
||||
unsigned int outputCount = mSoundTouch->numSamples();
|
||||
if (outputCount > 0)
|
||||
this->ProcessStereoResults(outputCount, outputLeftTrack.get(), outputRightTrack.get());
|
||||
|
||||
// Flush the output WaveTracks (since they're buffered, too)
|
||||
outputLeftTrack->Flush();
|
||||
outputRightTrack->Flush();
|
||||
|
||||
// Clean up the buffers.
|
||||
delete [] leftBuffer;
|
||||
delete [] rightBuffer;
|
||||
delete [] soundTouchBuffer;
|
||||
|
||||
// Take the output tracks and insert in place of the original
|
||||
// sample data.
|
||||
leftTrack->ClearAndPaste(
|
||||
@@ -357,24 +349,20 @@ bool EffectSoundTouch::ProcessStereoResults(const unsigned int outputCount,
|
||||
WaveTrack* outputLeftTrack,
|
||||
WaveTrack* outputRightTrack)
|
||||
{
|
||||
float* outputSoundTouchBuffer = new float[outputCount*2];
|
||||
mSoundTouch->receiveSamples(outputSoundTouchBuffer, outputCount);
|
||||
Floats outputSoundTouchBuffer{ outputCount * 2 };
|
||||
mSoundTouch->receiveSamples(outputSoundTouchBuffer.get(), outputCount);
|
||||
|
||||
// Dis-interleave outputSoundTouchBuffer into separate track buffers.
|
||||
float* outputLeftBuffer = new float[outputCount];
|
||||
float* outputRightBuffer = new float[outputCount];
|
||||
Floats outputLeftBuffer{ outputCount };
|
||||
Floats outputRightBuffer{ outputCount };
|
||||
for (unsigned int index = 0; index < outputCount; index++)
|
||||
{
|
||||
outputLeftBuffer[index] = outputSoundTouchBuffer[index*2];
|
||||
outputRightBuffer[index] = outputSoundTouchBuffer[(index*2)+1];
|
||||
}
|
||||
|
||||
outputLeftTrack->Append((samplePtr)outputLeftBuffer, floatSample, outputCount);
|
||||
outputRightTrack->Append((samplePtr)outputRightBuffer, floatSample, outputCount);
|
||||
|
||||
delete[] outputSoundTouchBuffer;
|
||||
delete[] outputLeftBuffer;
|
||||
delete[] outputRightBuffer;
|
||||
outputLeftTrack->Append((samplePtr)outputLeftBuffer.get(), floatSample, outputCount);
|
||||
outputRightTrack->Append((samplePtr)outputRightBuffer.get(), floatSample, outputCount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user