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

Fix for bug 216 VST processing 4 to 12 times slower than in 1.3.8

This commit is contained in:
mchinen 2010-11-29 17:34:37 +00:00
parent 599fdd9d97
commit 10bec68701
2 changed files with 39 additions and 8 deletions

@ -1310,7 +1310,7 @@ bool VSTEffect::Process()
} }
if (mBlockSize == 0) { if (mBlockSize == 0) {
mBlockSize = left->GetMaxBlockSize() * 2; mBlockSize = mWTBlockSize = left->GetMaxBlockSize() * 2;
// Some VST effects (Antress Modern is an example), do not like // Some VST effects (Antress Modern is an example), do not like
// overly large block sizes. Unfortunately, I have not found a // overly large block sizes. Unfortunately, I have not found a
@ -1327,9 +1327,11 @@ bool VSTEffect::Process()
mInBuffer[i] = new float[mBlockSize]; mInBuffer[i] = new float[mBlockSize];
} }
//Process 2 audacity blockfiles per WaveTrack::Set independently of mBlockSize
//because it is extremely slow to do multiple Set()s per blockfile.
mOutBuffer = new float *[mOutputs]; mOutBuffer = new float *[mOutputs];
for (int i = 0; i < mOutputs; i++) { for (int i = 0; i < mOutputs; i++) {
mOutBuffer[i] = new float[mBlockSize]; mOutBuffer[i] = new float[mWTBlockSize + mBlockSize];
} }
// Turn the power off // Turn the power off
@ -1385,6 +1387,7 @@ bool VSTEffect::ProcessStereo(int count,
sampleCount len) sampleCount len)
{ {
bool rc = true; bool rc = true;
sampleCount amountLeft = 0;
// Initialize time info // Initialize time info
mTimeInfo.samplePos = 0.0; mTimeInfo.samplePos = 0.0;
@ -1401,6 +1404,10 @@ bool VSTEffect::ProcessStereo(int count,
sampleCount originalLen = len; sampleCount originalLen = len;
sampleCount ls = lstart; sampleCount ls = lstart;
sampleCount rs = rstart; sampleCount rs = rstart;
sampleCount outls = lstart;
sampleCount outrs = rstart;
sampleCount outBufferCursor = 0;
float **outBufSegment = new float *[mOutputs];
while (len) { while (len) {
int block = mBlockSize; int block = mBlockSize;
if (block > len) { if (block > len) {
@ -1412,12 +1419,27 @@ bool VSTEffect::ProcessStereo(int count,
right->Get((samplePtr)mInBuffer[1], floatSample, rs, block); right->Get((samplePtr)mInBuffer[1], floatSample, rs, block);
} }
callProcessReplacing(mInBuffer, mOutBuffer, block); for (int i = 0; i < mOutputs; i++)
outBufSegment[i] = mOutBuffer[i ] + outBufferCursor;
left->Set((samplePtr)mOutBuffer[0], floatSample, ls, block); callProcessReplacing(mInBuffer, outBufSegment, block);
if (right) { outBufferCursor += block;
right->Set((samplePtr)mOutBuffer[1], floatSample, rs, block); //Process 2 audacity blockfiles per WaveTrack::Set independently of mBlockSize
} //because it is extremely slow to do multiple Set()s per blockfile due to Undo History
//If we do more optimization we should probably align the Sets to blockfile boundries.
if (outBufferCursor >= mWTBlockSize) {
left->Set((samplePtr)mOutBuffer[0], floatSample, outls, mWTBlockSize);
if (right) {
right->Set((samplePtr)mOutBuffer[1], floatSample, outrs, mWTBlockSize);
}
if (outBufferCursor > mWTBlockSize) {
//snake the buffer down
memmove(mOutBuffer[0], mOutBuffer[0] + mWTBlockSize, SAMPLE_SIZE(floatSample) * (outBufferCursor - mWTBlockSize));
memmove(mOutBuffer[1], mOutBuffer[1] + mWTBlockSize, SAMPLE_SIZE(floatSample) * (outBufferCursor - mWTBlockSize));
}
outBufferCursor -= mWTBlockSize;
outls += mWTBlockSize;
outrs += mWTBlockSize;
}
len -= block; len -= block;
ls += block; ls += block;
@ -1438,6 +1460,14 @@ bool VSTEffect::ProcessStereo(int count,
} }
} }
//finish taking the remainder.
if (outBufferCursor) {
left->Set((samplePtr)mOutBuffer[0], floatSample, ls, outBufferCursor);
if (right) {
right->Set((samplePtr)mOutBuffer[1], floatSample, rs, outBufferCursor);
}
}
// Tell effect we're done // Tell effect we're done
callDispatcher(effStopProcess, 0, 0, NULL, 0.0); callDispatcher(effStopProcess, 0, 0, NULL, 0.0);

@ -108,6 +108,7 @@ class VSTEffect:public Effect
VstTimeInfo mTimeInfo; VstTimeInfo mTimeInfo;
sampleCount mBlockSize; sampleCount mBlockSize;
sampleCount mWTBlockSize;
float **mInBuffer; float **mInBuffer;
float **mOutBuffer; float **mOutBuffer;
int mInputs; int mInputs;