Highpass filter in SDL
This commit is contained in:
parent
3c1a805770
commit
dc59fdf40e
@ -103,6 +103,7 @@ typedef enum {
|
|||||||
GB_HIGHPASS_OFF, // Do not apply any filter, keep DC offset
|
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_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_REMOVE_DC_OFFSET, // Remove DC Offset without affecting the waveform
|
||||||
|
GB_HIGHPASS_MAX
|
||||||
} GB_highpass_mode_t;
|
} GB_highpass_mode_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
47
SDL/gui.c
47
SDL/gui.c
@ -58,6 +58,7 @@ configuration_t configuration =
|
|||||||
SDL_SCANCODE_SPACE
|
SDL_SCANCODE_SPACE
|
||||||
},
|
},
|
||||||
.color_correction_mode = GB_COLOR_CORRECTION_EMULATE_HARDWARE,
|
.color_correction_mode = GB_COLOR_CORRECTION_EMULATE_HARDWARE,
|
||||||
|
.highpass_mode = GB_HIGHPASS_ACCURATE,
|
||||||
.scaling_mode = GB_SDL_SCALING_INTEGER_FACTOR,
|
.scaling_mode = GB_SDL_SCALING_INTEGER_FACTOR,
|
||||||
.blend_frames = true
|
.blend_frames = true
|
||||||
};
|
};
|
||||||
@ -227,10 +228,12 @@ static void item_help(unsigned index)
|
|||||||
static void enter_graphics_menu(unsigned index);
|
static void enter_graphics_menu(unsigned index);
|
||||||
static void enter_controls_menu(unsigned index);
|
static void enter_controls_menu(unsigned index);
|
||||||
static void enter_joypad_menu(unsigned index);
|
static void enter_joypad_menu(unsigned index);
|
||||||
|
static void enter_audio_menu(unsigned index);
|
||||||
|
|
||||||
static const struct menu_item paused_menu[] = {
|
static const struct menu_item paused_menu[] = {
|
||||||
{"Resume", NULL},
|
{"Resume", NULL},
|
||||||
{"Graphic Options", enter_graphics_menu},
|
{"Graphic Options", enter_graphics_menu},
|
||||||
|
{"Audio Options", enter_audio_menu},
|
||||||
{"Keyboard", enter_controls_menu},
|
{"Keyboard", enter_controls_menu},
|
||||||
{"Joypad", enter_joypad_menu},
|
{"Joypad", enter_joypad_menu},
|
||||||
{"Help", item_help},
|
{"Help", item_help},
|
||||||
@ -238,14 +241,7 @@ static const struct menu_item paused_menu[] = {
|
|||||||
{NULL,}
|
{NULL,}
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct menu_item nonpaused_menu[] = {
|
static const struct menu_item *const nonpaused_menu = &paused_menu[1];
|
||||||
{"Graphic Options", enter_graphics_menu},
|
|
||||||
{"Keyboard", enter_controls_menu},
|
|
||||||
{"Joypad", enter_joypad_menu},
|
|
||||||
{"Help", item_help},
|
|
||||||
{"Exit", item_exit},
|
|
||||||
{NULL,}
|
|
||||||
};
|
|
||||||
|
|
||||||
const char *current_scaling_mode(unsigned index)
|
const char *current_scaling_mode(unsigned index)
|
||||||
{
|
{
|
||||||
@ -409,6 +405,41 @@ static void enter_graphics_menu(unsigned index)
|
|||||||
current_selection = 0;
|
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)
|
static const char *key_name(unsigned index)
|
||||||
{
|
{
|
||||||
return SDL_GetScancodeName(configuration.keys[index]);
|
return SDL_GetScancodeName(configuration.keys[index]);
|
||||||
|
@ -37,6 +37,8 @@ typedef struct {
|
|||||||
enum scaling_mode scaling_mode;
|
enum scaling_mode scaling_mode;
|
||||||
bool blend_frames;
|
bool blend_frames;
|
||||||
|
|
||||||
|
GB_highpass_mode_t highpass_mode;
|
||||||
|
|
||||||
bool div_joystick;
|
bool div_joystick;
|
||||||
bool flip_joystick_bit_1;
|
bool flip_joystick_bit_1;
|
||||||
bool swap_joysticks_bits_1_and_2;
|
bool swap_joysticks_bits_1_and_2;
|
||||||
|
23
SDL/main.c
23
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);
|
GB_set_turbo_mode(gb, event.type == SDL_JOYBUTTONDOWN, false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
bool audio_playing = SDL_GetAudioStatus() == SDL_AUDIO_PLAYING;
|
||||||
|
if (audio_playing) {
|
||||||
|
SDL_PauseAudio(true);
|
||||||
|
}
|
||||||
run_gui(true);
|
run_gui(true);
|
||||||
|
if (audio_playing) {
|
||||||
|
SDL_PauseAudio(false);
|
||||||
|
}
|
||||||
GB_set_color_correction_mode(gb, configuration.color_correction_mode);
|
GB_set_color_correction_mode(gb, configuration.color_correction_mode);
|
||||||
|
GB_set_highpass_filter_mode(gb, configuration.highpass_mode);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -137,11 +145,19 @@ static void handle_events(GB_gameboy_t *gb)
|
|||||||
|
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
switch (event.key.keysym.scancode) {
|
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);
|
run_gui(true);
|
||||||
|
if (audio_playing) {
|
||||||
|
SDL_PauseAudio(false);
|
||||||
|
}
|
||||||
GB_set_color_correction_mode(gb, configuration.color_correction_mode);
|
GB_set_color_correction_mode(gb, configuration.color_correction_mode);
|
||||||
|
GB_set_highpass_filter_mode(gb, configuration.highpass_mode);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case SDL_SCANCODE_C:
|
case SDL_SCANCODE_C:
|
||||||
if (event.type == SDL_KEYDOWN && (event.key.keysym.mod & KMOD_CTRL)) {
|
if (event.type == SDL_KEYDOWN && (event.key.keysym.mod & KMOD_CTRL)) {
|
||||||
GB_debugger_break(gb);
|
GB_debugger_break(gb);
|
||||||
@ -318,6 +334,7 @@ restart:
|
|||||||
GB_set_rgb_encode_callback(&gb, rgb_encode);
|
GB_set_rgb_encode_callback(&gb, rgb_encode);
|
||||||
GB_set_sample_rate(&gb, have_aspec.freq);
|
GB_set_sample_rate(&gb, have_aspec.freq);
|
||||||
GB_set_color_correction_mode(&gb, configuration.color_correction_mode);
|
GB_set_color_correction_mode(&gb, configuration.color_correction_mode);
|
||||||
|
GB_set_highpass_filter_mode(&gb, configuration.highpass_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool error = false;
|
bool error = false;
|
||||||
@ -435,7 +452,6 @@ usage:
|
|||||||
SDL_OpenAudio(&want_aspec, &have_aspec);
|
SDL_OpenAudio(&want_aspec, &have_aspec);
|
||||||
|
|
||||||
/* Start Audio */
|
/* Start Audio */
|
||||||
SDL_PauseAudio(false);
|
|
||||||
|
|
||||||
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
|
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
|
||||||
|
|
||||||
@ -447,6 +463,7 @@ usage:
|
|||||||
if (filename == NULL) {
|
if (filename == NULL) {
|
||||||
run_gui(false);
|
run_gui(false);
|
||||||
}
|
}
|
||||||
|
SDL_PauseAudio(false);
|
||||||
run(); // Never returns
|
run(); // Never returns
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user