encoding.vorbis #
encoding.vorbis
This module is a thin wrapper around stb_vorbis, which is a public domain Ogg Vorbis audio decoder, originally written by Sean Barrett.
Example:
import encoding.vorbis
x := vorbis.decode_file('coin.ogg')!
dump(x)
unsafe { x.free() }
... may produce something like this:
[x.v:4] x: vorbis.VorbisData{
path: 'coin.ogg'
channels: 2
sample_rate: 48000
len: 5760800
data: &0
}
Note: x.data points to the actual memory block that has the decoded content.
fn decode_file #
fn decode_file(path string) !DecodedSong
decode_file completely decodes the given file from path in memory.
Note: for bigger songs, the memory usage may be disproportionate, since vorbis/ogg songs are usually highly compressed with a lossy encoder.
fn decode_memory #
fn decode_memory(ptr &u8, len i32) !DecodedSong
decode_memory completely decodes the given encoded memory block that is pointed by ptr.
Note: for bigger songs, the memory usage may be disproportionate. Consider using decoding while playing instead, which can conserve the used RAM, at the cost of slightly higher CPU usage.
fn wrapper_version #
fn wrapper_version() string
wrapper_version returns the version of stb_vorbis.c, that this module wraps.
enum VorbisErrorCode #
enum VorbisErrorCode {
no_error
need_more_data = 1 // not a real error
invalid_api_mixing // can not mix API modes
out_of_memory // not enough memory
not_supported // uses floor 0
too_many_channels // STB_VORBIS_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_invalid_setup = 20 // vorbis decoding error (corrupt/invalid stream)
vorbis_invalid_stream // vorbis decoding error
ogg_missing_capture_pattern = 30
ogg_invalid_stream_structure_version
ogg_continued_packet_flag_invalid
ogg_incorrect_stream_serial_number
ogg_invalid_first_page
ogg_bad_packet_type
ogg_cant_find_last_page
ogg_seek_failed
ogg_skeleton_not_supported
}
struct C.stb_vorbis #
struct C.stb_vorbis {}
struct C.stb_vorbis_alloc #
struct C.stb_vorbis_alloc {
pub mut:
alloc_buffer &char
alloc_buffer_length_in_bytes i32
}
struct C.stb_vorbis_info #
struct C.stb_vorbis_info {
pub mut:
sample_rate u32
channels i32
setup_memory_required u32
setup_temp_memory_required u32
max_frame_size i32
}
struct DecodedSong #
struct DecodedSong {
pub mut:
path string
channels i32
sample_rate i32
sample_len i32
data &i16 = unsafe { nil }
}
DecodedSong contains the information about a fully decoded song, that was loaded either by decode_file/1 or by decode_memory/1 .
fn (DecodedSong) free #
fn (mut song DecodedSong) free()
free frees all the resources allocated for the decoded song