Giving two outputs in one I2S port

Hi,

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 https://ccrma.stanford.edu/~jos/pasp/Sound_Examples.html
#include "notification.h"

BluetoothA2DPSink a2dp_sink;

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

void setup()
{

  a2dp_sink.start("MyMusic");
  Serial.begin(115200);
  delay(30000);
  Serial.printf("WAV start\n");
   a2dp_sink.pause();
   audioLogger = &Serial;
   file = new AudioFileSourcePROGMEM( sample, sizeof(sample) );
   out = new AudioOutputI2S();
   wav = new AudioGeneratorWAV();
   wav->begin(file, out);
   delay(3000);
   wav->stop();
   a2dp_sink.play();
}

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

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

AudioFileSourcePROGMEM.h

AudioGeneratorWAV.h

AudioOutputI2S.h

I've changed pin configuration here

BluetoothA2DPSink.h

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.