Skip to content

Commit

Permalink
Support volume on each input channel
Browse files Browse the repository at this point in the history
Call stub->SetGain(float) to set an input's volume before mixing.
  • Loading branch information
earlephilhower committed Feb 25, 2018
1 parent ca50839 commit 3c7ffbe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions examples/MixerSample/MixerSample.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void setup()
out = new AudioOutputI2S();
mixer = new AudioOutputMixer(32, out);
stub[0] = mixer->NewInput();
stub[0]->SetGain(0.3);
wav[0] = new AudioGeneratorWAV();
wav[0]->begin(file[0], stub[0]);
// Begin wav[1] later in loop()
Expand All @@ -50,6 +51,7 @@ void loop()
if (!go) {
Serial.printf("starting 2\n");
stub[1] = mixer->NewInput();
stub[1]->SetGain(0.4);
wav[1] = new AudioGeneratorWAV();
file[1] = new AudioFileSourcePROGMEM( viola, sizeof(viola) );
wav[1]->begin(file[1], stub[1]);
Expand Down
7 changes: 5 additions & 2 deletions src/AudioOutputMixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ AudioOutputMixerStub::AudioOutputMixerStub(AudioOutputMixer *sink, int id) : Aud
{
this->id = id;
this->parent = sink;
SetGain(1.0);
}

AudioOutputMixerStub::~AudioOutputMixerStub()
Expand Down Expand Up @@ -54,8 +55,10 @@ bool AudioOutputMixerStub::begin()

bool AudioOutputMixerStub::ConsumeSample(int16_t sample[2])
{
// int16_t amp[2] = { Amplify(sample[LEFTCHANNEL]), Amplify(sample[RIGHTCHANNEL]) };
return parent->ConsumeSample(sample, id);
int16_t amp[2];
amp[LEFTCHANNEL] = Amplify(sample[LEFTCHANNEL]);
amp[RIGHTCHANNEL] = Amplify(sample[RIGHTCHANNEL]);
return parent->ConsumeSample(amp, id);
}

bool AudioOutputMixerStub::stop()
Expand Down

0 comments on commit 3c7ffbe

Please sign in to comment.