Ignore:
Timestamp:
Nov 17, 2018, 10:19:27 PM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/constantq
Children:
d1d4ad4
Parents:
088760e (diff), a114fe0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into feature/constantq

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_avcodec.c

    r088760e rc03d191  
    9090  sint_t selected_stream;
    9191  uint_t eof;
    92   uint_t multi;
    9392};
    9493
    9594// create or re-create the context when _do or _do_multi is called
    96 void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s,
    97     uint_t multi);
     95void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s);
    9896// actually read a frame
    9997void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s,
     
    285283  s->avFrame = avFrame;
    286284
    287   // default to mono output
    288   aubio_source_avcodec_reset_resampler(s, 0);
     285  aubio_source_avcodec_reset_resampler(s);
    289286
    290287  if (s->avr == NULL) goto beach;
    291288
    292289  s->eof = 0;
    293   s->multi = 0;
    294290
    295291  //av_log_set_level(AV_LOG_QUIET);
     
    304300}
    305301
    306 void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s,
    307     uint_t multi)
     302void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s)
    308303{
    309304  // create or reset resampler to/from mono/multi-channel
    310   if ( (multi != s->multi) || (s->avr == NULL) ) {
     305  if ( s->avr == NULL ) {
    311306    int err;
    312307    int64_t input_layout = av_get_default_channel_layout(s->input_channels);
    313     uint_t output_channels = multi ? s->input_channels : 1;
    314     int64_t output_layout = av_get_default_channel_layout(output_channels);
     308    int64_t output_layout = av_get_default_channel_layout(s->input_channels);
    315309#ifdef HAVE_AVRESAMPLE
    316310    AVAudioResampleContext *avr = avresample_alloc_context();
    317     AVAudioResampleContext *oldavr = s->avr;
    318311#elif defined(HAVE_SWRESAMPLE)
    319312    SwrContext *avr = swr_alloc();
    320     SwrContext *oldavr = s->avr;
    321313#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
    322314
     
    346338    }
    347339    s->avr = avr;
    348     if (oldavr != NULL) {
    349 #ifdef HAVE_AVRESAMPLE
    350       avresample_close( oldavr );
    351 #elif defined(HAVE_SWRESAMPLE)
    352       swr_close ( oldavr );
    353 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
    354       av_free ( oldavr );
    355       oldavr = NULL;
    356     }
    357     s->multi = multi;
    358340  }
    359341}
     
    496478void aubio_source_avcodec_do(aubio_source_avcodec_t * s, fvec_t * read_data,
    497479    uint_t * read) {
    498   uint_t i;
     480  uint_t i, j;
    499481  uint_t end = 0;
    500482  uint_t total_wrote = 0;
    501   // switch from multi
    502   if (s->multi == 1) aubio_source_avcodec_reset_resampler(s, 0);
    503483  while (total_wrote < s->hop_size) {
    504484    end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
    505485    for (i = 0; i < end; i++) {
    506       read_data->data[i + total_wrote] = s->output[i + s->read_index];
     486      read_data->data[i + total_wrote] = 0.;
     487      for (j = 0; j < s->input_channels; j++) {
     488        read_data->data[i + total_wrote] +=
     489          s->output[(i + s->read_index) * s->input_channels + j];
     490      }
     491      read_data->data[i + total_wrote] *= 1./s->input_channels;
    507492    }
    508493    total_wrote += end;
     
    532517  uint_t end = 0;
    533518  uint_t total_wrote = 0;
    534   // switch from mono
    535   if (s->multi == 0) aubio_source_avcodec_reset_resampler(s, 1);
    536519  while (total_wrote < s->hop_size) {
    537520    end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
Note: See TracChangeset for help on using the changeset viewer.