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.
#include "hermite.h"
#include "resampler.h"
#include <stdlib.h>
#include "../boolean.h"
#define CHANNELS 2
struct hermite_resampler
struct ssnes_resampler
{
float chan_data[CHANNELS][4];
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);
}
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 hermite_process(hermite_resampler_t *re, struct hermite_data *data)
void resampler_process(ssnes_resampler_t *re, struct resampler_data *data)
{
double r_step = 1.0 / data->ratio;
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;
}
void hermite_free(hermite_resampler_t *re)
void resampler_free(ssnes_resampler_t *re)
{
free(re);
}

View File

@ -15,20 +15,15 @@
* 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
#define __SSNES_HERMITE_H
#ifndef __SSNES_RESAMPLER_H
#define __SSNES_RESAMPLER_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 hermite_data
struct resampler_data
{
const float *data_in;
float *data_out;
@ -39,8 +34,9 @@ struct hermite_data
double ratio;
};
void hermite_process(hermite_resampler_t *re, struct hermite_data *data);
void hermite_free(hermite_resampler_t *re);
ssnes_resampler_t *resampler_new(void);
void resampler_process(ssnes_resampler_t *re, struct resampler_data *data);
void resampler_free(ssnes_resampler_t *re);
#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.source = hermite_new();
g_extern.audio_data.source = resampler_new();
if (!g_extern.audio_data.source)
g_extern.audio_active = false;
@ -374,7 +374,7 @@ void uninit_audio(void)
driver.audio->free(driver.audio_data);
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);
g_extern.audio_data.data = NULL;

View File

@ -56,7 +56,7 @@
#include "netplay.h"
#endif
#include "audio/hermite.h"
#include "audio/resampler.h"
#if defined(_WIN32) && !defined(_XBOX)
#define WIN32_LEAN_AND_MEAN
@ -282,7 +282,7 @@ struct global
struct
{
hermite_resampler_t *source;
ssnes_resampler_t *source;
float *data;
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)
{
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_out = g_extern.audio_data.outsamples;
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;
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_frames = src_data.output_frames;