Merge branch 'master' of github.com:Themaister/SSNES

Conflicts:
	console/rom_ext.c
	console/rom_ext.h
This commit is contained in:
TwinAphex51224 2012-02-25 20:15:22 +01:00
commit c310e32dd0
3 changed files with 49 additions and 18 deletions

View File

@ -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)
@ -103,23 +95,35 @@ 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));
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);
}
}
// 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) * 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;
}
}
ssnes_resampler_t *resampler_new(void)
@ -186,8 +190,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

View File

@ -20,6 +20,8 @@
#include "rom_ext.h"
#include "../boolean.h"
#include "../libsnes.hpp"
#include <string.h>
#include <ctype.h>
const char *ssnes_console_get_rom_ext(void)
{
@ -46,3 +48,27 @@ 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; id[i] != '\0'; i++)
{
char c = id[i];
if (isspace(c) || isblank(c))
name[i] = '_';
else
name[i] = tolower(c);
}
}

View File

@ -18,13 +18,14 @@
#ifndef ROM_EXT_H__
#define ROM_EXT_H__
#include <stddef.h>
// 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);
#ifdef __CELLOS_LV2__
void ssnes_exitspawn(const char * filepath);
#endif
// Transforms a library id to a name suitable as a pathname.
void ssnes_console_name_from_id(char *name, size_t size);
#endif