From: Paul Brossier Date: Thu, 26 Sep 2013 19:56:55 +0000 (-0500) Subject: src/io/source_sndfile.c: call a float a float, do the right thing when a trying to... X-Git-Tag: 0.4.0-beta1~110^2~36 X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=50e10a9ea800c0cdef013e81c73cbdff89b6a284;p=aubio.git src/io/source_sndfile.c: call a float a float, do the right thing when a trying to read to a matrix with a number of channels different from the file --- diff --git a/src/io/source_sndfile.c b/src/io/source_sndfile.c index f46e6749..48cc5a83 100644 --- a/src/io/source_sndfile.c +++ b/src/io/source_sndfile.c @@ -58,7 +58,7 @@ struct _aubio_source_sndfile_t { // some temporary memory for sndfile to write at uint_t scratch_size; - smpl_t *scratch_data; + float *scratch_data; }; aubio_source_sndfile_t * new_aubio_source_sndfile(char_t * path, uint_t samplerate, uint_t hop_size) { @@ -198,18 +198,30 @@ void aubio_source_sndfile_do_multi(aubio_source_sndfile_t * s, fmat_t * read_dat data = read_data->data; } - /* de-interleaving data */ - for (j = 0; j < read_samples / input_channels; j++) { - for (i = 0; i < input_channels; i++) { - data[i][j] = (smpl_t)s->scratch_data[input_channels*j+i]; + if (read_data->height < input_channels) { + // destination matrix has less channels than the file; copy only first + // channels of the file, de-interleaving data + for (j = 0; j < read_samples / input_channels; j++) { + for (i = 0; i < read_data->height; i++) { + data[i][j] = (smpl_t)s->scratch_data[j * input_channels + i]; + } + } + } else { + // destination matrix has as many or more channels than the file; copy each + // channel from the file to the destination matrix, de-interleaving data + for (j = 0; j < read_samples / input_channels; j++) { + for (i = 0; i < input_channels; i++) { + data[i][j] = (smpl_t)s->scratch_data[j * input_channels + i]; + } } } - // if read_data has more channels than the file + if (read_data->height > input_channels) { - // copy last channel to all additional channels + // destination matrix has more channels than the file; copy last channel + // of the file to each additional channels, de-interleaving data for (j = 0; j < read_samples / input_channels; j++) { for (i = input_channels; i < read_data->height; i++) { - data[i][j] = s->scratch_data[ j * input_channels + (input_channels - 1)]; + data[i][j] = (smpl_t)s->scratch_data[j * input_channels + (input_channels - 1)]; } } }