From e110bd90f5d48f6fd48059033710e8404547f897 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 2 Aug 2014 13:40:38 +0200 Subject: [PATCH] Refactor DSP filter init/deinit --- driver.c | 27 +++------------------ driver.h | 2 -- frontend/menu/backend/menu_common_backend.c | 4 +-- general.h | 4 ++- retroarch.c | 16 +++++++++++- settings_data.c | 8 +++--- 6 files changed, 29 insertions(+), 32 deletions(-) diff --git a/driver.c b/driver.c index 072d9cc2be..32ad38a4bd 100644 --- a/driver.c +++ b/driver.c @@ -27,7 +27,6 @@ #include "audio/resampler.h" #include "gfx/thread_wrapper.h" #include "audio/thread_wrapper.h" -#include "audio/dsp_filter.h" #include "gfx/gfx_common.h" #ifdef HAVE_X11 @@ -696,24 +695,6 @@ void uninit_drivers(void) driver.audio_data = NULL; } -void rarch_init_dsp_filter(void) -{ - rarch_deinit_dsp_filter(); - if (!*g_settings.audio.dsp_plugin) - return; - - g_extern.audio_data.dsp = rarch_dsp_filter_new(g_settings.audio.dsp_plugin, g_extern.audio_data.in_rate); - if (!g_extern.audio_data.dsp) - RARCH_ERR("[DSP]: Failed to initialize DSP filter \"%s\".\n", g_settings.audio.dsp_plugin); -} - -void rarch_deinit_dsp_filter(void) -{ - if (g_extern.audio_data.dsp) - rarch_dsp_filter_free(g_extern.audio_data.dsp); - g_extern.audio_data.dsp = NULL; -} - void init_audio(void) { audio_convert_init_simd(); @@ -817,7 +798,7 @@ void init_audio(void) RARCH_WARN("Audio rate control was desired, but driver does not support needed features.\n"); } - rarch_init_dsp_filter(); + rarch_main_command(RARCH_CMD_DSP_FILTER_DEINIT); g_extern.measure_data.buffer_free_samples_count = 0; @@ -935,7 +916,7 @@ void uninit_audio(void) free(g_extern.audio_data.outsamples); g_extern.audio_data.outsamples = NULL; - rarch_deinit_dsp_filter(); + rarch_main_command(RARCH_CMD_DSP_FILTER_DEINIT); compute_audio_buffer_statistics(); } @@ -1197,7 +1178,7 @@ void init_video_input(void) } #ifdef HAVE_OVERLAY - rarch_main_command(RARCH_CMD_OVERLAY_FREE); + rarch_main_command(RARCH_CMD_OVERLAY_DEINIT); rarch_main_command(RARCH_CMD_OVERLAY_INIT); #endif @@ -1207,7 +1188,7 @@ void init_video_input(void) void uninit_video_input(void) { #ifdef HAVE_OVERLAY - rarch_main_command(RARCH_CMD_OVERLAY_FREE); + rarch_main_command(RARCH_CMD_OVERLAY_DEINIT); #endif if (!driver.input_data_own && driver.input_data != driver.video_data && driver.input && driver.input->free) diff --git a/driver.h b/driver.h index 6f020fd3c1..aabf9a9a25 100644 --- a/driver.h +++ b/driver.h @@ -562,8 +562,6 @@ void rarch_init_filter(enum retro_pixel_format); unsigned dspfilter_get_last_idx(void); #endif -void rarch_init_dsp_filter(void); -void rarch_deinit_dsp_filter(void); const char *rarch_dspfilter_get_name(void *data); // Used by RETRO_ENVIRONMENT_GET_CAMERA_INTERFACE diff --git a/frontend/menu/backend/menu_common_backend.c b/frontend/menu/backend/menu_common_backend.c index 12e42eebf5..4bca2b05ea 100644 --- a/frontend/menu/backend/menu_common_backend.c +++ b/frontend/menu/backend/menu_common_backend.c @@ -3704,7 +3704,7 @@ static int menu_common_setting_set(unsigned setting, unsigned action) menu_common_setting_push_current_menu(driver.menu->menu_stack, g_extern.overlay_dir, setting, driver.menu->selection_ptr, action); break; case MENU_ACTION_START: - rarch_main_command(RARCH_CMD_OVERLAY_FREE); + rarch_main_command(RARCH_CMD_OVERLAY_DEINIT); *g_settings.input.overlay = '\0'; break; default: @@ -3766,8 +3766,8 @@ static int menu_common_setting_set(unsigned setting, unsigned action) menu_common_setting_push_current_menu(driver.menu->menu_stack, g_settings.audio.filter_dir, setting, driver.menu->selection_ptr, action); break; case MENU_ACTION_START: + rarch_main_command(RARCH_CMD_DSP_FILTER_DEINIT); *g_settings.audio.dsp_plugin = '\0'; - rarch_deinit_dsp_filter(); break; } break; diff --git a/general.h b/general.h index 2d6c599643..869b431bdb 100644 --- a/general.h +++ b/general.h @@ -105,7 +105,9 @@ enum basic_event RARCH_CMD_AUDIO_STOP, RARCH_CMD_AUDIO_START, RARCH_CMD_OVERLAY_INIT, - RARCH_CMD_OVERLAY_FREE, + RARCH_CMD_OVERLAY_DEINIT, + RARCH_CMD_DSP_FILTER_INIT, + RARCH_CMD_DSP_FILTER_DEINIT, }; enum menu_enums diff --git a/retroarch.c b/retroarch.c index f8a4f58ed1..5b70a9246f 100644 --- a/retroarch.c +++ b/retroarch.c @@ -3221,7 +3221,7 @@ void rarch_main_command(unsigned action) } #endif break; - case RARCH_CMD_OVERLAY_FREE: + case RARCH_CMD_OVERLAY_DEINIT: #ifdef HAVE_OVERLAY if (driver.overlay) input_overlay_free(driver.overlay); @@ -3229,6 +3229,20 @@ void rarch_main_command(unsigned action) memset(&driver.overlay_state, 0, sizeof(driver.overlay_state)); #endif break; + case RARCH_CMD_DSP_FILTER_INIT: + rarch_main_command(RARCH_CMD_DSP_FILTER_DEINIT); + if (!*g_settings.audio.dsp_plugin) + break; + + g_extern.audio_data.dsp = rarch_dsp_filter_new(g_settings.audio.dsp_plugin, g_extern.audio_data.in_rate); + if (!g_extern.audio_data.dsp) + RARCH_ERR("[DSP]: Failed to initialize DSP filter \"%s\".\n", g_settings.audio.dsp_plugin); + break; + case RARCH_CMD_DSP_FILTER_DEINIT: + if (g_extern.audio_data.dsp) + rarch_dsp_filter_free(g_extern.audio_data.dsp); + g_extern.audio_data.dsp = NULL; + break; } } diff --git a/settings_data.c b/settings_data.c index 94601d3673..04447b5dcc 100644 --- a/settings_data.c +++ b/settings_data.c @@ -982,6 +982,7 @@ static void general_write_handler(const void *data) bool has_set_autosave = false; bool has_set_overlay_init = false; bool has_set_overlay_free = false; + bool has_set_dsp_init = false; const rarch_setting_t *setting = (const rarch_setting_t*)data; if (!setting) @@ -1090,8 +1091,7 @@ static void general_write_handler(const void *data) #ifdef HAVE_DYLIB strlcpy(g_settings.audio.dsp_plugin, setting->value.string, sizeof(g_settings.audio.dsp_plugin)); #endif - rarch_deinit_dsp_filter(); - rarch_init_dsp_filter(); + has_set_dsp_init = true; } else if (!strcmp(setting->name, "state_slot")) g_settings.state_slot = *setting->value.integer; @@ -1338,9 +1338,11 @@ static void general_write_handler(const void *data) if (has_set_autosave) rarch_main_command(RARCH_CMD_AUTOSAVE); if (has_set_overlay_free) - rarch_main_command(RARCH_CMD_OVERLAY_FREE); + rarch_main_command(RARCH_CMD_OVERLAY_DEINIT); if (has_set_overlay_init) rarch_main_command(RARCH_CMD_OVERLAY_INIT); + if (has_set_dsp_init) + rarch_main_command(RARCH_CMD_DSP_FILTER_INIT); } #define NEXT (list[index++])