ref: 1d01e51537416eb1169b03d3f98ee2b56343d4aa
parent: 50a82601a2b01542ccd0c5ea07b08e195c76c1f8
author: Paul Brossier <piem@piem.org>
date: Thu Sep 22 22:43:35 EDT 2016
src/io/source_sndfile.c: add support for multi-channel resampling
--- a/src/io/source_sndfile.c
+++ b/src/io/source_sndfile.c
@@ -59,8 +59,9 @@
smpl_t ratio;
uint_t input_hop_size;
#ifdef HAVE_SAMPLERATE
- aubio_resampler_t *resampler;
+ aubio_resampler_t **resamplers;
fvec_t *input_data;
+ fmat_t *input_mat;
#endif /* HAVE_SAMPLERATE */
// some temporary memory for sndfile to write at
@@ -126,11 +127,17 @@
}
#ifdef HAVE_SAMPLERATE
- s->resampler = NULL;
s->input_data = NULL;
+ s->input_mat = NULL;
+ s->resamplers = NULL;
if (s->ratio != 1) {
+ uint_t i;
+ s->resamplers = AUBIO_ARRAY(aubio_resampler_t*, s->input_channels);
s->input_data = new_fvec(s->input_hop_size);
- s->resampler = new_aubio_resampler(s->ratio, 4);
+ s->input_mat = new_fmat(s->input_channels, s->input_hop_size);
+ for (i = 0; i < (uint_t)s->input_channels; i++) {
+ s->resamplers[i] = new_aubio_resampler(s->ratio, 4);
+ }
if (s->ratio > 1) {
// we would need to add a ring buffer for these
if ( (uint_t)(s->input_hop_size * s->ratio + .5) != s->hop_size ) {
@@ -189,8 +196,8 @@
}
#ifdef HAVE_SAMPLERATE
- if (s->resampler) {
- aubio_resampler_do(s->resampler, s->input_data, read_data);
+ if (s->resamplers) {
+ aubio_resampler_do(s->resamplers[0], s->input_data, read_data);
}
#endif /* HAVE_SAMPLERATE */
@@ -213,9 +220,7 @@
smpl_t **ptr_data;
#ifdef HAVE_SAMPLERATE
if (s->ratio != 1) {
- AUBIO_ERR("source_sndfile: no multi channel resampling yet\n");
- return;
- //ptr_data = s->input_data->data;
+ ptr_data = s->input_mat->data;
} else
#endif /* HAVE_SAMPLERATE */
{
@@ -251,8 +256,15 @@
}
#ifdef HAVE_SAMPLERATE
- if (s->resampler) {
- //aubio_resampler_do(s->resampler, s->input_data, read_data);
+ if (s->resamplers) {
+ for (i = 0; i < input_channels; i++) {
+ fvec_t input_chan, read_chan;
+ input_chan.data = s->input_mat->data[i];
+ input_chan.length = s->input_mat->length;
+ read_chan.data = read_data->data[i];
+ read_chan.length = read_data->length;
+ aubio_resampler_do(s->resamplers[i], &input_chan, &read_chan);
+ }
}
#endif /* HAVE_SAMPLERATE */
@@ -313,11 +325,20 @@
if (!s) return;
aubio_source_sndfile_close(s);
#ifdef HAVE_SAMPLERATE
- if (s->resampler != NULL) {
- del_aubio_resampler(s->resampler);
+ if (s->resamplers != NULL) {
+ uint_t i = 0, input_channels = s->input_channels;
+ for (i = 0; i < input_channels; i ++) {
+ if (s->resamplers[i] != NULL) {
+ del_aubio_resampler(s->resamplers[i]);
+ }
+ }
+ AUBIO_FREE(s->resamplers);
}
if (s->input_data) {
del_fvec(s->input_data);
+ }
+ if (s->input_mat) {
+ del_fmat(s->input_mat);
}
#endif /* HAVE_SAMPLERATE */
if (s->path) AUBIO_FREE(s->path);