Rename resampler functions to something more generic.

This commit is contained in:
Themaister 2012-02-23 23:19:23 +01:00
parent a797e1dbf4
commit aecd9a1ecb
5 changed files with 20 additions and 24 deletions

View File

@ -17,12 +17,13 @@
// Hermite resampler based on bsnes' audio library. // Hermite resampler based on bsnes' audio library.
#include "hermite.h" #include "resampler.h"
#include <stdlib.h> #include <stdlib.h>
#include "../boolean.h"
#define CHANNELS 2 #define CHANNELS 2
struct hermite_resampler struct ssnes_resampler
{ {
float chan_data[CHANNELS][4]; float chan_data[CHANNELS][4];
double r_frac; double r_frac;
@ -46,13 +47,12 @@ static inline float hermite_kernel(float mu1, float a, float b, float c, float d
return (a0 * b) + (a1 * m0) + (a2 * m1) + (a3 * c); return (a0 * b) + (a1 * m0) + (a2 * m1) + (a3 * c);
} }
hermite_resampler_t *hermite_new(void) ssnes_resampler_t *resampler_new(void)
{ {
return (hermite_resampler_t*)calloc(1, sizeof(hermite_resampler_t)); return (ssnes_resampler_t*)calloc(1, sizeof(ssnes_resampler_t));
} }
// We make sure to allocate enough output data beforehand ... ;) void resampler_process(ssnes_resampler_t *re, struct resampler_data *data)
void hermite_process(hermite_resampler_t *re, struct hermite_data *data)
{ {
double r_step = 1.0 / data->ratio; double r_step = 1.0 / data->ratio;
size_t processed_out = 0; size_t processed_out = 0;
@ -88,7 +88,7 @@ void hermite_process(hermite_resampler_t *re, struct hermite_data *data)
data->output_frames = processed_out; data->output_frames = processed_out;
} }
void hermite_free(hermite_resampler_t *re) void resampler_free(ssnes_resampler_t *re)
{ {
free(re); free(re);
} }

View File

@ -15,20 +15,15 @@
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
*/ */
// Hermite resampler based on bsnes' audio library.
// Attempts to be similiar to the libsamplerate process interface.
#ifndef __SSNES_HERMITE_H #ifndef __SSNES_RESAMPLER_H
#define __SSNES_HERMITE_H #define __SSNES_RESAMPLER_H
#include <stddef.h> #include <stddef.h>
#include "../boolean.h"
typedef struct hermite_resampler hermite_resampler_t; typedef struct ssnes_resampler ssnes_resampler_t;
hermite_resampler_t *hermite_new(void); struct resampler_data
struct hermite_data
{ {
const float *data_in; const float *data_in;
float *data_out; float *data_out;
@ -39,8 +34,9 @@ struct hermite_data
double ratio; double ratio;
}; };
void hermite_process(hermite_resampler_t *re, struct hermite_data *data); ssnes_resampler_t *resampler_new(void);
void hermite_free(hermite_resampler_t *re); void resampler_process(ssnes_resampler_t *re, struct resampler_data *data);
void resampler_free(ssnes_resampler_t *re);
#endif #endif

View File

@ -325,7 +325,7 @@ void init_audio(void)
g_extern.audio_data.chunk_size = g_extern.audio_data.nonblock_chunk_size; g_extern.audio_data.chunk_size = g_extern.audio_data.nonblock_chunk_size;
} }
g_extern.audio_data.source = hermite_new(); g_extern.audio_data.source = resampler_new();
if (!g_extern.audio_data.source) if (!g_extern.audio_data.source)
g_extern.audio_active = false; g_extern.audio_active = false;
@ -374,7 +374,7 @@ void uninit_audio(void)
driver.audio->free(driver.audio_data); driver.audio->free(driver.audio_data);
if (g_extern.audio_data.source) if (g_extern.audio_data.source)
hermite_free(g_extern.audio_data.source); resampler_free(g_extern.audio_data.source);
free(g_extern.audio_data.data); free(g_extern.audio_data.data);
g_extern.audio_data.data = NULL; g_extern.audio_data.data = NULL;

View File

@ -56,7 +56,7 @@
#include "netplay.h" #include "netplay.h"
#endif #endif
#include "audio/hermite.h" #include "audio/resampler.h"
#if defined(_WIN32) && !defined(_XBOX) #if defined(_WIN32) && !defined(_XBOX)
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
@ -282,7 +282,7 @@ struct global
struct struct
{ {
hermite_resampler_t *source; ssnes_resampler_t *source;
float *data; float *data;
size_t data_ptr; size_t data_ptr;

View File

@ -298,7 +298,7 @@ static bool audio_flush(const int16_t *data, size_t samples)
if (dsp_output.should_resample) if (dsp_output.should_resample)
{ {
struct hermite_data src_data = {0}; struct resampler_data src_data = {0};
src_data.data_in = dsp_output.samples ? dsp_output.samples : g_extern.audio_data.data; src_data.data_in = dsp_output.samples ? dsp_output.samples : g_extern.audio_data.data;
src_data.data_out = g_extern.audio_data.outsamples; src_data.data_out = g_extern.audio_data.outsamples;
src_data.input_frames = dsp_output.samples ? dsp_output.frames : (samples / 2); src_data.input_frames = dsp_output.samples ? dsp_output.frames : (samples / 2);
@ -308,7 +308,7 @@ static bool audio_flush(const int16_t *data, size_t samples)
src_data.ratio = g_extern.audio_data.src_ratio; src_data.ratio = g_extern.audio_data.src_ratio;
hermite_process(g_extern.audio_data.source, &src_data); resampler_process(g_extern.audio_data.source, &src_data);
output_data = g_extern.audio_data.outsamples; output_data = g_extern.audio_data.outsamples;
output_frames = src_data.output_frames; output_frames = src_data.output_frames;