(Audio filters) Cleanups

This commit is contained in:
twinaphex 2015-03-15 06:17:40 +01:00
parent 7a552e61ea
commit 9f088d8e72
4 changed files with 34 additions and 28 deletions

View File

@ -57,12 +57,12 @@ endif
CC := $(compiler) -Wall CC := $(compiler) -Wall
CXX := $(subst CC,++,$(compiler)) -std=gnu++0x -Wall CXX := $(subst CC,++,$(compiler)) -std=gnu++0x -Wall
flags := -fPIC $(extra_flags) flags := -fPIC $(extra_flags) -I../../libretro-common/include
asflags := -fPIC $(extra_flags) asflags := -fPIC $(extra_flags)
objects := objects :=
ifeq (1,$(use_neon)) ifeq (1,$(use_neon))
ASMFLAGS := -INEON/asm ASMFLAGS := -INEON/asm
asflags += -mfpu=neon asflags += -mfpu=neon
endif endif

View File

@ -17,6 +17,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <retro_inline.h>
#include "fft/fft.c" #include "fft/fft.c"
@ -185,7 +186,7 @@ static void generate_response(fft_complex_t *response,
// Modified Bessel function of first order. // Modified Bessel function of first order.
// Check Wiki for mathematical definition ... // Check Wiki for mathematical definition ...
static inline double kaiser_besseli0(double x) static INLINE double kaiser_besseli0(double x)
{ {
unsigned i; unsigned i;
double sum = 0.0; double sum = 0.0;
@ -211,7 +212,7 @@ static inline double kaiser_besseli0(double x)
return sum; return sum;
} }
static inline double kaiser_window(double index, double beta) static INLINE double kaiser_window(double index, double beta)
{ {
return kaiser_besseli0(beta * sqrt(1 - index * index)); return kaiser_besseli0(beta * sqrt(1 - index * index));
} }

View File

@ -25,19 +25,20 @@
#define sqr(a) ((a) * (a)) #define sqr(a) ((a) * (a))
/* filter types */ /* filter types */
enum IIRFilter { enum IIRFilter
LPF, /* low pass filter */ {
HPF, /* High pass filter */ LPF, /* low pass filter */
BPCSGF,/* band pass filter 1 */ HPF, /* High pass filter */
BPZPGF,/* band pass filter 2 */ BPCSGF, /* band pass filter 1 */
APF, /* Allpass filter*/ BPZPGF, /* band pass filter 2 */
NOTCH, /* Notch Filter */ APF, /* Allpass filter*/
RIAA_phono, /* RIAA record/tape deemphasis */ NOTCH, /* Notch Filter */
PEQ, /* Peaking band EQ filter */ RIAA_phono, /* RIAA record/tape deemphasis */
BBOOST, /* Bassboost filter */ PEQ, /* Peaking band EQ filter */
LSH, /* Low shelf filter */ BBOOST, /* Bassboost filter */
HSH, /* High shelf filter */ LSH, /* Low shelf filter */
RIAA_CD /* CD de-emphasis */ HSH, /* High shelf filter */
RIAA_CD /* CD de-emphasis */
}; };
struct iir_data struct iir_data
@ -90,8 +91,8 @@ static void iir_process(void *data, struct dspfilter_output *output,
float in_l = out[0]; float in_l = out[0];
float in_r = out[1]; float in_r = out[1];
float l = (b0 * in_l + b1 * xn1_l + b2 * xn2_l - a1 * yn1_l - a2 * yn2_l) / a0; float l = (b0 * in_l + b1 * xn1_l + b2 * xn2_l - a1 * yn1_l - a2 * yn2_l) / a0;
float r = (b0 * in_r + b1 * xn1_r + b2 * xn2_r - a1 * yn1_r - a2 * yn2_r) / a0; float r = (b0 * in_r + b1 * xn1_r + b2 * xn2_r - a1 * yn1_r - a2 * yn2_r) / a0;
xn2_l = xn1_l; xn2_l = xn1_l;
xn1_l = in_l; xn1_l = in_l;
@ -140,9 +141,11 @@ static void make_poly_from_roots(
const double *roots, unsigned num_roots, float *poly) const double *roots, unsigned num_roots, float *poly)
{ {
unsigned i, j; unsigned i, j;
poly[0] = 1; poly[0] = 1;
poly[1] = -roots[0]; poly[1] = -roots[0];
memset(poly + 2, 0, (num_roots + 1 - 2) * sizeof(*poly)); memset(poly + 2, 0, (num_roots + 1 - 2) * sizeof(*poly));
for (i = 1; i < num_roots; i++) for (i = 1; i < num_roots; i++)
for (j = num_roots; j > 0; j--) for (j = num_roots; j > 0; j--)
poly[j] -= poly[j - 1] * roots[i]; poly[j] -= poly[j - 1] * roots[i];

View File

@ -18,6 +18,7 @@
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <retro_inline.h>
struct comb struct comb
{ {
@ -30,7 +31,15 @@ struct comb
float damp1, damp2; float damp1, damp2;
}; };
static inline float comb_process(struct comb *c, float input) struct allpass
{
float *buffer;
float feedback;
unsigned bufsize;
unsigned bufidx;
};
static INLINE float comb_process(struct comb *c, float input)
{ {
float output = c->buffer[c->bufidx]; float output = c->buffer[c->bufidx];
c->filterstore = (output * c->damp2) + (c->filterstore * c->damp1); c->filterstore = (output * c->damp2) + (c->filterstore * c->damp1);
@ -44,15 +53,8 @@ static inline float comb_process(struct comb *c, float input)
return output; return output;
} }
struct allpass
{
float *buffer;
float feedback;
unsigned bufsize;
unsigned bufidx;
};
static inline float allpass_process(struct allpass *a, float input) static INLINE float allpass_process(struct allpass *a, float input)
{ {
float bufout = a->buffer[a->bufidx]; float bufout = a->buffer[a->bufidx];
float output = -input + bufout; float output = -input + bufout;