Mono to Stereo - simply buffer.copy() from first to second channel?

Hi all,

I’m working on a Mono Synthesizer which outputs the same signal to both stereo channels. Now currently, both channels are calculated in numerous loops (oscillator, filter, gain etc), but wouldn’t it be more efficient to just calculate the left channel and at the end of the main loop copy that data to the right channel. Or is this a big no no? It seems pointless to me to do everything twice, since the signals need to be identical.

If you’re already doing sample-by-sample processing why not just set the right channel sample equal to the left channel sample after you’ve calculated the left?

for (int sample = 0; sample < numSamples; sample++)
    leftChannelData[sample] = ... // calculate left channel

    rightChannelData[sample] = leftChannelData[sample]

Thanks to vector operations, it will be faster to copy the whole buffer in one go at the end of processBlock.
And no, there is o reason why you should compute it twice…

1 Like

The method is perfectly legitimate when you talking about non-synth processing inside the plug-ins processBlock, however with the Synthesiser class, the voice structure means that you are probably adding the signal that you have generated to the buffer you are passed in SynthVoice::renderNextBlock (instead of replacing) . At which point you don’t want to be copying the left signal to the right as it will contain some of the other voices.

I would generate the signal storing it in a temp buffer (allocated during prepareToPlay) and then add it to the left and right channels in SynthVoice::renderNextBlock.

1 Like

That isn’t a problem since it is monophonic, but thanks for the heads up for future problems. Although that issue will be easily identified. :wink:

That’s what I do, but to me that’s still an unnecessary operation and at 48.000 * upsample factor * loops, it will add up.

Unless your synth is code is completely trivial, doing it that way will have very little overhead.