Hello,
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)
{
bufferToFill.clearActiveBufferRegion();
return;
}
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";
#endif
}
}
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)
Thanks