earlephilhower / ESP8266Audio

Arduino library to play MOD, WAV, FLAC, MIDI, RTTTL, MP3, and AAC files on I2S DACs or with a software emulated delta-sigma DAC on the ESP8266 and ESP32
GNU General Public License v3.0
2.02k stars 432 forks source link

Add FlipChannels and IsolateChannel to mixer stub #657

Open ChuckMash opened 9 months ago

ChuckMash commented 9 months ago

Adds additional utilities to mixer stubs.

FlipChannels

stub->FlipChannels(true); // Enables Left and Right channel switch/flip for this mixer stub

stub->FlipChannels(false); // Disables Left and Right channel switch/flip for this mixer stub

stub->FlipChannels(); // Inverts current switch/flip setting

IsolateChanel

stub->IsolateChannel(1); // Isolates left channel, effectively muting right channel

stub->IsolateChannel(2); // Isolates right channel, effectively muting left channel

stub->IsolateChannel(0); // Disables channel isolation,

Among other things, this is useful for playing a specific channel from 2 different audio sources to a specific channel in the audio output.


mixer = new AudioOutputMixer(1024, out);

stub[0] = mixer->NewInput();
stub[0]->SetGain(.5);
stub[0]->IsolateChannel(1);

stub[1] = mixer->NewInput();
stub[1]->SetGain(.5);
stub[1]->IsolateChannel(2);

//stub[0]->FlipChannels(true);
//stub[1]->FlipChannels(true);

play_file1 = new AudioFileSourceSD("/1.mp3");
play_file2 = new AudioFileSourceSD("/2.mp3");

mp31 = new AudioGeneratorMP3();
mp32 = new AudioGeneratorMP3();

mp31->begin(play_file1, stub[0]);
mp32->begin(play_file2, stub[1]);

In this example, the output heard is the left channel from 1.mp3 and the right channel from 2.mp3.