mixer summing mode and how to properly handle the end of an input stream? #763
Replies: 1 comment
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
bc547
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I am trying to build an audio application for a game where I can play multiple sounds simultaneously and output to an I2S stream.
Typically, there would a background sound with a duration of several minutes that plays continuously in a loop, and several short sound clips that play at certain unpredictable times (e.g., button press, person movement detection,…).
So far, I managed to store the sounds on an SD card and play the background sound and at a button press the clips (simultaneously). My current setup looks like this:
The files on the SD card are read like this:
…
However, I’m not sure how to properly handle the following situations:
Currently the mixer uses a relative weight for each input stream. This allows to play e.g., the background sound quieter relative to a sound clip. But because of this weighting system, if a sound clip starts to play, the background sound volume is reduced suddenly and increases again at the end of the sound clip.
Is it possible to have a mixer that just sums all input samples? Or even better set an absolute volume for the stream when adding it to the mixer. This way there are no sudden volume changes for the other streams when adding/removing streams from the mixer.
I am aware this might potentially cause some clipping, but I do not consider this an issue since my audio files are mastered properly and have at least 3dB headroom. Also, these sounds are not coherent, so on average summing a few streams will rarely overflow.
Since some operations are blocking if there is no new data, how can I properly handle the case when a sound reaches the end?
At this moment I check if each audioFile input stream has at least 1024 bytes available before calling copier.copy(). If it has less bytes available, I set the mixer weight to 0 to avoid blocking the copier, or if it needs to loop, I rewind the file pointer to 0 again (
audioFile1.seek(0,SeekSet);
).Are there better methods for this?
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions