diff --git a/audio/ext/rarch_dsp.h b/audio/ext/rarch_dsp.h deleted file mode 100644 index c9a9ecbdac..0000000000 --- a/audio/ext/rarch_dsp.h +++ /dev/null @@ -1,113 +0,0 @@ -///// -// API header for external RetroArch DSP plugins. -// -// - -#ifndef __RARCH_DSP_PLUGIN_H -#define __RARCH_DSP_PLUGIN_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef _WIN32 -#ifdef RARCH_DLL_IMPORT -#define RARCH_API_EXPORT __declspec(dllimport) -#else -#define RARCH_API_EXPORT __declspec(dllexport) -#endif -#define RARCH_API_CALLTYPE __cdecl -#else -#define RARCH_API_EXPORT -#define RARCH_API_CALLTYPE -#endif - -#ifndef RARCH_FALSE -#define RARCH_FALSE 0 -#endif - -#ifndef RARCH_TRUE -#define RARCH_TRUE 1 -#endif - -#define RARCH_DSP_API_VERSION 5 - -typedef struct rarch_dsp_info -{ - // Input sample rate that the DSP plugin receives. - float input_rate; -} rarch_dsp_info_t; - -typedef struct rarch_dsp_output -{ - // The DSP plugin has to provide the buffering for the output samples. - // This is for performance reasons to avoid redundant copying of data. - // The samples are laid out in interleaving order: LRLRLRLR - // The range of the samples are [-1.0, 1.0]. - // This range cannot be exceeded without horrible audio glitches. - const float *samples; - - // Frames which the DSP plugin outputted for the current process. - // One frame is here defined as a combined sample of - // left and right channels. - // (I.e. 44.1kHz, 16bit stereo will have - // 88.2k samples/sec and 44.1k frames/sec.) - unsigned frames; -} rarch_dsp_output_t; - -typedef struct rarch_dsp_input -{ - // Input data for the DSP. The samples are interleaved in order: LRLRLRLR - const float *samples; - - // Number of frames for input data. - // One frame is here defined as a combined sample of - // left and right channels. - // (I.e. 44.1kHz, 16bit stereo will have - // 88.2k samples/sec and 44.1k frames/sec.) - unsigned frames; -} rarch_dsp_input_t; - -typedef struct rarch_dsp_plugin -{ - // Creates a handle of the plugin. Returns NULL if failed. - void *(*init)(const rarch_dsp_info_t *info); - - // Processes input data. - // The plugin is allowed to return variable sizes for output data. - void (*process)(void *data, rarch_dsp_output_t *output, - const rarch_dsp_input_t *input); - - // Frees the handle. - void (*free)(void *data); - - // API version used to compile the plugin. - // Used to detect mismatches in API. - // Must be set to RARCH_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; - - // Called every frame, allows creating a GUI main loop in the main thread. - // GUI events can be processed here in a non-blocking fashion. - // Can be set to NULL to ignore it. - void (*events)(void *data); -} rarch_dsp_plugin_t; - -// Called by RetroArch at startup to get the callback struct. -// This is NOT dynamically allocated! -RARCH_API_EXPORT const rarch_dsp_plugin_t* RARCH_API_CALLTYPE - rarch_dsp_plugin_init(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/audio/filters/echo.c b/audio/filters/echo.c index 87c4138c4f..22d4cb1123 100644 --- a/audio/filters/echo.c +++ b/audio/filters/echo.c @@ -170,7 +170,7 @@ static void echo_dsp_config(void *data) (void)data; } -static const rarch_dsp_plugin_t dsp_plug = { +static const struct dspfilter_implementation generic_echo_dsp = { echo_dsp_init, echo_dsp_process, echo_dsp_free, @@ -180,9 +180,9 @@ static const rarch_dsp_plugin_t dsp_plug = { NULL }; -const rarch_dsp_plugin_t *rarch_dsp_plugin_init(void) +const struct dspfilter_implementation *rarch_dsp_plugin_init(void) { - return &dsp_plug; + return &generic_echo_dsp; } #ifdef RARCH_INTERNAL diff --git a/audio/filters/eq.c b/audio/filters/eq.c index 3dd631bebf..e02625619f 100644 --- a/audio/filters/eq.c +++ b/audio/filters/eq.c @@ -402,7 +402,7 @@ static void eq_dsp_config(void *data) (void)data; } -const rarch_dsp_plugin_t dsp_plug = { +const struct dspfilter_implementation generic_eq_dsp = { eq_dsp_init, eq_dsp_process, eq_dsp_free, @@ -412,9 +412,9 @@ const rarch_dsp_plugin_t dsp_plug = { NULL }; -const rarch_dsp_plugin_t *rarch_dsp_plugin_init(void) +const struct dspfilter_implementation *rarch_dsp_plugin_init(void) { - return &dsp_plug; + return &generic_eq_dsp; } #ifdef RARCH_INTERNAL diff --git a/audio/filters/iir.c b/audio/filters/iir.c index 6ed67808c7..4c59b276c5 100644 --- a/audio/filters/iir.c +++ b/audio/filters/iir.c @@ -365,7 +365,7 @@ static void iir_dsp_config(void* data) { } -const rarch_dsp_plugin_t dsp_plug = { +const struct dspfilter_implementation generic_iir_dsp = { iir_dsp_init, iir_dsp_process, iir_dsp_free, @@ -379,10 +379,9 @@ const rarch_dsp_plugin_t dsp_plug = { NULL }; - -const rarch_dsp_plugin_t *rarch_dsp_plugin_init(void) +const struct dspfilter_implementation *rarch_dsp_plugin_init(void) { - return &dsp_plug; + return &generic_iir_dsp; } #ifdef RARCH_INTERNAL diff --git a/audio/filters/phaser.c b/audio/filters/phaser.c index 88d31336b9..70372ca4fc 100644 --- a/audio/filters/phaser.c +++ b/audio/filters/phaser.c @@ -172,7 +172,7 @@ static void phaser_dsp_config(void *data) (void)data; } -const rarch_dsp_plugin_t dsp_plug = { +const struct dspfilter_implementation generic_phaser_dsp = { phaser_dsp_init, phaser_dsp_process, phaser_dsp_free, @@ -182,9 +182,9 @@ const rarch_dsp_plugin_t dsp_plug = { NULL }; -const rarch_dsp_plugin_t *rarch_dsp_plugin_init(void) +const struct dspfilter_implementation *rarch_dsp_plugin_init(void) { - return &dsp_plug; + return &generic_phaser_dsp; } #ifdef RARCH_INTERNAL diff --git a/audio/filters/rarch_dsp.h b/audio/filters/rarch_dsp.h index fc40526eed..f8f0568c48 100644 --- a/audio/filters/rarch_dsp.h +++ b/audio/filters/rarch_dsp.h @@ -15,14 +15,20 @@ * */ -#ifndef __RARCH_DSP_PLUGIN_H -#define __RARCH_DSP_PLUGIN_H +#ifndef DSPFILTER_API_H__ +#define DSPFILTER_API_H__ #ifdef __cplusplus extern "C" { #endif -#define RARCH_DSP_API_VERSION 5 +// Dynamic library endpoint. +typedef const struct dspfilter_implementation *(*dspfilter_get_implementation_t)(void); +// Called at startup to get the callback struct. +// This is NOT dynamically allocated! +const struct dspfilter_implementation *rarch_dsp_plugin_init(void); + +#define RARCH_DSP_API_VERSION 6 typedef struct rarch_dsp_info { @@ -60,42 +66,39 @@ typedef struct rarch_dsp_input unsigned frames; } rarch_dsp_input_t; -typedef struct rarch_dsp_plugin +// Creates a handle of the plugin. Returns NULL if failed. +typedef void *(*dspfilter_init_t)(const rarch_dsp_info_t *info); + +// Frees the handle. +typedef void (*dspfilter_free_t)(void *data); + +// Processes input data. +// The plugin is allowed to return variable sizes for output data. +typedef void (*dspfilter_process_t)(void *data, rarch_dsp_output_t *output, + const rarch_dsp_input_t *input); + +// Signal plugin that it may open a configuring window or +// something similar. The behavior of this function +// is thus plugin dependent. Implementing this is optional, +// and can be set to NULL. +typedef void (*dspfilter_config_t)(void *data); + +// Called every frame, allows creating a GUI main loop in the main thread. +// GUI events can be processed here in a non-blocking fashion. +// Can be set to NULL to ignore it. +typedef void (*dspfilter_events_t)(void *data); + +struct dspfilter_implementation { - // Creates a handle of the plugin. Returns NULL if failed. - void *(*init)(const rarch_dsp_info_t *info); + dspfilter_init_t init; + dspfilter_process_t process; + dspfilter_free_t free; + int api_version; // Must be RARCH_DSP_API_VERSION + dspfilter_config_t config; + const char *ident; // Human readable identifier of implementation. + dspfilter_events_t events; +}; - // Processes input data. - // The plugin is allowed to return variable sizes for output data. - void (*process)(void *data, rarch_dsp_output_t *output, - const rarch_dsp_input_t *input); - - // Frees the handle. - void (*free)(void *data); - - // API version used to compile the plugin. - // Used to detect mismatches in API. - // Must be set to RARCH_DSP_API_VERSION on compile. - int api_version; - - // Signal plugin that it may open a configuring window or - // something similar. 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; - - // Called every frame, allows creating a GUI main loop in the main thread. - // GUI events can be processed here in a non-blocking fashion. - // Can be set to NULL to ignore it. - void (*events)(void *data); -} rarch_dsp_plugin_t; - -// Called by RetroArch at startup to get the callback struct. -// This is NOT dynamically allocated! -const rarch_dsp_plugin_t *rarch_dsp_plugin_init(void); #ifdef __cplusplus } diff --git a/audio/filters/reverb.c b/audio/filters/reverb.c index 08634b4f2e..e09b69c850 100644 --- a/audio/filters/reverb.c +++ b/audio/filters/reverb.c @@ -376,7 +376,7 @@ static void reverb_dsp_config(void *data) (void)data; } -const rarch_dsp_plugin_t dsp_plug = { +const struct dspfilter_implementation generic_reverb_dsp = { reverb_dsp_init, reverb_dsp_process, reverb_dsp_free, @@ -386,9 +386,9 @@ const rarch_dsp_plugin_t dsp_plug = { NULL }; -const rarch_dsp_plugin_t *rarch_dsp_plugin_init(void) +const struct dspfilter_implementation *rarch_dsp_plugin_init(void) { - return &dsp_plug; + return &generic_reverb_dsp; } #ifdef RARCH_INTERNAL diff --git a/audio/filters/volume.c b/audio/filters/volume.c index e719488601..bcbf5b9f1d 100644 --- a/audio/filters/volume.c +++ b/audio/filters/volume.c @@ -110,7 +110,7 @@ static void volume_dsp_config(void *data) (void)data; } -const rarch_dsp_plugin_t dsp_plug = { +const struct dspfilter_implementation generic_volume_dsp = { volume_dsp_init, volume_dsp_process, volume_dsp_free, @@ -120,9 +120,9 @@ const rarch_dsp_plugin_t dsp_plug = { NULL }; -const rarch_dsp_plugin_t *rarch_dsp_plugin_init(void) +const struct dspfilter_implementation *rarch_dsp_plugin_init(void) { - return &dsp_plug; + return &generic_volume_dsp; } #ifdef RARCH_INTERNAL diff --git a/audio/filters/wah.c b/audio/filters/wah.c index 39351dfff3..95beb8554f 100644 --- a/audio/filters/wah.c +++ b/audio/filters/wah.c @@ -165,7 +165,7 @@ static void wah_dsp_config(void *data) { } -const rarch_dsp_plugin_t dsp_plug = { +const struct dspfilter_implementation generic_wah_dsp = { wah_dsp_init, wah_dsp_process, wah_dsp_free, @@ -175,9 +175,9 @@ const rarch_dsp_plugin_t dsp_plug = { NULL }; -const rarch_dsp_plugin_t *rarch_dsp_plugin_init(void) +const struct dspfilter_implementation *rarch_dsp_plugin_init(void) { - return &dsp_plug; + return &generic_wah_dsp; } #ifdef RARCH_INTERNAL diff --git a/driver.c b/driver.c index 476ef67157..e6ed29f7bc 100644 --- a/driver.c +++ b/driver.c @@ -26,6 +26,7 @@ #include "audio/resampler.h" #include "gfx/thread_wrapper.h" #include "audio/thread_wrapper.h" +#include "audio/filters/rarch_dsp.h" #include "gfx/gfx_common.h" #ifdef HAVE_X11 @@ -968,12 +969,13 @@ void uninit_drivers(void) void rarch_init_dsp_filter(void) { - const rarch_dsp_plugin_t* (RARCH_API_CALLTYPE *plugin_init)(void); + dspfilter_get_implementation_t cb; + rarch_dsp_info_t info = {0}; + if (!(*g_settings.audio.dsp_plugin)) return; - rarch_dsp_info_t info = {0}; - plugin_init = NULL; + cb = NULL; #ifdef HAVE_DYLIB g_extern.audio_data.dsp_lib = dylib_load(g_settings.audio.dsp_plugin); @@ -983,16 +985,16 @@ void rarch_init_dsp_filter(void) return; } - plugin_init = (const rarch_dsp_plugin_t *(RARCH_API_CALLTYPE*)(void))dylib_proc(g_extern.audio_data.dsp_lib, "rarch_dsp_plugin_init"); + cb = (dspfilter_get_implementation_t)dylib_proc(g_extern.audio_data.dsp_lib, "rarch_dsp_plugin_init"); #endif - if (!plugin_init) + if (!cb) { RARCH_ERR("Failed to find symbol \"rarch_dsp_plugin_init\" in DSP plugin.\n"); goto error; } - g_extern.audio_data.dsp_plugin = plugin_init(); + g_extern.audio_data.dsp_plugin = cb(); if (!g_extern.audio_data.dsp_plugin) { RARCH_ERR("Failed to get a valid DSP plugin.\n"); diff --git a/general.h b/general.h index 6c72820fc0..6fecd961c3 100644 --- a/general.h +++ b/general.h @@ -29,7 +29,7 @@ #include "autosave.h" #include "dynamic.h" #include "cheats.h" -#include "audio/ext/rarch_dsp.h" +#include "audio/filters/rarch_dsp.h" #include "compat/strl.h" #include "performance.h" #include "core_options.h" @@ -489,7 +489,7 @@ struct global #ifdef HAVE_DYLIB dylib_t dsp_lib; #endif - const rarch_dsp_plugin_t *dsp_plugin; + const struct dspfilter_implementation *dsp_plugin; void *dsp_handle; bool rate_control;