package vendor:stb/vorbis
Overview
Bindings for stb_vorbis.c.
Index
Types (5)
Constants (4)
Variables (0)
This section is empty.
Procedures (27)
Procedure Groups (0)
This section is empty.
Types
Error ¶
Error :: enum i32 { none = 0, need_more_data = 1, // not a real error invalid_api_mixing, // can't mix API modes outofmem, // not enough memory feature_not_supported, // uses floor 0 too_many_channels, // MAX_CHANNELS is too small file_open_failure, // fopen() failed seek_without_length, // can't seek in unknown-length file unexpected_eof = 10, // file is truncated? seek_invalid, // seek past EOF // vorbis errors: invalid_setup = 20, invalid_stream, // ogg errors: missing_capture_pattern = 30, invalid_stream_structure_version, continued_packet_flag_invalid, incorrect_stream_serial_number, invalid_first_page, bad_packet_type, cant_find_last_page, seek_failed, ogg_skeleton_not_supported, }
Related Procedures With Parameters
vorbis ¶
vorbis :: struct {}
Related Procedures With Parameters
- close
- decode_frame_pushdata
- flush_pushdata
- get_comment
- get_error
- get_file_offset
- get_frame_float
- get_frame_short
- get_frame_short_interleaved
- get_info
- get_sample_offset
- get_samples_float
- get_samples_float_interleaved
- get_samples_short
- get_samples_short_interleaved
- seek
- seek_frame
- seek_start
- stream_length_in_samples
- stream_length_in_seconds
Related Procedures With Returns
vorbis_alloc ¶
Related Procedures With Parameters
Constants
FAST_HUFFMAN_LENGTH ¶
FAST_HUFFMAN_LENGTH :: 10
FAST_HUFFMAN_LENGTH [number] sets the log size of the huffman-acceleration table. Maximum supported value is 24. with larger numbers, more decodings are O(1), but the table size is larger so worse cache missing, so you'll have to probe (and try multiple ogg vorbis files) to find the sweet spot.
MAX_CHANNELS ¶
MAX_CHANNELS :: 16
MAX_CHANNELS [number] globally define this to the maximum number of channels you need. The spec does not put a restriction on channels except that the count is stored in a byte, so 255 is the hard limit. Reducing this saves about 16 bytes per value, so using 16 saves (255-16)*16 or around 4KB. Plus anything other memory usage I forgot to account for. Can probably go as low as 8 (7.1 audio), 6 (5.1 audio), or 2 (stereo only).
NO_STDIO ¶
NO_STDIO :: ODIN_ARCH == .wasm32 || ODIN_ARCH == .wasm64p32
PUSHDATA_CRC_COUNT ¶
PUSHDATA_CRC_COUNT :: 4
PUSHDATA_CRC_COUNT [number] after a flush_pushdata(), stb_vorbis begins scanning for the next valid page, without backtracking. when it finds something that looks like a page, it streams through it and verifies its CRC32. Should that validation fail, it keeps scanning. But it's possible that while streaming through to check the CRC32 of one candidate page, it sees another candidate page. This #define determines how many "overlapping" candidate pages it can search at once. Note that "real" pages are typically ~4KB to ~8KB, whereas garbage pages could be as big as 64KB, but probably average ~16KB. So don't hose ourselves by scanning an apparent 64KB page and missing a ton of real ones in the interim; so minimum of 2
Variables
This section is empty.
Procedures
close ¶C · stb_vorbis_closeSource · stb_vorbis.odin:97
close :: proc "c" (f: ^vorbis) ---
close an ogg vorbis file and free all memory in use
decode_filename ¶C · stb_vorbis_decode_filenameSource · stb_vorbis.odin:205
decode_filename :: proc "c" ( filename: cstring, channels, sample_rate: ^i32, output: ^[^]i16, ) -> i32 ---
decode an entire file and output the data interleaved into a malloc()ed buffer stored in *output. The return value is the number of samples decoded, or -1 if the file could not be opened or was not an ogg vorbis file. When you're done with it, just free() the pointer returned in *output.
decode_frame_pushdata ¶C · stb_vorbis_decode_frame_pushdataSource · stb_vorbis.odin:167
decode_frame_pushdata :: proc "c" ( f: ^vorbis, datablock: [^]u8, datablock_length_in_bytes: i32, channels: ^i32, output: ^[^]^f32, samples: ^i32, ) -> i32 ---
decode a frame of audio sample data if possible from the passed-in data block
return value: number of bytes we used from datablock
possible cases: 0 bytes used, 0 samples output (need more data) N bytes used, 0 samples output (resynching the stream, keep going) N bytes used, M samples output (one frame of data) note that after opening a file, you will ALWAYS get one N-bytes,0-sample frame, because Vorbis always "discards" the first frame.
Note that on resynch, stb_vorbis will rarely consume all of the buffer, instead only datablock_length_in_bytes-3 or less. This is because it wants to avoid missing parts of a page header if they cross a datablock boundary, without writing state-machiney code to record a partial detection.
The number of channels returned are stored in *channels (which can be
NULL--it is always the same as the number of channels reported by
get_info). *output will contain an array of float* buffers, one per
channel. In other words, (*output)[0][0] contains the first sample from
the first channel, and (*output)[1][0] contains the first sample from
the second channel.
*output points into stb_vorbis's internal output buffer storage; these
buffers are owned by stb_vorbis and application code should not free
them or modify their contents. They are transient and will be overwritten
once you ask for more data to get decoded, so be sure to grab any data
you need before then.
decode_memory ¶C · stb_vorbis_decode_memorySource · stb_vorbis.odin:207
flush_pushdata ¶C · stb_vorbis_flush_pushdataSource · stb_vorbis.odin:185
flush_pushdata :: proc "c" (f: ^vorbis) ---
inform stb_vorbis that your next datablock will not be contiguous with previous ones (e.g. you've seeked in the data); future attempts to decode frames will cause stb_vorbis to resynchronize (as noted above), and once it sees a valid Ogg page (typically 4-8KB, as large as 64KB), it will begin decoding the next frame.
if you want to seek using pushdata, you need to seek in your file, then call stb_vorbis_flush_pushdata(), then start calling decoding, then once decoding is returning you data, call stb_vorbis_get_sample_offset, and if you don't like the result, seek your file again and repeat.
get_comment ¶C · stb_vorbis_get_commentSource · stb_vorbis.odin:91
get_comment :: proc "c" (f: ^vorbis) -> vorbis_comment ---
get ogg comments
get_error ¶C · stb_vorbis_get_errorSource · stb_vorbis.odin:94
get the last error detected (clears it, too)
get_file_offset ¶C · stb_vorbis_get_file_offsetSource · stb_vorbis.odin:108
returns the current seek point within the file, or offset from the beginning of the memory buffer. In pushdata mode it returns 0.
get_frame_float ¶C · stb_vorbis_get_frame_floatSource · stb_vorbis.odin:265
decode the next frame and return the number of samples. the number of
channels returned are stored in *channels (which can be NULL--it is always
the same as the number of channels reported by get_info). *output will
contain an array of float* buffers, one per channel. These outputs will
be overwritten on the next call to stb_vorbis_get_frame_*.
You generally should not intermix calls to stb_vorbis_get_frame_*()
and stb_vorbis_get_samples_*(), since the latter calls the former.
get_frame_short ¶C · stb_vorbis_get_frame_shortSource · stb_vorbis.odin:279
get_frame_short_interleaved ¶C · stb_vorbis_get_frame_short_interleavedSource · stb_vorbis.odin:278
get_frame_short_interleaved :: proc "c" ( f: ^vorbis, num_c: i32, buffer: [^]i16, num_shorts: i32, ) -> i32 ---
decode the next frame and return the number of samples per channel. Note that for interleaved data, you pass in the number of shorts (the size of your array), but the return value is the number of samples per channel, not the total number of samples.
The data is coerced to the number of channels you request according to the channel coercion rules (see below). You must pass in the size of your buffer(s) so that stb_vorbis will not overwrite the end of the buffer. The maximum buffer size needed can be gotten from get_info(); however, the Vorbis I specification implies an absolute maximum of 4096 samples per channel.
get_info ¶C · stb_vorbis_get_infoSource · stb_vorbis.odin:88
get_info :: proc "c" (f: ^vorbis) -> vorbis_info ---
get general information about the file
get_sample_offset ¶C · stb_vorbis_get_sample_offsetSource · stb_vorbis.odin:104
this function returns the offset (in samples) from the beginning of the file that will be returned by the next decode, if it is known, or -1 otherwise. after a flush_pushdata() call, this may take a while before it becomes valid again. NOT WORKING YET after a seek with PULLDATA API
get_samples_float ¶C · stb_vorbis_get_samples_floatSource · stb_vorbis.odin:299
get_samples_float_interleaved ¶C · stb_vorbis_get_samples_float_interleavedSource · stb_vorbis.odin:298
get_samples_float_interleaved :: proc "c" ( f: ^vorbis, channels: i32, buffer: [^]f32, num_floats: i32, ) -> i32 ---
gets num_samples samples, not necessarily on a frame boundary--this requires buffering so you have to supply the buffers. DOES NOT APPLY THE COERCION RULES. Returns the number of samples stored per channel; it may be less than requested at the end of the file. If there are no more samples in the file, returns 0.
get_samples_short ¶C · stb_vorbis_get_samples_shortSource · stb_vorbis.odin:307
get_samples_short_interleaved ¶C · stb_vorbis_get_samples_short_interleavedSource · stb_vorbis.odin:306
get_samples_short_interleaved :: proc "c" ( f: ^vorbis, channels: i32, buffer: [^]i16, num_shorts: i32, ) -> i32 ---
gets num_samples samples, not necessarily on a frame boundary--this requires buffering so you have to supply the buffers. Applies the coercion rules above to produce 'channels' channels. Returns the number of samples stored per channel; it may be less than requested at the end of the file. If there are no more samples in the file, returns 0.
open_file ¶C · stb_vorbis_open_fileSource · stb_vorbis.odin:229
open_file :: proc "c" ( f: ^c.FILE, close_handle_on_close: b32, error: ^Error, alloc_buffer: ^vorbis_alloc, ) -> ^vorbis ---
create an ogg vorbis decoder from an open FILE *, looking for a stream at the current seek point (ftell). on failure, returns NULL and sets error. note that stb_vorbis must "own" this stream; if you seek it in between calls to stb_vorbis, it will become confused. Moreover, if you attempt to perform stb_vorbis_seek_() operations on this file, it will assume it owns the entire rest of the file after the start point. Use the next function, stb_vorbis_open_file_section(), to limit it.
open_file_section ¶C · stb_vorbis_open_file_sectionSource · stb_vorbis.odin:237
open_file_section :: proc "c" ( f: ^c.FILE, close_handle_on_close: b32, error: ^Error, alloc_buffer: ^vorbis_alloc, len: u32, ) -> ^vorbis ---
create an ogg vorbis decoder from an open FILE *, looking for a stream at the current seek point (ftell); the stream will be of length 'len' bytes. on failure, returns NULL and sets *error. note that stb_vorbis must "own" this stream; if you seek it in between calls to stb_vorbis, it will become confused.
open_filename ¶C · stb_vorbis_open_filenameSource · stb_vorbis.odin:219
open_filename :: proc "c" ( filename: cstring, error: ^Error, alloc_buffer: ^vorbis_alloc, ) -> ^vorbis ---
create an ogg vorbis decoder from a filename via fopen(). on failure, returns NULL and sets *error (possibly to VORBIS_file_open_failure).
open_memory ¶C · stb_vorbis_open_memorySource · stb_vorbis.odin:213
open_memory :: proc "c" ( data: [^]u8, len: i32, error: ^Error, alloc_buffer: ^vorbis_alloc, ) -> ^vorbis ---
create an ogg vorbis decoder from an ogg vorbis stream in memory (note this must be the entire stream!). on failure, returns NULL and sets *error
open_pushdata ¶C · stb_vorbis_open_pushdataSource · stb_vorbis.odin:132
open_pushdata :: proc "c" ( datablock: [^]u8, datablock_length_in_bytes: i32, datablock_memory_consumed_in_bytes: ^i32, error: ^Error, alloc_buffer: ^vorbis_alloc, ) -> ^vorbis ---
create a vorbis decoder by passing in the initial data block containing the ogg&vorbis headers (you don't need to do parse them, just provide the first N bytes of the file--you're told if it's not enough, see below) on success, returns an stb_vorbis *, does not set error, returns the amount of data parsed/consumed on this call in *datablock_memory_consumed_in_bytes; on failure, returns NULL on error and sets *error, does not change *datablock_memory_consumed if returns NULL and *error is VORBIS_need_more_data, then the input block was incomplete and you need to pass in a larger block from the start of the file
seek ¶C · stb_vorbis_seekSource · stb_vorbis.odin:248
seek_frame ¶C · stb_vorbis_seek_frameSource · stb_vorbis.odin:247
these functions seek in the Vorbis file to (approximately) 'sample_number'.
after calling seek_frame(), the next call to get_frame_*() will include
the specified sample. after calling stb_vorbis_seek(), the next call to
stb_vorbis_get_samples_* will start with the specified sample. If you
do not need to seek to EXACTLY the target sample when using get_samples_*,
you can also use seek_frame().
seek_start ¶C · stb_vorbis_seek_startSource · stb_vorbis.odin:251
this function is equivalent to stb_vorbis_seek(f,0)
stream_length_in_samples ¶C · stb_vorbis_stream_length_in_samplesSource · stb_vorbis.odin:254
these functions return the total length of the vorbis stream
stream_length_in_seconds ¶C · stb_vorbis_stream_length_in_secondsSource · stb_vorbis.odin:255
Procedure Groups
This section is empty.
Source Files
Generation Information
Generated with odin version dev-2026-10 (vendor "odin") Windows_amd64 @ 2026-10-14 23:35:37.403868600 +0000 UTC