Minor cleanups for hermite.

This commit is contained in:
Themaister 2011-11-03 23:48:36 +01:00
parent f19d99d523
commit a6f7a2311f
3 changed files with 18 additions and 29 deletions

View File

@ -54,20 +54,19 @@ hermite_resampler_t *hermite_new(void)
return re;
}
// We make sure to allocate enough output data beforehand ... ;)
void hermite_process(hermite_resampler_t *re, struct hermite_data *data)
{
double r_step = 1.0 / data->ratio;
size_t processed_out = 0;
size_t processed_in = 0;
size_t in_frames = data->input_frames;
size_t out_frames = data->output_frames;
const float *in_data = data->data_in;
float *out_data = data->data_out;
while (processed_in < in_frames && processed_out < out_frames)
for (size_t i = 0; i < in_frames; i++)
{
while (re->r_frac <= 1.0 && processed_out < out_frames)
while (re->r_frac <= 1.0)
{
re->r_frac += r_step;
for (unsigned i = 0; i < CHANNELS; i++)
@ -79,23 +78,17 @@ void hermite_process(hermite_resampler_t *re, struct hermite_data *data)
processed_out++;
}
if (re->r_frac >= 1.0)
re->r_frac -= 1.0;
for (unsigned i = 0; i < CHANNELS; i++)
{
re->r_frac -= 1.0;
for (unsigned i = 0; i < CHANNELS; i++)
{
re->chan_data[i][0] = re->chan_data[i][1];
re->chan_data[i][1] = re->chan_data[i][2];
re->chan_data[i][2] = re->chan_data[i][3];
re->chan_data[i][3] = *in_data++;
}
processed_in++;
re->chan_data[i][0] = re->chan_data[i][1];
re->chan_data[i][1] = re->chan_data[i][2];
re->chan_data[i][2] = re->chan_data[i][3];
re->chan_data[i][3] = *in_data++;
}
}
data->input_frames_used = processed_in;
data->output_frames_gen = processed_out;
data->output_frames = processed_out;
}
void hermite_free(hermite_resampler_t *re)

View File

@ -36,9 +36,6 @@ struct hermite_data
size_t input_frames;
size_t output_frames;
size_t input_frames_used;
size_t output_frames_gen;
double ratio;
};

17
ssnes.c
View File

@ -274,20 +274,19 @@ static bool audio_flush(const int16_t *data, unsigned samples)
if (g_extern.audio_data.dsp_plugin)
g_extern.audio_data.dsp_plugin->process(g_extern.audio_data.dsp_handle, &dsp_output, &dsp_input);
struct hermite_data src_data = {
.data_in = dsp_output.samples ? dsp_output.samples : g_extern.audio_data.data,
.data_out = g_extern.audio_data.outsamples,
.input_frames = dsp_output.samples ? dsp_output.frames : (samples / 2),
.ratio = g_extern.audio_data.src_ratio,
.output_frames = samples * g_extern.audio_data.src_ratio,
};
if (dsp_output.should_resample)
{
struct hermite_data src_data = {
.data_in = dsp_output.samples ? dsp_output.samples : g_extern.audio_data.data,
.data_out = g_extern.audio_data.outsamples,
.input_frames = dsp_output.samples ? dsp_output.frames : (samples / 2),
.ratio = g_extern.audio_data.src_ratio,
};
hermite_process(g_extern.audio_data.source, &src_data);
output_data = g_extern.audio_data.outsamples;
output_frames = src_data.output_frames_gen;
output_frames = src_data.output_frames;
}
else
{