FastLED 3.9.15
Loading...
Searching...
No Matches

◆ vorbis_find_page()

static uint32 fl::third_party::vorbis::vorbis_find_page ( stb_vorbis * f,
uint32 * end,
uint32 * last )
static

Definition at line 4319 of file stb_vorbis.cpp.hpp.

4320{
4321 for(;;) {
4322 int32_t n;
4323 if (f->eof) return 0;
4324 n = get8(f);
4325 if (n == 0x4f) { // page header candidate
4326 uint32_t retry_loc = stb_vorbis_get_file_offset(f);
4327 int32_t i;
4328 // check if we're off the end of a file_section stream
4329 if (retry_loc - 25 > f->stream_len)
4330 return 0;
4331 // check the rest of the header
4332 for (i=1; i < 4; ++i)
4333 if (get8(f) != ogg_page_header[i])
4334 break;
4335 if (f->eof) return 0;
4336 if (i == 4) {
4337 uint8 header[27];
4338 uint32 i, crc, goal, len;
4339 for (i=0; i < 4; ++i)
4340 header[i] = ogg_page_header[i];
4341 for (; i < 27; ++i)
4342 header[i] = get8(f);
4343 if (f->eof) return 0;
4344 if (header[4] != 0) goto invalid;
4345 goal = header[22] + (header[23] << 8) + ((uint32)header[24]<<16) + ((uint32)header[25]<<24);
4346 for (i=22; i < 26; ++i)
4347 header[i] = 0;
4348 crc = 0;
4349 for (i=0; i < 27; ++i)
4350 crc = crc32_update(crc, header[i]);
4351 len = 0;
4352 for (i=0; i < header[26]; ++i) {
4353 int32_t s = get8(f);
4354 crc = crc32_update(crc, s);
4355 len += s;
4356 }
4357 if (len && f->eof) return 0;
4358 for (i=0; i < len; ++i)
4359 crc = crc32_update(crc, get8(f));
4360 // finished parsing probable page
4361 if (crc == goal) {
4362 // we could now check that it's either got the last
4363 // page flag set, OR it's followed by the capture
4364 // pattern, but I guess TECHNICALLY you could have
4365 // a file with garbage between each ogg page and recover
4366 // from it automatically? So even though that paranoia
4367 // might decrease the chance of an invalid decode by
4368 // another 2^32, not worth it since it would hose those
4369 // invalid-but-useful files?
4370 if (end)
4372 if (last) {
4373 if (header[5] & 0x04)
4374 *last = 1;
4375 else
4376 *last = 0;
4377 }
4378 set_file_offset(f, retry_loc-1);
4379 return 1;
4380 }
4381 }
4382 invalid:
4383 // not a valid page, so rewind and look for next one
4384 set_file_offset(f, retry_loc);
4385 }
4386 }
4387}
static uint8 ogg_page_header[4]
FL_ALWAYS_INLINE uint32 crc32_update(uint32 crc, uint8 byte) FL_NOEXCEPT
static uint8 get8(vorb *z) FL_NOEXCEPT
uint32_t stb_vorbis_get_file_offset(stb_vorbis *f) FL_NOEXCEPT
static int32_t set_file_offset(stb_vorbis *f, uint32_t loc) FL_NOEXCEPT
fl::u32 uint32_t
Definition coder.h:219
fl::i32 int32_t
Definition coder.h:220
constexpr T * end(T(&array)[N]) FL_NOEXCEPT

References crc32_update(), fl::end(), FL_NOEXCEPT, get8(), ogg_page_header, set_file_offset(), and stb_vorbis_get_file_offset().

Referenced by go_to_page_before(), seek_to_sample_coarse(), and stb_vorbis_stream_length_in_samples().

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