[Question] Play audio files simultaneously and stream UDP sound half duplex #419
-
Hi all, First of all thanks for this great library! Question 1I'm wondering if it's possible to play 2+ audio files simultaneously from for example the SD card of SPIFFS? Currently I've only found examples that are able to play 1 sound at a time. Question 2Is it possible to send and receive data over UDP? I've found 2 examples with UDP send and receive. I understand and assume it's not possible to send and receive simultaneously, but it would be nice if it was possible to have both abilities on a single ESP32 and just switch to whatever is needed (either send or receive) on the go. An example setup would be: Setup 1: Setup 2: When setup 1 starts talking into the microphone it sends the UDP data to setup 2. Once setup 1 is done talking and setup 2 starts talking it sends this over to setup 1. Basically a bidirectional half duplex (full would be nice, but not expected of course) call/walkie-talkie system over UDP. Thanks for any help :). |
Beta Was this translation helpful? Give feedback.
Replies: 12 comments 10 replies
-
In order to play 2 sources at the same time you need to mix the two signals, so I suggest that you read the corresponding chapter in the wiki. UDP is a lossy protocol and it might be possible to get things to work if you keep the sample rate very low. You might want to try it in combination with a CODEC. However I would suggest that you also look into ESP-Now! |
Beta Was this translation helpful? Give feedback.
-
Awesome, thanks for your reply, I'll look into the UDP part and ESP-Now later. I'm now playing files from the SD card and was able to run the input mixer, I noticed that the Wiki mentions And if I can use |
Beta Was this translation helpful? Give feedback.
-
For mixing on the input side you actually would need to use PCM files. |
Beta Was this translation helpful? Give feedback.
-
I would have expected that something like the following should work. You can decrease the file size by moving to mono and decreasing the sample size:
|
Beta Was this translation helpful? Give feedback.
-
Just look at the error message: InputMixer<uint16_t> is nonsense! |
Beta Was this translation helpful? Give feedback.
-
But this does not correspond with what you have shown in the error message: |
Beta Was this translation helpful? Give feedback.
-
I can reproduce your issue in PlatformIO, but somehow it does not make any sense to me. |
Beta Was this translation helpful? Give feedback.
-
It seems that the initializer_list in the Vector was causing this. |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot! The SD mixer example works great! It seems to only work at max with 2 files at the same time, with 3 simultaneously the audio becomes very bad quickly. Right now I'm changing the audio files on the-go with simply calling a new SD open: void loop()
{
copier.copy();
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) { // Re-play the sound every X seconds, audioFile2 remains unchanged
previousMillis = currentMillis;
audioFile1 = SD.open("/sound.pcm");
}
} Sometimes the changing on the go results in a loud short crack sound, the same sound you hear when you unplug or plug an AUX jack in a speaker that's already on. Am I doing this the right way, or is there a better/more efficient way to change the mixed audio files on the go? |
Beta Was this translation helpful? Give feedback.
-
You can try to reduce the sample rate if you want to support more files. |
Beta Was this translation helpful? Give feedback.
-
Hey guys, did you figure it out how to play sounds from the SD card simultaneously? I have a similar setup, playing a longer background music and from time to time (triggered via mqtt/serial) short sounds must be mixed in. Any ideas? :) PS: I'm using the AudioKit |
Beta Was this translation helpful? Give feedback.
-
i didn't try it with a SD card, i had my two sounds in the flash memory. this worked pretty well. |
Beta Was this translation helpful? Give feedback.
In order to play 2 sources at the same time you need to mix the two signals, so I suggest that you read the corresponding chapter in the wiki.
UDP is a lossy protocol and it might be possible to get things to work if you keep the sample rate very low. You might want to try it in combination with a CODEC.
However I would suggest that you also look into ESP-Now!