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

◆ drain_resampler_init()

void MayaFlux::IO::AudioStreamContext::drain_resampler_init ( )

Drain any samples buffered inside the resampler.

swr_init() and seek+flush sequences can leave delay-compensation samples inside SwrContext. Calling this discards them so that the next decode_frames() call starts from a clean resampler state. Must be called after open() and after every seek+flush pair.

Definition at line 152 of file AudioStreamContext.cpp.

153{
154 if (!swr_context || channels == 0)
155 return;
156
157 constexpr int k_drain_samples = 2048;
158 uint8_t** buf = nullptr;
159 int linesize = 0;
160
161 int alloc = av_samples_alloc_array_and_samples(
162 &buf, &linesize,
163 static_cast<int>(channels), k_drain_samples,
164 AV_SAMPLE_FMT_DBL, 0);
165
166 if (alloc < 0 || !buf)
167 return;
168
169 while (swr_convert(swr_context, buf, k_drain_samples, nullptr, 0) > 0) { }
170
171 av_freep(&buf[0]);
172 av_freep(&buf);
173}
SwrContext * swr_context
Owned; freed in destructor.

References channels, and swr_context.

Referenced by open().

+ Here is the caller graph for this function: