mirror of
https://github.com/libretro/RetroArch
synced 2025-03-06 04:13:52 +00:00
commit
67819bee3f
1
Makefile
1
Makefile
@ -41,6 +41,7 @@ OBJ = frontend/frontend.o \
|
||||
gfx/fonts/fonts.o \
|
||||
gfx/fonts/bitmapfont.o \
|
||||
audio/resampler.o \
|
||||
audio/dsp_filter.o \
|
||||
audio/sinc.o \
|
||||
audio/cc_resampler.o \
|
||||
performance.o
|
||||
|
@ -46,6 +46,7 @@ OBJ = frontend/frontend.o \
|
||||
gfx/image/image_rpng.o \
|
||||
gfx/image_context.o \
|
||||
audio/resampler.o \
|
||||
audio/dsp_filter.o \
|
||||
audio/sinc.o \
|
||||
audio/cc_resampler.o \
|
||||
performance.o
|
||||
|
397
audio/dsp_filter.c
Normal file
397
audio/dsp_filter.c
Normal file
@ -0,0 +1,397 @@
|
||||
/* 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/>.
|
||||
*/
|
||||
|
||||
#include "../general.h"
|
||||
|
||||
#include "dsp_filter.h"
|
||||
#include "../dynamic.h"
|
||||
#include "../conf/config_file.h"
|
||||
#include "filters/dspfilter.h"
|
||||
#include "../file_path.h"
|
||||
#include "../file_ext.h"
|
||||
#include "../compat/posix_string.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
struct rarch_dsp_plug
|
||||
{
|
||||
#ifdef HAVE_DYLIB
|
||||
dylib_t lib;
|
||||
#endif
|
||||
const struct dspfilter_implementation *impl;
|
||||
};
|
||||
|
||||
struct rarch_dsp_instance
|
||||
{
|
||||
const struct dspfilter_implementation *impl;
|
||||
void *impl_data;
|
||||
};
|
||||
|
||||
struct rarch_dsp_filter
|
||||
{
|
||||
config_file_t *conf;
|
||||
|
||||
struct rarch_dsp_plug *plugs;
|
||||
unsigned num_plugs;
|
||||
|
||||
struct rarch_dsp_instance *instances;
|
||||
unsigned num_instances;
|
||||
};
|
||||
|
||||
const struct dspfilter_implementation *find_implementation(rarch_dsp_filter_t *dsp, const char *ident)
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < dsp->num_plugs; i++)
|
||||
{
|
||||
if (!strcmp(dsp->plugs[i].impl->short_ident, ident))
|
||||
return dsp->plugs[i].impl;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct dsp_userdata
|
||||
{
|
||||
config_file_t *conf;
|
||||
const char *prefix[2];
|
||||
};
|
||||
|
||||
static int get_float(void *userdata, const char *key_str, float *value, float default_value)
|
||||
{
|
||||
struct dsp_userdata *dsp = (struct dsp_userdata*)userdata;
|
||||
|
||||
char key[2][256];
|
||||
snprintf(key[0], sizeof(key[0]), "%s_%s", dsp->prefix[0], key_str);
|
||||
snprintf(key[1], sizeof(key[1]), "%s_%s", dsp->prefix[1], key_str);
|
||||
|
||||
bool got = config_get_float(dsp->conf, key[0], value);
|
||||
got = got || config_get_float(dsp->conf, key[1], value);
|
||||
|
||||
if (!got)
|
||||
*value = default_value;
|
||||
return got;
|
||||
}
|
||||
|
||||
static int get_int(void *userdata, const char *key_str, int *value, int default_value)
|
||||
{
|
||||
struct dsp_userdata *dsp = (struct dsp_userdata*)userdata;
|
||||
|
||||
char key[2][256];
|
||||
snprintf(key[0], sizeof(key[0]), "%s_%s", dsp->prefix[0], key_str);
|
||||
snprintf(key[1], sizeof(key[1]), "%s_%s", dsp->prefix[1], key_str);
|
||||
|
||||
bool got = config_get_int(dsp->conf, key[0], value);
|
||||
got = got || config_get_int(dsp->conf, key[1], value);
|
||||
|
||||
if (!got)
|
||||
*value = default_value;
|
||||
return got;
|
||||
}
|
||||
|
||||
// Yup, still C >__<
|
||||
#define get_array_setup() \
|
||||
struct dsp_userdata *dsp = (struct dsp_userdata*)userdata; \
|
||||
\
|
||||
char key[2][256]; \
|
||||
snprintf(key[0], sizeof(key[0]), "%s_%s", dsp->prefix[0], key_str); \
|
||||
snprintf(key[1], sizeof(key[1]), "%s_%s", dsp->prefix[1], key_str); \
|
||||
\
|
||||
char *str = NULL; \
|
||||
bool got = config_get_string(dsp->conf, key[0], &str); \
|
||||
got = got || config_get_string(dsp->conf, key[1], &str);
|
||||
|
||||
#define get_array_body(T) \
|
||||
if (got) \
|
||||
{ \
|
||||
unsigned i; \
|
||||
struct string_list *list = string_split(str, " "); \
|
||||
*values = (T*)calloc(list->size, sizeof(T)); \
|
||||
for (i = 0; i < list->size; i++) \
|
||||
(*values)[i] = (T)strtod(list->elems[i].data, NULL); \
|
||||
*out_num_values = list->size; \
|
||||
string_list_free(list); \
|
||||
return true; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
*values = (T*)calloc(num_default_values, sizeof(T)); \
|
||||
memcpy(*values, default_values, sizeof(T) * num_default_values); \
|
||||
*out_num_values = num_default_values; \
|
||||
return false; \
|
||||
}
|
||||
|
||||
static int get_float_array(void *userdata, const char *key_str,
|
||||
float **values, unsigned *out_num_values,
|
||||
const float *default_values, unsigned num_default_values)
|
||||
{
|
||||
get_array_setup()
|
||||
get_array_body(float)
|
||||
}
|
||||
|
||||
static int get_int_array(void *userdata, const char *key_str,
|
||||
int **values, unsigned *out_num_values,
|
||||
const int *default_values, unsigned num_default_values)
|
||||
{
|
||||
get_array_setup()
|
||||
get_array_body(int)
|
||||
}
|
||||
|
||||
static int get_string(void *userdata, const char *key_str,
|
||||
char **output, const char *default_output)
|
||||
{
|
||||
get_array_setup()
|
||||
|
||||
if (got)
|
||||
{
|
||||
*output = str;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
*output = strdup(default_output);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static void dspfilter_free(void *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
static const struct dspfilter_config dspfilter_config = {
|
||||
get_float,
|
||||
get_int,
|
||||
get_float_array,
|
||||
get_int_array,
|
||||
get_string,
|
||||
dspfilter_free,
|
||||
};
|
||||
|
||||
static bool create_filter_graph(rarch_dsp_filter_t *dsp, float sample_rate)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
unsigned filters = 0;
|
||||
if (!config_get_uint(dsp->conf, "filters", &filters))
|
||||
return false;
|
||||
|
||||
dsp->instances = (struct rarch_dsp_instance*)calloc(filters, sizeof(*dsp->instances));
|
||||
if (!dsp->instances)
|
||||
return false;
|
||||
|
||||
dsp->num_instances = filters;
|
||||
|
||||
for (i = 0; i < filters; i++)
|
||||
{
|
||||
char key[64];
|
||||
snprintf(key, sizeof(key), "filter%u", i);
|
||||
|
||||
char name[64];
|
||||
if (!config_get_array(dsp->conf, key, name, sizeof(name)))
|
||||
return false;
|
||||
|
||||
dsp->instances[i].impl = find_implementation(dsp, name);
|
||||
if (!dsp->instances[i].impl)
|
||||
return false;
|
||||
|
||||
struct dsp_userdata userdata;
|
||||
userdata.conf = dsp->conf;
|
||||
userdata.prefix[0] = key; // Index-specific configs take priority over ident-specific.
|
||||
userdata.prefix[1] = dsp->instances[i].impl->short_ident;
|
||||
|
||||
struct dspfilter_info info = { sample_rate };
|
||||
dsp->instances[i].impl_data = dsp->instances[i].impl->init(&info, &dspfilter_config, &userdata);
|
||||
if (!dsp->instances[i].impl_data)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined(HAVE_FILTERS_BUILTIN)
|
||||
extern const struct dspfilter_implementation *panning_dspfilter_get_implementation(dspfilter_simd_mask_t mask);
|
||||
extern const struct dspfilter_implementation *iir_dspfilter_get_implementation(dspfilter_simd_mask_t mask);
|
||||
extern const struct dspfilter_implementation *echo_dspfilter_get_implementation(dspfilter_simd_mask_t mask);
|
||||
|
||||
static const dspfilter_get_implementation_t dsp_plugs_builtin[] = {
|
||||
panning_dspfilter_get_implementation,
|
||||
iir_dspfilter_get_implementation,
|
||||
echo_dspfilter_get_implementation,
|
||||
};
|
||||
|
||||
static bool append_plugs(rarch_dsp_filter_t *dsp)
|
||||
{
|
||||
unsigned i;
|
||||
dspfilter_simd_mask_t mask = rarch_get_cpu_features();
|
||||
|
||||
dsp->plugs = (struct rarch_dsp_plug*)calloc(ARRAY_SIZE(dsp_plugs_builtin), sizeof(*dsp->plugs));
|
||||
if (!dsp->plugs)
|
||||
return false;
|
||||
dsp->num_plugs = ARRAY_SIZE(dsp_plugs_builtin);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(dsp_plugs_builtin); i++)
|
||||
{
|
||||
dsp->plugs[i].impl = dsp_plugs_builtin[i](mask);
|
||||
if (!dsp->plugs[i].impl)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#elif defined(HAVE_DYLIB)
|
||||
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 (i = 0; i < list->size; i++)
|
||||
{
|
||||
dylib_t lib = dylib_load(list->elems[i].data);
|
||||
if (!lib)
|
||||
continue;
|
||||
|
||||
dspfilter_get_implementation_t cb = (dspfilter_get_implementation_t)dylib_proc(lib, "dspfilter_get_implementation");
|
||||
if (!cb)
|
||||
{
|
||||
dylib_close(lib);
|
||||
continue;
|
||||
}
|
||||
|
||||
const struct dspfilter_implementation *impl = cb(mask);
|
||||
if (!impl)
|
||||
{
|
||||
dylib_close(lib);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (impl->api_version != DSPFILTER_API_VERSION)
|
||||
{
|
||||
dylib_close(lib);
|
||||
continue;
|
||||
}
|
||||
|
||||
struct rarch_dsp_plug *new_plugs = (struct rarch_dsp_plug*)realloc(dsp->plugs, sizeof(*dsp->plugs) * (dsp->num_plugs + 1));
|
||||
if (!new_plugs)
|
||||
{
|
||||
dylib_close(lib);
|
||||
return false;
|
||||
}
|
||||
|
||||
RARCH_LOG("[DSP]: Found plug: %s (%s).\n", impl->ident, impl->short_ident);
|
||||
|
||||
dsp->plugs = new_plugs;
|
||||
dsp->plugs[dsp->num_plugs].lib = lib;
|
||||
dsp->plugs[dsp->num_plugs].impl = impl;
|
||||
dsp->num_plugs++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
rarch_dsp_filter_t *rarch_dsp_filter_new(const char *filter_config, float sample_rate)
|
||||
{
|
||||
#if !defined(HAVE_FILTERS_BUILTIN) && defined(HAVE_DYLIB)
|
||||
char basedir[PATH_MAX];
|
||||
#endif
|
||||
struct string_list *plugs = NULL;
|
||||
|
||||
rarch_dsp_filter_t *dsp = (rarch_dsp_filter_t*)calloc(1, sizeof(*dsp));
|
||||
if (!dsp)
|
||||
return NULL;
|
||||
|
||||
dsp->conf = config_file_new(filter_config);
|
||||
if (!dsp->conf)
|
||||
{
|
||||
RARCH_ERR("[DSP]: Did not find config: %s\n", filter_config);
|
||||
goto error;
|
||||
}
|
||||
|
||||
#if defined(HAVE_FILTERS_BUILTIN)
|
||||
if (!append_plugs(dsp))
|
||||
goto error;
|
||||
#elif defined(HAVE_DYLIB)
|
||||
fill_pathname_basedir(basedir, filter_config, sizeof(basedir));
|
||||
|
||||
plugs = dir_list_new(basedir, EXT_EXECUTABLES, false);
|
||||
if (!plugs)
|
||||
goto error;
|
||||
|
||||
if (!append_plugs(dsp, plugs))
|
||||
goto error;
|
||||
|
||||
string_list_free(plugs);
|
||||
plugs = NULL;
|
||||
#endif
|
||||
|
||||
if (!create_filter_graph(dsp, sample_rate))
|
||||
goto error;
|
||||
|
||||
return dsp;
|
||||
|
||||
error:
|
||||
string_list_free(plugs);
|
||||
rarch_dsp_filter_free(dsp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void rarch_dsp_filter_free(rarch_dsp_filter_t *dsp)
|
||||
{
|
||||
unsigned i;
|
||||
if (!dsp)
|
||||
return;
|
||||
|
||||
for (i = 0; i < dsp->num_instances; i++)
|
||||
{
|
||||
if (dsp->instances[i].impl_data && dsp->instances[i].impl)
|
||||
dsp->instances[i].impl->free(dsp->instances[i].impl_data);
|
||||
}
|
||||
free(dsp->instances);
|
||||
|
||||
#ifdef HAVE_DYLIB
|
||||
for (i = 0; i < dsp->num_plugs; i++)
|
||||
{
|
||||
if (dsp->plugs[i].lib)
|
||||
dylib_close(dsp->plugs[i].lib);
|
||||
}
|
||||
free(dsp->plugs);
|
||||
#endif
|
||||
|
||||
if (dsp->conf)
|
||||
config_file_free(dsp->conf);
|
||||
|
||||
free(dsp);
|
||||
}
|
||||
|
||||
void rarch_dsp_filter_process(rarch_dsp_filter_t *dsp, struct rarch_dsp_data *data)
|
||||
{
|
||||
unsigned i;
|
||||
struct dspfilter_output output = {0};
|
||||
struct dspfilter_input input = {0};
|
||||
|
||||
output.samples = data->input;
|
||||
output.frames = data->input_frames;
|
||||
|
||||
for (i = 0; i < dsp->num_instances; i++)
|
||||
{
|
||||
input.samples = output.samples;
|
||||
input.frames = output.frames;
|
||||
dsp->instances[i].impl->process(dsp->instances[i].impl_data, &output, &input);
|
||||
}
|
||||
|
||||
data->output = output.samples;
|
||||
data->output_frames = output.frames;
|
||||
}
|
||||
|
@ -13,21 +13,26 @@
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __RARCH_BOOLEAN_H
|
||||
#define __RARCH_BOOLEAN_H
|
||||
#ifndef RARCH_DSP_FILTER_H__
|
||||
#define RARCH_DSP_FILTER_H__
|
||||
|
||||
#ifndef __cplusplus
|
||||
typedef struct rarch_dsp_filter rarch_dsp_filter_t;
|
||||
|
||||
#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
|
||||
rarch_dsp_filter_t *rarch_dsp_filter_new(const char *filter_config, float sample_rate);
|
||||
|
||||
void rarch_dsp_filter_free(rarch_dsp_filter_t *dsp);
|
||||
|
||||
struct rarch_dsp_data
|
||||
{
|
||||
float *input;
|
||||
unsigned input_frames;
|
||||
|
||||
// Set by rarch_dsp_filter_process().
|
||||
float *output;
|
||||
unsigned output_frames;
|
||||
};
|
||||
|
||||
void rarch_dsp_filter_process(rarch_dsp_filter_t *dsp, struct rarch_dsp_data *data);
|
||||
|
||||
#endif
|
||||
|
19
audio/filters/Echo.dsp
Normal file
19
audio/filters/Echo.dsp
Normal file
@ -0,0 +1,19 @@
|
||||
filters = 1
|
||||
filter0 = echo
|
||||
|
||||
# Somewhat fancy Echo filter. Can take any number of echo channels with varying delays (ms) and feedback factors.
|
||||
# Echo output from all channels can be fed back into each other to create a somewhat reverb-like effect if desired.
|
||||
|
||||
# Defaults, 200 ms delay echo with feedback:
|
||||
# Delay in ms. Takes an array with multiple channels.
|
||||
# echo_delay = "200"
|
||||
# Feedback factor for echo.
|
||||
# echo_feedback = "0.5"
|
||||
# Overall echo amplification. If too high, the echo becomes unstable due to feedback.
|
||||
# echo_amp = "0.2"
|
||||
|
||||
# Reverby preset.
|
||||
# echo_delay = " 60 80 120 172 200 320 380"
|
||||
# echo_feedback = "0.5 0.5 0.4 0.3 0.5 0.3 0.2"
|
||||
|
||||
# echo_amp = "0.12"
|
23
audio/filters/IIR.dsp
Normal file
23
audio/filters/IIR.dsp
Normal file
@ -0,0 +1,23 @@
|
||||
filters = 1
|
||||
filter0 = iir
|
||||
|
||||
# Defaults.
|
||||
#iir_frequency = 1024.0
|
||||
#iir_quality = 0.707
|
||||
#iir_gain = 0.0
|
||||
#iir_type = LPF
|
||||
|
||||
# Filter types:
|
||||
# LPF: Low-pass
|
||||
# HPF: High-pass
|
||||
# BPCSGF: Band-pass #1
|
||||
# BPZPGF: Band-pass #2
|
||||
# APF: Allpass
|
||||
# NOTCH: Notch filter
|
||||
# RIAA_phono: RIAA record/tape deemphasis
|
||||
# PEQ: peaking band EQ
|
||||
# BBOOST: Bassboost
|
||||
# LSH: Low-shelf
|
||||
# HSH: High-shelf
|
||||
# RIAA_CD: CD de-emphasis
|
||||
|
@ -1,58 +1,58 @@
|
||||
compiler := gcc
|
||||
extra_flags :=
|
||||
use_neon := 0
|
||||
release := release
|
||||
DYLIB := so
|
||||
build = release
|
||||
DYLIB := so
|
||||
|
||||
ifeq ($(platform),)
|
||||
platform = unix
|
||||
ifeq ($(shell uname -a),)
|
||||
platform = win
|
||||
else ifneq ($(findstring MINGW,$(shell uname -a)),)
|
||||
platform = win
|
||||
else ifneq ($(findstring Darwin,$(shell uname -a)),)
|
||||
platform = osx
|
||||
arch = intel
|
||||
ifeq ($(shell uname -p),powerpc)
|
||||
arch = ppc
|
||||
endif
|
||||
else ifneq ($(findstring win,$(shell uname -a)),)
|
||||
platform = win
|
||||
endif
|
||||
platform = unix
|
||||
ifeq ($(shell uname -a),)
|
||||
platform = win
|
||||
else ifneq ($(findstring MINGW,$(shell uname -a)),)
|
||||
platform = win
|
||||
else ifneq ($(findstring Darwin,$(shell uname -a)),)
|
||||
platform = osx
|
||||
arch = intel
|
||||
ifeq ($(shell uname -p),powerpc)
|
||||
arch = ppc
|
||||
endif
|
||||
else ifneq ($(findstring win,$(shell uname -a)),)
|
||||
platform = win
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(platform),gcc)
|
||||
extra_rules_gcc := $(shell $(compiler) -dumpmachine)
|
||||
extra_rules_gcc := $(shell $(compiler) -dumpmachine)
|
||||
endif
|
||||
|
||||
ifneq (,$(findstring armv7,$(extra_rules_gcc)))
|
||||
extra_flags += -mcpu=cortex-a9 -mtune=cortex-a9 -mfpu=neon
|
||||
use_neon := 1
|
||||
extra_flags += -mcpu=cortex-a9 -mtune=cortex-a9 -mfpu=neon
|
||||
use_neon := 1
|
||||
endif
|
||||
|
||||
ifneq (,$(findstring hardfloat,$(extra_rules_gcc)))
|
||||
extra_flags += -mfloat-abi=hard
|
||||
extra_flags += -mfloat-abi=hard
|
||||
endif
|
||||
|
||||
ifeq (release,$(build))
|
||||
extra_flags += -O2
|
||||
extra_flags += -O2
|
||||
endif
|
||||
|
||||
ifeq (debug,$(build))
|
||||
extra_flags += -O0 -g
|
||||
extra_flags += -O0 -g
|
||||
endif
|
||||
|
||||
ldflags := -shared -Wl,--version-script=link.T
|
||||
ldflags := -shared -lm -Wl,--version-script=link.T
|
||||
|
||||
ifeq ($(platform), unix)
|
||||
DYLIB = so
|
||||
DYLIB = so
|
||||
else ifeq ($(platform), osx)
|
||||
compiler := $(CC)
|
||||
DYLIB = dylib
|
||||
ldflags := -dynamiclib
|
||||
compiler := $(CC)
|
||||
DYLIB = dylib
|
||||
ldflags := -dynamiclib
|
||||
else
|
||||
extra_flags += -static-libgcc -static-libstdc++
|
||||
DYLIB = dll
|
||||
extra_flags += -static-libgcc -static-libstdc++
|
||||
DYLIB = dll
|
||||
endif
|
||||
|
||||
CC := $(compiler)
|
||||
@ -60,15 +60,15 @@ CXX := $(subst CC,++,$(compiler)) -std=gnu++0x
|
||||
flags := -fPIC $(extra_flags)
|
||||
asflags := -fPIC $(extra_flags)
|
||||
objects :=
|
||||
flags += -std=c99
|
||||
|
||||
|
||||
ifeq (1,$(use_neon))
|
||||
ASMFLAGS := -INEON/asm
|
||||
asflags += -mfpu=neon
|
||||
ASMFLAGS := -INEON/asm
|
||||
asflags += -mfpu=neon
|
||||
endif
|
||||
|
||||
objects += echo.$(DYLIB) eq.$(DYLIB) iir.$(DYLIB) phaser.$(DYLIB) reverb.$(DYLIB) volume.$(DYLIB) wah.$(DYLIB)
|
||||
plugs := $(wildcard *.c)
|
||||
objects := $(plugs:.c=.o)
|
||||
targets := $(objects:.o=.$(DYLIB))
|
||||
|
||||
all: build;
|
||||
|
||||
@ -81,7 +81,7 @@ all: build;
|
||||
%.$(DYLIB): %.o
|
||||
$(CC) -o $@ $(ldflags) $(flags) $^
|
||||
|
||||
build: $(objects)
|
||||
build: $(targets)
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
|
23
audio/filters/Panning.dsp
Normal file
23
audio/filters/Panning.dsp
Normal file
@ -0,0 +1,23 @@
|
||||
filters = 1
|
||||
filter0 = panning
|
||||
|
||||
# Gains are linear.
|
||||
|
||||
# The default. Left and right channels map to each other.
|
||||
panning_left_mix = "1.0 0.0"
|
||||
panning_right_mix = "0.0 1.0"
|
||||
|
||||
# Some examples:
|
||||
#
|
||||
# Mono:
|
||||
# panning_left_mix = "0.5 0.5"
|
||||
# panning_right_mix = "0.5 0.5"
|
||||
|
||||
# Swap left and right channels:
|
||||
# panning_left_mix = "0.0 1.0"
|
||||
# panning_right_mix = "1.0 0.0"
|
||||
#
|
||||
# Mono on one speaker:
|
||||
# panning_left_mix = "0.5 0.5"
|
||||
# panning_right_mix = "0.0 0.0"
|
||||
|
@ -43,26 +43,25 @@ extern "C" {
|
||||
typedef unsigned dspfilter_simd_mask_t;
|
||||
|
||||
// Dynamic library endpoint.
|
||||
typedef const struct dspfilter_implementation *(*dspfilter_get_implementation_t)(dspfilter_simd_mask_t);
|
||||
typedef const struct dspfilter_implementation *(*dspfilter_get_implementation_t)(dspfilter_simd_mask_t mask);
|
||||
// The same SIMD mask argument is forwarded to create() callback as well to avoid having to keep lots of state around.
|
||||
const struct dspfilter_implementation *rarch_dsp_plugin_init(dspfilter_simd_mask_t);
|
||||
const struct dspfilter_implementation *dspfilter_get_implementation(dspfilter_simd_mask_t mask);
|
||||
|
||||
#define RARCH_DSP_API_VERSION 6
|
||||
#define DSPFILTER_API_VERSION 1
|
||||
|
||||
typedef struct rarch_dsp_info
|
||||
struct dspfilter_info
|
||||
{
|
||||
// Input sample rate that the DSP plugin receives.
|
||||
float input_rate;
|
||||
} rarch_dsp_info_t;
|
||||
};
|
||||
|
||||
typedef struct rarch_dsp_output
|
||||
struct dspfilter_output
|
||||
{
|
||||
// The DSP plugin has to provide the buffering for the output samples.
|
||||
// This is for performance reasons to avoid redundant copying of data.
|
||||
// The DSP plugin has to provide the buffering for the output samples or reuse the input buffer directly.
|
||||
// The samples are laid out in interleaving order: LRLRLRLR
|
||||
// The range of the samples are [-1.0, 1.0].
|
||||
// This range cannot be exceeded without horrible audio glitches.
|
||||
const float *samples;
|
||||
// It is not necessary to manually clip values.
|
||||
float *samples;
|
||||
|
||||
// Frames which the DSP plugin outputted for the current process.
|
||||
// One frame is here defined as a combined sample of
|
||||
@ -70,12 +69,16 @@ typedef struct rarch_dsp_output
|
||||
// (I.e. 44.1kHz, 16bit stereo will have
|
||||
// 88.2k samples/sec and 44.1k frames/sec.)
|
||||
unsigned frames;
|
||||
} rarch_dsp_output_t;
|
||||
};
|
||||
|
||||
typedef struct rarch_dsp_input
|
||||
struct dspfilter_input
|
||||
{
|
||||
// Input data for the DSP. The samples are interleaved in order: LRLRLRLR
|
||||
const float *samples;
|
||||
// It is valid for a DSP plug to use this buffer for output as long as the output size is less or equal to the input.
|
||||
// This is useful for filters which can output one sample for each input sample and do not need to maintain its own buffers.
|
||||
// Block based filters must provide their own buffering scheme.
|
||||
// The input size is not bound, but it can be safely assumed that it will not exceed ~100ms worth of audio at a time.
|
||||
float *samples;
|
||||
|
||||
// Number of frames for input data.
|
||||
// One frame is here defined as a combined sample of
|
||||
@ -83,41 +86,59 @@ typedef struct rarch_dsp_input
|
||||
// (I.e. 44.1kHz, 16bit stereo will have
|
||||
// 88.2k samples/sec and 44.1k frames/sec.)
|
||||
unsigned frames;
|
||||
} rarch_dsp_input_t;
|
||||
};
|
||||
|
||||
// Returns true if config key was found. Otherwise, returns false, and sets value to default value.
|
||||
typedef int (*dspfilter_config_get_float_t)(void *userdata, const char *key, float *value, float default_value);
|
||||
typedef int (*dspfilter_config_get_int_t)(void *userdata, const char *key, int *value, int default_value);
|
||||
|
||||
// Allocates an array with values. free() with dspfilter_config_free_t.
|
||||
typedef int (*dspfilter_config_get_float_array_t)(void *userdata, const char *key,
|
||||
float **values, unsigned *out_num_values,
|
||||
const float *default_values, unsigned num_default_values);
|
||||
|
||||
typedef int (*dspfilter_config_get_int_array_t)(void *userdata, const char *key,
|
||||
int **values, unsigned *out_num_values,
|
||||
const int *default_values, unsigned num_default_values);
|
||||
|
||||
typedef int (*dspfilter_config_get_string_t)(void *userdata, const char *key, char **output, const char *default_output);
|
||||
|
||||
// Calls free() in host runtime. Sometimes needed on Windows. free() on NULL is fine.
|
||||
typedef void (*dspfilter_config_free_t)(void *ptr);
|
||||
|
||||
struct dspfilter_config
|
||||
{
|
||||
dspfilter_config_get_float_t get_float;
|
||||
dspfilter_config_get_int_t get_int;
|
||||
|
||||
dspfilter_config_get_float_array_t get_float_array;
|
||||
dspfilter_config_get_int_array_t get_int_array;
|
||||
|
||||
dspfilter_config_get_string_t get_string;
|
||||
dspfilter_config_free_t free; // Avoid problems where DSP plug and host are linked against different C runtimes.
|
||||
};
|
||||
|
||||
// Creates a handle of the plugin. Returns NULL if failed.
|
||||
typedef void *(*dspfilter_init_t)(const rarch_dsp_info_t *info);
|
||||
typedef void *(*dspfilter_init_t)(const struct dspfilter_info *info, const struct dspfilter_config *config, void *userdata);
|
||||
|
||||
// Frees the handle.
|
||||
typedef void (*dspfilter_free_t)(void *data);
|
||||
|
||||
// Processes input data.
|
||||
// The plugin is allowed to return variable sizes for output data.
|
||||
typedef void (*dspfilter_process_t)(void *data, rarch_dsp_output_t *output,
|
||||
const rarch_dsp_input_t *input);
|
||||
|
||||
// Signal plugin that it may open a configuring window or
|
||||
// something similar. The behavior of this function
|
||||
// is thus plugin dependent. Implementing this is optional,
|
||||
// and can be set to NULL.
|
||||
typedef void (*dspfilter_config_t)(void *data);
|
||||
|
||||
// Called every frame, allows creating a GUI main loop in the main thread.
|
||||
// GUI events can be processed here in a non-blocking fashion.
|
||||
// Can be set to NULL to ignore it.
|
||||
typedef void (*dspfilter_events_t)(void *data);
|
||||
typedef void (*dspfilter_process_t)(void *data, struct dspfilter_output *output,
|
||||
const struct dspfilter_input *input);
|
||||
|
||||
struct dspfilter_implementation
|
||||
{
|
||||
dspfilter_init_t init;
|
||||
dspfilter_process_t process;
|
||||
dspfilter_free_t free;
|
||||
int api_version; // Must be RARCH_DSP_API_VERSION
|
||||
dspfilter_config_t config;
|
||||
const char *ident; // Human readable identifier of implementation.
|
||||
dspfilter_events_t events;
|
||||
};
|
||||
|
||||
unsigned api_version; // Must be DSPFILTER_API_VERSION
|
||||
const char *ident; // Human readable identifier of implementation.
|
||||
const char *short_ident; // Computer-friendly short version of ident. Lower case, no spaces and special characters, etc.
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
/* 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-
|
||||
@ -12,176 +11,157 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "dspfilter.h"
|
||||
#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))
|
||||
#define min(a, b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
struct echo_filter
|
||||
struct echo_channel
|
||||
{
|
||||
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;
|
||||
float *buffer;
|
||||
unsigned ptr;
|
||||
unsigned frames;
|
||||
float feedback;
|
||||
};
|
||||
|
||||
struct echo_filter_data
|
||||
struct echo_data
|
||||
{
|
||||
struct echo_filter echo_l;
|
||||
struct echo_filter echo_r;
|
||||
float buf[4096];
|
||||
struct echo_channel *channels;
|
||||
unsigned num_channels;
|
||||
float amp;
|
||||
};
|
||||
|
||||
#ifdef RARCH_INTERNAL
|
||||
#define rarch_dsp_plugin_init echo_dsp_plugin_init
|
||||
#endif
|
||||
|
||||
static float echo_process(void *data, float in)
|
||||
static void echo_free(void *data)
|
||||
{
|
||||
struct echo_filter *echo = (struct echo_filter*)data;
|
||||
unsigned i;
|
||||
struct echo_data *echo = (struct echo_data*)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;
|
||||
for (i = 0; i < echo->num_channels; i++)
|
||||
free(echo->channels[i].buffer);
|
||||
free(echo->channels);
|
||||
free(echo);
|
||||
}
|
||||
|
||||
static void echo_dsp_process(void *data, rarch_dsp_output_t *output,
|
||||
const rarch_dsp_input_t *input)
|
||||
static void echo_process(void *data, struct dspfilter_output *output,
|
||||
const struct dspfilter_input *input)
|
||||
{
|
||||
int num_samples, i;
|
||||
struct echo_filter_data *echo = (struct echo_filter_data*)data;
|
||||
output->samples = echo->buf;
|
||||
num_samples = input->frames * 2;
|
||||
unsigned i, c;
|
||||
struct echo_data *echo = (struct echo_data*)data;
|
||||
|
||||
for (i = 0; i < num_samples;)
|
||||
output->samples = input->samples;
|
||||
output->frames = input->frames;
|
||||
|
||||
float *out = output->samples;
|
||||
|
||||
for (i = 0; i < input->frames; i++, out += 2)
|
||||
{
|
||||
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;
|
||||
}
|
||||
float echo_left = 0.0f;
|
||||
float echo_right = 0.0f;
|
||||
|
||||
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)
|
||||
for (c = 0; c < echo->num_channels; c++)
|
||||
{
|
||||
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));
|
||||
echo_left += echo->channels[c].buffer[(echo->channels[c].ptr << 1) + 0];
|
||||
echo_right += echo->channels[c].buffer[(echo->channels[c].ptr << 1) + 1];
|
||||
}
|
||||
|
||||
if (echo->history)
|
||||
free(echo->history);
|
||||
echo_left *= echo->amp;
|
||||
echo_right *= echo->amp;
|
||||
|
||||
float left = out[0] + echo_left;
|
||||
float right = out[1] + echo_right;
|
||||
|
||||
for (c = 0; c < echo->num_channels; c++)
|
||||
{
|
||||
float feedback_left = out[0] + echo->channels[c].feedback * echo_left;
|
||||
float feedback_right = out[1] + echo->channels[c].feedback * echo_right;
|
||||
|
||||
echo->channels[c].buffer[(echo->channels[c].ptr << 1) + 0] = feedback_left;
|
||||
echo->channels[c].buffer[(echo->channels[c].ptr << 1) + 1] = feedback_right;
|
||||
|
||||
echo->channels[c].ptr = (echo->channels[c].ptr + 1) % echo->channels[c].frames;
|
||||
}
|
||||
|
||||
out[0] = left;
|
||||
out[1] = right;
|
||||
}
|
||||
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)
|
||||
static void *echo_init(const struct dspfilter_info *info,
|
||||
const struct dspfilter_config *config, void *userdata)
|
||||
{
|
||||
struct echo_filter_data *echo = (struct echo_filter_data*)calloc(1, sizeof(*echo));;
|
||||
|
||||
unsigned i;
|
||||
struct echo_data *echo = (struct echo_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;
|
||||
float *delay = NULL, *feedback = NULL;
|
||||
unsigned num_delay = 0, num_feedback = 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;
|
||||
static const float default_delay[] = { 200.0f };
|
||||
static const float default_feedback[] = { 0.5f };
|
||||
|
||||
fprintf(stderr, "[Echo] loaded!\n");
|
||||
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);
|
||||
|
||||
unsigned channels = num_feedback = num_delay = min(num_delay, num_feedback);
|
||||
|
||||
echo->channels = (struct echo_channel*)calloc(channels, sizeof(*echo->channels));
|
||||
if (!echo->channels)
|
||||
goto error;
|
||||
|
||||
echo->num_channels = channels;
|
||||
|
||||
for (i = 0; i < channels; i++)
|
||||
{
|
||||
unsigned frames = (unsigned)(delay[i] * info->input_rate / 1000.0f + 0.5f);
|
||||
if (!frames)
|
||||
goto error;
|
||||
|
||||
echo->channels[i].buffer = (float*)calloc(frames, 2 * sizeof(float));
|
||||
if (!echo->channels[i].buffer)
|
||||
goto error;
|
||||
|
||||
echo->channels[i].frames = frames;
|
||||
echo->channels[i].feedback = feedback[i];
|
||||
}
|
||||
|
||||
config->free(delay);
|
||||
config->free(feedback);
|
||||
return echo;
|
||||
|
||||
error:
|
||||
config->free(delay);
|
||||
config->free(feedback);
|
||||
echo_free(echo);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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
|
||||
static const struct dspfilter_implementation echo_plug = {
|
||||
echo_init,
|
||||
echo_process,
|
||||
echo_free,
|
||||
|
||||
DSPFILTER_API_VERSION,
|
||||
"Multi-Echo",
|
||||
"echo",
|
||||
};
|
||||
|
||||
const struct dspfilter_implementation *rarch_dsp_plugin_init(dspfilter_simd_mask_t simd)
|
||||
#ifdef HAVE_FILTERS_BUILTIN
|
||||
#define dspfilter_get_implementation echo_dspfilter_get_implementation
|
||||
#endif
|
||||
|
||||
const struct dspfilter_implementation *dspfilter_get_implementation(dspfilter_simd_mask_t mask)
|
||||
{
|
||||
(void)simd;
|
||||
return &generic_echo_dsp;
|
||||
(void)mask;
|
||||
return &echo_plug;
|
||||
}
|
||||
|
||||
#ifdef RARCH_INTERNAL
|
||||
#undef rarch_dsp_plugin_init
|
||||
#endif
|
||||
#undef dspfilter_get_implementation
|
||||
|
||||
|
@ -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
|
@ -1,7 +1,6 @@
|
||||
/* 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
|
||||
* Copyright (C) 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-
|
||||
@ -13,409 +12,348 @@
|
||||
*
|
||||
* 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 "dspfilter.h"
|
||||
#include <math.h>
|
||||
|
||||
#ifdef __SSE2__
|
||||
#include <emmintrin.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#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 */
|
||||
enum IIRFilter {
|
||||
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)
|
||||
struct iir_data
|
||||
{
|
||||
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];
|
||||
float b0, b1, b2;
|
||||
float a0, a1, a2;
|
||||
|
||||
struct
|
||||
{
|
||||
float xn1, xn2;
|
||||
float yn1, yn2;
|
||||
} l, r;
|
||||
};
|
||||
|
||||
static void iir_free(void *data)
|
||||
{
|
||||
free(data);
|
||||
}
|
||||
|
||||
static void iir_init(void *data, int samplerate, int filter_type)
|
||||
static void iir_process(void *data, struct dspfilter_output *output,
|
||||
const struct dspfilter_input *input)
|
||||
{
|
||||
struct iir_filter *iir = (struct iir_filter*)data;
|
||||
unsigned i;
|
||||
struct iir_data *iir = (struct iir_data*)data;
|
||||
|
||||
if (!iir)
|
||||
return;
|
||||
output->samples = input->samples;
|
||||
output->frames = input->frames;
|
||||
|
||||
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
|
||||
float *out = output->samples;
|
||||
|
||||
float b0 = iir->b0;
|
||||
float b1 = iir->b1;
|
||||
float b2 = iir->b2;
|
||||
float a0 = iir->a0;
|
||||
float a1 = iir->a1;
|
||||
float a2 = iir->a2;
|
||||
|
||||
float xn1_l = iir->l.xn1;
|
||||
float xn2_l = iir->l.xn2;
|
||||
float yn1_l = iir->l.yn1;
|
||||
float yn2_l = iir->l.yn2;
|
||||
|
||||
float xn1_r = iir->r.xn1;
|
||||
float xn2_r = iir->r.xn2;
|
||||
float yn1_r = iir->r.yn1;
|
||||
float yn2_r = iir->r.yn2;
|
||||
|
||||
for (i = 0; i < input->frames; i++, out += 2)
|
||||
{
|
||||
float in_l = out[0];
|
||||
float in_r = out[1];
|
||||
|
||||
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_r = xn1_r;
|
||||
xn1_r = in_r;
|
||||
yn2_r = yn1_r;
|
||||
yn1_r = r;
|
||||
|
||||
out[0] = l;
|
||||
out[1] = r;
|
||||
}
|
||||
|
||||
iir->l.xn1 = xn1_l;
|
||||
iir->l.xn2 = xn2_l;
|
||||
iir->l.yn1 = yn1_l;
|
||||
iir->l.yn2 = yn2_l;
|
||||
|
||||
iir->r.xn1 = xn1_r;
|
||||
iir->r.xn2 = xn2_r;
|
||||
iir->r.yn1 = yn1_r;
|
||||
iir->r.yn2 = yn2_r;
|
||||
}
|
||||
|
||||
#define CHECK(x) if (!strcmp(str, #x)) return x
|
||||
static enum IIRFilter str_to_type(const char *str)
|
||||
{
|
||||
CHECK(LPF);
|
||||
CHECK(HPF);
|
||||
CHECK(BPCSGF);
|
||||
CHECK(BPZPGF);
|
||||
CHECK(APF);
|
||||
CHECK(NOTCH);
|
||||
CHECK(RIAA_phono);
|
||||
CHECK(PEQ);
|
||||
CHECK(BBOOST);
|
||||
CHECK(LSH);
|
||||
CHECK(HSH);
|
||||
CHECK(RIAA_CD);
|
||||
return LPF; // Fallback.
|
||||
}
|
||||
|
||||
static void make_poly_from_roots(
|
||||
const double *roots, unsigned num_roots, float *poly)
|
||||
{
|
||||
unsigned 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_filter_init(struct iir_data *iir,
|
||||
float sample_rate, float freq, float qual, float gain, enum IIRFilter filter_type)
|
||||
{
|
||||
double omega = 2.0 * M_PI * freq / sample_rate;
|
||||
double cs = cos(omega);
|
||||
double sn = sin(omega);
|
||||
double a1pha = sn / (2.0 * qual);
|
||||
double A = exp(log(10.0) * gain / 40.0);
|
||||
double beta = sqrt(A + A);
|
||||
|
||||
float b0 = 0.0, b1 = 0.0, b2 = 0.0, a0 = 0.0, a1 = 0.0, a2 = 0.0;
|
||||
|
||||
// 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 ;
|
||||
b0 = (1.0 - cs) / 2.0;
|
||||
b1 = 1.0 - cs ;
|
||||
b2 = (1.0 - cs) / 2.0;
|
||||
a0 = 1.0 + a1pha;
|
||||
a1 = -2.0 * cs;
|
||||
a2 = 1.0 - 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 ;
|
||||
b0 = (1.0 + cs) / 2.0;
|
||||
b1 = -(1.0 + cs);
|
||||
b2 = (1.0 + cs) / 2.0;
|
||||
a0 = 1.0 + a1pha;
|
||||
a1 = -2.0 * cs;
|
||||
a2 = 1.0 - 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;
|
||||
b0 = 1.0 - a1pha;
|
||||
b1 = -2.0 * cs;
|
||||
b2 = 1.0 + a1pha;
|
||||
a0 = 1.0 + a1pha;
|
||||
a1 = -2.0 * cs;
|
||||
a2 = 1.0 - 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 ;
|
||||
b0 = a1pha;
|
||||
b1 = 0.0;
|
||||
b2 = -a1pha;
|
||||
a0 = 1.0 + a1pha;
|
||||
a1 = -2.0 * cs;
|
||||
a2 = 1.0 - 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;
|
||||
b0 = sn / 2.0;
|
||||
b1 = 0.0;
|
||||
b2 = -sn / 2.0;
|
||||
a0 = 1.0 + a1pha;
|
||||
a1 = -2.0 * cs;
|
||||
a2 = 1.0 - 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;
|
||||
b0 = 1.0;
|
||||
b1 = -2.0 * cs;
|
||||
b2 = 1.0;
|
||||
a0 = 1.0 + a1pha;
|
||||
a1 = -2.0 * cs;
|
||||
a2 = 1.0 - a1pha;
|
||||
break;
|
||||
case RIAA_phono: /* http://www.dsprelated.com/showmessage/73300/3.php */
|
||||
if (samplerate == 44100) {
|
||||
{
|
||||
float b[3], a[3];
|
||||
|
||||
if ((int)sample_rate == 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);
|
||||
make_poly_from_roots(zeros, 2, b);
|
||||
make_poly_from_roots(poles, 2, a);
|
||||
}
|
||||
else if (samplerate == 48000) {
|
||||
else if ((int)sample_rate == 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);
|
||||
make_poly_from_roots(zeros, 2, b);
|
||||
make_poly_from_roots(poles, 2, a);
|
||||
}
|
||||
else if (samplerate == 88200) {
|
||||
else if ((int)sample_rate == 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);
|
||||
make_poly_from_roots(zeros, 2, b);
|
||||
make_poly_from_roots(poles, 2, a);
|
||||
}
|
||||
else if (samplerate == 96000) {
|
||||
else if ((int)sample_rate == 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;
|
||||
make_poly_from_roots(zeros, 2, b);
|
||||
make_poly_from_roots(poles, 2, a);
|
||||
}
|
||||
|
||||
b0 = b[0];
|
||||
b1 = b[1];
|
||||
b2 = b[2];
|
||||
a0 = a[0];
|
||||
a1 = a[1];
|
||||
a2 = a[2];
|
||||
|
||||
/* Normalise to 0dB at 1kHz (Thanks to Glenn Davis) */
|
||||
double y = 2.0 * M_PI * 1000.0 / sample_rate;
|
||||
double b_re = b0 + b1 * cos(-y) + b2 * cos(-2.0 * y);
|
||||
double a_re = a0 + a1 * cos(-y) + a2 * cos(-2.0 * y);
|
||||
double b_im = b1 * sin(-y) + b2 * sin(-2.0 * y);
|
||||
double a_im = a1 * sin(-y) + a2 * sin(-2.0 * y);
|
||||
double g = 1.0 / sqrt((sqr(b_re) + sqr(b_im)) / (sqr(a_re) + sqr(a_im)));
|
||||
b0 *= g; b1 *= g; 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 ;
|
||||
b0 = 1.0 + a1pha * A;
|
||||
b1 = -2.0 * cs;
|
||||
b2 = 1.0 - a1pha * A;
|
||||
a0 = 1.0 + a1pha / A;
|
||||
a1 = -2.0 * cs;
|
||||
a2 = 1.0 - a1pha / 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;
|
||||
beta = sqrt((A * A + 1) / 1.0 - (pow((A - 1), 2)));
|
||||
b0 = A * ((A + 1) - (A - 1) * cs + beta * sn);
|
||||
b1 = 2 * A * ((A - 1) - (A + 1) * cs);
|
||||
b2 = A * ((A + 1) - (A - 1) * cs - beta * sn);
|
||||
a0 = ((A + 1) + (A - 1) * cs + beta * sn);
|
||||
a1 = -2 * ((A - 1) + (A + 1) * cs);
|
||||
a2 = (A + 1) + (A - 1) * cs - beta * 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;
|
||||
b0 = A * ((A + 1) - (A - 1) * cs + beta * sn);
|
||||
b1 = 2 * A * ((A - 1) - (A + 1) * cs);
|
||||
b2 = A * ((A + 1) - (A - 1) * cs - beta * sn);
|
||||
a0 = (A + 1) + (A - 1) * cs + beta * sn;
|
||||
a1 = -2 * ((A - 1) + (A + 1) * cs);
|
||||
a2 = (A + 1) + (A - 1) * cs - beta * 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);
|
||||
omega = 2.0 * M_PI * 5283.0 / sample_rate;
|
||||
cs = cos(omega);
|
||||
sn = sin(omega);
|
||||
a1pha = sn / (2.0 * 0.4845);
|
||||
A = exp(log(10.0) * -9.477 / 40.0);
|
||||
beta = sqrt(A + 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;
|
||||
b0 = A * ((A + 1.0) + (A - 1.0) * cs + beta * sn);
|
||||
b1 = -2.0 * A * ((A - 1.0) + (A + 1.0) * cs);
|
||||
b2 = A * ((A + 1.0) + (A - 1.0) * cs - beta * sn);
|
||||
a0 = (A + 1.0) - (A - 1.0) * cs + beta * sn;
|
||||
a1 = 2.0 * ((A - 1.0) - (A + 1.0) * cs);
|
||||
a2 = (A + 1.0) - (A - 1.0) * cs - beta * 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
|
||||
iir->b0 = b0;
|
||||
iir->b1 = b1;
|
||||
iir->b2 = b2;
|
||||
iir->a0 = a0;
|
||||
iir->a1 = a1;
|
||||
iir->a2 = a2;
|
||||
}
|
||||
|
||||
#ifdef __SSE2__
|
||||
static void iir_process_batch(void *data, float *out, const float *in, unsigned frames)
|
||||
static void *iir_init(const struct dspfilter_info *info,
|
||||
const struct dspfilter_config *config, void *userdata)
|
||||
{
|
||||
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));
|
||||
|
||||
struct iir_data *iir = (struct iir_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);
|
||||
float freq, qual, gain;
|
||||
config->get_float(userdata, "frequency", &freq, 1024.0f);
|
||||
config->get_float(userdata, "quality", &qual, 0.707f);
|
||||
config->get_float(userdata, "gain", &gain, 0.0f);
|
||||
|
||||
char *type = NULL;
|
||||
config->get_string(userdata, "type", &type, "LPF");
|
||||
|
||||
enum IIRFilter filter = str_to_type(type);
|
||||
config->free(type);
|
||||
|
||||
iir_filter_init(iir, info->input_rate, freq, qual, gain, filter);
|
||||
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;
|
||||
static const struct dspfilter_implementation iir_plug = {
|
||||
iir_init,
|
||||
iir_process,
|
||||
iir_free,
|
||||
|
||||
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
|
||||
DSPFILTER_API_VERSION,
|
||||
"IIR",
|
||||
"iir",
|
||||
};
|
||||
|
||||
#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
|
||||
};
|
||||
#ifdef HAVE_FILTERS_BUILTIN
|
||||
#define dspfilter_get_implementation iir_dspfilter_get_implementation
|
||||
#endif
|
||||
|
||||
const struct dspfilter_implementation *rarch_dsp_plugin_init(dspfilter_simd_mask_t simd)
|
||||
const struct dspfilter_implementation *dspfilter_get_implementation(dspfilter_simd_mask_t mask)
|
||||
{
|
||||
(void)simd;
|
||||
#ifdef __SSE2__
|
||||
if (simd & DSPFILTER_SIMD_SSE2)
|
||||
return &sse2_iir_dsp;
|
||||
#endif
|
||||
return &generic_iir_dsp;
|
||||
(void)mask;
|
||||
return &iir_plug;
|
||||
}
|
||||
|
||||
#ifdef RARCH_INTERNAL
|
||||
#undef rarch_dsp_plugin_init
|
||||
#endif
|
||||
#undef dspfilter_get_implementation
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
{
|
||||
global: rarch_dsp_*;
|
||||
global: dspfilter_get_implementation;
|
||||
local: *;
|
||||
};
|
||||
|
105
audio/filters/panning.c
Normal file
105
audio/filters/panning.c
Normal file
@ -0,0 +1,105 @@
|
||||
/* 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/>.
|
||||
*/
|
||||
|
||||
#include "dspfilter.h"
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct panning_data
|
||||
{
|
||||
float left[2];
|
||||
float right[2];
|
||||
};
|
||||
|
||||
static void panning_free(void *data)
|
||||
{
|
||||
free(data);
|
||||
}
|
||||
|
||||
static void panning_process(void *data, struct dspfilter_output *output,
|
||||
const struct dspfilter_input *input)
|
||||
{
|
||||
unsigned i;
|
||||
struct panning_data *pan = (struct panning_data*)data;
|
||||
|
||||
output->samples = input->samples;
|
||||
output->frames = input->frames;
|
||||
|
||||
float *out = output->samples;
|
||||
|
||||
for (i = 0; i < input->frames; i++, out += 2)
|
||||
{
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
static void *panning_init(const struct dspfilter_info *info,
|
||||
const struct dspfilter_config *config, void *userdata)
|
||||
{
|
||||
struct panning_data *pan = (struct panning_data*)calloc(1, sizeof(*pan));
|
||||
if (!pan)
|
||||
return NULL;
|
||||
|
||||
float *left = NULL, *right = NULL;
|
||||
unsigned num_left = 0, num_right = 0;
|
||||
|
||||
static const float default_left[] = { 1.0f, 0.0f };
|
||||
static const float default_right[] = { 0.0f, 1.0f };
|
||||
|
||||
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);
|
||||
|
||||
if (num_left == 2)
|
||||
memcpy(pan->left, left, sizeof(pan->left));
|
||||
else
|
||||
memcpy(pan->left, default_left, sizeof(pan->left));
|
||||
|
||||
if (num_right == 2)
|
||||
memcpy(pan->right, right, sizeof(pan->right));
|
||||
else
|
||||
memcpy(pan->right, default_right, sizeof(pan->right));
|
||||
|
||||
config->free(left);
|
||||
config->free(right);
|
||||
|
||||
return pan;
|
||||
}
|
||||
|
||||
static const struct dspfilter_implementation panning = {
|
||||
panning_init,
|
||||
panning_process,
|
||||
panning_free,
|
||||
|
||||
DSPFILTER_API_VERSION,
|
||||
"Panning",
|
||||
"panning",
|
||||
};
|
||||
|
||||
#ifdef HAVE_FILTERS_BUILTIN
|
||||
#define dspfilter_get_implementation panning_dspfilter_get_implementation
|
||||
#endif
|
||||
|
||||
const struct dspfilter_implementation *dspfilter_get_implementation(dspfilter_simd_mask_t mask)
|
||||
{
|
||||
(void)mask;
|
||||
return &panning;
|
||||
}
|
||||
|
||||
#undef dspfilter_get_implementation
|
||||
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -195,7 +195,6 @@ static const struct cmd_map map[] = {
|
||||
{ "CHEAT_INDEX_MINUS", RARCH_CHEAT_INDEX_MINUS },
|
||||
{ "CHEAT_TOGGLE", RARCH_CHEAT_TOGGLE },
|
||||
{ "SCREENSHOT", RARCH_SCREENSHOT },
|
||||
{ "DSP_CONFIG", RARCH_DSP_CONFIG },
|
||||
{ "MUTE", RARCH_MUTE },
|
||||
{ "NETPLAY_FLIP", RARCH_NETPLAY_FLIP },
|
||||
{ "SLOWMOTION", RARCH_SLOWMOTION },
|
||||
|
@ -674,7 +674,6 @@ static const bool input_autodetect_enable = true;
|
||||
#define RETRO_LBL_CHEAT_INDEX_MINUS "Cheat Index Minus"
|
||||
#define RETRO_LBL_CHEAT_TOGGLE "Cheat Toggle"
|
||||
#define RETRO_LBL_SCREENSHOT "Screenshot"
|
||||
#define RETRO_LBL_DSP_CONFIG "DSP Config"
|
||||
#define RETRO_LBL_MUTE "Mute Audio"
|
||||
#define RETRO_LBL_NETPLAY_FLIP "Netplay Flip Players"
|
||||
#define RETRO_LBL_SLOWMOTION "Slowmotion"
|
||||
@ -736,7 +735,6 @@ static const struct retro_keybind retro_keybinds_1[] = {
|
||||
{ true, RARCH_CHEAT_INDEX_MINUS, RETRO_LBL_CHEAT_INDEX_MINUS, RETROK_t, NO_BTN, 0, AXIS_NONE },
|
||||
{ true, RARCH_CHEAT_TOGGLE, RETRO_LBL_CHEAT_TOGGLE, RETROK_u, NO_BTN, 0, AXIS_NONE },
|
||||
{ true, RARCH_SCREENSHOT, RETRO_LBL_SCREENSHOT, RETROK_F8, NO_BTN, 0, AXIS_NONE },
|
||||
{ true, RARCH_DSP_CONFIG, RETRO_LBL_DSP_CONFIG, RETROK_c, NO_BTN, 0, AXIS_NONE },
|
||||
{ true, RARCH_MUTE, RETRO_LBL_MUTE, RETROK_F9, NO_BTN, 0, AXIS_NONE },
|
||||
{ true, RARCH_NETPLAY_FLIP, RETRO_LBL_NETPLAY_FLIP, RETROK_i, NO_BTN, 0, AXIS_NONE },
|
||||
{ true, RARCH_SLOWMOTION, RETRO_LBL_SLOWMOTION, RETROK_e, NO_BTN, 0, AXIS_NONE },
|
||||
@ -799,7 +797,6 @@ static const struct retro_keybind retro_keybinds_menu[] = {
|
||||
{ true, RARCH_CHEAT_INDEX_MINUS, RETRO_LBL_CHEAT_INDEX_MINUS, RETROK_t, NO_BTN, 0, AXIS_NONE },
|
||||
{ true, RARCH_CHEAT_TOGGLE, RETRO_LBL_CHEAT_TOGGLE, RETROK_u, NO_BTN, 0, AXIS_NONE },
|
||||
{ true, RARCH_SCREENSHOT, RETRO_LBL_SCREENSHOT, RETROK_F8, NO_BTN, 0, AXIS_NONE },
|
||||
{ true, RARCH_DSP_CONFIG, RETRO_LBL_DSP_CONFIG, RETROK_c, NO_BTN, 0, AXIS_NONE },
|
||||
{ true, RARCH_MUTE, RETRO_LBL_MUTE, RETROK_F9, NO_BTN, 0, AXIS_NONE },
|
||||
{ true, RARCH_NETPLAY_FLIP, RETRO_LBL_NETPLAY_FLIP, RETROK_i, NO_BTN, 0, AXIS_NONE },
|
||||
{ true, RARCH_SLOWMOTION, RETRO_LBL_SLOWMOTION, RETROK_e, NO_BTN, 0, AXIS_NONE },
|
||||
|
140
driver.c
140
driver.c
@ -26,7 +26,7 @@
|
||||
#include "audio/resampler.h"
|
||||
#include "gfx/thread_wrapper.h"
|
||||
#include "audio/thread_wrapper.h"
|
||||
#include "audio/filters/rarch_dsp.h"
|
||||
#include "audio/dsp_filter.h"
|
||||
#include "gfx/gfx_common.h"
|
||||
|
||||
#ifdef HAVE_X11
|
||||
@ -970,144 +970,22 @@ void uninit_drivers(void)
|
||||
driver.input_data_own = false;
|
||||
}
|
||||
|
||||
#ifdef HAVE_FILTERS_BUILTIN
|
||||
static const struct dspfilter_implementation *(*dspfilter_drivers[]) (dspfilter_simd_mask_t) =
|
||||
{
|
||||
NULL,
|
||||
&echo_dsp_plugin_init,
|
||||
#ifndef _WIN32
|
||||
#ifndef ANDROID
|
||||
&eq_dsp_plugin_init,
|
||||
#endif
|
||||
#endif
|
||||
&iir_dsp_plugin_init,
|
||||
&phaser_dsp_plugin_init,
|
||||
&reverb_dsp_plugin_init,
|
||||
&volume_dsp_plugin_init,
|
||||
&wah_dsp_plugin_init,
|
||||
};
|
||||
|
||||
unsigned dspfilter_get_last_idx(void)
|
||||
{
|
||||
return sizeof(dspfilter_drivers) / sizeof(dspfilter_drivers[0]);
|
||||
}
|
||||
|
||||
static dspfilter_get_implementation_t dspfilter_get_implementation_from_idx(unsigned i)
|
||||
{
|
||||
if (i < dspfilter_get_last_idx())
|
||||
return dspfilter_drivers[i];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
const char *rarch_dspfilter_get_name(void *data)
|
||||
{
|
||||
const struct dspfilter_implementation *impl;
|
||||
(void)data;
|
||||
#ifdef HAVE_FILTERS_BUILTIN
|
||||
unsigned cpu_features;
|
||||
dspfilter_get_implementation_t cb = (dspfilter_get_implementation_t)dspfilter_get_implementation_from_idx(g_settings.audio.filter_idx);
|
||||
if (cb)
|
||||
{
|
||||
cpu_features = rarch_get_cpu_features();
|
||||
impl = (const struct dspfilter_implementation *)cb(cpu_features);
|
||||
if (impl)
|
||||
return impl->ident;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
#else
|
||||
impl = (const struct dspfilter_implementation*)data;
|
||||
if (!impl || !impl->ident)
|
||||
return NULL;
|
||||
|
||||
return impl->ident;
|
||||
#endif
|
||||
}
|
||||
|
||||
void rarch_init_dsp_filter(void)
|
||||
{
|
||||
unsigned cpu_features;
|
||||
dspfilter_get_implementation_t cb;
|
||||
rarch_dsp_info_t info = {0};
|
||||
|
||||
#ifdef HAVE_FILTERS_BUILTIN
|
||||
if (!g_settings.audio.filter_idx)
|
||||
#else
|
||||
if (!(*g_settings.audio.dsp_plugin))
|
||||
#endif
|
||||
rarch_deinit_dsp_filter();
|
||||
if (!*g_settings.audio.dsp_plugin)
|
||||
return;
|
||||
|
||||
cb = NULL;
|
||||
|
||||
#if defined(HAVE_FILTERS_BUILTIN)
|
||||
cb = (dspfilter_get_implementation_t)dspfilter_get_implementation_from_idx(g_settings.audio.filter_idx);
|
||||
#elif defined(HAVE_DYLIB)
|
||||
g_extern.audio_data.dsp_lib = dylib_load(g_settings.audio.dsp_plugin);
|
||||
if (!g_extern.audio_data.dsp_lib)
|
||||
{
|
||||
RARCH_ERR("Failed to open DSP plugin: \"%s\" ...\n", g_settings.audio.dsp_plugin);
|
||||
return;
|
||||
}
|
||||
|
||||
cb = (dspfilter_get_implementation_t)dylib_proc(g_extern.audio_data.dsp_lib, "rarch_dsp_plugin_init");
|
||||
#endif
|
||||
|
||||
if (!cb)
|
||||
{
|
||||
RARCH_ERR("Failed to find symbol \"rarch_dsp_plugin_init\" in DSP plugin.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
cpu_features = rarch_get_cpu_features();
|
||||
g_extern.audio_data.dsp_plugin = cb(cpu_features);
|
||||
|
||||
if (!g_extern.audio_data.dsp_plugin)
|
||||
{
|
||||
RARCH_ERR("Failed to get a valid DSP plugin.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (g_extern.audio_data.dsp_plugin->api_version != RARCH_DSP_API_VERSION)
|
||||
{
|
||||
RARCH_ERR("DSP plugin API mismatch. RetroArch: %d, Plugin: %d\n", RARCH_DSP_API_VERSION, g_extern.audio_data.dsp_plugin->api_version);
|
||||
goto error;
|
||||
}
|
||||
|
||||
RARCH_LOG("Loaded DSP plugin: \"%s\"\n", g_extern.audio_data.dsp_plugin->ident ? g_extern.audio_data.dsp_plugin->ident : "Unknown");
|
||||
|
||||
info.input_rate = g_settings.audio.in_rate;
|
||||
|
||||
g_extern.audio_data.dsp_handle = g_extern.audio_data.dsp_plugin->init(&info);
|
||||
if (!g_extern.audio_data.dsp_handle)
|
||||
{
|
||||
RARCH_ERR("Failed to init DSP plugin.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
error:
|
||||
#ifdef HAVE_DYLIB
|
||||
if (g_extern.audio_data.dsp_lib)
|
||||
dylib_close(g_extern.audio_data.dsp_lib);
|
||||
g_extern.audio_data.dsp_lib = NULL;
|
||||
#endif
|
||||
g_extern.audio_data.dsp_plugin = NULL;
|
||||
g_extern.audio_data.dsp = rarch_dsp_filter_new(g_settings.audio.dsp_plugin, g_settings.audio.in_rate);
|
||||
if (!g_extern.audio_data.dsp)
|
||||
RARCH_ERR("[DSP]: Failed to init DSP filter \"%s\".\n", g_settings.audio.dsp_plugin);
|
||||
}
|
||||
|
||||
void rarch_deinit_dsp_filter(void)
|
||||
{
|
||||
if (g_extern.audio_data.dsp_plugin && g_extern.audio_data.dsp_plugin->free)
|
||||
g_extern.audio_data.dsp_plugin->free(g_extern.audio_data.dsp_handle);
|
||||
#ifdef HAVE_DYLIB
|
||||
if (g_extern.audio_data.dsp_lib)
|
||||
dylib_close(g_extern.audio_data.dsp_lib);
|
||||
#endif
|
||||
g_extern.audio_data.dsp_handle = NULL;
|
||||
g_extern.audio_data.dsp_plugin = NULL;
|
||||
if (g_extern.audio_data.dsp)
|
||||
rarch_dsp_filter_free(g_extern.audio_data.dsp);
|
||||
g_extern.audio_data.dsp = NULL;
|
||||
}
|
||||
|
||||
void init_audio(void)
|
||||
|
13
driver.h
13
driver.h
@ -27,7 +27,7 @@
|
||||
#include "gfx/scaler/scaler.h"
|
||||
#include "gfx/image_context.h"
|
||||
#include "gfx/filters/softfilter.h"
|
||||
#include "audio/filters/rarch_dsp.h"
|
||||
#include "audio/dsp_filter.h"
|
||||
#include "input/overlay.h"
|
||||
#include "frontend/frontend_context.h"
|
||||
|
||||
@ -96,7 +96,6 @@ enum // RetroArch specific bind IDs.
|
||||
RARCH_CHEAT_INDEX_MINUS,
|
||||
RARCH_CHEAT_TOGGLE,
|
||||
RARCH_SCREENSHOT,
|
||||
RARCH_DSP_CONFIG,
|
||||
RARCH_MUTE,
|
||||
RARCH_NETPLAY_FLIP,
|
||||
RARCH_SLOWMOTION,
|
||||
@ -710,16 +709,6 @@ extern const struct softfilter_implementation *supertwoxsai_get_implementation(s
|
||||
extern const struct softfilter_implementation *twoxbr_get_implementation(softfilter_simd_mask_t simd);
|
||||
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);
|
||||
#endif
|
||||
|
||||
#include "driver_funcs.h"
|
||||
|
@ -1008,7 +1008,7 @@ static void menu_parse_and_resolve(void *data, unsigned menu_type)
|
||||
else if (menu_type == RGUI_SETTINGS_VIDEO_SOFTFILTER)
|
||||
exts = EXT_EXECUTABLES;
|
||||
else if (menu_type == RGUI_SETTINGS_AUDIO_DSP_FILTER)
|
||||
exts = EXT_EXECUTABLES;
|
||||
exts = "dsp";
|
||||
else if (menu_type == RGUI_SETTINGS_OVERLAY_PRESET)
|
||||
exts = "cfg";
|
||||
else if (menu_common_type_is(menu_type) == RGUI_FILE_DIRECTORY)
|
||||
@ -2539,34 +2539,14 @@ static int menu_common_setting_set(void *data, unsigned setting, unsigned action
|
||||
case RGUI_SETTINGS_AUDIO_DSP_FILTER:
|
||||
switch (action)
|
||||
{
|
||||
#ifdef HAVE_FILTERS_BUILTIN
|
||||
case RGUI_ACTION_LEFT:
|
||||
if (g_settings.audio.filter_idx > 0)
|
||||
g_settings.audio.filter_idx--;
|
||||
break;
|
||||
case RGUI_ACTION_RIGHT:
|
||||
if ((g_settings.audio.filter_idx + 1) != dspfilter_get_last_idx())
|
||||
g_settings.audio.filter_idx++;
|
||||
break;
|
||||
#endif
|
||||
case RGUI_ACTION_OK:
|
||||
#if defined(HAVE_FILTERS_BUILTIN)
|
||||
rarch_deinit_dsp_filter();
|
||||
rarch_init_dsp_filter();
|
||||
#elif defined(HAVE_DYLIB)
|
||||
file_list_push(rgui->menu_stack, g_settings.audio.filter_dir, setting, rgui->selection_ptr);
|
||||
menu_clear_navigation(rgui);
|
||||
#endif
|
||||
rgui->need_refresh = true;
|
||||
break;
|
||||
case RGUI_ACTION_START:
|
||||
#if defined(HAVE_FILTERS_BUILTIN)
|
||||
g_settings.audio.filter_idx = 0;
|
||||
#elif defined(HAVE_DYLIB)
|
||||
strlcpy(g_settings.audio.dsp_plugin, "", sizeof(g_settings.audio.dsp_plugin));
|
||||
#endif
|
||||
*g_settings.audio.dsp_plugin = '\0';
|
||||
rarch_deinit_dsp_filter();
|
||||
rarch_init_dsp_filter();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -2902,7 +2882,6 @@ static int menu_common_setting_set(void *data, unsigned setting, unsigned action
|
||||
case RGUI_SETTINGS_BIND_CHEAT_INDEX_MINUS:
|
||||
case RGUI_SETTINGS_BIND_CHEAT_TOGGLE:
|
||||
case RGUI_SETTINGS_BIND_SCREENSHOT:
|
||||
case RGUI_SETTINGS_BIND_DSP_CONFIG:
|
||||
case RGUI_SETTINGS_BIND_MUTE:
|
||||
case RGUI_SETTINGS_BIND_NETPLAY_FLIP:
|
||||
case RGUI_SETTINGS_BIND_SLOWMOTION:
|
||||
@ -4082,10 +4061,7 @@ static void menu_common_setting_set_label(char *type_str, size_t type_str_size,
|
||||
}
|
||||
break;
|
||||
case RGUI_SETTINGS_AUDIO_DSP_FILTER:
|
||||
{
|
||||
const char *filter_name = rarch_dspfilter_get_name((void*)g_extern.audio_data.dsp_plugin);
|
||||
strlcpy(type_str, filter_name ? filter_name : "N/A", type_str_size);
|
||||
}
|
||||
strlcpy(type_str, path_basename(g_settings.audio.dsp_plugin), type_str_size);
|
||||
break;
|
||||
#ifdef HAVE_OVERLAY
|
||||
case RGUI_SETTINGS_OVERLAY_PRESET:
|
||||
@ -4214,7 +4190,6 @@ static void menu_common_setting_set_label(char *type_str, size_t type_str_size,
|
||||
case RGUI_SETTINGS_BIND_CHEAT_INDEX_MINUS:
|
||||
case RGUI_SETTINGS_BIND_CHEAT_TOGGLE:
|
||||
case RGUI_SETTINGS_BIND_SCREENSHOT:
|
||||
case RGUI_SETTINGS_BIND_DSP_CONFIG:
|
||||
case RGUI_SETTINGS_BIND_MUTE:
|
||||
case RGUI_SETTINGS_BIND_NETPLAY_FLIP:
|
||||
case RGUI_SETTINGS_BIND_SLOWMOTION:
|
||||
|
@ -205,7 +205,6 @@ typedef enum
|
||||
RGUI_SETTINGS_BIND_CHEAT_INDEX_MINUS,
|
||||
RGUI_SETTINGS_BIND_CHEAT_TOGGLE,
|
||||
RGUI_SETTINGS_BIND_SCREENSHOT,
|
||||
RGUI_SETTINGS_BIND_DSP_CONFIG,
|
||||
RGUI_SETTINGS_BIND_MUTE,
|
||||
RGUI_SETTINGS_BIND_NETPLAY_FLIP,
|
||||
RGUI_SETTINGS_BIND_SLOWMOTION,
|
||||
|
11
general.h
11
general.h
@ -29,7 +29,7 @@
|
||||
#include "autosave.h"
|
||||
#include "dynamic.h"
|
||||
#include "cheats.h"
|
||||
#include "audio/filters/rarch_dsp.h"
|
||||
#include "audio/dsp_filter.h"
|
||||
#include "compat/strl.h"
|
||||
#include "performance.h"
|
||||
#include "core_options.h"
|
||||
@ -239,9 +239,6 @@ struct settings
|
||||
|
||||
char dsp_plugin[PATH_MAX];
|
||||
char filter_dir[PATH_MAX];
|
||||
#ifdef HAVE_FILTERS_BUILTIN
|
||||
unsigned filter_idx;
|
||||
#endif
|
||||
|
||||
bool rate_control;
|
||||
float rate_control_delta;
|
||||
@ -496,11 +493,7 @@ struct global
|
||||
size_t rewind_ptr;
|
||||
size_t rewind_size;
|
||||
|
||||
#ifdef HAVE_DYLIB
|
||||
dylib_t dsp_lib;
|
||||
#endif
|
||||
const struct dspfilter_implementation *dsp_plugin;
|
||||
void *dsp_handle;
|
||||
rarch_dsp_filter_t *dsp;
|
||||
|
||||
bool rate_control;
|
||||
double orig_src_ratio;
|
||||
|
@ -485,17 +485,9 @@ 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/panning.c"
|
||||
#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"
|
||||
#include "../audio/filters/echo.c"
|
||||
#endif
|
||||
/*============================================================
|
||||
DYNAMIC
|
||||
@ -503,6 +495,7 @@ DYNAMIC
|
||||
#include "../dynamic.c"
|
||||
#include "../dynamic_dummy.c"
|
||||
#include "../gfx/filter.c"
|
||||
#include "../audio/dsp_filter.c"
|
||||
|
||||
|
||||
/*============================================================
|
||||
|
@ -851,7 +851,6 @@ const struct input_bind_map input_config_bind_map[RARCH_BIND_LIST_END_NULL] = {
|
||||
DECLARE_META_BIND(2, cheat_index_minus, RARCH_CHEAT_INDEX_MINUS, "Cheat index -"),
|
||||
DECLARE_META_BIND(2, cheat_toggle, RARCH_CHEAT_TOGGLE, "Cheat toggle"),
|
||||
DECLARE_META_BIND(2, screenshot, RARCH_SCREENSHOT, "Take screenshot"),
|
||||
DECLARE_META_BIND(2, dsp_config, RARCH_DSP_CONFIG, "DSP config"),
|
||||
DECLARE_META_BIND(2, audio_mute, RARCH_MUTE, "Audio mute toggle"),
|
||||
DECLARE_META_BIND(2, netplay_flip_players, RARCH_NETPLAY_FLIP, "Netplay flip players"),
|
||||
DECLARE_META_BIND(2, slowmotion, RARCH_SLOWMOTION, "Slow motion"),
|
||||
|
35
retroarch.c
35
retroarch.c
@ -388,16 +388,15 @@ static bool audio_flush(const int16_t *data, size_t samples)
|
||||
g_extern.audio_data.volume_gain);
|
||||
RARCH_PERFORMANCE_STOP(audio_convert_s16);
|
||||
|
||||
rarch_dsp_output_t dsp_output = {0};
|
||||
rarch_dsp_input_t dsp_input = {0};
|
||||
dsp_input.samples = g_extern.audio_data.data;
|
||||
dsp_input.frames = samples >> 1;
|
||||
struct rarch_dsp_data dsp_data = {0};
|
||||
dsp_data.input = g_extern.audio_data.data;
|
||||
dsp_data.input_frames = samples >> 1;
|
||||
|
||||
if (g_extern.audio_data.dsp_plugin)
|
||||
g_extern.audio_data.dsp_plugin->process(g_extern.audio_data.dsp_handle, &dsp_output, &dsp_input);
|
||||
if (g_extern.audio_data.dsp)
|
||||
rarch_dsp_filter_process(g_extern.audio_data.dsp, &dsp_data);
|
||||
|
||||
src_data.data_in = dsp_output.samples ? dsp_output.samples : g_extern.audio_data.data;
|
||||
src_data.input_frames = dsp_output.samples ? dsp_output.frames : (samples >> 1);
|
||||
src_data.data_in = dsp_data.output ? dsp_data.output : g_extern.audio_data.data;
|
||||
src_data.input_frames = dsp_data.output ? dsp_data.output_frames : (samples >> 1);
|
||||
|
||||
src_data.data_out = g_extern.audio_data.outsamples;
|
||||
|
||||
@ -2575,19 +2574,6 @@ static void check_screenshot(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
static void check_dsp_config(void)
|
||||
{
|
||||
if (!g_extern.audio_data.dsp_plugin || !g_extern.audio_data.dsp_plugin->config)
|
||||
return;
|
||||
|
||||
static bool old_pressed;
|
||||
bool pressed = input_key_pressed_func(RARCH_DSP_CONFIG);
|
||||
if (pressed && !old_pressed)
|
||||
g_extern.audio_data.dsp_plugin->config(g_extern.audio_data.dsp_handle);
|
||||
|
||||
old_pressed = pressed;
|
||||
}
|
||||
|
||||
static void check_mute(void)
|
||||
{
|
||||
if (!g_extern.audio_active)
|
||||
@ -2765,7 +2751,6 @@ static void do_state_checks(void)
|
||||
check_cheats();
|
||||
check_disk();
|
||||
|
||||
check_dsp_config();
|
||||
check_reset();
|
||||
#ifdef HAVE_NETPLAY
|
||||
}
|
||||
@ -3063,12 +3048,6 @@ bool rarch_main_iterate(void)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
#ifdef HAVE_DYLIB
|
||||
// DSP plugin GUI events.
|
||||
if (g_extern.audio_data.dsp_handle && g_extern.audio_data.dsp_plugin && g_extern.audio_data.dsp_plugin->events)
|
||||
g_extern.audio_data.dsp_plugin->events(g_extern.audio_data.dsp_handle);
|
||||
#endif
|
||||
|
||||
// SHUTDOWN on consoles should exit RetroArch completely.
|
||||
if (g_extern.system.shutdown)
|
||||
return false;
|
||||
|
@ -831,8 +831,8 @@ bool config_load_file(const char *path, bool set_defaults)
|
||||
* setting the filter later doesn't cause a problem meanwhile */
|
||||
CONFIG_GET_INT(video.filter_idx, "filter_index");
|
||||
#endif
|
||||
CONFIG_GET_INT(audio.filter_idx, "audio_filter_index");
|
||||
#endif
|
||||
|
||||
#ifdef RARCH_CONSOLE
|
||||
/* TODO - will be refactored later to make it more clean - it's more
|
||||
* important that it works for consoles right now */
|
||||
@ -1327,7 +1327,6 @@ bool config_save_file(const char *path)
|
||||
config_set_bool(conf, "rewind_enable", g_settings.rewind_enable);
|
||||
#ifdef HAVE_FILTERS_BUILTIN
|
||||
config_set_int(conf, "filter_index", g_settings.video.filter_idx);
|
||||
config_set_int(conf, "audio_filter_index", g_settings.audio.filter_idx);
|
||||
#endif
|
||||
config_set_int(conf, "audio_latency", g_settings.audio.latency);
|
||||
config_set_bool(conf, "audio_sync", g_settings.audio.sync);
|
||||
|
Loading…
x
Reference in New Issue
Block a user