MCPcopy Create free account
hub / github.com/SFML/SFML / seek

Method seek

src/SFML/Audio/SoundFileReaderFlac.cpp:331–357  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

329
330////////////////////////////////////////////////////////////
331void SoundFileReaderFlac::seek(std::uint64_t sampleOffset)
332{
333 assert(m_decoder && "No decoder available. Call SoundFileReaderFlac::open() to create a new one.");
334
335 // Reset the callback data (the "write" callback will be called)
336 m_clientData.buffer = nullptr;
337 m_clientData.remaining = 0;
338 m_clientData.leftovers.clear();
339
340 // FLAC decoder expects absolute sample offset, so we take the channel count out
341 if (sampleOffset < m_clientData.info.sampleCount)
342 {
343 // The "write" callback will populate the leftovers buffer with the first batch of samples from the
344 // seek destination, and since we want that data in this typical case, we don't re-clear it afterward
345 FLAC__stream_decoder_seek_absolute(m_decoder.get(), sampleOffset / m_clientData.info.channelCount);
346 }
347 else
348 {
349 // FLAC decoder can't skip straight to EOF, so we short-seek by one sample and skip the rest
350 FLAC__stream_decoder_seek_absolute(m_decoder.get(),
351 (m_clientData.info.sampleCount / m_clientData.info.channelCount) - 1);
352 FLAC__stream_decoder_skip_single_frame(m_decoder.get());
353
354 // This was re-populated during the seek, but we're skipping everything in this, so we need it emptied
355 m_clientData.leftovers.clear();
356 }
357}
358
359
360////////////////////////////////////////////////////////////

Callers 1

streamSeekFunction · 0.45

Calls 2

getMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected