From 5adc85a207c4e91f181707c106e6a292ed2e591a Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 12 Sep 2015 21:04:20 +0200 Subject: [PATCH] Create libretro-common/include/filters.h --- audio/drivers_resampler/sinc.c | 35 +----------- libretro-common/gfx/scaler/scaler_filter.c | 21 +++----- libretro-common/include/filters.h | 63 ++++++++++++++++++++++ 3 files changed, 72 insertions(+), 47 deletions(-) create mode 100644 libretro-common/include/filters.h diff --git a/audio/drivers_resampler/sinc.c b/audio/drivers_resampler/sinc.c index 8b773c7964..8f157700dc 100644 --- a/audio/drivers_resampler/sinc.c +++ b/audio/drivers_resampler/sinc.c @@ -25,6 +25,7 @@ #endif #include +#include #include #include "../audio_resampler_driver.h" @@ -116,43 +117,9 @@ typedef struct rarch_sinc_resampler float *main_buffer; } rarch_sinc_resampler_t; -static INLINE double sinc(double val) -{ - if (fabs(val) < 0.00001) - return 1.0; - return sin(val) / val; -} - #if defined(SINC_WINDOW_LANCZOS) #define window_function(idx) (sinc(M_PI * (idx))) #elif defined(SINC_WINDOW_KAISER) -/* Modified Bessel function of first order. - * Check Wiki for mathematical definition ... */ -static INLINE double besseli0(double x) -{ - unsigned i; - double sum = 0.0; - double factorial = 1.0; - double factorial_mult = 0.0; - double x_pow = 1.0; - double two_div_pow = 1.0; - double x_sqr = x * x; - - /* Approximate. This is an infinite sum. - * Luckily, it converges rather fast. */ - for (i = 0; i < 18; i++) - { - sum += x_pow * two_div_pow / (factorial * factorial); - - factorial_mult += 1.0; - x_pow *= x_sqr; - two_div_pow *= 0.25; - factorial *= factorial_mult; - } - - return sum; -} - #define window_function(idx) (besseli0(SINC_WINDOW_KAISER_BETA * sqrt(1 - (idx) * (idx)))) #else #error "No SINC window function defined." diff --git a/libretro-common/gfx/scaler/scaler_filter.c b/libretro-common/gfx/scaler/scaler_filter.c index 3829f3f45d..756161df3f 100644 --- a/libretro-common/gfx/scaler/scaler_filter.c +++ b/libretro-common/gfx/scaler/scaler_filter.c @@ -20,16 +20,19 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include +#include +#include + #include #include #include -#include +#include +#include + #ifndef M_PI #define M_PI 3.14159265358979323846 #endif -#include -#include -#include static bool allocate_filters(struct scaler_ctx *ctx) { @@ -113,13 +116,6 @@ static bool gen_filter_bilinear(struct scaler_ctx *ctx) return true; } -static INLINE double filter_sinc(double phase) -{ - if (fabs(phase) < 0.0001) - return 1.0; - return sin(phase) / phase; -} - static void gen_filter_sinc_sub(struct scaler_filter *filter, int len, int pos, int step, double phase_mul) { @@ -134,7 +130,7 @@ static void gen_filter_sinc_sub(struct scaler_filter *filter, { double sinc_phase = M_PI * ((double)((sinc_size << 15) + (pos & 0xffff)) / 0x10000 - j); double lanczos_phase = sinc_phase / ((sinc_size >> 1)); - int16_t sinc_val = FILTER_UNITY * filter_sinc(sinc_phase * phase_mul) * filter_sinc(lanczos_phase) * phase_mul; + int16_t sinc_val = FILTER_UNITY * sinc(sinc_phase * phase_mul) * sinc(lanczos_phase) * phase_mul; filter->filter[i * sinc_size + j] = sinc_val; } @@ -172,7 +168,6 @@ static bool gen_filter_sinc(struct scaler_ctx *ctx) return true; } - static bool validate_filter(struct scaler_ctx *ctx) { int i; diff --git a/libretro-common/include/filters.h b/libretro-common/include/filters.h new file mode 100644 index 0000000000..2933180bfe --- /dev/null +++ b/libretro-common/include/filters.h @@ -0,0 +1,63 @@ +/* Copyright (C) 2010-2015 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (filters.h). + * --------------------------------------------------------------------------------------- + * + * Permission is hereby granted, free of charge, + * to any person obtaining a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef _LIBRETRO_SDK_FILTERS_H +#define _LIBRETRO_SDK_FILTERS_H + +#include +#include + +static INLINE double sinc(double val) +{ + if (fabs(val) < 0.00001) + return 1.0; + return sin(val) / val; +} + +/* Modified Bessel function of first order. + * Check Wiki for mathematical definition ... */ +static INLINE double besseli0(double x) +{ + unsigned i; + double sum = 0.0; + double factorial = 1.0; + double factorial_mult = 0.0; + double x_pow = 1.0; + double two_div_pow = 1.0; + double x_sqr = x * x; + + /* Approximate. This is an infinite sum. + * Luckily, it converges rather fast. */ + for (i = 0; i < 18; i++) + { + sum += x_pow * two_div_pow / (factorial * factorial); + + factorial_mult += 1.0; + x_pow *= x_sqr; + two_div_pow *= 0.25; + factorial *= factorial_mult; + } + + return sum; +} + +#endif