mirror of
https://github.com/libretro/RetroArch
synced 2025-02-03 17:54:04 +00:00
Create libretro-common/include/filters.h
This commit is contained in:
parent
80b3bc6254
commit
5adc85a207
@ -25,6 +25,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <retro_inline.h>
|
#include <retro_inline.h>
|
||||||
|
#include <filters.h>
|
||||||
#include <memalign.h>
|
#include <memalign.h>
|
||||||
|
|
||||||
#include "../audio_resampler_driver.h"
|
#include "../audio_resampler_driver.h"
|
||||||
@ -116,43 +117,9 @@ typedef struct rarch_sinc_resampler
|
|||||||
float *main_buffer;
|
float *main_buffer;
|
||||||
} rarch_sinc_resampler_t;
|
} 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)
|
#if defined(SINC_WINDOW_LANCZOS)
|
||||||
#define window_function(idx) (sinc(M_PI * (idx)))
|
#define window_function(idx) (sinc(M_PI * (idx)))
|
||||||
#elif defined(SINC_WINDOW_KAISER)
|
#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))))
|
#define window_function(idx) (besseli0(SINC_WINDOW_KAISER_BETA * sqrt(1 - (idx) * (idx))))
|
||||||
#else
|
#else
|
||||||
#error "No SINC window function defined."
|
#error "No SINC window function defined."
|
||||||
|
@ -20,16 +20,19 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include <gfx/scaler/filter.h>
|
#include <gfx/scaler/filter.h>
|
||||||
#include <gfx/scaler/scaler_int.h>
|
#include <gfx/scaler/scaler_int.h>
|
||||||
#include <retro_miscellaneous.h>
|
#include <retro_miscellaneous.h>
|
||||||
#include <math.h>
|
#include <retro_inline.h>
|
||||||
|
#include <filters.h>
|
||||||
|
|
||||||
#ifndef M_PI
|
#ifndef M_PI
|
||||||
#define M_PI 3.14159265358979323846
|
#define M_PI 3.14159265358979323846
|
||||||
#endif
|
#endif
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <retro_inline.h>
|
|
||||||
|
|
||||||
static bool allocate_filters(struct scaler_ctx *ctx)
|
static bool allocate_filters(struct scaler_ctx *ctx)
|
||||||
{
|
{
|
||||||
@ -113,13 +116,6 @@ static bool gen_filter_bilinear(struct scaler_ctx *ctx)
|
|||||||
return true;
|
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,
|
static void gen_filter_sinc_sub(struct scaler_filter *filter,
|
||||||
int len, int pos, int step, double phase_mul)
|
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 sinc_phase = M_PI * ((double)((sinc_size << 15) + (pos & 0xffff)) / 0x10000 - j);
|
||||||
double lanczos_phase = sinc_phase / ((sinc_size >> 1));
|
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;
|
filter->filter[i * sinc_size + j] = sinc_val;
|
||||||
}
|
}
|
||||||
@ -172,7 +168,6 @@ static bool gen_filter_sinc(struct scaler_ctx *ctx)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool validate_filter(struct scaler_ctx *ctx)
|
static bool validate_filter(struct scaler_ctx *ctx)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
63
libretro-common/include/filters.h
Normal file
63
libretro-common/include/filters.h
Normal file
@ -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 <math.h>
|
||||||
|
#include <retro_inline.h>
|
||||||
|
|
||||||
|
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
|
Loading…
x
Reference in New Issue
Block a user