[PATCH - resample 1/1] Using float instead of s16 for libsamplerate
Natively libsamplerate operates in floats. Using the new convert_float API instead of dropping resoluton in convert_s16.
Signed-off-by: Pavel Hofman pavel.hofman@ivitera.com
diff --git a/rate/rate_samplerate.c b/rate/rate_samplerate.c index 53a0627..c612983 100644 --- a/rate/rate_samplerate.c +++ b/rate/rate_samplerate.c @@ -23,12 +23,12 @@ #include <alsa/asoundlib.h> #include <alsa/pcm_rate.h>
+typedef float float_t; + struct rate_src { double ratio; int converter; unsigned int channels; - float *src_buf; - float *dst_buf; SRC_STATE *state; SRC_DATA data; }; @@ -53,9 +53,6 @@ static void pcm_src_free(void *obj) { struct rate_src *rate = obj;
- free(rate->src_buf); - free(rate->dst_buf); - rate->src_buf = rate->dst_buf = NULL;
if (rate->state) { src_delete(rate->state); @@ -79,17 +76,6 @@ static int pcm_src_init(void *obj, snd_pcm_rate_info_t *info)
rate->ratio = (double)info->out.rate / (double)info->in.rate;
- free(rate->src_buf); - rate->src_buf = malloc(sizeof(float) * rate->channels * info->in.period_size); - free(rate->dst_buf); - rate->dst_buf = malloc(sizeof(float) * rate->channels * info->out.period_size); - if (! rate->src_buf || ! rate->dst_buf) { - pcm_src_free(rate); - return -ENOMEM; - } - - rate->data.data_in = rate->src_buf; - rate->data.data_out = rate->dst_buf; rate->data.src_ratio = rate->ratio; rate->data.end_of_input = 0;
@@ -112,8 +98,8 @@ static void pcm_src_reset(void *obj) src_reset(rate->state); }
-static void pcm_src_convert_s16(void *obj, int16_t *dst, unsigned int dst_frames, - const int16_t *src, unsigned int src_frames) +static void pcm_src_convert_float(void *obj, float_t *dst, unsigned int dst_frames, + const float_t *src, unsigned int src_frames) { struct rate_src *rate = obj; unsigned int ofs; @@ -121,15 +107,17 @@ static void pcm_src_convert_s16(void *obj, int16_t *dst, unsigned int dst_frames rate->data.input_frames = src_frames; rate->data.output_frames = dst_frames; rate->data.end_of_input = 0; + rate->data.data_in = src; + rate->data.data_out = dst; + - src_short_to_float_array(src, rate->src_buf, src_frames * rate->channels); src_process(rate->state, &rate->data); if (rate->data.output_frames_gen < dst_frames) ofs = dst_frames - rate->data.output_frames_gen; else ofs = 0; - src_float_to_short_array(rate->dst_buf, dst + ofs * rate->channels, - rate->data.output_frames_gen * rate->channels); + /*src_float_to_short_array(rate->dst_buf, dst + ofs * rate->channels, + rate->data.output_frames_gen * rate->channels); */ }
static void pcm_src_close(void *obj) @@ -157,7 +145,7 @@ static snd_pcm_rate_ops_t pcm_src_ops = { .free = pcm_src_free, .reset = pcm_src_reset, .adjust_pitch = pcm_src_adjust_pitch, - .convert_s16 = pcm_src_convert_s16, + .convert_float = pcm_src_convert_float, .input_frames = input_frames, .output_frames = output_frames, #if SND_PCM_RATE_PLUGIN_VERSION >= 0x010002
participants (1)
-
Pavel Hofman