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

◆ stb_vorbis_stream_length_in_samples()

uint32_t fl::third_party::vorbis::stb_vorbis_stream_length_in_samples ( stb_vorbis * f)

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

4705{
4706 uint32_t restore_offset, previous_safe;
4707 uint32_t end, last_page_loc;
4708
4710 if (!f->total_samples) {
4711 uint32_t last;
4712 uint32 lo,hi;
4713 char header[6];
4714
4715 // first, store the current decode position so we can restore it
4716 restore_offset = stb_vorbis_get_file_offset(f);
4717
4718 // now we want to seek back 64K from the end (the last page must
4719 // be at most a little less than 64K, but let's allow a little slop)
4720 if (f->stream_len >= 65536 && f->stream_len-65536 >= f->first_audio_page_offset)
4721 previous_safe = f->stream_len - 65536;
4722 else
4723 previous_safe = f->first_audio_page_offset;
4724
4725 set_file_offset(f, previous_safe);
4726 // previous_safe is now our candidate 'earliest known place that seeking
4727 // to will lead to the final page'
4728
4729 if (!vorbis_find_page(f, &end, &last)) {
4730 // if we can't find a page, we're hosed!
4732 f->total_samples = 0xffffffff;
4733 goto done;
4734 }
4735
4736 // check if there are more pages
4737 last_page_loc = stb_vorbis_get_file_offset(f);
4738
4739 // stop when the last_page flag is set, not when we reach eof;
4740 // this allows us to stop short of a 'file_section' end without
4741 // explicitly checking the length of the section
4742 while (!last) {
4743 set_file_offset(f, end);
4744 if (!vorbis_find_page(f, &end, &last)) {
4745 // the last page we found didn't have the 'last page' flag
4746 // set. whoops!
4747 break;
4748 }
4749 //previous_safe = last_page_loc+1; // NOTE: not used after this point, but note for debugging
4750 last_page_loc = stb_vorbis_get_file_offset(f);
4751 }
4752
4753 set_file_offset(f, last_page_loc);
4754
4755 // parse the header
4756 getn(f, (unsigned char *)header, 6);
4757 // extract the absolute granule position
4758 lo = get32(f);
4759 hi = get32(f);
4760 if (lo == 0xffffffff && hi == 0xffffffff) {
4763 goto done;
4764 }
4765 if (hi)
4766 lo = 0xfffffffe; // saturate
4767 f->total_samples = lo;
4768
4769 f->p_last.page_start = last_page_loc;
4770 f->p_last.page_end = end;
4772
4773 done:
4774 set_file_offset(f, restore_offset);
4775 }
4776 return f->total_samples == SAMPLE_unknown ? 0 : f->total_samples;
4777}
bool done
static int32_t error(vorb *f, enum STBVorbisError e) FL_NOEXCEPT
static uint32 vorbis_find_page(stb_vorbis *f, uint32 *end, uint32 *last) FL_NOEXCEPT
static constexpr uint32_t SAMPLE_unknown
static int32_t getn(vorb *z, uint8 *data, int32_t n) 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
static uint32 get32(vorb *f) FL_NOEXCEPT
fl::u32 uint32_t
Definition coder.h:219
constexpr T * end(T(&array)[N]) FL_NOEXCEPT
#define FL_STBV_IS_PUSH_MODE(f)

References done, fl::end(), error(), FL_NOEXCEPT, FL_STBV_IS_PUSH_MODE, get32(), getn(), SAMPLE_unknown, set_file_offset(), stb_vorbis_get_file_offset(), VORBIS_cant_find_last_page, vorbis_find_page(), and VORBIS_invalid_api_mixing.

Referenced by seek_to_sample_coarse(), and stb_vorbis_stream_length_in_seconds().

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