From d4fcdba6cd9f5fda2cc5a5bd0a2caa6e795f218a Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 26 Sep 2014 17:05:24 +0200 Subject: [PATCH] (Resampler) Start hooking up config code bit by bit --- audio/resamplers/cc_resampler.c | 5 ++-- audio/resamplers/nearest.c | 5 ++-- audio/resamplers/resampler.c | 16 ++++++++---- audio/resamplers/resampler.h | 45 ++++++++++++++++++++++++++++++--- audio/resamplers/sinc.c | 6 +++-- 5 files changed, 63 insertions(+), 14 deletions(-) diff --git a/audio/resamplers/cc_resampler.c b/audio/resamplers/cc_resampler.c index 25f3bcc029..d8d7d55dea 100644 --- a/audio/resamplers/cc_resampler.c +++ b/audio/resamplers/cc_resampler.c @@ -545,8 +545,8 @@ static void resampler_CC_free(void *re_) memalign_free__(re); } -static void *resampler_CC_init(double bandwidth_mod, - resampler_simd_mask_t mask) +static void *resampler_CC_init(const struct resampler_config *config, + double bandwidth_mod, resampler_simd_mask_t mask) { int i; rarch_CC_resampler_t *re = (rarch_CC_resampler_t*) @@ -557,6 +557,7 @@ static void *resampler_CC_init(double bandwidth_mod, * C codepath or NEON codepath. This will help out * Android. */ (void)mask; + (void)config; if (!re) return NULL; diff --git a/audio/resamplers/nearest.c b/audio/resamplers/nearest.c index 421d407937..76d5a873f8 100644 --- a/audio/resamplers/nearest.c +++ b/audio/resamplers/nearest.c @@ -52,12 +52,13 @@ static void resampler_nearest_free(void *re_) free(re); } -static void *resampler_nearest_init(double bandwidth_mod, - resampler_simd_mask_t mask) +static void *resampler_nearest_init(const struct resampler_config *config, + double bandwidth_mod, resampler_simd_mask_t mask) { rarch_nearest_resampler_t *re = (rarch_nearest_resampler_t*) calloc(1, sizeof(rarch_nearest_resampler_t)); + (void)config; (void)mask; if (!re) diff --git a/audio/resamplers/resampler.c b/audio/resamplers/resampler.c index bff5fbb2d2..724bff2e66 100644 --- a/audio/resamplers/resampler.c +++ b/audio/resamplers/resampler.c @@ -17,12 +17,9 @@ #ifdef RARCH_INTERNAL #include "../../performance.h" #endif +#include "../../conf/config_file_userdata.h" #include -#ifdef HAVE_CONFIG_H -#include "../../config.h" -#endif - static const rarch_resampler_t *resampler_drivers[] = { &sinc_resampler, &CC_resampler, @@ -30,6 +27,15 @@ static const rarch_resampler_t *resampler_drivers[] = { NULL, }; +static const struct resampler_config resampler_config = { + config_userdata_get_float, + config_userdata_get_int, + config_userdata_get_float_array, + config_userdata_get_int_array, + config_userdata_get_string, + config_userdata_free, +}; + static int find_resampler_driver_index(const char *driver) { unsigned i; @@ -95,7 +101,7 @@ static bool resampler_append_plugs(void **re, { resampler_simd_mask_t mask = rarch_get_cpu_features(); - *re = (*backend)->init(bw_ratio, mask); + *re = (*backend)->init(&resampler_config, bw_ratio, mask); if (!*re) return false; diff --git a/audio/resamplers/resampler.h b/audio/resamplers/resampler.h index 0366e8d446..8e23205bdb 100644 --- a/audio/resamplers/resampler.h +++ b/audio/resamplers/resampler.h @@ -49,7 +49,7 @@ extern "C" { /* A bit-mask of all supported SIMD instruction sets. * Allows an implementation to pick different - * dspfilter_implementation structs. + * resampler_implementation structs. */ typedef unsigned resampler_simd_mask_t; @@ -66,10 +66,49 @@ struct resampler_data double ratio; }; +/* Returns true if config key was found. Otherwise, + * returns false, and sets value to default value. + */ +typedef int (*resampler_config_get_float_t)(void *userdata, + const char *key, float *value, float default_value); + +typedef int (*resampler_config_get_int_t)(void *userdata, + const char *key, int *value, int default_value); + +/* Allocates an array with values. free() with resampler_config_free_t. */ +typedef int (*resampler_config_get_float_array_t)(void *userdata, + const char *key, float **values, unsigned *out_num_values, + const float *default_values, unsigned num_default_values); + +typedef int (*resampler_config_get_int_array_t)(void *userdata, + const char *key, int **values, unsigned *out_num_values, + const int *default_values, unsigned num_default_values); + +typedef int (*resampler_config_get_string_t)(void *userdata, + const char *key, char **output, const char *default_output); + +/* Calls free() in host runtime. Sometimes needed on Windows. + * free() on NULL is fine. */ +typedef void (*resampler_config_free_t)(void *ptr); + +struct resampler_config +{ + resampler_config_get_float_t get_float; + resampler_config_get_int_t get_int; + + resampler_config_get_float_array_t get_float_array; + resampler_config_get_int_array_t get_int_array; + + resampler_config_get_string_t get_string; + /* Avoid problems where resampler plug and host are + * linked against different C runtimes. */ + resampler_config_free_t free; +}; + /* Bandwidth factor. Will be < 1.0 for downsampling, > 1.0 for upsampling. * Corresponds to expected resampling ratio. */ -typedef void *(*resampler_init_t)(double bandwidth_mod, - resampler_simd_mask_t mask); +typedef void *(*resampler_init_t)(const struct resampler_config *config, + double bandwidth_mod, resampler_simd_mask_t mask); /* Frees the handle. */ typedef void (*resampler_free_t)(void *data); diff --git a/audio/resamplers/sinc.c b/audio/resamplers/sinc.c index 126f700177..49ad1d8873 100644 --- a/audio/resamplers/sinc.c +++ b/audio/resamplers/sinc.c @@ -484,13 +484,15 @@ static void resampler_sinc_free(void *re) free(resampler); } -static void *resampler_sinc_new(double bandwidth_mod, - resampler_simd_mask_t mask) +static void *resampler_sinc_new(const struct resampler_config *config, + double bandwidth_mod, resampler_simd_mask_t mask) { size_t phase_elems, elems; double cutoff; rarch_sinc_resampler_t *re = (rarch_sinc_resampler_t*) calloc(1, sizeof(*re)); + (void)config; + if (!re) return NULL;