diff --git a/SDL/gui.c b/SDL/gui.c index e34028d..8bc6551 100644 --- a/SDL/gui.c +++ b/SDL/gui.c @@ -106,7 +106,8 @@ configuration_t configuration = .scaling_mode = GB_SDL_SCALING_INTEGER_FACTOR, .blending_mode = GB_FRAME_BLENDING_MODE_ACCURATE, .rewind_length = 60 * 2, - .model = MODEL_CGB + .model = MODEL_CGB, + .volume = 100, }; @@ -681,8 +682,32 @@ void cycle_highpass_filter_backwards(unsigned index) } } +const char *volume_string(unsigned index) +{ + static char ret[5]; + sprintf(ret, "%d%%", configuration.volume); + return ret; +} + +void increase_volume(unsigned index) +{ + configuration.volume += 5; + if (configuration.volume > 100) { + configuration.volume = 100; + } +} + +void decrease_volume(unsigned index) +{ + configuration.volume -= 5; + if (configuration.volume > 100) { + configuration.volume = 0; + } +} + static const struct menu_item audio_menu[] = { {"Highpass Filter:", cycle_highpass_filter, highpass_filter_string, cycle_highpass_filter_backwards}, + {"Volume:", increase_volume, volume_string, decrease_volume}, {"Back", return_to_root_menu}, {NULL,} }; diff --git a/SDL/gui.h b/SDL/gui.h index 8ef2a68..4a3b55f 100644 --- a/SDL/gui.h +++ b/SDL/gui.h @@ -104,6 +104,7 @@ typedef struct { /* v0.13 */ uint8_t dmg_palette; GB_border_mode_t border_mode; + uint8_t volume; } configuration_t; extern configuration_t configuration; diff --git a/SDL/main.c b/SDL/main.c index c2b5549..35c9a75 100644 --- a/SDL/main.c +++ b/SDL/main.c @@ -420,6 +420,11 @@ static void gb_audio_callback(GB_gameboy_t *gb, GB_sample_t *sample) return; } + if (configuration.volume != 100) { + sample->left = sample->left * configuration.volume / 100; + sample->right = sample->right * configuration.volume / 100; + } + SDL_QueueAudio(device_id, sample, sizeof(*sample)); }