MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ setup_resampler()

bool MayaFlux::IO::SoundFileReader::setup_resampler ( const std::shared_ptr< FFmpegContext > &  ctx)
private

Set up the FFmpeg resampler if needed.

Returns
True if setup succeeded.

Definition at line 240 of file SoundFileReader.cpp.

241{
242 if (!ctx || !ctx->codec_context) {
243 return false;
244 }
245
246 AVChannelLayout out_ch_layout;
247 av_channel_layout_copy(&out_ch_layout, &ctx->codec_context->ch_layout);
248
249 uint32_t out_sample_rate = m_target_sample_rate > 0 ? m_target_sample_rate : ctx->codec_context->sample_rate;
250
251 AVSampleFormat out_sample_fmt = (m_audio_options & AudioReadOptions::DEINTERLEAVE) != AudioReadOptions::NONE
252 ? AV_SAMPLE_FMT_DBLP
253 : AV_SAMPLE_FMT_DBL;
254
255 int ret = swr_alloc_set_opts2(&ctx->swr_context,
256 &out_ch_layout, out_sample_fmt, out_sample_rate,
257 &ctx->codec_context->ch_layout, ctx->codec_context->sample_fmt,
258 ctx->codec_context->sample_rate,
259 0, nullptr);
260
261 av_channel_layout_uninit(&out_ch_layout);
262
263 if (ret < 0 || !ctx->swr_context) {
264 set_error("Failed to allocate resampler");
265 return false;
266 }
267
268 if (swr_init(ctx->swr_context) < 0) {
269 set_error("Failed to initialize resampler");
270 return false;
271 }
272
273 return true;
274}
uint32_t m_target_sample_rate
Target sample rate for resampling (0 = use source rate).
void set_error(const std::string &error) const
Set the last error message.
AudioReadOptions m_audio_options
Audio-specific read options.

References MayaFlux::IO::DEINTERLEAVE, m_audio_options, m_target_sample_rate, MayaFlux::IO::NONE, and set_error().

Referenced by open().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: