From f93279a86289670284291598d75e84cbdd99380d Mon Sep 17 00:00:00 2001 From: Keith Bowes Date: Mon, 12 Dec 2022 15:26:31 -0500 Subject: [PATCH] Added an option for mono output Fixes #40 --- libretro/libretro.cpp | 26 +++++++++++++++++++++++--- libretro/libretro_core_options.h | 13 +++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index 2f9d0ed..eea711a 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -75,6 +75,11 @@ static enum { SHOW_CROSSHAIR_ON, } show_crosshair; +static enum { + AUDIO_TYPE_MONO, + AUDIO_TYPE_STEREO, +} audio_type; + static bool libretro_supports_bitmasks = false; static bool show_advanced_av_settings = true; @@ -1207,7 +1212,20 @@ static void check_variables(void) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { sound.SetVolume(Api::Sound::CHANNEL_S5B, atoi(var.value)); - } + } + + var.key = "nestopia_audio_type"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) + { + if (strcmp(var.value, "mono") == 0) + { + audio_type = AUDIO_TYPE_MONO; + } + else + { + audio_type = AUDIO_TYPE_STEREO; + } + } /* "Show settings" are not required if categories are supported */ option_display.visible = !libretro_supports_option_categories; @@ -1264,8 +1282,10 @@ void retro_run(void) draw_crosshair(crossx, crossy); unsigned frames = is_pal ? SAMPLERATE / 50 : SAMPLERATE / 60; - for (unsigned i = 0; i < frames; i++) - audio_stereo_buffer[(i << 1) + 0] = audio_stereo_buffer[(i << 1) + 1] = audio_buffer[i]; + for (unsigned i = 0; i < frames; i++) { + audio_stereo_buffer[(i << 1) + 0] = audio_buffer[i]; + audio_stereo_buffer[(i << 1) + 1] = audio_type == AUDIO_TYPE_STEREO ? audio_buffer[i] : 0; + } bool updated = false; if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated) diff --git a/libretro/libretro_core_options.h b/libretro/libretro_core_options.h index 37006f6..d1a87af 100644 --- a/libretro/libretro_core_options.h +++ b/libretro/libretro_core_options.h @@ -509,6 +509,19 @@ struct retro_core_option_v2_definition option_defs_us[] = { }, "100" }, + { + "nestopia_audio_type", + "Audio output", + NULL, + "Specify whether the audio output should be mono or stereo.", + NULL, + "audio", + { + { "mono", NULL }, + { "stereo", NULL }, + }, + "stereo" + }, /* Input */