diff --git a/src/sfizz/Voice.cpp b/src/sfizz/Voice.cpp index b18416f5..45e6ab4e 100644 --- a/src/sfizz/Voice.cpp +++ b/src/sfizz/Voice.cpp @@ -327,33 +327,28 @@ void sfz::Voice::processStereo(AudioSpan buffer) noexcept copy(rightBuffer, span1); add(leftBuffer, rightBuffer); subtract(span1, leftBuffer); - applyGain(sqrtTwoInv, leftBuffer); - applyGain(sqrtTwoInv, rightBuffer); + + // Add const aliases to be slightly more readable + const auto midBuffer = leftBuffer; + const auto sideBuffer = rightBuffer; + applyGain(sqrtTwoInv, midBuffer); + applyGain(sqrtTwoInv, sideBuffer); // Apply the width process widthEnvelope.getBlock(span1); - fill(span2, 1.0f); - add(span1, span2); - applyGain(piFour, span2); - cos(span2, span1); - sin(span2, span2); - applyGain(span1, leftBuffer); - applyGain(span2, rightBuffer); + width(span1, midBuffer, sideBuffer); - // Apply a position to the "left" channel which is supposed to be our mid channel - // TODO: add panning here too? + // Copy the mid channel into another span + const auto midBufferRight = span2; + copy(midBuffer, midBufferRight); positionEnvelope.getBlock(span1); - fill(span2, 1.0f); - add(span1, span2); - applyGain(piFour, span2); - cos(span2, span1); - sin(span2, span2); - copy(leftBuffer, span3); - copy(rightBuffer, leftBuffer); - multiplyAdd(span1, span3, leftBuffer); - multiplyAdd(span2, span3, rightBuffer); - applyGain(sqrtTwoInv, leftBuffer); - applyGain(sqrtTwoInv, rightBuffer); + pan(span1, midBuffer, midBufferRight); + + // Rebuild left/right + add(sideBuffer, midBuffer); + applyGain(sqrtTwoInv, leftBuffer); + add(midBufferRight, sideBuffer); + applyGain(sqrtTwoInv, rightBuffer); } void sfz::Voice::fillWithData(AudioSpan buffer) noexcept