From bdc8cd1cb1172e098db3c93e863134f7331b63fa Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 25 Feb 2012 16:33:33 +0100 Subject: [PATCH 1/4] Apply deltas to last phase as well. --- audio/sinc.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/audio/sinc.c b/audio/sinc.c index 8af6397ff9..cffa5ea120 100644 --- a/audio/sinc.c +++ b/audio/sinc.c @@ -103,7 +103,7 @@ static void init_sinc_table(ssnes_resampler_t *resamp) // Sinc phases: [..., p + 3, p + 2, p + 1, p + 0, p - 1, p - 2, p - 3, p - 4, ...] for (int i = 0; i < PHASES; i++) { - for (int j = 0; j < 2 * SIDELOBES; j++) + for (int j = 0; j < TAPS; j++) { double p = (double)i / PHASES; double sinc_phase = M_PI * (p + (SIDELOBES - 1 - j)); @@ -114,12 +114,23 @@ static void init_sinc_table(ssnes_resampler_t *resamp) // Optimize linear interpolation. for (int i = 0; i < PHASES - 1; i++) { - for (int j = 0; j < 2 * SIDELOBES; j++) + for (int j = 0; j < TAPS; j++) { resamp->phase_table[i][DELTA_INDEX][j] = (resamp->phase_table[i + 1][PHASE_INDEX][j] - resamp->phase_table[i][PHASE_INDEX][j]) / SUBPHASES; } } + + // Interpolation between [PHASES - 1] => [PHASES] + for (int j = 0; j < TAPS; j++) + { + double p = 1.0; + double sinc_phase = M_PI * (p + (SIDELOBES - 1 - j)); + double phase = sinc(sinc_phase) * blackman(sinc_phase / SIDELOBES); + + float result = (phase - resamp->phase_table[PHASES - 1][PHASE_INDEX][j]) / SUBPHASES; + resamp->phase_table[PHASES - 1][DELTA_INDEX][j] = result; + } } ssnes_resampler_t *resampler_new(void) @@ -186,8 +197,8 @@ static void process_sinc(ssnes_resampler_t *resamp, float *out_buffer) [1] = { .v = sum_r }, }; - out_buffer[0] = u[0].f[0] + u[0].f[1] + u[0].f[2] + u[0].f[3]; - out_buffer[1] = u[1].f[0] + u[1].f[1] + u[1].f[2] + u[1].f[3]; + out_buffer[0] = (u[0].f[0] + u[0].f[1]) + (u[0].f[2] + u[0].f[3]); + out_buffer[1] = (u[1].f[0] + u[1].f[1]) + (u[1].f[2] + u[1].f[3]); #endif } #else // Plain ol' C99 From 3dc5b21b783c5248ac76655c1cd5ed8603cfdfa2 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 25 Feb 2012 16:45:06 +0100 Subject: [PATCH 2/4] Use lanzcos instead (better SNR). --- audio/sinc.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/audio/sinc.c b/audio/sinc.c index cffa5ea120..4013a9e6ce 100644 --- a/audio/sinc.c +++ b/audio/sinc.c @@ -85,17 +85,9 @@ static inline double sinc(double val) return sin(val) / val; } -static inline double blackman(double index) +static inline double lanzcos(double index) { - index *= 0.5; - index += 0.5; - - double alpha = 0.16; - double a0 = (1.0 - alpha) / 2.0; - double a1 = 0.5; - double a2 = alpha / 2.0; - - return a0 - a1 * cos(2.0 * M_PI * index) + a2 * cos(4.0 * M_PI * index); + return sinc(index); } static void init_sinc_table(ssnes_resampler_t *resamp) @@ -107,7 +99,8 @@ static void init_sinc_table(ssnes_resampler_t *resamp) { double p = (double)i / PHASES; double sinc_phase = M_PI * (p + (SIDELOBES - 1 - j)); - resamp->phase_table[i][PHASE_INDEX][j] = sinc(sinc_phase) * blackman(sinc_phase / SIDELOBES); + resamp->phase_table[i][PHASE_INDEX][j] = sinc(sinc_phase) * + lanzcos(sinc_phase / SIDELOBES); } } @@ -126,7 +119,7 @@ static void init_sinc_table(ssnes_resampler_t *resamp) { double p = 1.0; double sinc_phase = M_PI * (p + (SIDELOBES - 1 - j)); - double phase = sinc(sinc_phase) * blackman(sinc_phase / SIDELOBES); + double phase = sinc(sinc_phase) * lanzcos(sinc_phase / SIDELOBES); float result = (phase - resamp->phase_table[PHASES - 1][PHASE_INDEX][j]) / SUBPHASES; resamp->phase_table[PHASES - 1][DELTA_INDEX][j] = result; From 2e9fade00ac16e6698bc791fc2a56a68dc0d93ea Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 25 Feb 2012 17:05:52 +0100 Subject: [PATCH 3/4] Add name generation from id. --- console/rom_ext.c | 27 +++++++++++++++++++++++++++ console/rom_ext.h | 5 +++++ 2 files changed, 32 insertions(+) diff --git a/console/rom_ext.c b/console/rom_ext.c index d524dd1c9c..be4dc8e211 100644 --- a/console/rom_ext.c +++ b/console/rom_ext.c @@ -19,6 +19,7 @@ #include "../boolean.h" #include "../libsnes.hpp" #include +#include const char *ssnes_console_get_rom_ext(void) { @@ -46,3 +47,29 @@ const char *ssnes_console_get_rom_ext(void) return NULL; } +void ssnes_console_name_from_id(char *name, size_t size) +{ + if (size == 0) + return; + + const char *id = snes_library_id(); + if (!id || strlen(id) >= size) + { + name[0] = '\0'; + return; + } + + name[strlen(id)] = '\0'; + + for (size_t i = 0; i < size && id[i]; i++) + { + char c = id[i]; + if (isspace(c) || isblank(c)) + name[i] = '_'; + else if (isupper(c)) + name[i] = tolower(c); + else + name[i] = c; + } +} + diff --git a/console/rom_ext.h b/console/rom_ext.h index 0702dc475a..33c900fdd1 100644 --- a/console/rom_ext.h +++ b/console/rom_ext.h @@ -18,10 +18,15 @@ #ifndef ROM_EXT_H__ #define ROM_EXT_H__ +#include + // Get rom extensions for current library. // Infers info from snes_library_id(). // Returns NULL if library doesn't have any preferences in particular. const char *ssnes_console_get_rom_ext(void); +// Transforms a library id to a name suitable as a pathname. +void ssnes_console_name_from_id(char *name, size_t size); + #endif From a03c11d7d0e302a156fdbce2a758e18b9ba87428 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 25 Feb 2012 17:29:02 +0100 Subject: [PATCH 4/4] Clarify a bit. --- console/rom_ext.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/console/rom_ext.c b/console/rom_ext.c index be4dc8e211..048baf9891 100644 --- a/console/rom_ext.c +++ b/console/rom_ext.c @@ -61,15 +61,13 @@ void ssnes_console_name_from_id(char *name, size_t size) name[strlen(id)] = '\0'; - for (size_t i = 0; i < size && id[i]; i++) + for (size_t i = 0; id[i] != '\0'; i++) { char c = id[i]; if (isspace(c) || isblank(c)) name[i] = '_'; - else if (isupper(c)) - name[i] = tolower(c); else - name[i] = c; + name[i] = tolower(c); } }