From 52b96fae264d5bd9a0eca954f0290acf63994539 Mon Sep 17 00:00:00 2001 From: Steve Fosdick Date: Mon, 25 Sep 2023 21:54:50 +0100 Subject: [PATCH] music5000: make output filtering optional. This changes the selection behaviour in the menu so if the currently selected filter is selected a second time (as a toggle) no filtering is done. --- src/gui-allegro.c | 15 ++++++++++++++- src/music5000.c | 10 +++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/gui-allegro.c b/src/gui-allegro.c index b4beb779..8974dfdd 100644 --- a/src/gui-allegro.c +++ b/src/gui-allegro.c @@ -591,6 +591,19 @@ static int radio_event_simple(ALLEGRO_EVENT *event, int current) return num; } +static int radio_event_with_deselect(ALLEGRO_EVENT *event, int current) +{ + int id = menu_get_id(event); + int num = menu_get_num(event); + ALLEGRO_MENU *menu = (ALLEGRO_MENU *)(event->user.data3); + + if (num == current) + num = -1; + else + al_set_menu_item_flags(menu, menu_id_num(id, current), ALLEGRO_MENU_ITEM_CHECKBOX); + return num; +} + static void file_load_state(ALLEGRO_EVENT *event) { ALLEGRO_DISPLAY *display = (ALLEGRO_DISPLAY *)(event->user.data2); @@ -1384,7 +1397,7 @@ void gui_allegro_event(ALLEGRO_EVENT *event) sound_music5000 = !sound_music5000; break; case IDM_SOUND_MFILT: - music5000_fno = radio_event_simple(event, music5000_fno); + music5000_fno = radio_event_with_deselect(event, music5000_fno); break; case IDM_SOUND_PAULA: sound_paula = !sound_paula; diff --git a/src/music5000.c b/src/music5000.c index bc4502ca..6ffa839a 100644 --- a/src/music5000.c +++ b/src/music5000.c @@ -409,8 +409,12 @@ static void music5000_get_sample(int16_t *left, int16_t *right, const m5000_fcoe static int window = FREQ_M5 * 30; #endif - int sl = applyfilter(fcp, xyv_l, (double)(m5000.sleft + m3000.sleft) / 262144.0) * 262144; - int sr = applyfilter(fcp, xyv_r, (double)(m5000.sright + m3000.sright) / 262144.0) * 262144; + int sl = m5000.sleft + m3000.sleft; + int sr = m5000.sright + m3000.sright; + if (fcp) { + sl = applyfilter(fcp, xyv_l, (double)sl); + sr = applyfilter(fcp, xyv_r, (double)sr); + } fput_samples(music5000_fp, sl, sr); @@ -506,7 +510,7 @@ void music5000_streamfrag(void) if (sound_music5000) { if ((buf = al_get_audio_stream_fragment(stream))) { - music5000_fillbuf(buf, BUFLEN_M5, &m500_filters[music5000_fno]); + music5000_fillbuf(buf, BUFLEN_M5, music5000_fno < 0 ? NULL : &m500_filters[music5000_fno]); al_set_audio_stream_fragment(stream, buf); al_set_audio_stream_playing(stream, true); }