I am developing a simple audio application to try and get to grips with Juce, similar to that of the voice memo's app on an iphone, but with 4 layers of audio. (also with Mute and Solo buttons etc.) I can record and playback each layer, however I am struggling to play back all the layers at the same time. I have a class called TransportBar which has a master "Play" button, which I want to play all 4 layers at the same time.
To do this, I made an AudioSampleBuffer called "masterBuffer", which makes a copy of all of the layerBuffer's. I created a getter function for this as the Layers and Transport bar are created in different classes:
In the Layer.cpp file:
AudioSampleBuffer Layer::getLayerBuffer() const
{
return layerBuffer;
}
I then made a reference to the Layer class in the TransportBar class, and wrote the following code to copy the layerBuffer data to a masterBuffer:
float TransportBar::processSample(float input)
{
float masterOutput = 0.f;
if (playState.get() == true)
{
//play
masterBuffer.makeCopyOf(layerRef.getAudioSampleBuffer());
masterOutput = *(masterBuffer.getReadPointer(0, bufferPosition));
//create click
if ((bufferPosition % (bufferSize / 16)) == 0)
masterOutput += 0.25f;
++bufferPosition;
if (bufferPosition == bufferSize)
{
bufferPosition = 0;
playState = false;
}
}
return masterOutput;
}
This should make a copy of the layerBuffer's to a masterBuffer so I can use it for the output.
Finally, in my audioDeviceIOCallback, I have written this block of code to assign the right buffer:
if (layer.getPlayState() == true || layer2.getPlayState() == true || layer3.getPlayState() == true || layer4.getPlayState() == true )
{
output = layer.processSample (mix) + layer2.processSample(mix) + layer3.processSample(mix) + layer4.processSample(mix);
}
else if (transportBar.getPlayState() == true)
{
layer.processSample(mix);
output = transportBar.processSample(mix);
}
When I press the play buttons on the layers, they playback the audio perfectly fine, however when I press play on the transportBar, all I can hear is a quick click then nothing. Any ideas how to fix this?
