Add volume control to SDL
This commit is contained in:
parent
2f1b8e5b57
commit
9f3bffd4dd
27
SDL/gui.c
27
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,}
|
||||
};
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user