[rectified] Panning, what am I missing? AudioBuffer


Trying to do a simple linear pan but I’m not sure where it’s going wrong. I’ve modified the PlayingSoundFilesTutorial_03.h PIP for simplicity…

The main bits:

float level = 1.0;
float levelL = 0.5;
float levelR = 0.5;
void setLevel (const float newValue) {
    level = juce::jmax (newValue, 0.0f);
void setPan (const float newValue) {
    const float value = (newValue / 2.0f) + 0.5f;
    // #linear
    const float l = 1.0f - value;
    const float r = value;
    levelL = (juce::jmin (juce::jmax (l, 0.0f), 1.0f));
    levelR = (juce::jmin (juce::jmax (r, 0.0f), 1.0f));
void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) override
    if (readerSource.get() == nullptr)

    transportSource.getNextAudioBlock (bufferToFill);
        const float l = level * levelL;
        const float r = level * levelR;
        bufferToFill.buffer->applyGain (0, 0, bufferToFill.buffer->getNumSamples(), l);
        bufferToFill.buffer->applyGain (1, 0, bufferToFill.buffer->getNumSamples(), r);
       #if JUCE_DEBUG
        std::cout << "l: " << l << "\n";
        std::cout << "r: " << r << "\n";

I’ve added a couple sliders to the PIP one for level range: 0.0 - 1.0 and one for the pan value range: -1.0 - 1.0

PlayingSoundFilesTutorial_03.h (10.0 KB)


I’m on mobile so I can’t run the project, but what is going wrong exactly?

By the way you should apply the gain on the region specified in the AudioSourceChannelInfo. There is a starting point and duration stores in there :slight_smile:

Holy fuck!


I might need a break honestly.


I did not even know there was such an option!