Changes to the mono and stereo processes

- Corrected possible issues in the computation
- Removed an unnecessary copy in the mono process
- Trying to make the processes clearer
This commit is contained in:
Paul Ferrand 2020-02-10 14:16:21 +01:00
parent 35d62280a7
commit 33cc4a6518

View file

@ -290,23 +290,23 @@ void sfz::Voice::processMono(AudioSpan<float> buffer) noexcept
auto leftBuffer = buffer.getSpan(0); auto leftBuffer = buffer.getSpan(0);
auto rightBuffer = buffer.getSpan(1); auto rightBuffer = buffer.getSpan(1);
auto span1 = tempSpan1.first(numSamples); auto modulationSpan = tempSpan1.first(numSamples);
// Amplitude envelope // Amplitude envelope
amplitudeEnvelope.getBlock(span1); amplitudeEnvelope.getBlock(modulationSpan);
applyGain<float>(span1, leftBuffer); applyGain<float>(modulationSpan, leftBuffer);
// Crossfade envelope // Crossfade envelope
crossfadeEnvelope.getBlock(span1); crossfadeEnvelope.getBlock(modulationSpan);
applyGain<float>(span1, leftBuffer); applyGain<float>(modulationSpan, leftBuffer);
// Volume envelope // Volume envelope
volumeEnvelope.getBlock(span1); volumeEnvelope.getBlock(modulationSpan);
applyGain<float>(span1, leftBuffer); applyGain<float>(modulationSpan, leftBuffer);
// AmpEG envelope // AmpEG envelope
egEnvelope.getBlock(span1); egEnvelope.getBlock(modulationSpan);
applyGain<float>(span1, leftBuffer); applyGain<float>(modulationSpan, leftBuffer);
// Filtering and EQ // Filtering and EQ
const float* inputChannel[1] { leftBuffer.data() }; const float* inputChannel[1] { leftBuffer.data() };
@ -322,59 +322,67 @@ void sfz::Voice::processMono(AudioSpan<float> buffer) noexcept
// Prepare for stereo output // Prepare for stereo output
copy<float>(leftBuffer, rightBuffer); copy<float>(leftBuffer, rightBuffer);
panEnvelope.getBlock(span1); // Apply panning
copy<float>(leftBuffer, rightBuffer); panEnvelope.getBlock(modulationSpan);
pan<float>(span1, leftBuffer, rightBuffer); pan<float>(modulationSpan, leftBuffer, rightBuffer);
} }
void sfz::Voice::processStereo(AudioSpan<float> buffer) noexcept void sfz::Voice::processStereo(AudioSpan<float> buffer) noexcept
{ {
const auto numSamples = buffer.getNumFrames(); const auto numSamples = buffer.getNumFrames();
auto span1 = tempSpan1.first(numSamples); auto modulationSpan = tempSpan1.first(numSamples);
auto leftBuffer = buffer.getSpan(0); auto leftBuffer = buffer.getSpan(0);
auto rightBuffer = buffer.getSpan(1); auto rightBuffer = buffer.getSpan(1);
// Amplitude envelope // Amplitude envelope
amplitudeEnvelope.getBlock(span1); amplitudeEnvelope.getBlock(modulationSpan);
buffer.applyGain(span1); buffer.applyGain(modulationSpan);
// Crossfade envelope // Crossfade envelope
crossfadeEnvelope.getBlock(span1); crossfadeEnvelope.getBlock(modulationSpan);
buffer.applyGain(span1); buffer.applyGain(modulationSpan);
// Volume envelope // Volume envelope
volumeEnvelope.getBlock(span1); volumeEnvelope.getBlock(modulationSpan);
buffer.applyGain(span1); buffer.applyGain(modulationSpan);
// AmpEG envelope // AmpEG envelope
egEnvelope.getBlock(span1); egEnvelope.getBlock(modulationSpan);
buffer.applyGain(span1); buffer.applyGain(modulationSpan);
// Create mid/side from left/right in the output buffer // Create mid/side from left/right in the output buffer
copy<float>(rightBuffer, span1);
add<float>(leftBuffer, rightBuffer);
subtract<float>(span1, leftBuffer);
// Add const aliases to be slightly more readable // Add const aliases to be slightly more readable
const auto leftBufferCopy = tempSpan2.first(numSamples);
copy<float>(leftBuffer, leftBufferCopy);
const auto midBuffer = leftBuffer; const auto midBuffer = leftBuffer;
add<float>(rightBuffer, midBuffer);
const auto sideBuffer = rightBuffer; const auto sideBuffer = rightBuffer;
applyGain<float>(-1.0f, sideBuffer);
add<float>(leftBufferCopy, sideBuffer);
applyGain<float>(sqrtTwoInv<float>, midBuffer); applyGain<float>(sqrtTwoInv<float>, midBuffer);
applyGain<float>(sqrtTwoInv<float>, sideBuffer); applyGain<float>(sqrtTwoInv<float>, sideBuffer);
// Apply the width process // Apply the width process
widthEnvelope.getBlock(span1); widthEnvelope.getBlock(modulationSpan);
width<float>(span1, midBuffer, sideBuffer); width<float>(modulationSpan, midBuffer, sideBuffer);
// Copy the mid channel into another span // Copy the mid channel into another span
const auto midBufferRight = tempSpan2.first(numSamples); const auto midBufferCopy = tempSpan3.first(numSamples);
copy<float>(midBuffer, midBufferRight); copy<float>(midBuffer, midBufferCopy);
positionEnvelope.getBlock(span1); positionEnvelope.getBlock(modulationSpan);
pan<float>(span1, midBuffer, midBufferRight); pan<float>(modulationSpan, midBuffer, midBufferCopy);
// Rebuild left/right // Rebuild left/right
add<float>(sideBuffer, midBuffer); // Recall that midBuffer and leftBuffer point to the same buffer
add<float>(sideBuffer, leftBuffer);
applyGain(sqrtTwoInv<float>, leftBuffer); applyGain(sqrtTwoInv<float>, leftBuffer);
add<float>(midBufferRight, sideBuffer);
// Recall that sideBuffer and rightBuffer point to the same buffer
applyGain<float>(-1.0f, sideBuffer);
add<float>(midBufferCopy, sideBuffer);
applyGain(sqrtTwoInv<float>, rightBuffer); applyGain(sqrtTwoInv<float>, rightBuffer);
// Filtering and EQ // Filtering and EQ