Skip to content

Commit

Permalink
music5000: make output filtering optional.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Steve Fosdick committed Oct 4, 2023
1 parent 3240cd5 commit 52b96fa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
15 changes: 14 additions & 1 deletion src/gui-allegro.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions src/music5000.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 52b96fa

Please sign in to comment.