Allow to use media framework together with bl00mbox
Currently the media framework assumes exclusive access to audio output and doesn't work together with bl00mbox.
It would be great to have an ability to either use media framework's output as a patch in bl00mbox, or at least have the audio produced by media framework and bl00mbox mixed together.
I have tried this crude hack for now to be able to prototype things already and it works, so it seems like there shouldn't be any fundamental troubles with running media and bl00mbox together:
diff --git a/components/st3m/st3m_media.c b/components/st3m/st3m_media.c
index 382683ea6faa..815f20ac95d4 100644
--- a/components/st3m/st3m_media.c
+++ b/components/st3m/st3m_media.c
@@ -14,17 +14,21 @@ static st3m_media *audio_media = NULL;
static int16_t *audio_buffer = NULL;
+// XXX : it would be better to be able to push and pop the
+// st3m_audio_player_function
+void bl00mbox_audio_render(int16_t *rx, int16_t *tx, uint16_t len);
+
void st3m_media_audio_render(int16_t *rx, int16_t *tx, uint16_t len) {
+ bl00mbox_audio_render(rx, tx, len);
if (!audio_media) return;
for (int i = 0; i < len; i++) {
if ((audio_media->audio_r + 1 != audio_media->audio_w) &&
(audio_media->audio_r + 1 - AUDIO_BUF_SIZE !=
audio_media->audio_w)) {
- tx[i] = audio_media->audio_buffer[audio_media->audio_r++];
+ tx[i] += audio_media->audio_buffer[audio_media->audio_r++];
if (audio_media->audio_r >= AUDIO_BUF_SIZE)
audio_media->audio_r = 0;
- } else
- tx[i] = 0;
+ }
}
}
int st3m_media_samples_queued(void) {
@@ -34,10 +38,6 @@ int st3m_media_samples_queued(void) {
return audio_media->audio_w - audio_media->audio_r;
}
-// XXX : it would be better to be able to push and pop the
-// st3m_audio_player_function
-void bl00mbox_audio_render(int16_t *rx, int16_t *tx, uint16_t len);
-
void st3m_media_stop(void) {
if (audio_media && audio_media->destroy) audio_media->destroy(audio_media);
audio_media = 0;