Created
July 29, 2020 01:25
-
-
Save Xenakios/6647ae927869e26b5ae15a9abcea0d85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MixerCallBack : public AudioIODeviceCallback | |
{ | |
public: | |
std::vector<float> channelGains; | |
std::vector<float> channelPans; | |
MixerCallBack() | |
{ | |
channelGains.resize(16); | |
channelPans.resize(16); | |
} | |
void audioDeviceIOCallback(const float **inputChannelData, int numInputChannels, float **outputChannelData, int numOutputChannels, int numSamples) override | |
{ | |
// zero output buffer before starting to sum into it | |
for (int i=0;i<numOutputChannels;++i) | |
{ | |
for (int j=0;j<numSamples;++j) | |
{ | |
outputChannelData[i][j] = 0.0f; | |
} | |
} | |
for (int i=0;i<numInputChannels;++i) | |
{ | |
for (int j=0;j<numSamples;++j) | |
{ | |
float s = inputChannelData[i][j]; | |
float gain = channelGains[i]; | |
float gain_l = 1.0-channelPans[i]; | |
float gain_r = channelPans[i]; | |
outputChannelData[0][j] += s * gain * gain_l; | |
outputChannelData[1][j] += s * gain * gain_r; | |
} | |
} | |
} | |
void audioDeviceAboutToStart(juce::AudioIODevice *device) override | |
{ | |
} | |
void audioDeviceStopped() override | |
{} | |
}; | |
void test_mixer_cb() | |
{ | |
ScopedJuceInitialiser_GUI mm; | |
AudioDeviceManager man; | |
man.initialiseWithDefaultDevices(8, 2); | |
MixerCallBack mcb; | |
mcb.channelGains[0] = 1.0; | |
mcb.channelPans[0] = 0.5; | |
man.addAudioCallback(&mcb); | |
Thread::sleep(2000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment