Trying to switch left and right channel in audio app but receiving mono output


#1

Hi,

I’ve been following some tutorials and decided to try a very simple thing to get a bit firmer grasp on JUCE. I load a stereo WAV file and employ basic Play and Stop functionality via AudioTransportSource class. While playing the file, the only processing I’d like to do is switching the channels. I do that in the getNextAudioBlock() method below … only to get both output channels playing the right channel of the incoming file. I know there must be something very basic I’m missing, but I don’t see it.

</
void MainComponent::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
{
transport.getNextAudioBlock(bufferToFill);

auto* leftIn = bufferToFill.buffer->getReadPointer(0, bufferToFill.startSample);
auto* rightIn = bufferToFill.buffer->getReadPointer(1, bufferToFill.startSample);

auto* leftOut = bufferToFill.buffer->getWritePointer(0, bufferToFill.startSample);
auto* rightOut = bufferToFill.buffer->getWritePointer(1, bufferToFill.startSample);

for (auto sample = 0; sample < bufferToFill.numSamples; ++sample)
{
    leftOut[sample] = rightIn[sample];
    rightOut[sample] = leftIn[sample];
}

}>


#2

The input and output pointers point to the same buffers, so you need to change the loop to make copies of the samples with something like :


#3

Thanks @Xenakios, I’ve just realized that and was going to delete the post, only to realize somebody has already reached out :slight_smile: I appreciate it, cheers!