diff --git a/retro-core/main/main.c b/retro-core/main/main.c index 50043bdf..b93e4052 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 952098a0..b24eae65 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 aa46e5fa..bfba361b 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 060766f3..6ac33421 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 f1f0ac3f..aa0901c2 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 ef6304b8..3939800f 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];