From 7f1cd62c8a2fbb9235e6d09069f16c25bc7a9d42 Mon Sep 17 00:00:00 2001 From: Themaister Date: Tue, 17 May 2011 19:20:41 +0200 Subject: [PATCH] Update DSP API for config callback. Clean up API a bit to have separate SSNES_*_API_VERSION defines. --- audio/ext.c | 4 ++-- audio/ext/ssnes_audio.h | 21 ++++++++++++++++----- audio/ext/ssnes_dsp.h | 21 ++++++++++++++++++--- config.def.h | 1 + driver.c | 6 ++++-- driver.h | 3 ++- general.h | 2 +- gfx/ext.c | 4 ++-- gfx/ext/ssnes_video.h | 16 ++++++++++++++-- settings.c | 5 +++++ ssnes.c | 27 ++++++++++++++++++++++++++- 11 files changed, 91 insertions(+), 19 deletions(-) diff --git a/audio/ext.c b/audio/ext.c index 4adf942b16..4e2b0081e6 100644 --- a/audio/ext.c +++ b/audio/ext.c @@ -81,9 +81,9 @@ static void* audio_ext_init(const char *device, unsigned rate, unsigned latency) SSNES_LOG("Loaded external audio driver: \"%s\"\n", ext->driver->ident ? ext->driver->ident : "Unknown"); - if (ext->driver->api_version != SSNES_API_VERSION) + if (ext->driver->api_version != SSNES_AUDIO_API_VERSION) { - SSNES_ERR("API mismatch in external video plugin. SSNES: %d, Plugin: %d ...\n", SSNES_API_VERSION, ext->driver->api_version); + SSNES_ERR("API mismatch in external video plugin. SSNES: %d, Plugin: %d ...\n", SSNES_AUDIO_API_VERSION, ext->driver->api_version); goto error; } diff --git a/audio/ext/ssnes_audio.h b/audio/ext/ssnes_audio.h index f1abe1daef..dc56808d4d 100644 --- a/audio/ext/ssnes_audio.h +++ b/audio/ext/ssnes_audio.h @@ -22,12 +22,23 @@ extern "C" { #define SSNES_API_CALLTYPE #endif +#ifndef SSNES_TRUE #define SSNES_TRUE 1 -#define SSNES_FALSE 0 -#define SSNES_OK 1 -#define SSNES_ERROR 0 +#endif -#define SSNES_API_VERSION 1 +#ifndef SSNES_FALSE +#define SSNES_FALSE 0 +#endif + +#ifndef SSNES_OK +#define SSNES_OK 1 +#endif + +#ifndef SSNES_ERROR +#define SSNES_ERROR 0 +#endif + +#define SSNES_AUDIO_API_VERSION 1 typedef struct ssnes_audio_driver_info { @@ -95,7 +106,7 @@ typedef struct ssnes_audio_driver // Human readable identification string for the driver. const char *ident; - // Must be set to SSNES_API_VERSION. + // Must be set to SSNES_AUDIO_API_VERSION. // Used for detecting API mismatch. int api_version; } ssnes_audio_driver_t; diff --git a/audio/ext/ssnes_dsp.h b/audio/ext/ssnes_dsp.h index aaa9abc6c0..9c7b1ab8bf 100644 --- a/audio/ext/ssnes_dsp.h +++ b/audio/ext/ssnes_dsp.h @@ -22,10 +22,15 @@ extern "C" { #define SSNES_API_CALLTYPE #endif +#ifndef SSNES_FALSE #define SSNES_FALSE 0 -#define SSNES_TRUE 1 +#endif -#define SSNES_API_VERSION 1 +#ifndef SSNES_TRUE +#define SSNES_TRUE 1 +#endif + +#define SSNES_DSP_API_VERSION 2 typedef struct ssnes_dsp_info { @@ -89,12 +94,22 @@ typedef struct ssnes_dsp_plugin void (*process)(void *data, ssnes_dsp_output_t *output, const ssnes_dsp_input_t *input); - // Frees the handle. + // Frees the handle. void (*free)(void *data); // API version used to compile the plugin. // Used to detect mismatches in API. + // Must be set to SSNES_DSP_API_VERSION on compile. int api_version; + + // Signal plugin that it may open a configuring window or + // something similiar. The behavior of this function + // is thus plugin dependent. Implementing this is optional, + // and can be set to NULL. + void (*config)(void *data); + + // Human readable identification string. + const char *ident; } ssnes_dsp_plugin_t; // Called by SSNES at startup to get the callback struct. diff --git a/config.def.h b/config.def.h index f52a4a770c..0b5091a21d 100644 --- a/config.def.h +++ b/config.def.h @@ -246,6 +246,7 @@ static const struct snes_keybind snes_keybinds_1[] = { { SSNES_CHEAT_INDEX_MINUS, SDLK_t, NO_BTN, AXIS_NONE }, { SSNES_CHEAT_TOGGLE, SDLK_u, NO_BTN, AXIS_NONE }, { SSNES_SCREENSHOT, SDLK_PRINT, NO_BTN, AXIS_NONE }, + { SSNES_DSP_CONFIG, SDLK_c, NO_BTN, AXIS_NONE }, { -1 } }; diff --git a/driver.c b/driver.c index 0932cfaf1c..bf7c44d8b9 100644 --- a/driver.c +++ b/driver.c @@ -175,12 +175,14 @@ static void init_dsp_plugin(void) goto error; } - if (g_extern.audio_data.dsp_plugin->api_version != SSNES_API_VERSION) + if (g_extern.audio_data.dsp_plugin->api_version != SSNES_DSP_API_VERSION) { - SSNES_ERR("DSP plugin API mismatch!\n"); + SSNES_ERR("DSP plugin API mismatch! SSNES: %d, Plugin: %d\n", SSNES_DSP_API_VERSION, g_extern.audio_data.dsp_plugin->api_version); goto error; } + SSNES_LOG("Loaded DSP plugin: \"%s\"\n", g_extern.audio_data.dsp_plugin->ident ? g_extern.audio_data.dsp_plugin->ident : "Unknown"); + ssnes_dsp_info_t info = { .input_rate = g_settings.audio.in_rate, .output_rate = g_settings.audio.out_rate diff --git a/driver.h b/driver.h index 2f127ef1dd..a4c1dfaabb 100644 --- a/driver.h +++ b/driver.h @@ -45,7 +45,8 @@ enum SSNES_CHEAT_INDEX_PLUS, SSNES_CHEAT_INDEX_MINUS, SSNES_CHEAT_TOGGLE, - SSNES_SCREENSHOT + SSNES_SCREENSHOT, + SSNES_DSP_CONFIG }; diff --git a/general.h b/general.h index 74a99f4480..63632cc383 100644 --- a/general.h +++ b/general.h @@ -44,7 +44,7 @@ #define MAX_PLAYERS 5 -#define MAX_BINDS 32 // Needs to be increased every time there are new binds added. +#define MAX_BINDS 33 // Needs to be increased every time there are new binds added. #define SSNES_NO_JOYPAD 0xFFFF enum ssnes_shader_type diff --git a/gfx/ext.c b/gfx/ext.c index 2e93a79c8e..41f4ad67d2 100644 --- a/gfx/ext.c +++ b/gfx/ext.c @@ -217,10 +217,10 @@ static bool setup_video(ext_t *ext, const video_info_t *video, const input_drive { SSNES_LOG("Loaded driver: \"%s\"\n", ext->driver->ident ? ext->driver->ident : "Unknown"); - if (SSNES_API_VERSION != ext->driver->api_version) + if (SSNES_GRAPHICS_API_VERSION != ext->driver->api_version) { SSNES_ERR("API version mismatch detected!\n"); - SSNES_ERR("Required API version: %d, Library version: %d\n", SSNES_API_VERSION, ext->driver->api_version); + SSNES_ERR("Required API version: %d, Library version: %d\n", SSNES_GRAPHICS_API_VERSION, ext->driver->api_version); return false; } diff --git a/gfx/ext/ssnes_video.h b/gfx/ext/ssnes_video.h index 173291e911..20da5257d8 100644 --- a/gfx/ext/ssnes_video.h +++ b/gfx/ext/ssnes_video.h @@ -22,14 +22,26 @@ extern "C" { #define SSNES_API_CALLTYPE #endif -#define SSNES_API_VERSION 1 +#define SSNES_GRAPHICS_API_VERSION 1 // Since we don't want to rely on C++ or C99 for a proper boolean type, // and make sure return semantics are perfectly clear ... ;) + +#ifndef SSNES_OK #define SSNES_OK 1 +#endif + +#ifndef SSNES_ERROR #define SSNES_ERROR 0 +#endif + +#ifndef SSNES_TRUE #define SSNES_TRUE 1 +#endif + +#ifndef SSNES_FALSE #define SSNES_FALSE 0 +#endif #define SSNES_COLOR_FORMAT_XRGB1555 0 #define SSNES_COLOR_FORMAT_ARGB8888 1 @@ -222,7 +234,7 @@ typedef struct ssnes_video_driver // A human-readable identification of the video driver. const char *ident; - // Needs to be defined to SSNES_API_VERSION. + // Needs to be defined to SSNES_GRAPHICS_API_VERSION. // This is used to detect API mismatches. int api_version; } ssnes_video_driver_t; diff --git a/settings.c b/settings.c index c17a15a36d..a406efe0db 100644 --- a/settings.c +++ b/settings.c @@ -437,6 +437,7 @@ static const struct bind_map bind_maps[MAX_PLAYERS][MAX_BINDS - 1] = { DECLARE_BIND(cheat_index_minus, SSNES_CHEAT_INDEX_MINUS) DECLARE_BIND(cheat_toggle, SSNES_CHEAT_TOGGLE) DECLARE_BIND(screenshot, SSNES_SCREENSHOT) + DECLARE_BIND(dsp_config, SSNES_DSP_CONFIG) }, { DECLARE_BIND(player2_a, SNES_DEVICE_ID_JOYPAD_A) @@ -470,6 +471,7 @@ static const struct bind_map bind_maps[MAX_PLAYERS][MAX_BINDS - 1] = { DECLARE_BIND(cheat_index_minus, SSNES_CHEAT_INDEX_MINUS) DECLARE_BIND(cheat_toggle, SSNES_CHEAT_TOGGLE) DECLARE_BIND(screenshot, SSNES_SCREENSHOT) + DECLARE_BIND(dsp_config, SSNES_DSP_CONFIG) }, { DECLARE_BIND(player3_a, SNES_DEVICE_ID_JOYPAD_A) @@ -503,6 +505,7 @@ static const struct bind_map bind_maps[MAX_PLAYERS][MAX_BINDS - 1] = { DECLARE_BIND(cheat_index_minus, SSNES_CHEAT_INDEX_MINUS) DECLARE_BIND(cheat_toggle, SSNES_CHEAT_TOGGLE) DECLARE_BIND(screenshot, SSNES_SCREENSHOT) + DECLARE_BIND(dsp_config, SSNES_DSP_CONFIG) }, { DECLARE_BIND(player4_a, SNES_DEVICE_ID_JOYPAD_A) @@ -536,6 +539,7 @@ static const struct bind_map bind_maps[MAX_PLAYERS][MAX_BINDS - 1] = { DECLARE_BIND(cheat_index_minus, SSNES_CHEAT_INDEX_MINUS) DECLARE_BIND(cheat_toggle, SSNES_CHEAT_TOGGLE) DECLARE_BIND(screenshot, SSNES_SCREENSHOT) + DECLARE_BIND(dsp_config, SSNES_DSP_CONFIG) }, { DECLARE_BIND(player5_a, SNES_DEVICE_ID_JOYPAD_A) @@ -569,6 +573,7 @@ static const struct bind_map bind_maps[MAX_PLAYERS][MAX_BINDS - 1] = { DECLARE_BIND(cheat_index_minus, SSNES_CHEAT_INDEX_MINUS) DECLARE_BIND(cheat_toggle, SSNES_CHEAT_TOGGLE) DECLARE_BIND(screenshot, SSNES_SCREENSHOT) + DECLARE_BIND(dsp_config, SSNES_DSP_CONFIG) }, }; diff --git a/ssnes.c b/ssnes.c index 51cc14a5f5..4f94c82548 100644 --- a/ssnes.c +++ b/ssnes.c @@ -1347,6 +1347,21 @@ static void check_screenshot(void) old_pressed = pressed; } +#ifdef HAVE_DYLIB +static void check_dsp_config(void) +{ + if (!g_extern.audio_data.dsp_plugin || !g_extern.audio_data.dsp_plugin->config) + return; + + static bool old_pressed = false; + bool pressed = driver.input->key_pressed(driver.input_data, SSNES_DSP_CONFIG); + if (pressed && !old_pressed) + g_extern.audio_data.dsp_plugin->config(g_extern.audio_data.dsp_handle); + + old_pressed = pressed; +} +#endif + static void do_state_checks(void) { if (!g_extern.netplay) @@ -1374,10 +1389,20 @@ static void do_state_checks(void) #ifdef HAVE_XML check_shader_dir(); #endif + +#ifdef HAVE_DYLIB + check_dsp_config(); +#endif } check_fullscreen(); - check_input_rate(); + +#ifdef HAVE_DYLIB + // DSP plugin doesn't use variable input rate. + if (!g_extern.audio_data.dsp_plugin) +#endif + check_input_rate(); + check_screenshot(); }