+void aubio_source_avcodec_set_multi(aubio_source_avcodec_t * s, uint_t multi) {
+ if ( (multi != s->multi) || (s->avr == NULL) ) {
+ int64_t input_layout = av_get_default_channel_layout(s->input_channels);
+ int64_t mono_layout = av_get_default_channel_layout(1);
+ if (s->avr != NULL) {
+ avresample_close( s->avr );
+ av_free ( s->avr );
+ s->avr = NULL;
+ }
+ AVAudioResampleContext *avr = s->avr;
+ avr = avresample_alloc_context();
+
+ av_opt_set_int(avr, "in_channel_layout", input_layout, 0);
+ if (multi) {
+ av_opt_set_int(avr, "out_channel_layout", input_layout, 0);
+ } else {
+ av_opt_set_int(avr, "out_channel_layout", mono_layout, 0);
+ }
+ av_opt_set_int(avr, "in_sample_rate", s->input_samplerate, 0);
+ av_opt_set_int(avr, "out_sample_rate", s->samplerate, 0);
+ av_opt_set_int(avr, "in_sample_fmt", s->avCodecCtx->sample_fmt, 0);
+ av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_FLT, 0);
+ int err;
+ if ( ( err = avresample_open(avr) ) < 0) {
+ char errorstr[256];
+ av_strerror (err, errorstr, sizeof(errorstr));
+ AUBIO_ERR("Could not open AVAudioResampleContext for %s (%s)\n",
+ s->path, errorstr);
+ //goto beach;
+ return;
+ }
+ s->avr = avr;
+ s->multi = multi;
+ }
+}
+