Copy block (mono->stereo)


Pretty simple question, I think. I have this code:

//create an audio block that points to the data in a buffer (4 channels)
dsp::AudioBlock<float> block(buffer);
//get a single channel
dsp::AudioBlock<float> scBlock = block.getSingleChannelBlock(channel);
//take the block and make it stereo, for conv engine.

The buffer has 4 channels in. Channel at this point is 0 so I am getting the first channel and turning it into a block, so I can later use the dsp::convolution engine.

My question: how can I make my single channel audio block into a stereo block where the left and right channels are actually identical (copies of the channel)?

The reason I am asking is because it seems that the convolution engine is not convolving the L and R channels since I am feeding it a mono signal. I was hoping it would get a mono signal and copy it for me.

I am obviously incredibly new at this. If you must, rip me a new one.


I am pretty old at this and still regularly confused with all the audio buffer things in JUCE. :wink: Sorry I can’t help you further right now, I’d need to do some test code to understand how to get the behavior you need.


The AudioBlock only references the data.
But you can simply copy the data in AudioBuffer before you create the AudioBlock from it.

Simply use AudioBuffer::copyFrom()

buffer.copyFrom (1, 0, buffer.getReadPointer (0), buffer.getNumSamples());

Another method inside AudioBlock, you use AudioBlock::getSingleChannelBlock(), that you already found.
I haven’t tried, but I think this should work:

const auto left  = block.getSingleChannelBlock (0);
auto       right = block.getSingleChannelBlock (1);
right.copy (left);

Hope that helps.


@Xenakios No worries. Thanks for the encouragement.
@daniel I will try those methods. I thought about making anew buffer with two channels too but to be honest the documentation is super confusing to me. I guess I will keep trying. My professor said he was willing to help tomorrow. I will update once I find my solution. Thanks!


Solution: in processor header make a dummy audio buffer.

AudioBuffer<float> dummyBuffer;

Then in the process method I allocate space

dummyBuffer.setSize(2, buffer.getNumSamples());

and I copy from the appropriate channel from buffer:

auto* inData = buffer.getReadPointer (0);//followed by 1, 2, 3 (I have four inputs)

dummyBuffer.copyFrom(0, 0, inData, buffer.getNumSamples());//channel 0
dummyBuffer.copyFrom(1, 0, inData, buffer.getNumSamples());//channel 1


You should avoid doing that in the process method. A better place to allocate is in the prepareToPlay method.

Also, WorkBuffer or similar might be a bit more descriptive name for the buffer. :slight_smile: (I use DummyBuffer or similar if the object truly is something that isn’t really used but is required by some other part in the code.)


I did now, you are right.

Potatoe, potato :potato::potato::potato:

Thanks ya’ll. Unfortunately my goal has not yet been reached but this milestone is complete. We can mark this as resolved.