diff --git a/Core/apu.h b/Core/apu.h index 3bca456..bace09a 100644 --- a/Core/apu.h +++ b/Core/apu.h @@ -103,6 +103,7 @@ typedef enum { GB_HIGHPASS_OFF, // Do not apply any filter, keep DC offset GB_HIGHPASS_ACCURATE, // Apply a highpass filter similar to the one used on hardware GB_HIGHPASS_REMOVE_DC_OFFSET, // Remove DC Offset without affecting the waveform + GB_HIGHPASS_MAX } GB_highpass_mode_t; typedef struct { diff --git a/SDL/gui.c b/SDL/gui.c index 3076ddd..d44cc00 100644 --- a/SDL/gui.c +++ b/SDL/gui.c @@ -58,6 +58,7 @@ configuration_t configuration = SDL_SCANCODE_SPACE }, .color_correction_mode = GB_COLOR_CORRECTION_EMULATE_HARDWARE, + .highpass_mode = GB_HIGHPASS_ACCURATE, .scaling_mode = GB_SDL_SCALING_INTEGER_FACTOR, .blend_frames = true }; @@ -227,10 +228,12 @@ static void item_help(unsigned index) static void enter_graphics_menu(unsigned index); static void enter_controls_menu(unsigned index); static void enter_joypad_menu(unsigned index); +static void enter_audio_menu(unsigned index); static const struct menu_item paused_menu[] = { {"Resume", NULL}, {"Graphic Options", enter_graphics_menu}, + {"Audio Options", enter_audio_menu}, {"Keyboard", enter_controls_menu}, {"Joypad", enter_joypad_menu}, {"Help", item_help}, @@ -238,14 +241,7 @@ static const struct menu_item paused_menu[] = { {NULL,} }; -static const struct menu_item nonpaused_menu[] = { - {"Graphic Options", enter_graphics_menu}, - {"Keyboard", enter_controls_menu}, - {"Joypad", enter_joypad_menu}, - {"Help", item_help}, - {"Exit", item_exit}, - {NULL,} -}; +static const struct menu_item *const nonpaused_menu = &paused_menu[1]; const char *current_scaling_mode(unsigned index) { @@ -409,6 +405,41 @@ static void enter_graphics_menu(unsigned index) current_selection = 0; } +const char *highpass_filter_string(unsigned index) +{ + return (const char *[]){"None (Keep DC Offset)", "Accurate", "Preserve Waveform"} + [configuration.highpass_mode]; +} + +void cycle_highpass_filter(unsigned index) +{ + configuration.highpass_mode++; + if (configuration.highpass_mode == GB_HIGHPASS_MAX) { + configuration.highpass_mode = 0; + } +} + +void cycle_highpass_filter_backwards(unsigned index) +{ + if (configuration.highpass_mode == 0) { + configuration.highpass_mode = GB_HIGHPASS_MAX - 1; + } + else { + configuration.highpass_mode--; + } +} + +static const struct menu_item audio_menu[] = { + {"Highpass Filter:", cycle_highpass_filter, highpass_filter_string, cycle_highpass_filter_backwards}, + {"Back", return_to_root_menu}, + {NULL,} +}; + +static void enter_audio_menu(unsigned index) +{ + current_menu = audio_menu; + current_selection = 0; +} static const char *key_name(unsigned index) { return SDL_GetScancodeName(configuration.keys[index]); diff --git a/SDL/gui.h b/SDL/gui.h index 41ac374..9a4b56e 100644 --- a/SDL/gui.h +++ b/SDL/gui.h @@ -37,6 +37,8 @@ typedef struct { enum scaling_mode scaling_mode; bool blend_frames; + GB_highpass_mode_t highpass_mode; + bool div_joystick; bool flip_joystick_bit_1; bool swap_joysticks_bits_1_and_2; diff --git a/SDL/main.c b/SDL/main.c index 9df3e43..59469fd 100755 --- a/SDL/main.c +++ b/SDL/main.c @@ -119,8 +119,16 @@ static void handle_events(GB_gameboy_t *gb) GB_set_turbo_mode(gb, event.type == SDL_JOYBUTTONDOWN, false); } else { + bool audio_playing = SDL_GetAudioStatus() == SDL_AUDIO_PLAYING; + if (audio_playing) { + SDL_PauseAudio(true); + } run_gui(true); + if (audio_playing) { + SDL_PauseAudio(false); + } GB_set_color_correction_mode(gb, configuration.color_correction_mode); + GB_set_highpass_filter_mode(gb, configuration.highpass_mode); } break; @@ -137,11 +145,19 @@ static void handle_events(GB_gameboy_t *gb) case SDL_KEYDOWN: switch (event.key.keysym.scancode) { - case SDL_SCANCODE_ESCAPE: + case SDL_SCANCODE_ESCAPE: { + bool audio_playing = SDL_GetAudioStatus() == SDL_AUDIO_PLAYING; + if (audio_playing) { + SDL_PauseAudio(true); + } run_gui(true); + if (audio_playing) { + SDL_PauseAudio(false); + } GB_set_color_correction_mode(gb, configuration.color_correction_mode); + GB_set_highpass_filter_mode(gb, configuration.highpass_mode); break; - + } case SDL_SCANCODE_C: if (event.type == SDL_KEYDOWN && (event.key.keysym.mod & KMOD_CTRL)) { GB_debugger_break(gb); @@ -318,6 +334,7 @@ restart: GB_set_rgb_encode_callback(&gb, rgb_encode); GB_set_sample_rate(&gb, have_aspec.freq); GB_set_color_correction_mode(&gb, configuration.color_correction_mode); + GB_set_highpass_filter_mode(&gb, configuration.highpass_mode); } bool error = false; @@ -435,7 +452,6 @@ usage: SDL_OpenAudio(&want_aspec, &have_aspec); /* Start Audio */ - SDL_PauseAudio(false); SDL_EventState(SDL_DROPFILE, SDL_ENABLE); @@ -447,6 +463,7 @@ usage: if (filename == NULL) { run_gui(false); } + SDL_PauseAudio(false); run(); // Never returns return 0; }