This commit is contained in:
twinaphex 2017-01-09 12:14:46 +01:00
parent 830cadc01d
commit 6f2dc9196b
12 changed files with 130 additions and 108 deletions

View File

@ -28,7 +28,7 @@
#include <string/stdstring.h>
#include "audio_dsp_filter.h"
#include "audio_filters/dspfilter.h"
#include "libretro_dspfilter.h"
struct rarch_dsp_plug
{

View File

@ -57,7 +57,7 @@ endif
CC := $(compiler) -Wall
CXX := $(subst CC,++,$(compiler)) -std=gnu++0x -Wall
flags := $(CPPFLAGS) $(CFLAGS) -fPIC $(extra_flags) -I../../libretro-common/include
flags := $(CPPFLAGS) $(CFLAGS) -fPIC $(extra_flags) -I../../libretro-common/include -I../
asflags := $(ASFLAGS) -fPIC $(extra_flags)
objects :=

View File

@ -13,12 +13,12 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "dspfilter.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <retro_miscellaneous.h>
#include <libretro_dspfilter.h>
#define CHORUS_MAX_DELAY 4096
#define CHORUS_DELAY_MASK (CHORUS_MAX_DELAY - 1)
@ -46,11 +46,12 @@ static void chorus_process(void *data, struct dspfilter_output *output,
const struct dspfilter_input *input)
{
unsigned i;
float *out = NULL;
struct chorus_data *ch = (struct chorus_data*)data;
output->samples = input->samples;
output->frames = input->frames;
float *out = output->samples;
output->samples = input->samples;
output->frames = input->frames;
out = output->samples;
for (i = 0; i < input->frames; i++, out += 2)
{
@ -77,7 +78,8 @@ static void chorus_process(void *data, struct dspfilter_output *output,
r_a = ch->old[1][(ch->old_ptr - delay_int - 0) & CHORUS_DELAY_MASK];
r_b = ch->old[1][(ch->old_ptr - delay_int - 1) & CHORUS_DELAY_MASK];
/* Lerp introduces aliasing of the chorus component, but doing full polyphase here is probably overkill. */
/* Lerp introduces aliasing of the chorus component,
* but doing full polyphase here is probably overkill. */
chorus_l = l_a * (1.0f - delay_frac) + l_b * delay_frac;
chorus_r = r_a * (1.0f - delay_frac) + r_b * delay_frac;
@ -138,7 +140,8 @@ static const struct dspfilter_implementation chorus_plug = {
#define dspfilter_get_implementation chorus_dspfilter_get_implementation
#endif
const struct dspfilter_implementation *dspfilter_get_implementation(dspfilter_simd_mask_t mask)
const struct dspfilter_implementation *
dspfilter_get_implementation(dspfilter_simd_mask_t mask)
{
(void)mask;
return &chorus_plug;

View File

@ -16,8 +16,7 @@
#include <stdlib.h>
#include <retro_miscellaneous.h>
#include "dspfilter.h"
#include <libretro_dspfilter.h>
struct echo_channel
{
@ -49,12 +48,13 @@ static void echo_process(void *data, struct dspfilter_output *output,
const struct dspfilter_input *input)
{
unsigned i, c;
float *out = NULL;
struct echo_data *echo = (struct echo_data*)data;
output->samples = input->samples;
output->frames = input->frames;
output->samples = input->samples;
output->frames = input->frames;
float *out = output->samples;
out = output->samples;
for (i = 0; i < input->frames; i++, out += 2)
{
@ -94,25 +94,35 @@ static void *echo_init(const struct dspfilter_info *info,
const struct dspfilter_config *config, void *userdata)
{
unsigned i, channels;
float *delay = NULL, *feedback = NULL;
unsigned num_delay = 0, num_feedback = 0;
struct echo_channel *echo_channels = NULL;
float *delay = NULL;
float *feedback = NULL;
unsigned num_delay = 0;
unsigned num_feedback = 0;
static const float default_delay[] = { 200.0f };
static const float default_delay[] = { 200.0f };
static const float default_feedback[] = { 0.5f };
struct echo_data *echo = (struct echo_data*)calloc(1, sizeof(*echo));
struct echo_data *echo = (struct echo_data*)
calloc(1, sizeof(*echo));
if (!echo)
return NULL;
config->get_float_array(userdata, "delay", &delay, &num_delay, default_delay, 1);
config->get_float_array(userdata, "feedback", &feedback, &num_feedback, default_feedback, 1);
config->get_float_array(userdata, "delay", &delay,
&num_delay, default_delay, 1);
config->get_float_array(userdata, "feedback", &feedback,
&num_feedback, default_feedback, 1);
config->get_float(userdata, "amp", &echo->amp, 0.2f);
channels = num_feedback = num_delay = MIN(num_delay, num_feedback);
echo->channels = (struct echo_channel*)calloc(channels, sizeof(*echo->channels));
if (!echo->channels)
echo_channels = (struct echo_channel*)calloc(channels,
sizeof(*echo_channels));
if (!echo_channels)
goto error;
echo->channels = echo_channels;
echo->num_channels = channels;
for (i = 0; i < channels; i++)

View File

@ -19,8 +19,7 @@
#include <retro_inline.h>
#include <retro_miscellaneous.h>
#include <filters.h>
#include "dspfilter.h"
#include <libretro_dspfilter.h>
#include "fft/fft.c"

View File

@ -13,10 +13,11 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "fft.h"
#include <math.h>
#include <stdlib.h>
#include "fft.h"
#include <retro_miscellaneous.h>
struct fft
@ -128,8 +129,8 @@ void fft_free(fft_t *fft)
static void butterfly(fft_complex_t *a, fft_complex_t *b, fft_complex_t mod)
{
mod = fft_complex_mul(mod, *b);
*b = fft_complex_sub(*a, mod);
*a = fft_complex_add(*a, mod);
*b = fft_complex_sub(*a, mod);
*a = fft_complex_add(*a, mod);
}
static void butterflies(fft_complex_t *butterfly_buf,
@ -141,7 +142,8 @@ static void butterflies(fft_complex_t *butterfly_buf,
{
int phase_step = (int)samples * phase_dir / (int)step_size;
for (j = i; j < i + step_size; j++)
butterfly(&butterfly_buf[j], &butterfly_buf[j + step_size], phase_lut[phase_step * (int)(j - i)]);
butterfly(&butterfly_buf[j], &butterfly_buf[j + step_size],
phase_lut[phase_step * (int)(j - i)]);
}
}
@ -180,7 +182,9 @@ void fft_process_inverse(fft_t *fft,
{
unsigned step_size;
unsigned samples = fft->size;
interleave_complex(fft->bitinverse_buffer, fft->interleave_buffer, in, samples, 1);
interleave_complex(fft->bitinverse_buffer, fft->interleave_buffer,
in, samples, 1);
for (step_size = 1; step_size < samples; step_size <<= 1)
{

View File

@ -14,12 +14,12 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "dspfilter.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <retro_miscellaneous.h>
#include <libretro_dspfilter.h>
#define sqr(a) ((a) * (a))
@ -60,34 +60,29 @@ static void iir_free(void *data)
static void iir_process(void *data, struct dspfilter_output *output,
const struct dspfilter_input *input)
{
float b0, b1, b2, a0, a1, a2;
float xn1_l, xn2_l, yn1_l, yn2_l;
float xn1_r, xn2_r, yn1_r, yn2_r;
unsigned i;
float *out;
struct iir_data *iir = (struct iir_data*)data;
float *out = output->samples;
output->samples = input->samples;
output->frames = input->frames;
float b0 = iir->b0;
float b1 = iir->b1;
float b2 = iir->b2;
float a0 = iir->a0;
float a1 = iir->a1;
float a2 = iir->a2;
out = output->samples;
float xn1_l = iir->l.xn1;
float xn2_l = iir->l.xn2;
float yn1_l = iir->l.yn1;
float yn2_l = iir->l.yn2;
b0 = iir->b0;
b1 = iir->b1;
b2 = iir->b2;
a0 = iir->a0;
a1 = iir->a1;
a2 = iir->a2;
float xn1_r = iir->r.xn1;
float xn2_r = iir->r.xn2;
float yn1_r = iir->r.yn1;
float yn2_r = iir->r.yn2;
xn1_l = iir->l.xn1;
xn2_l = iir->l.xn2;
yn1_l = iir->l.yn1;
yn2_l = iir->l.yn2;
xn1_r = iir->r.xn1;
xn2_r = iir->r.xn2;
yn1_r = iir->r.yn1;
yn2_r = iir->r.yn2;
output->samples = input->samples;
output->frames = input->frames;
for (i = 0; i < input->frames; i++, out += 2)
{
@ -97,18 +92,18 @@ static void iir_process(void *data, struct dspfilter_output *output,
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;
xn2_l = xn1_l;
xn1_l = in_l;
yn2_l = yn1_l;
yn1_l = l;
xn2_l = xn1_l;
xn1_l = in_l;
yn2_l = yn1_l;
yn1_l = l;
xn2_r = xn1_r;
xn1_r = in_r;
yn2_r = yn1_r;
yn1_r = r;
xn2_r = xn1_r;
xn1_r = in_r;
yn2_r = yn1_r;
yn1_r = r;
out[0] = l;
out[1] = r;
out[0] = l;
out[1] = r;
}
iir->l.xn1 = xn1_l;
@ -326,9 +321,9 @@ static void *iir_init(const struct dspfilter_info *info,
const struct dspfilter_config *config, void *userdata)
{
float freq, qual, gain;
enum IIRFilter filter;
char *type = NULL;
struct iir_data *iir = (struct iir_data*)calloc(1, sizeof(*iir));
enum IIRFilter filter = LPF;
char *type = NULL;
struct iir_data *iir = (struct iir_data*)calloc(1, sizeof(*iir));
if (!iir)
return NULL;

View File

@ -13,11 +13,12 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "dspfilter.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <libretro_dspfilter.h>
struct panning_data
{
float left[2];
@ -33,38 +34,45 @@ static void panning_process(void *data, struct dspfilter_output *output,
const struct dspfilter_input *input)
{
unsigned i;
float *out;
struct panning_data *pan = (struct panning_data*)data;
float *out = output->samples;
output->samples = input->samples;
output->frames = input->frames;
out = output->samples;
for (i = 0; i < input->frames; i++, out += 2)
{
float left = out[0];
float left = out[0];
float right = out[1];
out[0] = left * pan->left[0] + right * pan->left[1];
out[1] = left * pan->right[0] + right * pan->right[1];
out[0] = left * pan->left[0] + right * pan->left[1];
out[1] = left * pan->right[0] + right * pan->right[1];
}
}
static void *panning_init(const struct dspfilter_info *info,
const struct dspfilter_config *config, void *userdata)
{
static const float default_left[] = { 1.0f, 0.0f };
static const float default_left[] = { 1.0f, 0.0f };
static const float default_right[] = { 0.0f, 1.0f };
float *left = NULL, *right = NULL;
unsigned num_left = 0, num_right = 0;
struct panning_data *pan = (struct panning_data*)calloc(1, sizeof(*pan));
float *left = NULL;
float *right = NULL;
unsigned num_left = 0;
unsigned num_right = 0;
struct panning_data *pan = (struct panning_data*)
calloc(1, sizeof(*pan));
if (!pan)
return NULL;
config->get_float_array(userdata, "left_mix", &left, &num_left, default_left, 2);
config->get_float_array(userdata, "right_mix", &right, &num_right, default_right, 2);
config->get_float_array(userdata, "left_mix",
&left, &num_left, default_left, 2);
config->get_float_array(userdata, "right_mix",
&right, &num_right, default_right, 2);
memcpy(pan->left, (num_left == 2) ? left : default_left, sizeof(pan->left));
memcpy(pan->right, (num_right == 2) ? right : default_right, sizeof(pan->right));
memcpy(pan->left, (num_left == 2) ?
left : default_left, sizeof(pan->left));
memcpy(pan->right, (num_right == 2) ?
right : default_right, sizeof(pan->right));
config->free(left);
config->free(right);
@ -86,7 +94,8 @@ static const struct dspfilter_implementation panning = {
#define dspfilter_get_implementation panning_dspfilter_get_implementation
#endif
const struct dspfilter_implementation *dspfilter_get_implementation(dspfilter_simd_mask_t mask)
const struct dspfilter_implementation *
dspfilter_get_implementation(dspfilter_simd_mask_t mask)
{
(void)mask;
return &panning;

View File

@ -14,12 +14,12 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "dspfilter.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <retro_miscellaneous.h>
#include <libretro_dspfilter.h>
#define phaserlfoshape 4.0
#define phaserlfoskipsamples 20
@ -51,12 +51,12 @@ static void phaser_process(void *data, struct dspfilter_output *output,
{
unsigned i, c;
int s;
float m[2], tmp[2], *out;
float m[2], tmp[2];
struct phaser_data *ph = (struct phaser_data*)data;
float *out = output->samples;
output->samples = input->samples;
output->frames = input->frames;
out = output->samples;
output->samples = input->samples;
output->frames = input->frames;
for (i = 0; i < input->frames; i++, out += 2)
{

View File

@ -14,11 +14,12 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "dspfilter.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <retro_inline.h>
#include <libretro_dspfilter.h>
struct comb
{
@ -41,8 +42,8 @@ struct allpass
static INLINE float comb_process(struct comb *c, float input)
{
float output = c->buffer[c->bufidx];
c->filterstore = (output * c->damp2) + (c->filterstore * c->damp1);
float output = c->buffer[c->bufidx];
c->filterstore = (output * c->damp2) + (c->filterstore * c->damp1);
c->buffer[c->bufidx] = input + (c->filterstore * c->feedback);
@ -56,8 +57,8 @@ static INLINE float comb_process(struct comb *c, float input)
static INLINE float allpass_process(struct allpass *a, float input)
{
float bufout = a->buffer[a->bufidx];
float output = -input + bufout;
float bufout = a->buffer[a->bufidx];
float output = -input + bufout;
a->buffer[a->bufidx] = input + bufout * a->feedback;
a->bufidx++;
@ -129,8 +130,9 @@ static float revmodel_process(struct revmodel *rev, float in)
{
int i;
float mono_out = 0.0f;
float mono_in = in;
float input = mono_in * rev->gain;
float mono_in = in;
float input = mono_in * rev->gain;
for (i = 0; i < numcombs; i++)
mono_out += comb_process(&rev->combL[i], input);
@ -204,19 +206,19 @@ static void revmodel_setmode(struct revmodel *rev, float value)
static void revmodel_init(struct revmodel *rev)
{
rev->combL[0].buffer = rev->bufcombL1; rev->combL[0].bufsize = combtuningL1;
rev->combL[1].buffer = rev->bufcombL2; rev->combL[1].bufsize = combtuningL2;
rev->combL[2].buffer = rev->bufcombL3; rev->combL[2].bufsize = combtuningL3;
rev->combL[3].buffer = rev->bufcombL4; rev->combL[3].bufsize = combtuningL4;
rev->combL[4].buffer = rev->bufcombL5; rev->combL[4].bufsize = combtuningL5;
rev->combL[5].buffer = rev->bufcombL6; rev->combL[5].bufsize = combtuningL6;
rev->combL[6].buffer = rev->bufcombL7; rev->combL[6].bufsize = combtuningL7;
rev->combL[7].buffer = rev->bufcombL8; rev->combL[7].bufsize = combtuningL8;
rev->combL[0].buffer = rev->bufcombL1; rev->combL[0].bufsize = combtuningL1;
rev->combL[1].buffer = rev->bufcombL2; rev->combL[1].bufsize = combtuningL2;
rev->combL[2].buffer = rev->bufcombL3; rev->combL[2].bufsize = combtuningL3;
rev->combL[3].buffer = rev->bufcombL4; rev->combL[3].bufsize = combtuningL4;
rev->combL[4].buffer = rev->bufcombL5; rev->combL[4].bufsize = combtuningL5;
rev->combL[5].buffer = rev->bufcombL6; rev->combL[5].bufsize = combtuningL6;
rev->combL[6].buffer = rev->bufcombL7; rev->combL[6].bufsize = combtuningL7;
rev->combL[7].buffer = rev->bufcombL8; rev->combL[7].bufsize = combtuningL8;
rev->allpassL[0].buffer = rev->bufallpassL1; rev->allpassL[0].bufsize = allpasstuningL1;
rev->allpassL[1].buffer = rev->bufallpassL2; rev->allpassL[1].bufsize = allpasstuningL2;
rev->allpassL[2].buffer = rev->bufallpassL3; rev->allpassL[2].bufsize = allpasstuningL3;
rev->allpassL[3].buffer = rev->bufallpassL4; rev->allpassL[3].bufsize = allpasstuningL4;
rev->allpassL[0].buffer = rev->bufallpassL1; rev->allpassL[0].bufsize = allpasstuningL1;
rev->allpassL[1].buffer = rev->bufallpassL2; rev->allpassL[1].bufsize = allpasstuningL2;
rev->allpassL[2].buffer = rev->bufallpassL3; rev->allpassL[2].bufsize = allpasstuningL3;
rev->allpassL[3].buffer = rev->bufallpassL4; rev->allpassL[3].bufsize = allpasstuningL4;
rev->allpassL[0].feedback = 0.5f;
rev->allpassL[1].feedback = 0.5f;

View File

@ -14,12 +14,12 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "dspfilter.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <retro_miscellaneous.h>
#include <libretro_dspfilter.h>
#define WAHWAH_LFO_SKIP_SAMPLES 30
@ -48,12 +48,11 @@ static void wahwah_process(void *data, struct dspfilter_output *output,
const struct dspfilter_input *input)
{
unsigned i;
float *out;
struct wahwah_data *wah = (struct wahwah_data*)data;
float *out = output->samples;
output->samples = input->samples;
output->frames = input->frames;
out = output->samples;
for (i = 0; i < input->frames; i++, out += 2)
{
@ -113,7 +112,7 @@ static void *wahwah_init(const struct dspfilter_info *info,
config->get_float(userdata, "resonance", &wah->res, 2.5f);
wah->lfoskip = wah->freq * 2.0 * M_PI / info->input_rate;
wah->phase = wah->startphase * M_PI / 180.0;
wah->phase = wah->startphase * M_PI / 180.0;
return wah;
}
@ -132,7 +131,8 @@ static const struct dspfilter_implementation wahwah_plug = {
#define dspfilter_get_implementation wahwah_dspfilter_get_implementation
#endif
const struct dspfilter_implementation *dspfilter_get_implementation(dspfilter_simd_mask_t mask)
const struct dspfilter_implementation *
dspfilter_get_implementation(dspfilter_simd_mask_t mask)
{
(void)mask;
return &wahwah_plug;