From e61ed3a36a88778c6551fd12cc3582b6362141ea Mon Sep 17 00:00:00 2001 From: Alex Duchesne Date: Fri, 29 Nov 2024 16:28:51 -0500 Subject: [PATCH] retro-core: Removed shared audio buffer It wasn't used by all apps, wasteful. --- retro-core/main/main.c | 1 - retro-core/main/main_gbc.c | 2 +- retro-core/main/main_lynx.cpp | 4 ++-- retro-core/main/main_pce.c | 5 +++-- retro-core/main/main_snes.c | 3 +++ retro-core/main/shared.h | 1 - 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/retro-core/main/main.c b/retro-core/main/main.c index 50043bdf0..b93e40529 100644 --- a/retro-core/main/main.c +++ b/retro-core/main/main.c @@ -1,6 +1,5 @@ #include "shared.h" -rg_audio_sample_t audioBuffer[AUDIO_BUFFER_LENGTH]; rg_app_t *app; diff --git a/retro-core/main/main_gbc.c b/retro-core/main/main_gbc.c index 952098a07..b24eae650 100644 --- a/retro-core/main/main_gbc.c +++ b/retro-core/main/main_gbc.c @@ -267,7 +267,7 @@ void gbc_main(void) RG_PANIC("Emulator init failed!"); gnuboy_set_framebuffer(currentUpdate->data); - gnuboy_set_soundbuffer((void *)audioBuffer, sizeof(audioBuffer) / 2); + gnuboy_set_soundbuffer(malloc(AUDIO_BUFFER_LENGTH * 4), AUDIO_SAMPLE_RATE); // Load ROM if (rg_extension_match(app->romPath, "zip")) diff --git a/retro-core/main/main_lynx.cpp b/retro-core/main/main_lynx.cpp index aa46e5faa..bfba361b6 100644 --- a/retro-core/main/main_lynx.cpp +++ b/retro-core/main/main_lynx.cpp @@ -210,7 +210,7 @@ extern "C" void lynx_main(void) } gPrimaryFrameBuffer = (UBYTE*)currentUpdate->data; - gAudioBuffer = (SWORD*)&audioBuffer; + gAudioBuffer = (SWORD*)malloc(AUDIO_BUFFER_LENGTH * 4); gAudioEnabled = 1; if (app->bootFlags & RG_BOOT_RESUME) @@ -264,7 +264,7 @@ extern "C" void lynx_main(void) rg_system_set_tick_rate(AUDIO_SAMPLE_RATE / (gAudioBufferPointer / 2)); rg_system_tick(rg_system_timer() - startTime); - rg_audio_submit(audioBuffer, gAudioBufferPointer >> 1); + rg_audio_submit((const rg_audio_frame_t *)gAudioBuffer, gAudioBufferPointer / 2); // See if we need to skip a frame to keep up if (skipFrames == 0) diff --git a/retro-core/main/main_pce.c b/retro-core/main/main_pce.c index 060766f36..6ac334211 100644 --- a/retro-core/main/main_pce.c +++ b/retro-core/main/main_pce.c @@ -135,11 +135,12 @@ static void audioTask(void *arg) RG_LOGI("task started. numSamples=%d.", (int)numSamples); while (1) { + rg_audio_sample_t samples[numSamples]; // TODO: Clearly we need to add a better way to remain in sync with the main task... while (emulationPaused) rg_task_yield(); - psg_update((int16_t *)audioBuffer, numSamples, 0xFF); - rg_audio_submit(audioBuffer, numSamples); + psg_update((int16_t *)samples, numSamples, 0xFF); + rg_audio_submit(samples, numSamples); } } diff --git a/retro-core/main/main_snes.c b/retro-core/main/main_snes.c index f1f0ac3fa..aa0901c21 100644 --- a/retro-core/main/main_snes.c +++ b/retro-core/main/main_snes.c @@ -68,6 +68,7 @@ static const char *SNES_BUTTONS[] = { static rg_surface_t *updates[2]; static rg_surface_t *currentUpdate; +static rg_audio_sample_t *audioBuffer; static bool apu_enabled = true; static bool lowpass_filter = false; @@ -305,6 +306,8 @@ void snes_main(void) updates[0]->height = SNES_HEIGHT; currentUpdate = updates[0]; + audioBuffer = (rg_audio_sample_t *)malloc(AUDIO_BUFFER_LENGTH * 4); + update_keymap(rg_settings_get_number(NS_APP, SETTING_KEYMAP, 0)); Settings.CyclesPercentage = 100; diff --git a/retro-core/main/shared.h b/retro-core/main/shared.h index ef6304b83..3939800f4 100644 --- a/retro-core/main/shared.h +++ b/retro-core/main/shared.h @@ -7,7 +7,6 @@ #define AUDIO_SAMPLE_RATE (32000) #define AUDIO_BUFFER_LENGTH (AUDIO_SAMPLE_RATE / 50 + 1) -extern rg_audio_sample_t audioBuffer[AUDIO_BUFFER_LENGTH]; extern rg_app_t *app; extern uint8_t shared_memory_block_64K[0x10000];