+void FFAudioStream::init_swr(int ichs, int ifmt, int irate)
+{
+ if( resample_context ) {
+ if( swr_ichs == ichs && swr_ifmt == ifmt && swr_irate == irate )
+ return;
+ swr_free(&resample_context);
+ }
+ swr_ichs = ichs; swr_ifmt = ifmt; swr_irate = irate;
+ if( ichs == channels && ifmt == AV_SAMPLE_FMT_FLT && irate == sample_rate )
+ return;
+ uint64_t ilayout = av_get_default_channel_layout(ichs);
+ if( !ilayout ) ilayout = ((uint64_t)1<<ichs) - 1;
+ uint64_t olayout = av_get_default_channel_layout(channels);
+ if( !olayout ) olayout = ((uint64_t)1<<channels) - 1;
+ resample_context = swr_alloc_set_opts(NULL,
+ olayout, AV_SAMPLE_FMT_FLT, sample_rate,
+ ilayout, (AVSampleFormat)ifmt, irate,
+ 0, NULL);
+ if( resample_context )
+ swr_init(resample_context);
+}
+