Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #156 #157

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion amy
Submodule amy updated from 191443 to 918124
1 change: 1 addition & 0 deletions tulip/esp32s3/esp32_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ list(APPEND MICROPY_SOURCE_EXTMOD
${AMY_DIR}/src/oscillators.c
${AMY_DIR}/src/partials.c
${AMY_DIR}/src/pcm.c
${AMY_DIR}/src/log2_exp2.c
)

list(APPEND MICROPY_SOURCE_QSTR
Expand Down
4 changes: 2 additions & 2 deletions tulip/esp32s3/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ TaskHandle_t midi_handle;
TaskHandle_t alles_handle;
TaskHandle_t alles_parse_handle;
TaskHandle_t alles_receive_handle;
TaskHandle_t amy_render_handle[AMY_CORES];
TaskHandle_t amy_render_handle;
TaskHandle_t alles_fill_buffer_handle;
TaskHandle_t idle_0_handle;
TaskHandle_t idle_1_handle;
Expand Down Expand Up @@ -130,7 +130,7 @@ float compute_cpu_usage(uint8_t debug) {
const char* const tasks[] = {
"esp_timer", "sys_evt", "Tmr Svc", "ipc0", "ipc1", "main", "wifi", "idle0", "idle1",
DISPLAY_TASK_NAME, USB_TASK_NAME, TOUCHSCREEN_TASK_NAME, TULIP_MP_TASK_NAME, MIDI_TASK_NAME, ALLES_TASK_NAME,
ALLES_PARSE_TASK_NAME, ALLES_RECEIVE_TASK_NAME, ALLES_RENDER_0_TASK_NAME, ALLES_RENDER_1_TASK_NAME, ALLES_FILL_BUFFER_TASK_NAME, 0
ALLES_PARSE_TASK_NAME, ALLES_RECEIVE_TASK_NAME, ALLES_RENDER_TASK_NAME, ALLES_FILL_BUFFER_TASK_NAME, 0
};
uxArraySize = uxTaskGetNumberOfTasks();
pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
Expand Down
8 changes: 3 additions & 5 deletions tulip/esp32s3/tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
#define ALLES_TASK_COREID (1)
#define ALLES_PARSE_TASK_COREID (0)
#define ALLES_RECEIVE_TASK_COREID (1)
#define ALLES_RENDER_0_TASK_COREID (1)
#define ALLES_RENDER_1_TASK_COREID (0)
#define ALLES_RENDER_TASK_COREID (1)
#define ALLES_FILL_BUFFER_TASK_COREID (0)

#define DISPLAY_TASK_STACK_SIZE (4 * 1024)
Expand All @@ -49,8 +48,7 @@
#define ALLES_TASK_NAME "alles_task"
#define ALLES_PARSE_TASK_NAME "alles_par_task"
#define ALLES_RECEIVE_TASK_NAME "alles_rec_task"
#define ALLES_RENDER_0_TASK_NAME "alles_r0_task"
#define ALLES_RENDER_1_TASK_NAME "alles_r1_task"
#define ALLES_RENDER_TASK_NAME "alles_r_task"
#define ALLES_FILL_BUFFER_TASK_NAME "alles_fb_task"

#define MAX_TASKS 20 // includes system tasks
Expand All @@ -63,7 +61,7 @@ extern TaskHandle_t midi_handle;
extern TaskHandle_t alles_handle;
extern TaskHandle_t alles_parse_handle;
extern TaskHandle_t alles_receive_handle;
extern TaskHandle_t amy_render_handle[AMY_CORES];
extern TaskHandle_t amy_render_handle;
extern TaskHandle_t alles_fill_buffer_handle;
extern TaskHandle_t idle_0_handle;
extern TaskHandle_t idle_1_handle;
Expand Down
34 changes: 17 additions & 17 deletions tulip/shared/alles.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Alles multicast synthesizer
// Brian Whitman
// [email protected]

#include "alles.h"

uint8_t board_level;
Expand Down Expand Up @@ -39,28 +40,29 @@ i2s_chan_handle_t tx_handle;

extern void mcast_listen_task(void *pvParameters);

// Wrap AMY's renderer into 2 FreeRTOS tasks, one per core
// Render the second core
void esp_render_task( void * pvParameters) {
uint8_t which = *((uint8_t *)pvParameters);
uint8_t start = 0;
uint8_t end = AMY_OSCS;
if (AMY_CORES == 2) {
start = (AMY_OSCS/2);
end = AMY_OSCS;
if(which == 0) { start = 0; end = (AMY_OSCS/2); }
}
fprintf(stderr,"I'm renderer #%d on core #%d and i'm handling oscs %d up until %d\n", which, xPortGetCoreID(), start, end);
while(1) {
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
render_task(start, end, which);
amy_render(AMY_OSCS/2, AMY_OSCS, 1);
xTaskNotifyGive(alles_fill_buffer_handle);
}
}

// Make AMY's FABT run forever , as a FreeRTOS task
void esp_fill_audio_buffer_task() {
while(1) {
int16_t *block = fill_audio_buffer_task();
// Get ready to render
amy_prepare_buffer();
// Tell the other core to start rendering
xTaskNotifyGive(amy_render_handle);
// Render me
amy_render(0, AMY_OSCS/2, 0);
// Wait for the other core to finish
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);

// Write to i2s
int16_t *block = amy_fill_buffer();
size_t written = 0;
i2s_channel_write(tx_handle, block, AMY_BLOCK_SIZE * BYTES_PER_SAMPLE * AMY_NCHANS, &written, portMAX_DELAY);
if(written != AMY_BLOCK_SIZE * BYTES_PER_SAMPLE * AMY_NCHANS) {
Expand Down Expand Up @@ -90,11 +92,9 @@ amy_err_t esp_amy_init() {
// We create a mutex for changing the event queue and pointers as two tasks do it at once
xQueueSemaphore = xSemaphoreCreateMutex();

// Create rendering threads, one per core so we can deal with dan ellis float math
static uint8_t zero = 0;
static uint8_t one = 1;
xTaskCreatePinnedToCore(&esp_render_task, ALLES_RENDER_0_TASK_NAME, ALLES_RENDER_TASK_STACK_SIZE, &zero, ALLES_RENDER_TASK_PRIORITY, &amy_render_handle[0], ALLES_RENDER_0_TASK_COREID);
if(AMY_CORES>1) xTaskCreatePinnedToCore(&esp_render_task, ALLES_RENDER_1_TASK_NAME, ALLES_RENDER_TASK_STACK_SIZE, &one, ALLES_RENDER_TASK_PRIORITY, &amy_render_handle[1], ALLES_RENDER_1_TASK_COREID);
// Create the second core rendering task
xTaskCreatePinnedToCore(&esp_render_task, ALLES_RENDER_TASK_NAME, ALLES_RENDER_TASK_STACK_SIZE, NULL, ALLES_RENDER_TASK_PRIORITY, &amy_render_handle, ALLES_RENDER_TASK_COREID);

// Wait for the render tasks to get going before starting the i2s task
delay_ms(100);

Expand Down
1 change: 0 additions & 1 deletion tulip/shared/alles.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "amy.h"


#ifdef __cplusplus
extern "C" {
#endif
Expand Down
4 changes: 2 additions & 2 deletions tulip/tdeck/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ TaskHandle_t midi_handle;
TaskHandle_t alles_handle;
TaskHandle_t alles_parse_handle;
TaskHandle_t alles_receive_handle;
TaskHandle_t amy_render_handle[AMY_CORES];
TaskHandle_t amy_render_handle;
TaskHandle_t alles_fill_buffer_handle;
TaskHandle_t idle_0_handle;
TaskHandle_t idle_1_handle;
Expand Down Expand Up @@ -131,7 +131,7 @@ float compute_cpu_usage(uint8_t debug) {
const char* const tasks[] = {
"esp_timer", "sys_evt", "Tmr Svc", "ipc0", "ipc1", "main", "wifi", "idle0", "idle1",
DISPLAY_TASK_NAME, USB_TASK_NAME, TOUCHSCREEN_TASK_NAME, TULIP_MP_TASK_NAME, MIDI_TASK_NAME, ALLES_TASK_NAME,
ALLES_PARSE_TASK_NAME, ALLES_RECEIVE_TASK_NAME, ALLES_RENDER_0_TASK_NAME, ALLES_RENDER_1_TASK_NAME, ALLES_FILL_BUFFER_TASK_NAME, 0
ALLES_PARSE_TASK_NAME, ALLES_RECEIVE_TASK_NAME, ALLES_RENDER_TASK_NAME, ALLES_FILL_BUFFER_TASK_NAME, 0
};
uxArraySize = uxTaskGetNumberOfTasks();
pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
Expand Down
4 changes: 2 additions & 2 deletions tulip/tlong/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ TaskHandle_t midi_handle;
TaskHandle_t alles_handle;
TaskHandle_t alles_parse_handle;
TaskHandle_t alles_receive_handle;
TaskHandle_t amy_render_handle[AMY_CORES];
TaskHandle_t amy_render_handle;
TaskHandle_t alles_fill_buffer_handle;
TaskHandle_t idle_0_handle;
TaskHandle_t idle_1_handle;
Expand Down Expand Up @@ -131,7 +131,7 @@ float compute_cpu_usage(uint8_t debug) {
const char* const tasks[] = {
"esp_timer", "sys_evt", "Tmr Svc", "ipc0", "ipc1", "main", "wifi", "idle0", "idle1",
DISPLAY_TASK_NAME, USB_TASK_NAME, TOUCHSCREEN_TASK_NAME, TULIP_MP_TASK_NAME, MIDI_TASK_NAME, ALLES_TASK_NAME,
ALLES_PARSE_TASK_NAME, ALLES_RECEIVE_TASK_NAME, ALLES_RENDER_0_TASK_NAME, ALLES_RENDER_1_TASK_NAME, ALLES_FILL_BUFFER_TASK_NAME, 0
ALLES_PARSE_TASK_NAME, ALLES_RECEIVE_TASK_NAME, ALLES_RENDER_TASK_NAME, ALLES_FILL_BUFFER_TASK_NAME, 0
};
uxArraySize = uxTaskGetNumberOfTasks();
pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
Expand Down