Changeset 1d01e515


Ignore:
Timestamp:
Sep 23, 2016, 2:43:35 AM (8 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
dab4a4c
Parents:
50a8260
Message:

src/io/source_sndfile.c: add support for multi-channel resampling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_sndfile.c

    r50a8260 r1d01e515  
    6060  uint_t input_hop_size;
    6161#ifdef HAVE_SAMPLERATE
    62   aubio_resampler_t *resampler;
     62  aubio_resampler_t **resamplers;
    6363  fvec_t *input_data;
     64  fmat_t *input_mat;
    6465#endif /* HAVE_SAMPLERATE */
    6566
     
    127128
    128129#ifdef HAVE_SAMPLERATE
    129   s->resampler = NULL;
    130130  s->input_data = NULL;
     131  s->input_mat = NULL;
     132  s->resamplers = NULL;
    131133  if (s->ratio != 1) {
     134    uint_t i;
     135    s->resamplers = AUBIO_ARRAY(aubio_resampler_t*, s->input_channels);
    132136    s->input_data = new_fvec(s->input_hop_size);
    133     s->resampler = new_aubio_resampler(s->ratio, 4);
     137    s->input_mat = new_fmat(s->input_channels, s->input_hop_size);
     138    for (i = 0; i < (uint_t)s->input_channels; i++) {
     139      s->resamplers[i] = new_aubio_resampler(s->ratio, 4);
     140    }
    134141    if (s->ratio > 1) {
    135142      // we would need to add a ring buffer for these
     
    190197
    191198#ifdef HAVE_SAMPLERATE
    192   if (s->resampler) {
    193     aubio_resampler_do(s->resampler, s->input_data, read_data);
     199  if (s->resamplers) {
     200    aubio_resampler_do(s->resamplers[0], s->input_data, read_data);
    194201  }
    195202#endif /* HAVE_SAMPLERATE */
     
    214221#ifdef HAVE_SAMPLERATE
    215222  if (s->ratio != 1) {
    216     AUBIO_ERR("source_sndfile: no multi channel resampling yet\n");
    217     return;
    218     //ptr_data = s->input_data->data;
     223    ptr_data = s->input_mat->data;
    219224  } else
    220225#endif /* HAVE_SAMPLERATE */
     
    252257
    253258#ifdef HAVE_SAMPLERATE
    254   if (s->resampler) {
    255     //aubio_resampler_do(s->resampler, s->input_data, read_data);
     259  if (s->resamplers) {
     260    for (i = 0; i < input_channels; i++) {
     261      fvec_t input_chan, read_chan;
     262      input_chan.data = s->input_mat->data[i];
     263      input_chan.length = s->input_mat->length;
     264      read_chan.data = read_data->data[i];
     265      read_chan.length = read_data->length;
     266      aubio_resampler_do(s->resamplers[i], &input_chan, &read_chan);
     267    }
    256268  }
    257269#endif /* HAVE_SAMPLERATE */
     
    314326  aubio_source_sndfile_close(s);
    315327#ifdef HAVE_SAMPLERATE
    316   if (s->resampler != NULL) {
    317     del_aubio_resampler(s->resampler);
     328  if (s->resamplers != NULL) {
     329    uint_t i = 0, input_channels = s->input_channels;
     330    for (i = 0; i < input_channels; i ++) {
     331      if (s->resamplers[i] != NULL) {
     332        del_aubio_resampler(s->resamplers[i]);
     333      }
     334    }
     335    AUBIO_FREE(s->resamplers);
    318336  }
    319337  if (s->input_data) {
    320338    del_fvec(s->input_data);
     339  }
     340  if (s->input_mat) {
     341    del_fmat(s->input_mat);
    321342  }
    322343#endif /* HAVE_SAMPLERATE */
Note: See TracChangeset for help on using the changeset viewer.