From bcd575296cbc4c087eab4fce02aa35dd6a10c60c Mon Sep 17 00:00:00 2001
From: moon2 <moon2protonmail@protonmail.com>
Date: Fri, 25 Aug 2023 02:35:04 +0000
Subject: [PATCH] bl00mbox: migration

bl00mbox and radspa have grown up. It is time for them to
gain independence in their very own repositories.

Check out gitlab.com/moon2embeddedaudio for future updates
or contributing.

We will continue to push updates to the flow3r project and
add hardware-specific features.

We see no reason to submodule it right away, but if it is
preferable for the flow3r firmware repo we're open to it.

Thanks for all the support and kind words, we'll try our
best to polish all the rough spots and add a ton of plugins
and features :D!
---
 components/bl00mbox/CMakeLists.txt           |  2 --
 components/bl00mbox/README.md                |  1 +
 components/bl00mbox/bl00mbox.c               |  2 --
 components/bl00mbox/bl00mbox_audio.c         |  7 -------
 components/bl00mbox/include/bl00mbox_audio.h | 10 +++-------
 components/st3m/st3m_audio.c                 |  4 ++++
 main/main.c                                  |  1 +
 7 files changed, 9 insertions(+), 18 deletions(-)
 create mode 100644 components/bl00mbox/README.md

diff --git a/components/bl00mbox/CMakeLists.txt b/components/bl00mbox/CMakeLists.txt
index 905d3ea301..9688b0e0fc 100644
--- a/components/bl00mbox/CMakeLists.txt
+++ b/components/bl00mbox/CMakeLists.txt
@@ -30,6 +30,4 @@ idf_component_register(
         plugins/bl00mbox
         radspa
         extern
-    REQUIRES
-        st3m
 )
diff --git a/components/bl00mbox/README.md b/components/bl00mbox/README.md
new file mode 100644
index 0000000000..4467c1e138
--- /dev/null
+++ b/components/bl00mbox/README.md
@@ -0,0 +1 @@
+Hi! bl00mbox/radspa is an external project. To find out more or contribute check out https://gitlab.com/moon2embeddedaudio
diff --git a/components/bl00mbox/bl00mbox.c b/components/bl00mbox/bl00mbox.c
index a31700e299..ad55b04417 100644
--- a/components/bl00mbox/bl00mbox.c
+++ b/components/bl00mbox/bl00mbox.c
@@ -2,10 +2,8 @@
 #include "bl00mbox.h"
 #include "bl00mbox_plugin_registry.h"
 #include "bl00mbox_audio.h"
-#include "st3m_audio.h"
 
 void bl00mbox_init(){
     bl00mbox_plugin_registry_init();
-    st3m_audio_set_player_function(bl00mbox_audio_render);
     bl00mbox_channels_init();
 }
diff --git a/components/bl00mbox/bl00mbox_audio.c b/components/bl00mbox/bl00mbox_audio.c
index 4b8ff07fec..d41e67880d 100644
--- a/components/bl00mbox/bl00mbox_audio.c
+++ b/components/bl00mbox/bl00mbox_audio.c
@@ -246,14 +246,7 @@ void bl00mbox_audio_render(int16_t * rx, int16_t * tx, uint16_t len){
 #endif
 
     for(uint16_t i = 0; i < mono_len; i++){
-        st3m_scope_write((acc[i])>>4);
-
         tx[2*i] = acc[i];
         tx[2*i+1] = acc[i];
     }
 }
-
-// TEMP
-void bl00mbox_player_function(int16_t * rx, int16_t * tx, uint16_t len){
-    bl00mbox_audio_render(rx, tx, len);
-}
diff --git a/components/bl00mbox/include/bl00mbox_audio.h b/components/bl00mbox/include/bl00mbox_audio.h
index a28eb9bc5b..8eead50f22 100644
--- a/components/bl00mbox/include/bl00mbox_audio.h
+++ b/components/bl00mbox/include/bl00mbox_audio.h
@@ -1,16 +1,12 @@
 //SPDX-License-Identifier: CC0-1.0
 #pragma once
 
-//TODO: move this to kconfig someday
-#define BL00MBOX_MAX_BUFFER_LEN 256
-#define BL00MBOX_DEFAULT_CHANNEL_VOLUME 3000
+//TODO: move this to kconfig someday?
+#define BL00MBOX_MAX_BUFFER_LEN 128
+#define BL00MBOX_DEFAULT_CHANNEL_VOLUME 8000
 #define BL00MBOX_CHANNELS 32
 #define BL00MBOX_BACKGROUND_MUTE_OVERRIDE_ENABLE
 
-//TODO: remove st3m scope dependency
-#include "st3m_audio.h"
-#include "st3m_scope.h"
-
 #include <stdio.h>
 #include <math.h>
 #include <string.h>
diff --git a/components/st3m/st3m_audio.c b/components/st3m/st3m_audio.c
index 1bb87f0b09..1ea7111aec 100644
--- a/components/st3m/st3m_audio.c
+++ b/components/st3m/st3m_audio.c
@@ -1,4 +1,5 @@
 #include "st3m_audio.h"
+#include "st3m_scope.h"
 
 #include <math.h>
 #include <stdio.h>
@@ -320,6 +321,9 @@ static void _audio_player_task(void *data) {
         UNLOCK;
 
         (*function)(buffer_rx, buffer_tx, FLOW3R_BSP_AUDIO_DMA_BUFFER_SIZE * 2);
+        for (uint16_t i = 0; i < FLOW3R_BSP_AUDIO_DMA_BUFFER_SIZE; i++) {
+            st3m_scope_write(buffer_tx[2 * i] >> 2);
+        }
 
         if (!hwmute && software_mute) {
             // Software muting needed. Only used on P1.
diff --git a/main/main.c b/main/main.c
index 5824bff716..ade4f7c08f 100644
--- a/main/main.c
+++ b/main/main.c
@@ -131,6 +131,7 @@ void flow3r_startup(void) {
     st3m_scope_init();
     st3m_audio_init();
     bl00mbox_init();
+    st3m_audio_set_player_function(bl00mbox_audio_render);
     st3m_badgenet_init();
 
     st3m_mode_set(st3m_mode_kind_starting, "micropython");
-- 
GitLab