From 20275f5b212bc536c93edf8dbb823a3308b5f2a0 Mon Sep 17 00:00:00 2001 From: Mateusz Faderewski Date: Fri, 18 Aug 2023 20:19:20 +0200 Subject: [PATCH] Cleanup sound code --- src/menu/sound.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/menu/sound.c b/src/menu/sound.c index 2286169f..39a1c5b4 100644 --- a/src/menu/sound.c +++ b/src/menu/sound.c @@ -13,21 +13,7 @@ static bool sound_initialized = false; -void sound_init_default (void) { - if (audio_get_frequency() != DEFAULT_FREQUENCY) { - if (sound_initialized) { - mixer_close(); - audio_close(); - } - audio_init(DEFAULT_FREQUENCY, NUM_BUFFERS); - mixer_init(NUM_CHANNELS); - mp3player_mixer_init(); - sound_initialized = true; - } -} - -void sound_init_mp3_playback (void) { - int frequency = mp3player_get_samplerate(); +static void sound_reconfigure (int frequency) { if ((frequency > 0) && (audio_get_frequency() != frequency)) { if (sound_initialized) { mixer_close(); @@ -40,6 +26,15 @@ void sound_init_mp3_playback (void) { } } + +void sound_init_default (void) { + sound_reconfigure(DEFAULT_FREQUENCY); +} + +void sound_init_mp3_playback (void) { + sound_reconfigure(mp3player_get_samplerate()); +} + void sound_poll (void) { if (sound_initialized && audio_can_write()) { short *audio_buffer = audio_write_begin();