Giving two outputs in one I2S port


I am using one I2S port for mic. So I'm left with one more port since ESP32 has only 2 I2S ports. I'm trying to give two outputs to one I2S port. One output is playing music through Bluetooth and another output is playing Audio file from PROGMEM but there is no success. I've given delay to play audio file. When that delay time is finished, my music starts sounding very weird like some devil is speaking in heavy voice.

Does anyone have any idea on how to achieve this?
Here's the code

#include <Arduino.h>

#include "AudioFileSourcePROGMEM.h"
#include "AudioGeneratorWAV.h"
#include "AudioOutputI2S.h"
#include <BluetoothA2DPSink.h>
// VIOLA sample taken from
#include "notification.h"

BluetoothA2DPSink a2dp_sink;

AudioGeneratorWAV *wav;
AudioFileSourcePROGMEM *file;
AudioOutputI2S *out;

void setup()

  Serial.printf("WAV start\n");
   audioLogger = &Serial;
   file = new AudioFileSourcePROGMEM( sample, sizeof(sample) );
   out = new AudioOutputI2S();
   wav = new AudioGeneratorWAV();
   wav->begin(file, out);

void loop()
    if (wav->isRunning()) {
      if (!wav->loop()) wav->stop();
    } else {
      Serial.printf("WAV done\n");

I start playing audio file after 30 seconds.
I've used same pins and same port for both task. Output is better when I use same pins.

.bck_io_num = 23, // BCLK pin of DAC module
.ws_io_num = 14, // WS pin of DAC module
.data_out_num = 22, // Din pin of DAC module
.data_in_num = I2S_PIN_NO_CHANGE};

Below are the links for header files




I've changed pin configuration here


I've changed pin configuration here

I hope I've added enough content

If You post code and schematics helpers will likely have tips.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.