From a6f7a2311fa2676d2afaee06562bd6493d428ef8 Mon Sep 17 00:00:00 2001 From: Themaister Date: Thu, 3 Nov 2011 23:48:36 +0100 Subject: [PATCH] Minor cleanups for hermite. --- audio/hermite.c | 27 ++++++++++----------------- audio/hermite.h | 3 --- ssnes.c | 17 ++++++++--------- 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/audio/hermite.c b/audio/hermite.c index 65b61e0ac9..c2a1f44d95 100644 --- a/audio/hermite.c +++ b/audio/hermite.c @@ -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) diff --git a/audio/hermite.h b/audio/hermite.h index 2ab798f1f1..43a78b67ef 100644 --- a/audio/hermite.h +++ b/audio/hermite.h @@ -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; }; diff --git a/ssnes.c b/ssnes.c index d51b0be9ae..65ce488cd9 100644 --- a/ssnes.c +++ b/ssnes.c @@ -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 {