Two input sources into single output #721
-
Hey, Phil, is it possible to combine simple microphone input with A2DP stream input and route it into the single output i2s speaker with amplifier using your library. I'm using ESP32-DevKitC(controller), MAX98357A(amplifier), INMP441(micro). And I've already managed to get 1)i2s in to i2s out and 2) a2dp in to i2s out working separately. And now I want to combine it. Just asking for your advice. |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 22 replies
-
I wouldn't see any reason why this should not work. ps. I assume you plan to use 2 different ESP32 to implement this... |
Beta Was this translation helpful? Give feedback.
-
I'm trying to do something like that:
|
Beta Was this translation helpful? Give feedback.
-
Hello, Phil, have to come back to you again. I have the same configuration: I'm using ESP32-DevKitC(controller), MAX98357A(amplifier), INMP441(micro).
I assume the reason is I can not correctly convert INMP441 i2s data format. |
Beta Was this translation helpful? Give feedback.
-
Just look at my link: it shows haw you can read 32 bits from I2S and convert it to the needed 16 bits e.g. for the mixer |
Beta Was this translation helpful? Give feedback.
-
Its working (i hear the sound from both sources and it's clean) for about 5 seconds after bluetooth connection, when I'm using format converter as you described. It sends me such message in logs and esp32 restarted after that: All I was manged to find about this assert is this suggests that there is an issue with the Bluetooth packet reception function. May it be the issue of heap over or stack overflow or may be some software problem? This is my current code state:
|
Beta Was this translation helpful? Give feedback.
-
Yes, the heap contentiously decreasing from 50000 available to 30000 and at the point of 30k it gives this "assert failed: host_recv_pkt_cb hci_hal_h4.c:548 (0)". Even when commend out the mixer.add(converter); |
Beta Was this translation helpful? Give feedback.
-
Honestly I did not expect this outcome and I would not know how to solve this. Maybe using the OutputMixer should avoid this issue, so it might be worth a trial: The starting point would be this sketch and you would call the mixer output logic in the callback replacing the i2s output. |
Beta Was this translation helpful? Give feedback.
-
I tried to set up a POC on the AudioKit. Initially, I was stumbling a bit over the big array size that we need to process. #include "BluetoothA2DPSink.h"
#include "AudioTools.h"
#include "AudioLibs/AudioKit.h"
AudioInfo info(44100, 2, 16);
BluetoothA2DPSink a2dp_sink;
AudioKitStream i2s;
OutputMixer<int16_t> mixer(i2s, 2);
const int buffer_size = 1024;
uint8_t buffer[buffer_size];
// Write data to mixer in callback
void read_data_stream(const uint8_t *data, uint32_t length) {
int open = length;
int pos = 0;
// limit write size
while(open>0){
int write_size = min(open, 1024);
int bytes_read = i2s.readBytes(buffer, write_size);
// mix data
mixer.write(data+pos, write_size);
mixer.write(buffer, write_size);
mixer.flushMixer();
open -= write_size;
pos += write_size;
}
}
void setup() {
Serial.begin(115200);
AudioLogger::instance().begin(Serial, AudioLogger::Warning);
// register callback
a2dp_sink.set_stream_reader(read_data_stream, false);
// setup input and output
auto cfg = i2s.defaultConfig(RXTX_MODE);
cfg.copyFrom(info);
cfg.input_device = AUDIO_HAL_ADC_INPUT_LINE2;
i2s.begin(cfg);
// setup Output mixer in RAM
mixer.begin(buffer_size, RAM);
// Start Bluetooth Audio Receiver
a2dp_sink.set_auto_reconnect(false);
a2dp_sink.start("a2dp-i2s");
}
void loop() { delay(1000); } Just replace the AudioKitStream with your I2SStreams and you need to deal with the 32 bits of the microphone. Something that was not necessary for my hardware... |
Beta Was this translation helpful? Give feedback.
-
Hi, Phil, thank you for this magnificent lib again. |
Beta Was this translation helpful? Give feedback.
-
This has nothing to do with echo cancellation: I suggest that you google "prevent audio feed back"! |
Beta Was this translation helpful? Give feedback.
I tried to set up a POC on the AudioKit. Initially, I was stumbling a bit over the big array size that we need to process.
The following sketch works like a charm: