Remove broken DSP plugs.

They will all have to be properly rewritten for new interface.
This commit is contained in:
Themaister 2014-05-20 12:34:50 +02:00
parent 79f4ed34ba
commit b498476531
11 changed files with 4 additions and 1992 deletions

View File

@ -225,7 +225,7 @@ static bool append_plugs(rarch_dsp_filter_t *dsp, struct string_list *list)
unsigned i;
dspfilter_simd_mask_t mask = rarch_get_cpu_features();
for (unsigned i = 0; i < dsp->num_plugs; i++)
for (i = 0; i < dsp->num_plugs; i++)
{
dylib_t lib = dylib_load(list->elems[i].data);
if (!lib)

View File

@ -1,33 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __RARCH_BOOLEAN_H
#define __RARCH_BOOLEAN_H
#ifndef __cplusplus
#if defined(_MSC_VER) && !defined(SN_TARGET_PS3)
/* Hack applied for MSVC when compiling in C89 mode as it isn't C99 compliant. */
#define bool unsigned char
#define true 1
#define false 0
#else
#include <stdbool.h>
#endif
#endif
#endif

View File

@ -1,187 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2014 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "rarch_dsp.h"
// 4 source echo.
#ifndef ALIGNED
#ifdef __GNUC__
#define ALIGNED __attribute__((aligned(16)))
#else
#define ALIGNED
#endif
#endif
#ifndef min
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif
struct echo_filter
{
float *history; // history buffer
int pos; // current position in history buffer
int amp; // amplification of echoes (0-256)
int delay; // delay in number of samples
int ms; // delay in miliseconds
int rate; // sample rate
float f_amp; // amplification (0-1)
float input_rate;
};
struct echo_filter_data
{
struct echo_filter echo_l;
struct echo_filter echo_r;
float buf[4096];
};
#ifdef RARCH_INTERNAL
#define rarch_dsp_plugin_init echo_dsp_plugin_init
#endif
static float echo_process(void *data, float in)
{
struct echo_filter *echo = (struct echo_filter*)data;
float smp = echo->history[echo->pos];
smp *= echo->f_amp;
smp += in;
echo->history[echo->pos] = smp;
echo->pos = (echo->pos + 1) % echo->delay;
return smp;
}
static void echo_dsp_process(void *data, rarch_dsp_output_t *output,
const rarch_dsp_input_t *input)
{
int num_samples, i;
struct echo_filter_data *echo = (struct echo_filter_data*)data;
output->samples = echo->buf;
num_samples = input->frames * 2;
for (i = 0; i < num_samples;)
{
echo->buf[i] = echo_process(&echo->echo_l, input->samples[i]);
i++;
echo->buf[i] = echo_process(&echo->echo_r, input->samples[i]);
i++;
}
output->frames = input->frames;
}
static void echo_dsp_free(void *data)
{
struct echo_filter_data *echo = (struct echo_filter_data*)data;
if (echo)
free(echo);
}
static void echo_set_delay(void *data, int ms)
{
int new_delay, how_much, i;
float *new_history;
struct echo_filter *echo = (struct echo_filter*)data;
new_delay = ms * echo->input_rate / 1000;
if (new_delay == 0)
new_delay = 1;
new_history = (float*)malloc(new_delay * sizeof(float));
memset(new_history, 0, new_delay * sizeof(float));
if (echo->history)
{
how_much = echo->delay - echo->pos;
how_much = min(how_much, new_delay);
memcpy(new_history, echo->history + echo->pos, how_much * sizeof(float));
if (how_much < new_delay)
{
i = how_much;
how_much = new_delay - how_much;
how_much = min(how_much, echo->delay);
how_much = min(how_much, echo->pos);
memcpy(new_history + i, echo->history, how_much * sizeof(float));
}
if (echo->history)
free(echo->history);
}
echo->history = new_history;
echo->pos = 0;
echo->delay = new_delay;
echo->ms = ms;
}
static void *echo_dsp_init(const rarch_dsp_info_t *info)
{
struct echo_filter_data *echo = (struct echo_filter_data*)calloc(1, sizeof(*echo));;
if (!echo)
return NULL;
echo->echo_l.history = NULL;
echo->echo_l.input_rate = info->input_rate;
echo_set_delay(&echo->echo_l, 200);
echo->echo_l.amp = 128;
echo->echo_l.f_amp = (float)echo->echo_l.amp / 256.0f;
echo->echo_l.pos = 0;
echo->echo_r.history = NULL;
echo->echo_r.input_rate = info->input_rate;
echo_set_delay(&echo->echo_r, 200);
echo->echo_r.amp = 128;
echo->echo_r.f_amp = (float)echo->echo_r.amp / 256.0f;
echo->echo_r.pos = 0;
fprintf(stderr, "[Echo] loaded!\n");
return echo;
}
static void echo_dsp_config(void *data)
{
(void)data;
}
static const struct dspfilter_implementation generic_echo_dsp = {
echo_dsp_init,
echo_dsp_process,
echo_dsp_free,
RARCH_DSP_API_VERSION,
echo_dsp_config,
"Echo",
NULL
};
const struct dspfilter_implementation *rarch_dsp_plugin_init(dspfilter_simd_mask_t simd)
{
(void)simd;
return &generic_echo_dsp;
}
#ifdef RARCH_INTERNAL
#undef rarch_dsp_plugin_init
#endif

View File

@ -1,422 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2014 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "rarch_dsp.h"
#include <math.h>
#include <stdlib.h>
#include <complex.h> //FIXME: This is a dependency missing pretty much everywhere except Linux
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include "boolean.h"
#include <string.h>
#ifndef M_PI
#define M_PI 3.14159265
#endif
#ifndef EQ_COEFF_SIZE
#define EQ_COEFF_SIZE 256
#endif
#ifndef EQ_FILT_SIZE
#define EQ_FILT_SIZE (EQ_COEFF_SIZE * 2)
#endif
#ifdef RARCH_INTERNAL
#define rarch_dsp_plugin_init eq_dsp_plugin_init
#endif
typedef struct dsp_eq_state dsp_eq_state_t;
static complex float phase_lut[2 * EQ_FILT_SIZE + 1];
static complex float * const phase_lut_ptr = phase_lut + EQ_FILT_SIZE;
static void generate_phase_lut(void)
{
int i;
for (i = -EQ_FILT_SIZE; i <= EQ_FILT_SIZE; i++)
{
float phase = (float)i / EQ_FILT_SIZE;
phase_lut_ptr[i] = cexpf(M_PI * I * phase);
}
}
static inline unsigned bitrange(unsigned len)
{
unsigned ret;
ret = 0;
while ((len >>= 1))
ret++;
return ret;
}
static inline unsigned bitswap(unsigned i, unsigned range)
{
unsigned ret, shifts;
ret = 0;
for (shifts = 0; shifts < range; shifts++)
ret |= i & (1 << (range - shifts - 1)) ? (1 << shifts) : 0;
return ret;
}
// When interleaving the butterfly buffer, addressing puts bits in reverse.
// [0, 1, 2, 3, 4, 5, 6, 7] => [0, 4, 2, 6, 1, 5, 3, 7]
static void interleave(complex float *butterfly_buf, size_t samples)
{
unsigned range, i, target;
range = bitrange(samples);
for (i = 0; i < samples; i++)
{
target = bitswap(i, range);
if (target > i)
{
complex float tmp = butterfly_buf[target];
butterfly_buf[target] = butterfly_buf[i];
butterfly_buf[i] = tmp;
}
}
}
static void butterfly(complex float *a, complex float *b, complex float mod)
{
complex float a_, b_;
mod *= *b;
a_ = *a + mod;
b_ = *a - mod;
*a = a_;
*b = b_;
}
static void butterflies(complex float *butterfly_buf, int phase_dir, size_t step_size, size_t samples)
{
unsigned i, j;
int phase_step;
for (i = 0; i < samples; i += 2 * step_size)
{
phase_step = EQ_FILT_SIZE * phase_dir / (int)step_size;
for (j = i; j < i + step_size; j++)
butterfly(&butterfly_buf[j], &butterfly_buf[j + step_size], phase_lut_ptr[phase_step * (int)(j - i)]);
}
}
static void calculate_fft_butterfly(complex float *butterfly_buf, size_t samples)
{
unsigned step_size;
// Interleave buffer to work with FFT.
interleave(butterfly_buf, samples);
// Fly, lovely butterflies! :D
for (step_size = 1; step_size < samples; step_size *= 2)
butterflies(butterfly_buf, -1, step_size, samples);
}
static void calculate_fft(const float *data, complex float *butterfly_buf, size_t samples)
{
unsigned i, step_size;
for (i = 0; i < samples; i++)
butterfly_buf[i] = data[i];
// Interleave buffer to work with FFT.
interleave(butterfly_buf, samples);
// Fly, lovely butterflies! :D
for (step_size = 1; step_size < samples; step_size *= 2)
butterflies(butterfly_buf, -1, step_size, samples);
}
static void calculate_ifft(complex float *butterfly_buf, size_t samples)
{
unsigned step_size, i;
float factor;
// Interleave buffer to work with FFT.
interleave(butterfly_buf, samples);
// Fly, lovely butterflies! In opposite direction! :D
for (step_size = 1; step_size < samples; step_size *= 2)
butterflies(butterfly_buf, 1, step_size, samples);
factor = 1.0 / samples;
for (i = 0; i < samples; i++)
butterfly_buf[i] *= factor;
}
struct eq_band
{
float gain;
unsigned min_bin;
unsigned max_bin;
};
struct dsp_eq_state
{
struct eq_band *bands;
unsigned num_bands;
complex float fft_coeffs[EQ_FILT_SIZE];
float cosine_window[EQ_COEFF_SIZE];
float last_buf[EQ_COEFF_SIZE];
float stage_buf[EQ_FILT_SIZE];
unsigned stage_ptr;
};
static void calculate_band_range(struct eq_band *band, float norm_freq)
{
unsigned max_bin = (unsigned)round(norm_freq * EQ_COEFF_SIZE);
band->gain = 1.0;
band->max_bin = max_bin;
}
static void recalculate_fft_filt(dsp_eq_state_t *eq)
{
unsigned i, j, start, end;
complex float freq_response[EQ_FILT_SIZE] = {0.0f};
for (i = 0; i < eq->num_bands; i++)
{
for (j = eq->bands[i].min_bin; j <= eq->bands[i].max_bin; j++)
freq_response[j] = eq->bands[i].gain;
}
memset(eq->fft_coeffs, 0, sizeof(eq->fft_coeffs));
for (start = 1, end = EQ_COEFF_SIZE - 1; start < EQ_COEFF_SIZE / 2; start++, end--)
freq_response[end] = freq_response[start];
calculate_ifft(freq_response, EQ_COEFF_SIZE);
// ifftshift(). Needs to be done for some reason ... TODO: Figure out why :D
memcpy(eq->fft_coeffs + EQ_COEFF_SIZE / 2, freq_response + 0, EQ_COEFF_SIZE / 2 * sizeof(complex float));
memcpy(eq->fft_coeffs + 0, freq_response + EQ_COEFF_SIZE / 2, EQ_COEFF_SIZE / 2 * sizeof(complex float));
for (i = 0; i < EQ_COEFF_SIZE; i++)
eq->fft_coeffs[i] *= eq->cosine_window[i];
calculate_fft_butterfly(eq->fft_coeffs, EQ_FILT_SIZE);
}
static void dsp_eq_free(dsp_eq_state_t *eq)
{
if (eq)
{
if (eq->bands)
free(eq->bands);
free(eq);
}
}
static dsp_eq_state_t *dsp_eq_new(float input_rate, const float *bands, unsigned num_bands)
{
unsigned i;
dsp_eq_state_t *state;
for (i = 1; i < num_bands; i++)
{
if (bands[i] <= bands[i - 1])
return NULL;
}
if (num_bands < 2)
return NULL;
state = (dsp_eq_state_t*)calloc(1, sizeof(*state));
if (!state)
return NULL;
state->num_bands = num_bands;
state->bands = (struct eq_band*)calloc(num_bands, sizeof(struct eq_band));
if (!state->bands)
goto error;
calculate_band_range(&state->bands[0], ((bands[0] + bands[1]) / 2.0) / input_rate);
state->bands[0].min_bin = 0;
for (i = 1; i < num_bands - 1; i++)
{
calculate_band_range(&state->bands[i], ((bands[i + 1] + bands[i + 0]) / 2.0) / input_rate);
state->bands[i].min_bin = state->bands[i - 1].max_bin + 1;
if (state->bands[i].max_bin < state->bands[i].min_bin)
fprintf(stderr, "[Equalizer]: Band @ %.2f Hz does not have enough spectral resolution to fit.\n", bands[i]);
}
state->bands[num_bands - 1].max_bin = EQ_COEFF_SIZE / 2;
state->bands[num_bands - 1].min_bin = state->bands[num_bands - 2].max_bin + 1;
state->bands[num_bands - 1].gain = 1.0f;
for (i = 0; i < EQ_COEFF_SIZE; i++)
state->cosine_window[i] = cosf(M_PI * (i + 0.5 - EQ_COEFF_SIZE / 2) / EQ_COEFF_SIZE);
generate_phase_lut();
recalculate_fft_filt(state);
return state;
error:
dsp_eq_free(state);
return NULL;
}
#if 0
static void dsp_eq_set_gain(dsp_eq_state_t *eq, unsigned band, float gain)
{
assert(band < eq->num_bands);
eq->bands[band].gain = gain;
recalculate_fft_filt(eq);
}
#endif
static size_t dsp_eq_process(dsp_eq_state_t *eq, float *output, size_t out_samples,
const float *input, size_t in_samples, unsigned stride)
{
size_t written = 0;
while (in_samples)
{
unsigned i;
size_t to_read = EQ_COEFF_SIZE - eq->stage_ptr;
if (to_read > in_samples)
to_read = in_samples;
for (i = 0; i < to_read; i++, input += stride)
eq->stage_buf[eq->stage_ptr + i] = *input;
in_samples -= to_read;
eq->stage_ptr += to_read;
if (eq->stage_ptr >= EQ_COEFF_SIZE)
{
complex float butterfly_buf[EQ_FILT_SIZE];
if (out_samples < EQ_COEFF_SIZE)
return written;
calculate_fft(eq->stage_buf, butterfly_buf, EQ_FILT_SIZE);
for (i = 0; i < EQ_FILT_SIZE; i++)
butterfly_buf[i] *= eq->fft_coeffs[i];
calculate_ifft(butterfly_buf, EQ_FILT_SIZE);
for (i = 0; i < EQ_COEFF_SIZE; i++, output += stride, out_samples--, written++)
*output = crealf(butterfly_buf[i]) + eq->last_buf[i];
for (i = 0; i < EQ_COEFF_SIZE; i++)
eq->last_buf[i] = crealf(butterfly_buf[i + EQ_COEFF_SIZE]);
eq->stage_ptr = 0;
}
}
return written;
}
#if 0
static float db2gain(float val)
{
return powf(10.0, val / 20.0);
}
static float noise(void)
{
return 2.0 * ((float)(rand()) / RAND_MAX - 0.5);
}
#endif
struct equalizer_filter_data
{
dsp_eq_state_t *eq_l;
dsp_eq_state_t *eq_r;
float out_buffer[8092];
};
static size_t equalizer_process(void *data, const float *in, unsigned frames)
{
struct equalizer_filter_data *eq = (struct equalizer_filter_data*)data;
size_t written = dsp_eq_process(eq->eq_l, eq->out_buffer + 0, 4096, in + 0, frames, 2);
dsp_eq_process(eq->eq_r, eq->out_buffer + 1, 4096, in + 1, frames, 2);
return written;
}
static void * eq_dsp_init(const rarch_dsp_info_t *info)
{
const float bands[] = { 30, 80, 150, 250, 500, 800, 1000, 2000, 3000, 5000, 8000, 10000, 12000, 15000 };
struct equalizer_filter_data *eq = (struct equalizer_filter_data*)calloc(1, sizeof(*eq));
if (!eq)
return NULL;
eq->eq_l = dsp_eq_new(info->input_rate, bands, sizeof(bands) / sizeof(bands[0]));
eq->eq_r = dsp_eq_new(info->input_rate, bands, sizeof(bands) / sizeof(bands[0]));
return eq;
}
static void eq_dsp_process(void *data, rarch_dsp_output_t *output,
const rarch_dsp_input_t *input)
{
struct equalizer_filter_data *eq = (struct equalizer_filter_data*)data;
output->samples = eq->out_buffer;
size_t out_frames = equalizer_process(eq, input->samples, input->frames);
output->frames = out_frames;
}
static void eq_dsp_free(void *data)
{
struct equalizer_filter_data *eq = (struct equalizer_filter_data*)data;
if (eq)
{
dsp_eq_free(eq->eq_l);
dsp_eq_free(eq->eq_r);
free(eq);
}
}
static void eq_dsp_config(void *data)
{
(void)data;
}
const struct dspfilter_implementation generic_eq_dsp = {
eq_dsp_init,
eq_dsp_process,
eq_dsp_free,
RARCH_DSP_API_VERSION,
eq_dsp_config,
"Equalizer",
NULL
};
const struct dspfilter_implementation *rarch_dsp_plugin_init(dspfilter_simd_mask_t simd)
{
(void)simd;
return &generic_eq_dsp;
}
#ifdef RARCH_INTERNAL
#undef rarch_dsp_plugin_init
#endif

View File

@ -1,421 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2014 - Daniel De Matteis
* Copyright (C) 2012-2014 - Brad Miller
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "rarch_dsp.h"
#include <string.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <math.h>
#ifdef __SSE2__
#include <emmintrin.h>
#endif
#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795
#endif
#ifndef ALIGNED
#ifdef __GNUC__
#define ALIGNED __attribute__((aligned(16)));
#else
#define ALIGNED
#endif
#endif
#define sqr(a) ((a) * (a))
#ifdef RARCH_INTERNAL
#define rarch_dsp_plugin_init iir_dsp_plugin_init
#endif
struct iir_filter
{
#ifdef __SSE2__
__m128 fir_coeff[2];
__m128 fir_buf[2];
__m128 iir_coeff;
__m128 iir_buf;
#endif
float pf_freq, pf_qfact, pf_gain;
int type, pf_q_is_bandwidth;
float xn1,xn2,yn1,yn2;
float omega, cs, a1pha, beta, b0, b1, b2, a0, a1,a2, A, sn;
};
struct iir_filter_data
{
struct iir_filter iir_l ALIGNED;
struct iir_filter iir_r ALIGNED;
float buf[4096] ALIGNED;
int rate;
unsigned type;
};
/* filter types */
enum
{
LPF, /* low pass filter */
HPF, /* High pass filter */
BPCSGF,/* band pass filter 1 */
BPZPGF,/* band pass filter 2 */
APF, /* Allpass filter*/
NOTCH, /* Notch Filter */
RIAA_phono, /* RIAA record/tape deemphasis */
PEQ, /* Peaking band EQ filter */
BBOOST, /* Bassboost filter */
LSH, /* Low shelf filter */
HSH, /* High shelf filter */
RIAA_CD /* CD de-emphasis */
};
//lynched from SoX >w>
static void iir_make_poly_from_roots(double const * roots, size_t num_roots, float * poly)
{
size_t i, j;
poly[0] = 1;
poly[1] = -roots[0];
memset(poly + 2, 0, (num_roots + 1 - 2) * sizeof(*poly));
for (i = 1; i < num_roots; ++i)
for (j = num_roots; j > 0; --j)
poly[j] -= poly[j - 1] * roots[i];
}
static void iir_init(void *data, int samplerate, int filter_type)
{
struct iir_filter *iir = (struct iir_filter*)data;
if (!iir)
return;
iir->xn1=0;
iir->xn2=0;
iir->yn1=0;
iir->yn2=0;
iir->omega = 2 * M_PI * iir->pf_freq/samplerate;
iir->cs = cos(iir->omega);
iir->sn = sin(iir->omega);
iir->a1pha = iir->sn / (2.0 * iir->pf_qfact);
iir->A = exp(log(10.0) * iir->pf_gain / 40);
iir->beta = sqrt(iir->A + iir->A);
//Set up filter coefficients according to type
switch (filter_type)
{
case LPF:
iir->b0 = (1.0 - iir->cs) / 2.0 ;
iir->b1 = 1.0 - iir->cs ;
iir->b2 = (1.0 - iir->cs) / 2.0 ;
iir->a0 = 1.0 + iir->a1pha ;
iir->a1 = -2.0 * iir->cs ;
iir->a2 = 1.0 - iir->a1pha ;
break;
case HPF:
iir->b0 = (1.0 + iir->cs) / 2.0 ;
iir->b1 = -(1.0 + iir->cs) ;
iir->b2 = (1.0 + iir->cs) / 2.0 ;
iir->a0 = 1.0 + iir->a1pha ;
iir->a1 = -2.0 * iir->cs ;
iir->a2 = 1.0 - iir->a1pha ;
break;
case APF:
iir->b0 = 1.0 - iir->a1pha;
iir->b1 = -2.0 * iir->cs;
iir->b2 = 1.0 + iir->a1pha;
iir->a0 = 1.0 + iir->a1pha;
iir->a1 = -2.0 * iir->cs;
iir->a2 = 1.0 - iir->a1pha;
break;
case BPZPGF:
iir->b0 = iir->a1pha ;
iir->b1 = 0.0 ;
iir->b2 = -iir->a1pha ;
iir->a0 = 1.0 + iir->a1pha ;
iir->a1 = -2.0 * iir->cs ;
iir->a2 = 1.0 - iir->a1pha ;
break;
case BPCSGF:
iir->b0=iir->sn/2.0;
iir->b1=0.0;
iir->b2=-iir->sn/2;
iir->a0=1.0+iir->a1pha;
iir->a1=-2.0*iir->cs;
iir->a2=1.0-iir->a1pha;
break;
case NOTCH:
iir->b0 = 1;
iir->b1 = -2 * iir->cs;
iir->b2 = 1;
iir->a0 = 1 + iir->a1pha;
iir->a1 = -2 * iir->cs;
iir->a2 = 1 - iir->a1pha;
break;
case RIAA_phono: /* http://www.dsprelated.com/showmessage/73300/3.php */
if (samplerate == 44100) {
static const double zeros[] = {-0.2014898, 0.9233820};
static const double poles[] = {0.7083149, 0.9924091};
iir_make_poly_from_roots(zeros, (size_t)2, &iir->b0);
iir_make_poly_from_roots(poles, (size_t)2, &iir->a0);
}
else if (samplerate == 48000) {
static const double zeros[] = {-0.1766069, 0.9321590};
static const double poles[] = {0.7396325, 0.9931330};
iir_make_poly_from_roots(zeros, (size_t)2, &iir->b0);
iir_make_poly_from_roots(poles, (size_t)2, &iir->a0);
}
else if (samplerate == 88200) {
static const double zeros[] = {-0.1168735, 0.9648312};
static const double poles[] = {0.8590646, 0.9964002};
iir_make_poly_from_roots(zeros, (size_t)2, &iir->b0);
iir_make_poly_from_roots(poles, (size_t)2, &iir->a0);
}
else if (samplerate == 96000) {
static const double zeros[] = {-0.1141486, 0.9676817};
static const double poles[] = {0.8699137, 0.9966946};
iir_make_poly_from_roots(zeros, (size_t)2, &iir->b0);
iir_make_poly_from_roots(poles, (size_t)2, &iir->a0);
}
{ /* Normalise to 0dB at 1kHz (Thanks to Glenn Davis) */
double y = 2 * M_PI * 1000 / samplerate ;
double b_re = iir->b0 + iir->b1 * cos(-y) + iir->b2 * cos(-2 * y);
double a_re = iir->a0 + iir->a1 * cos(-y) + iir->a2 * cos(-2 * y);
double b_im = iir->b1 * sin(-y) + iir->b2 * sin(-2 * y);
double a_im = iir->a1 * sin(-y) + iir->a2 * sin(-2 * y);
double g = 1 / sqrt((sqr(b_re) + sqr(b_im)) / (sqr(a_re) + sqr(a_im)));
iir->b0 *= g;
iir->b1 *= g;
iir->b2 *= g;
}
break;
case PEQ:
iir->b0 = 1 + iir->a1pha * iir->A ;
iir->b1 = -2 * iir->cs ;
iir->b2 = 1 - iir->a1pha * iir->A ;
iir->a0 = 1 + iir->a1pha / iir->A ;
iir->a1 = -2 * iir->cs ;
iir->a2 = 1 - iir->a1pha / iir->A ;
break;
case BBOOST:
iir->beta = sqrt((iir->A * iir->A + 1) / 1.0 - (pow((iir->A - 1), 2)));
iir->b0 = iir->A * ((iir->A + 1) - (iir->A - 1) * iir->cs + iir->beta * iir->sn);
iir->b1 = 2 * iir->A * ((iir->A - 1) - (iir->A + 1) * iir->cs);
iir->b2 = iir->A * ((iir->A + 1) - (iir->A - 1) * iir->cs - iir->beta * iir->sn);
iir->a0 = ((iir->A + 1) + (iir->A - 1) * iir->cs + iir->beta * iir->sn);
iir->a1 = -2 * ((iir->A - 1) + (iir->A + 1) * iir->cs);
iir->a2 = (iir->A + 1) + (iir->A - 1) * iir->cs - iir->beta * iir->sn;
break;
case LSH:
iir->b0 = iir->A * ((iir->A + 1) - (iir->A - 1) * iir->cs + iir->beta * iir->sn);
iir->b1 = 2 * iir->A * ((iir->A - 1) - (iir->A + 1) * iir->cs);
iir->b2 = iir->A * ((iir->A + 1) - (iir->A - 1) * iir->cs - iir->beta * iir->sn);
iir->a0 = (iir->A + 1) + (iir->A - 1) * iir->cs + iir->beta * iir->sn;
iir->a1 = -2 * ((iir->A - 1) + (iir->A + 1) * iir->cs);
iir->a2 = (iir->A + 1) + (iir->A - 1) * iir->cs - iir->beta * iir->sn;
break;
case RIAA_CD:
iir->omega = 2 * M_PI * 5283 / samplerate;
iir->cs = cos(iir->omega);
iir->sn = sin(iir->omega);
iir->a1pha = iir->sn / (2.0 * 0.4845);
iir->A = exp(log(10.0) * -9.477 / 40);
iir->beta = sqrt(iir->A + iir->A);
case HSH:
iir->b0 = iir->A * ((iir->A + 1) + (iir->A - 1) * iir->cs + iir->beta * iir->sn);
iir->b1 = -2 * iir->A * ((iir->A - 1) + (iir->A + 1) * iir->cs);
iir->b2 = iir->A * ((iir->A + 1) + (iir->A - 1) * iir->cs - iir->beta * iir->sn);
iir->a0 = (iir->A + 1) - (iir->A - 1) * iir->cs + iir->beta * iir->sn;
iir->a1 = 2 * ((iir->A - 1) - (iir->A + 1) * iir->cs);
iir->a2 = (iir->A + 1) - (iir->A - 1) * iir->cs - iir->beta * iir->sn;
break;
default:
break;
}
#ifdef __SSE2__
iir->fir_coeff[0] = _mm_set_ps(iir->b1 / iir->a0, iir->b1 / iir->a0, iir->b0 / iir->a0, iir->b0 / iir->a0);
iir->fir_coeff[1] = _mm_set_ps(0.0f, 0.0f, iir->b2 / iir->a0, iir->b2 / iir->a0);
iir->iir_coeff = _mm_set_ps(-iir->a2 / iir->a0, -iir->a2 / iir->a0, -iir->a1 / iir->a0, -iir->a1 / iir->a0);
#endif
}
#ifdef __SSE2__
static void iir_process_batch(void *data, float *out, const float *in, unsigned frames)
{
unsigned i;
struct iir_filter *iir = (struct iir_filter*)data;
__m128 fir_coeff[2] = { iir->fir_coeff[0], iir->fir_coeff[1] };
__m128 iir_coeff = iir->iir_coeff;
__m128 fir_buf[2] = { iir->fir_buf[0], iir->fir_buf[1] };
__m128 iir_buf = iir->iir_buf;
for (i = 0; (i + 4) <= (2 * frames); in += 4, i += 4, out += 4)
{
__m128 input = _mm_loadu_ps(in);
fir_buf[1] = _mm_shuffle_ps(fir_buf[0], fir_buf[1], _MM_SHUFFLE(1, 0, 3, 2));
fir_buf[0] = _mm_shuffle_ps(input, fir_buf[0], _MM_SHUFFLE(1, 0, 1, 0));
__m128 res[3] = {
_mm_mul_ps(fir_buf[0], fir_coeff[0]),
_mm_mul_ps(fir_buf[1], fir_coeff[1]),
_mm_mul_ps(iir_buf, iir_coeff),
};
__m128 result = _mm_add_ps(_mm_add_ps(res[0], res[1]), res[2]);
result = _mm_add_ps(result, _mm_shuffle_ps(result, result, _MM_SHUFFLE(0, 0, 3, 2)));
iir_buf = _mm_shuffle_ps(result, iir_buf, _MM_SHUFFLE(1, 0, 1, 0));
fir_buf[1] = _mm_shuffle_ps(fir_buf[0], fir_buf[1], _MM_SHUFFLE(1, 0, 3, 2));
fir_buf[0] = _mm_shuffle_ps(input, fir_buf[0], _MM_SHUFFLE(1, 0, 3, 2));
res[0] = _mm_mul_ps(fir_buf[0], fir_coeff[0]);
res[1] = _mm_mul_ps(fir_buf[1], fir_coeff[1]);
res[2] = _mm_mul_ps(iir_buf, iir_coeff);
__m128 result2 = _mm_add_ps(_mm_add_ps(res[0], res[1]), res[2]);
result2 = _mm_add_ps(result2, _mm_shuffle_ps(result2, result2, _MM_SHUFFLE(0, 0, 3, 2)));
iir_buf = _mm_shuffle_ps(result2, iir_buf, _MM_SHUFFLE(1, 0, 1, 0));
_mm_store_ps(out, _mm_shuffle_ps(result, result2, _MM_SHUFFLE(1, 0, 1, 0)));
}
iir->fir_buf[0] = fir_buf[0];
iir->fir_buf[1] = fir_buf[1];
iir->iir_buf = iir_buf;
}
#endif
static float iir_process(void *data, float samp)
{
struct iir_filter *iir = (struct iir_filter*)data;
float out, in = 0;
in = samp;
out = (iir->b0 * in + iir->b1 * iir->xn1 + iir->b2 * iir->xn2 - iir->a1 * iir->yn1 - iir->a2 * iir->yn2) / iir->a0;
iir->xn2 = iir->xn1;
iir->xn1 = in;
iir->yn2 = iir->yn1;
iir->yn1 = out;
return out;
}
static void * iir_dsp_init(const rarch_dsp_info_t *info)
{
struct iir_filter_data *iir = (struct iir_filter_data*)calloc(1, sizeof(*iir));
if (!iir)
return NULL;
iir->rate = info->input_rate;
iir->type = 0;
iir->iir_l.pf_freq = 1024;
iir->iir_l.pf_qfact = 0.707;
iir->iir_l.pf_gain = 0;
iir_init(&iir->iir_l, info->input_rate, 0);
iir->iir_r.pf_freq = 1024;
iir->iir_r.pf_qfact = 0.707;
iir->iir_r.pf_gain = 0;
iir_init(&iir->iir_r, info->input_rate, 0);
return iir;
}
static void iir_dsp_process(void *data, rarch_dsp_output_t *output,
const rarch_dsp_input_t *input)
{
int i, num_samples;
struct iir_filter_data *iir = (struct iir_filter_data*)data;
output->samples = iir->buf;
num_samples = input->frames * 2;
for (i = 0; i<num_samples;)
{
iir->buf[i] = iir_process(&iir->iir_l, input->samples[i]);
i++;
iir->buf[i] = iir_process(&iir->iir_r, input->samples[i]);
i++;
}
output->frames = input->frames;
}
#ifdef __SSE2__
static void iir_dsp_process_sse2(void *data, rarch_dsp_output_t *output,
const rarch_dsp_input_t *input)
{
struct iir_filter_data *iir = (struct iir_filter_data*)data;
output->samples = iir->buf;
iir_process_batch(&iir->iir_l, iir->buf, input->samples, input->frames);
output->frames = input->frames;
}
#endif
static void iir_dsp_free(void *data)
{
struct iir_filter_data *iir = (struct iir_filter_data*)data;
if (iir)
free(iir);
}
static void iir_dsp_config(void* data)
{
(void)data;
}
const struct dspfilter_implementation generic_iir_dsp = {
iir_dsp_init,
iir_dsp_process,
iir_dsp_free,
RARCH_DSP_API_VERSION,
iir_dsp_config,
"IIR",
NULL
};
#ifdef __SSE2__
const struct dspfilter_implementation sse2_iir_dsp = {
iir_dsp_init,
iir_dsp_process_sse2,
iir_dsp_free,
RARCH_DSP_API_VERSION,
iir_dsp_config,
"IIR (SSE2)",
NULL
};
#endif
const struct dspfilter_implementation *rarch_dsp_plugin_init(dspfilter_simd_mask_t simd)
{
(void)simd;
#ifdef __SSE2__
if (simd & DSPFILTER_SIMD_SSE2)
return &sse2_iir_dsp;
#endif
return &generic_iir_dsp;
}
#ifdef RARCH_INTERNAL
#undef rarch_dsp_plugin_init
#endif

View File

@ -1,193 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2014 - Daniel De Matteis
* Copyright (C) 2012-2014 - Brad Miller
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "rarch_dsp.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795
#endif
#define PHASERLFOSHAPE 4.0
#define PHASER_LFOSKIPSAMPLES 20
#ifdef RARCH_INTERNAL
#define rarch_dsp_plugin_init phaser_dsp_plugin_init
#endif
struct phaser_filter
{
float freq;
float startphase;
float fb;
int depth;
int stages;
int drywet;
unsigned long skipcount;
float old[24];
float gain;
float fbout;
float lfoskip;
float phase;
};
struct phaser_filter_data
{
struct phaser_filter phase_l;
struct phaser_filter phase_r;
float buf[4096];
};
static void phaser_init(void *data, int samplerate)
{
int j;
struct phaser_filter *phaser = (struct phaser_filter*)data;
phaser->skipcount = 0;
phaser->gain = 0.0;
phaser->fbout = 0.0;
phaser->lfoskip = phaser->freq * 2 * M_PI / samplerate;
phaser->phase = phaser->startphase * M_PI / 180;
for (j = 0; j < phaser->stages; j++)
phaser->old[j] = 0;
}
static float phaser_process(void *data, float in)
{
float m, tmp, out;
int j;
struct phaser_filter *phaser = (struct phaser_filter*)data;
m = in + phaser->fbout * phaser->fb / 100;
if (((phaser->skipcount++) % PHASER_LFOSKIPSAMPLES) == 0)
{
phaser->gain = (1 + cos(phaser->skipcount * phaser->lfoskip + phaser->phase)) / 2;
phaser->gain =(exp(phaser->gain * PHASERLFOSHAPE) - 1) / (exp(PHASERLFOSHAPE)-1);
phaser->gain = 1 - phaser->gain / 255 * phaser->depth;
}
for (j = 0; j < phaser->stages; j++)
{
tmp = phaser->old[j];
phaser->old[j] = phaser->gain * tmp + m;
m = tmp - phaser->gain * phaser->old[j];
}
phaser->fbout = m;
out = (m * phaser->drywet + in * (255 - phaser->drywet)) / 255;
if (out < -1.0) out = -1.0;
if (out > 1.0) out = 1.0;
return out;
}
static void * phaser_dsp_init(const rarch_dsp_info_t *info)
{
float freq, startphase, fb;
int depth, stages, drywet;
struct phaser_filter_data *phaser;
freq = 0.4;
startphase = 0;
fb = 0;
depth = 100;
stages = 2;
drywet = 128;
phaser = (struct phaser_filter_data*)calloc(1, sizeof(*phaser));
if (!phaser)
return NULL;
phaser->phase_l.freq = freq;
phaser->phase_l.startphase = startphase;
phaser->phase_l.fb = fb;
phaser->phase_l.depth = depth;
phaser->phase_l.stages = stages;
phaser->phase_l.drywet = drywet;
phaser_init(&phaser->phase_l, info->input_rate);
phaser->phase_r.freq = freq;
phaser->phase_r.startphase = startphase;
phaser->phase_r.fb = fb;
phaser->phase_r.depth = depth;
phaser->phase_r.stages = stages;
phaser->phase_r.drywet = drywet;
phaser_init(&phaser->phase_r, info->input_rate);
return phaser;
}
static void phaser_dsp_process(void *data, rarch_dsp_output_t *output,
const rarch_dsp_input_t *input)
{
int i, num_samples;
struct phaser_filter_data *phaser = (struct phaser_filter_data*)data;
output->samples = phaser->buf;
num_samples = input->frames * 2;
for (i = 0; i<num_samples;)
{
phaser->buf[i] = phaser_process(&phaser->phase_l, input->samples[i]);
i++;
phaser->buf[i] = phaser_process(&phaser->phase_r, input->samples[i]);
i++;
}
output->frames = input->frames;
}
static void phaser_dsp_free(void *data)
{
struct phaser_filter_data *phaser = (struct phaser_filter_data*)data;
if (phaser)
{
int j;
for (j = 0; j < phaser->phase_l.stages; j++)
phaser->phase_l.old[j] = 0;
for (j = 0; j < phaser->phase_r.stages; j++)
phaser->phase_r.old[j] = 0;
free(phaser);
}
}
static void phaser_dsp_config(void *data)
{
(void)data;
}
const struct dspfilter_implementation generic_phaser_dsp = {
phaser_dsp_init,
phaser_dsp_process,
phaser_dsp_free,
RARCH_DSP_API_VERSION,
phaser_dsp_config,
"Phaser",
NULL
};
const struct dspfilter_implementation *rarch_dsp_plugin_init(dspfilter_simd_mask_t simd)
{
(void)simd;
return &generic_phaser_dsp;
}
#ifdef RARCH_INTERNAL
#undef rarch_dsp_plugin_init
#endif

View File

@ -1,397 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2014 - Daniel De Matteis
* Copyright (C) 2012-2014 - Brad Miller
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "rarch_dsp.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define NUMCOMBS 8
#define NUMALLPASSES 4
#define MUTED 0
#define FIXEDGAIN 0.015f
#define SCALEWET 3
#define SCALEDRY 2
#define SCALEDAMP 0.4f
#define SCALEROOM 0.28f
#define OFFSETROOM 0.7f
#define INITIALROOM 0.5f
#define INITIALDAMP 0.5f
#define INITIALWET (1 / SCALEWET)
#define INITIALDRY 0
#define INITIALWIDTH 1
#define INITIALMODE 0
#define FREEZEMODE 0.5f
#define COMBTUNINGL1 1116
#define COMBTUNINGL2 1188
#define COMBTUNINGL3 1277
#define COMBTUNINGL4 1356
#define COMBTUNINGL5 1422
#define COMBTUNINGL6 1491
#define COMBTUNINGL7 1557
#define COMBTUNINGL8 1617
#define ALLPASSTUNINGL1 556
#define ALLPASSTUNINGL2 441
#define ALLPASSTUNINGL3 341
#define ALLPASSTUNINGL4 225
#ifdef RARCH_INTERNAL
#define rarch_dsp_plugin_init reverb_dsp_plugin_init
#endif
struct comb
{
float feedback;
float filterstore;
float damp1;
float damp2;
float *buffer;
int bufsize;
int bufidx;
};
struct allpass
{
float feedback;
float *buffer;
int bufsize;
int bufidx;
};
struct revmodel
{
float gain;
float roomsize, roomsize1;
float damp, damp1;
float wet, wet1, wet2;
float dry;
float width;
float mode;
struct comb combL[NUMCOMBS];
struct allpass allpassL[NUMALLPASSES];
float bufcombL1[COMBTUNINGL1];
float bufcombL2[COMBTUNINGL2];
float bufcombL3[COMBTUNINGL3];
float bufcombL4[COMBTUNINGL4];
float bufcombL5[COMBTUNINGL5];
float bufcombL6[COMBTUNINGL6];
float bufcombL7[COMBTUNINGL7];
float bufcombL8[COMBTUNINGL8];
float bufallpassL1[ALLPASSTUNINGL1];
float bufallpassL2[ALLPASSTUNINGL2];
float bufallpassL3[ALLPASSTUNINGL3];
float bufallpassL4[ALLPASSTUNINGL4];
};
// FIXME: Fix this really ugly hack
static inline float undenormalise(void *sample)
{
if (((*(unsigned int*)sample) & 0x7f800000) == 0)
return 0.0f;
return *(float*)sample;
}
static inline float comb_process(void *data, float input)
{
struct comb *comb = (struct comb*)data;
float output;
output = comb->buffer[comb->bufidx];
undenormalise(&output);
comb->filterstore = (output * comb->damp2) + (comb->filterstore * comb->damp1);
undenormalise(&comb->filterstore);
comb->buffer[comb->bufidx] = input + (comb->filterstore * comb->feedback);
if (++comb->bufidx >= comb->bufsize)
comb->bufidx = 0;
return output;
}
static inline float allpass_process(void *data, float input)
{
struct allpass *allpass = (struct allpass*)data;
float output, bufout;
bufout = allpass->buffer[allpass->bufidx];
undenormalise(&bufout);
output = -input + bufout;
allpass->buffer[allpass->bufidx] = input + (bufout * allpass->feedback);
if (++allpass->bufidx >= allpass->bufsize)
allpass->bufidx = 0;
return output;
}
static float revmodel_getmode(float mode)
{
if (mode >= FREEZEMODE)
return 1;
else
return 0;
}
static void revmodel_update(void *data)
{
int i;
struct revmodel *rev = (struct revmodel*)data;
rev->wet1 = rev->wet * (rev->width / 2 + 0.5f);
if (rev->mode >= FREEZEMODE)
{
rev->roomsize1 = 1;
rev->damp1 = 0;
rev->gain = MUTED;
}
else
{
rev->roomsize1 = rev->roomsize;
rev->damp1 = rev->damp;
rev->gain = FIXEDGAIN;
}
for (i = 0; i < NUMCOMBS; i++)
rev->combL[i].feedback = rev->roomsize1;
for (i = 0; i < NUMCOMBS; i++)
{
rev->combL[i].damp1 = rev->damp1;
rev->combL[i].damp2 = 1 - rev->damp1;
}
}
static void revmodel_set(void *data, float drytime,
float wettime, float damping, float roomwidth, float roomsize)
{
int i, j;
struct revmodel *rev = (struct revmodel*)data;
rev->wet = wettime;
revmodel_update(rev);
rev->roomsize = roomsize;
revmodel_update(rev);
rev->dry = drytime;
rev->damp = damping;
revmodel_update(rev);
rev->width = roomwidth;
revmodel_update(rev);
rev->mode = INITIALMODE;
revmodel_update(rev);
if (revmodel_getmode(rev->mode) >= FREEZEMODE)
return;
for (i = 0; i < NUMCOMBS; i++)
{
for (j = 0; j < rev->combL[i].bufsize; j++)
rev->combL[i].buffer[j] = 0;
}
for (i = 0; i < NUMALLPASSES; i++)
{
for (j = 0; j < rev->allpassL[i].bufsize; j++)
rev->allpassL[i].buffer[j] = 0;
}
}
static void revmodel_init(void *data)
{
struct revmodel *rev = (struct revmodel*)data;
rev->combL[0].filterstore = 0;
rev->combL[0].bufidx = 0;
rev->combL[0].buffer = (float*)rev->bufcombL1;
rev->combL[0].bufsize = COMBTUNINGL1;
rev->combL[1].filterstore = 0;
rev->combL[1].bufidx = 0;
rev->combL[1].buffer = (float*)rev->bufcombL2;
rev->combL[1].bufsize = COMBTUNINGL2;
rev->combL[2].filterstore = 0;
rev->combL[2].bufidx = 0;
rev->combL[2].buffer = (float*)rev->bufcombL3;
rev->combL[2].bufsize = COMBTUNINGL3;
rev->combL[3].filterstore = 0;
rev->combL[3].bufidx = 0;
rev->combL[3].buffer = (float*)rev->bufcombL4;
rev->combL[3].bufsize = COMBTUNINGL4;
rev->combL[4].filterstore = 0;
rev->combL[4].bufidx = 0;
rev->combL[4].buffer = (float*)rev->bufcombL5;
rev->combL[4].bufsize = COMBTUNINGL5;
rev->combL[5].filterstore = 0;
rev->combL[5].bufidx = 0;
rev->combL[5].buffer = (float*)rev->bufcombL6;
rev->combL[5].bufsize = COMBTUNINGL6;
rev->combL[6].filterstore = 0;
rev->combL[6].bufidx = 0;
rev->combL[6].buffer = (float*)rev->bufcombL7;
rev->combL[6].bufsize = COMBTUNINGL7;
rev->combL[7].filterstore = 0;
rev->combL[7].bufidx = 0;
rev->combL[7].buffer = (float*)rev->bufcombL8;
rev->combL[7].bufsize = COMBTUNINGL8;
rev->allpassL[0].bufidx = 0;
rev->allpassL[0].buffer = (float*)rev->bufallpassL1;
rev->allpassL[0].bufsize = ALLPASSTUNINGL1;
rev->allpassL[0].feedback = 0.5f;
rev->allpassL[1].bufidx = 0;
rev->allpassL[1].buffer = (float*)rev->bufallpassL2;
rev->allpassL[1].bufsize = ALLPASSTUNINGL2;
rev->allpassL[1].feedback = 0.5f;
rev->allpassL[2].bufidx = 0;
rev->allpassL[2].buffer = (float*)rev->bufallpassL3;
rev->allpassL[2].bufsize = ALLPASSTUNINGL3;
rev->allpassL[2].feedback = 0.5f;
rev->allpassL[3].bufidx = 0;
rev->allpassL[3].buffer = (float*)rev->bufallpassL4;
rev->allpassL[3].bufsize = ALLPASSTUNINGL4;
rev->allpassL[3].feedback = 0.5f;
}
static float revmodel_process(void *data, float in)
{
float samp, mono_out, mono_in, input;
int i;
struct revmodel *rev = (struct revmodel*)data;
samp = in;
mono_out = 0.0f;
mono_in = samp;
input = (mono_in) * rev->gain;
for(i=0; i < NUMCOMBS; i++)
mono_out += comb_process(&rev->combL[i], input);
for(i = 0; i < NUMALLPASSES; i++)
mono_out = allpass_process(&rev->allpassL[i], mono_out);
samp = mono_in * rev->dry + mono_out * rev->wet1;
return samp;
}
#define REVMODEL_GETWET(revmodel) (revmodel->wet / SCALEWET)
#define REVMODEL_GETROOMSIZE(revmodel) ((revmodel->roomsize - OFFSETROOM) / SCALEROOM)
#define REVMODEL_GETDRY(revmodel) (revmodel->dry / SCALEDRY)
#define REVMODEL_GETWIDTH(revmodel) (revmodel->width)
struct reverb_filter_data
{
struct revmodel rev_l;
struct revmodel rev_r;
float buf[4096];
};
static void * reverb_dsp_init(const rarch_dsp_info_t *info)
{
float drytime, wettime, damping, roomwidth, roomsize;
(void)info;
drytime = 0.43;
wettime = 0.57;
damping = 0.45;
roomwidth = 0.56;
roomsize = 0.56;
struct reverb_filter_data *reverb = (struct reverb_filter_data*)calloc(1, sizeof(*reverb));
if (!reverb)
return NULL;
revmodel_init(&reverb->rev_l);
revmodel_set(&reverb->rev_l, INITIALDRY,
INITIALWET * SCALEWET, INITIALDAMP * SCALEDAMP, INITIALWIDTH, (INITIALROOM * SCALEROOM) + OFFSETROOM);
revmodel_set(&reverb->rev_l, drytime, wettime, damping, roomwidth, roomsize);
revmodel_init(&reverb->rev_r);
revmodel_set(&reverb->rev_r, INITIALDRY,
INITIALWET * SCALEWET, INITIALDAMP * SCALEDAMP, INITIALWIDTH, (INITIALROOM * SCALEROOM) + OFFSETROOM);
revmodel_set(&reverb->rev_r, drytime, wettime, damping, roomwidth, roomsize);
return reverb;
}
static void reverb_dsp_process(void *data, rarch_dsp_output_t *output,
const rarch_dsp_input_t *input)
{
int i, num_samples;
struct reverb_filter_data *reverb = (struct reverb_filter_data*)data;
output->samples = reverb->buf;
num_samples = input->frames * 2;
for (i = 0; i < num_samples;)
{
reverb->buf[i] = revmodel_process(&reverb->rev_l, input->samples[i]);
i++;
reverb->buf[i] = revmodel_process(&reverb->rev_r, input->samples[i]);
i++;
}
output->frames = input->frames;
}
static void reverb_dsp_free(void *data)
{
struct reverb_filter_data *rev = (struct reverb_filter_data*)data;
if (rev)
free(rev);
}
static void reverb_dsp_config(void *data)
{
(void)data;
}
const struct dspfilter_implementation generic_reverb_dsp = {
reverb_dsp_init,
reverb_dsp_process,
reverb_dsp_free,
RARCH_DSP_API_VERSION,
reverb_dsp_config,
"Reverberatation",
NULL
};
const struct dspfilter_implementation *rarch_dsp_plugin_init(dspfilter_simd_mask_t simd)
{
(void)simd;
return &generic_reverb_dsp;
}
#ifdef RARCH_INTERNAL
#undef rarch_dsp_plugin_init
#endif

View File

@ -1,131 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2014 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "rarch_dsp.h"
#include <stdint.h>
#include <stdlib.h>
#include <math.h>
#ifdef RARCH_INTERNAL
#define rarch_dsp_plugin_init volume_dsp_plugin_init
#endif
struct volume_filter_data
{
#ifdef __GNUC__
float buf[4096] __attribute__((aligned(16)));
#else
float buf[4096];
#endif
float m_vol;
float m_pan_vol_l;
float m_pan_vol_r;
};
#if 0
static void pan2gain(float &left, float &right, int val)
{
left = (100 - val) / 100.0f;
right = (val + 100) / 100.0f;
if (left > 1.0)
left = 1.0;
if (right > 1.0)
right = 1.0;
}
static float db2gain(float val)
{
return powf(10.0, val / 20.0);
}
#endif
static void volume_process(void *data, const float *in, unsigned frames)
{
float vol_left, vol_right;
unsigned i;
struct volume_filter_data *vol = (struct volume_filter_data*)data;
if (!vol)
return;
vol_left = vol->m_vol * vol->m_pan_vol_l;
vol_right = vol->m_vol * vol->m_pan_vol_r;
for (i = 0; i < frames; i++)
{
vol->buf[(i << 1) + 0] = in[(i << 1) + 0] * vol_left;
vol->buf[(i << 1) + 1] = in[(i << 1) + 1] * vol_right;
}
}
static void *volume_dsp_init(const rarch_dsp_info_t *info)
{
struct volume_filter_data *vol = (struct volume_filter_data*)calloc(1, sizeof(*vol));
(void)info;
if (!vol)
return NULL;
vol->m_vol = 1.0;
vol->m_pan_vol_l = 1.0;
vol->m_pan_vol_r = 1.0;
return vol;
}
static void volume_dsp_process(void *data, rarch_dsp_output_t *output,
const rarch_dsp_input_t *input)
{
struct volume_filter_data *vol = (struct volume_filter_data*)data;
output->samples = vol->buf;
volume_process(vol, input->samples, input->frames);
output->frames = input->frames;
}
static void volume_dsp_free(void *data)
{
struct volume_filter_data *vol = (struct volume_filter_data*)data;
if (vol)
free(vol);
}
static void volume_dsp_config(void *data)
{
(void)data;
}
const struct dspfilter_implementation generic_volume_dsp = {
volume_dsp_init,
volume_dsp_process,
volume_dsp_free,
RARCH_DSP_API_VERSION,
volume_dsp_config,
"Volume",
NULL
};
const struct dspfilter_implementation *rarch_dsp_plugin_init(dspfilter_simd_mask_t simd)
{
(void)simd;
return &generic_volume_dsp;
}
#ifdef RARCH_INTERNAL
#undef rarch_dsp_plugin_init
#endif

View File

@ -1,187 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2014 - Daniel De Matteis
* Copyright (C) 2012-2014 - Brad Miller
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "rarch_dsp.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795
#endif
#ifndef LFOSKIPSAMPLES
#define LFOSKIPSAMPLES 30
#endif
#ifdef RARCH_INTERNAL
#define rarch_dsp_plugin_init wah_dsp_plugin_init
#endif
struct wahwah_filter
{
float phase;
float lfoskip;
unsigned long skipcount;
float xn1, xn2, yn1, yn2;
float b0, b1, b2, a0, a1, a2;
float freq, startphase;
float depth, freqofs, res;
};
struct wahwah_filter_data
{
struct wahwah_filter wah_l;
struct wahwah_filter wah_r;
float buf[4096];
};
static void wahwah_init(void *data, int samplerate)
{
struct wahwah_filter *wah = (struct wahwah_filter*)data;
wah->lfoskip = wah->freq * 2 * M_PI / samplerate;
wah->skipcount = 0;
wah->xn1 = 0;
wah->xn2 = 0;
wah->yn1 = 0;
wah->yn2 = 0;
wah->b0 = 0;
wah->b1 = 0;
wah->b2 = 0;
wah->a0 = 0;
wah->a1 = 0;
wah->a2 = 0;
wah->phase = wah->startphase * M_PI / 180;
}
static float wahwah_process(void *data, float samp)
{
float frequency, omega, sn, cs, alpha;
float in, out;
struct wahwah_filter *wah = (struct wahwah_filter*)data;
in = samp;
if ((wah->skipcount++) % LFOSKIPSAMPLES == 0)
{
frequency = (1 + cos(wah->skipcount * wah->lfoskip + wah->phase)) / 2;
frequency = frequency * wah->depth * (1 - wah->freqofs) + wah->freqofs;
frequency = exp((frequency - 1) * 6);
omega = M_PI * frequency;
sn = sin(omega);
cs = cos(omega);
alpha = sn / (2 * wah->res);
wah->b0 = (1 - cs) / 2;
wah->b1 = 1 - cs;
wah->b2 = (1 - cs) / 2;
wah->a0 = 1 + alpha;
wah->a1 = -2 * cs;
wah->a2 = 1 - alpha;
}
out = (wah->b0 * in + wah->b1 * wah->xn1 + wah->b2 * wah->xn2 - wah->a1 * wah->yn1 - wah->a2 * wah->yn2) / wah->a0;
wah->xn2 = wah->xn1;
wah->xn1 = in;
wah->yn2 = wah->yn1;
wah->yn1 = out;
samp = out;
return samp;
}
static void * wah_dsp_init(const rarch_dsp_info_t *info)
{
float freq = 1.5;
float startphase = 0.0;
float res = 2.5;
float depth = 0.70;
float freqofs = 0.30;
struct wahwah_filter_data *wah = (struct wahwah_filter_data*)calloc(1, sizeof(*wah));
if (!wah)
return NULL;
wah->wah_l.depth = depth;
wah->wah_l.freqofs = freqofs;
wah->wah_l.freq = freq;
wah->wah_l.startphase = startphase;
wah->wah_l.res = res;
wahwah_init(&wah->wah_l, info->input_rate);
wah->wah_r.depth = depth;
wah->wah_r.freqofs = freqofs;
wah->wah_r.freq = freq;
wah->wah_r.startphase = startphase;
wah->wah_r.res = res;
wahwah_init(&wah->wah_r, info->input_rate);
return wah;
}
static void wah_dsp_process(void *data, rarch_dsp_output_t *output,
const rarch_dsp_input_t *input)
{
int num_samples, i;
struct wahwah_filter_data *wah = (struct wahwah_filter_data*)data;
output->samples = wah->buf;
num_samples = input->frames * 2;
for (i = 0; i < num_samples;)
{
wah->buf[i] = wahwah_process(&wah->wah_l, input->samples[i]);
i++;
wah->buf[i] = wahwah_process(&wah->wah_r, input->samples[i]);
i++;
}
output->frames = input->frames;
}
static void wah_dsp_free(void *data)
{
struct wahwah_filter_data *wah = (struct wahwah_filter_data*)data;
if (wah)
free(wah);
}
static void wah_dsp_config(void *data)
{
(void)data;
}
const struct dspfilter_implementation generic_wah_dsp = {
wah_dsp_init,
wah_dsp_process,
wah_dsp_free,
RARCH_DSP_API_VERSION,
wah_dsp_config,
"Wah",
NULL
};
const struct dspfilter_implementation *rarch_dsp_plugin_init(dspfilter_simd_mask_t simd)
{
(void)simd;
return &generic_wah_dsp;
}
#ifdef RARCH_INTERNAL
#undef rarch_dsp_plugin_init
#endif

View File

@ -710,15 +710,7 @@ extern const struct softfilter_implementation *twoxbr_get_implementation(softfil
extern const struct softfilter_implementation *darken_get_implementation(softfilter_simd_mask_t simd);
extern const struct softfilter_implementation *scale2x_get_implementation(softfilter_simd_mask_t simd);
extern const struct dspfilter_implementation *echo_dsp_plugin_init(dspfilter_simd_mask_t simd);
#ifndef _WIN32
extern const struct dspfilter_implementation *eq_dsp_plugin_init(dspfilter_simd_mask_t simd);
#endif
extern const struct dspfilter_implementation *iir_dsp_plugin_init(dspfilter_simd_mask_t simd);
extern const struct dspfilter_implementation *phaser_dsp_plugin_init(dspfilter_simd_mask_t simd);
extern const struct dspfilter_implementation *reverb_dsp_plugin_init(dspfilter_simd_mask_t simd);
extern const struct dspfilter_implementation *volume_dsp_plugin_init(dspfilter_simd_mask_t simd);
extern const struct dspfilter_implementation *wah_dsp_plugin_init(dspfilter_simd_mask_t simd);
// TODO: DSP plugs.
#endif
#include "driver_funcs.h"

View File

@ -485,17 +485,7 @@ FILTERS
#include "../gfx/filters/lq2x.c"
#include "../gfx/filters/phosphor2x.c"
#include "../audio/filters/echo.c"
#ifndef ANDROID
#ifndef _WIN32
#include "../audio/filters/eq.c"
#endif
#endif
#include "../audio/filters/iir.c"
#include "../audio/filters/phaser.c"
#include "../audio/filters/reverb.c"
#include "../audio/filters/volume.c"
#include "../audio/filters/wah.c"
// TODO: Audio plugs.
#endif
/*============================================================
DYNAMIC
@ -503,6 +493,7 @@ DYNAMIC
#include "../dynamic.c"
#include "../dynamic_dummy.c"
#include "../gfx/filter.c"
#include "../audio/dsp_filter.c"
/*============================================================