Changeset a95b386 for src/io/source_avcodec.c
- Timestamp:
- Nov 17, 2018, 4:38:29 PM (6 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
- Children:
- ab8e838
- Parents:
- 75f9fff (diff), 2eb52bd (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/source_avcodec.c
r75f9fff ra95b386 90 90 sint_t selected_stream; 91 91 uint_t eof; 92 uint_t multi;93 92 }; 94 93 95 94 // 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); 95 void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s); 98 96 // actually read a frame 99 97 void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, … … 285 283 s->avFrame = avFrame; 286 284 287 // default to mono output 288 aubio_source_avcodec_reset_resampler(s, 0); 285 aubio_source_avcodec_reset_resampler(s); 289 286 290 287 if (s->avr == NULL) goto beach; 291 288 292 289 s->eof = 0; 293 s->multi = 0;294 290 295 291 //av_log_set_level(AV_LOG_QUIET); … … 304 300 } 305 301 306 void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s, 307 uint_t multi) 302 void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s) 308 303 { 309 304 // create or reset resampler to/from mono/multi-channel 310 if ( (multi != s->multi) || (s->avr == NULL)) {305 if ( s->avr == NULL ) { 311 306 int err; 312 307 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); 315 309 #ifdef HAVE_AVRESAMPLE 316 310 AVAudioResampleContext *avr = avresample_alloc_context(); 317 AVAudioResampleContext *oldavr = s->avr;318 311 #elif defined(HAVE_SWRESAMPLE) 319 312 SwrContext *avr = swr_alloc(); 320 SwrContext *oldavr = s->avr;321 313 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */ 322 314 … … 346 338 } 347 339 s->avr = avr; 348 if (oldavr != NULL) {349 #ifdef HAVE_AVRESAMPLE350 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;358 340 } 359 341 } … … 496 478 void aubio_source_avcodec_do(aubio_source_avcodec_t * s, fvec_t * read_data, 497 479 uint_t * read) { 498 uint_t i ;480 uint_t i, j; 499 481 uint_t end = 0; 500 482 uint_t total_wrote = 0; 501 // switch from multi502 if (s->multi == 1) aubio_source_avcodec_reset_resampler(s, 0);503 483 while (total_wrote < s->hop_size) { 504 484 end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote); 505 485 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; 507 492 } 508 493 total_wrote += end; … … 532 517 uint_t end = 0; 533 518 uint_t total_wrote = 0; 534 // switch from mono535 if (s->multi == 0) aubio_source_avcodec_reset_resampler(s, 1);536 519 while (total_wrote < s->hop_size) { 537 520 end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
Note: See TracChangeset
for help on using the changeset viewer.