### Basic Opus Encoding and Decoding Source: https://docs.rs/ruopus/0.1.2/ruopus/struct.OpusEncoder.html Example demonstrating how to initialize an encoder and decoder, encode a frame of silence, and decode the resulting packet. ```rust use ruopus::{OpusEncoder, OpusDecoder}; let mut enc = OpusEncoder::new(1); let mut dec = OpusDecoder::new(1); let frame = vec![0.0f32; 960]; // 20 ms of mono silence let packet = enc.encode(&frame, 64).unwrap(); let pcm = dec.decode_packet(&packet).unwrap(); assert_eq!(pcm.len(), 960); // The decoder finishes on the encoder's range state - bit exactness. assert_eq!(dec.final_range(), enc.final_range()); ``` -------------------------------- ### Page::parse Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.Page.html Parses one Ogg page from the start of a byte slice, verifying its CRC and returning the page along with the number of bytes occupied. ```APIDOC ## pub fn parse(data: &'a [u8]) -> Result<(Self, usize), OggError> ### Description Parses one page from the start of `data`, verifying its CRC. Returns the page and the total number of bytes it occupies. ### Parameters - **data** (&'a [u8]) - Required - The byte slice containing the Ogg page data. ### Errors - `OggError::MissingCapturePattern`: If `data` does not begin with `OggS`. - `OggError::Truncated`: If the declared length overruns `data`. - `OggError::BadCrc`: On checksum mismatch. - `OggError::UnsupportedVersion`: For any version other than 0. ``` -------------------------------- ### decode_coarse_energy Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/energy/fn.decode_coarse_energy.html Decodes the coarse energy for bands start..end (RFC 6716 §4.3.2.1, unquant_coarse_energy). ```APIDOC ## Function: decode_coarse_energy ### Description Decodes the coarse energy for bands `start..end` (RFC 6716 §4.3.2.1, `unquant_coarse_energy`). ### Signature `pub fn decode_coarse_energy(dec: &mut RangeDecoder<'_>, state: &mut EnergyState, start: usize, end: usize, intra: bool, channels: usize, lm: usize, budget_bits: u32)` ### Parameters - **dec** (&mut RangeDecoder<'_>) - The range decoder instance. - **state** (&mut EnergyState) - The current energy state. - **start** (usize) - The starting band index. - **end** (usize) - The ending band index. - **intra** (bool) - If true, disables the time-domain predictor. - **channels** (usize) - Number of channels. - **lm** (usize) - The frame-size exponent (frame duration 120 << lm samples). - **budget_bits** (u32) - The frame size in bits; affects fallback behavior for low bit budgets. ``` -------------------------------- ### pub fn init_caps(lm: usize, channels: usize) -> [i32; 21] Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/rate/fn.init_caps.html Calculates the maximum allocation per band in 1/8 bits. ```APIDOC ## init_caps ### Description Calculates the maximum allocation per band in 1/8 bits. ### Signature `pub fn init_caps(lm: usize, channels: usize) -> [i32; 21]` ### Parameters - **lm** (usize) - The allocation parameter. - **channels** (usize) - The number of channels. ### Returns - **[i32; 21]** - An array representing the maximum allocation per band. ``` -------------------------------- ### OggOpusWriter::new Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.OggOpusWriter.html Initializes a new OggOpusWriter and begins the stream by writing the ID and comment header pages. ```APIDOC ## pub fn new(head: &OpusHead, tags: &OpusTags, serial: u32) -> Self ### Description Begins a new Ogg Opus stream by writing the ID and comment header pages. ### Parameters - **head** (&OpusHead) - Required - The Opus header configuration. - **tags** (&OpusTags) - Required - The Opus metadata tags. - **serial** (u32) - Required - The serial number for the Ogg stream. ``` -------------------------------- ### Configuration Methods Source: https://docs.rs/ruopus/0.1.2/ruopus/struct.OpusEncoder.html Methods for configuring the encoder's behavior, including bandwidth, bitrate, signal type, and application profile. ```APIDOC ## Configuration Methods ### set_bandwidth(bandwidth: Bandwidth) Forces the coded audio bandwidth. Calling this pins the bandwidth, overriding automatic selection. ### set_auto_bandwidth() Restores automatic bandwidth selection, allowing the encoder to pick the bandwidth based on signal content. ### set_signal(signal: Signal) Sets the signal-content hint (Voice, Music, or Auto) to bias the automatic mode decision. ### set_application(application: Application) Sets the coding application profile (RestrictedLowDelay, Voip, or Audio). ### set_max_bandwidth(bandwidth: Bandwidth) Caps the bandwidth that the automatic selection may choose. ### set_bitrate(bitrate: Option) Sets the target bitrate in bits/s. Passing None restores CBR mode. ``` -------------------------------- ### init_caps function signature Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/rate/fn.init_caps.html Displays the function signature for initializing band capacities. ```rust pub fn init_caps(lm: usize, channels: usize) -> [i32; 21] ``` -------------------------------- ### SilkDecoder::new Source: https://docs.rs/ruopus/0.1.2/ruopus/silk/api/struct.SilkDecoder.html Creates a new instance of the SilkDecoder. ```APIDOC ## pub fn new() -> Self ### Description Creates a new decoder instance. ### Signature `pub fn new() -> Self` ``` -------------------------------- ### Create a new PageWriter Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.PageWriter.html Initializes a new writer for a logical bitstream using a specific serial number. ```rust pub const fn new(serial: u32) -> Self ``` -------------------------------- ### CeltEncoder Methods Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/encoder/struct.CeltEncoder.html Methods available for initializing and using the CeltEncoder. ```APIDOC ## new() Creates a mono 48 kHz encoder. ## with_channels(channels: usize) Creates a 48 kHz encoder with 1 or 2 channels. Panics unless channels is 1 or 2. ## set_complexity(complexity: u8) Sets the encode complexity 0-10 (clamped), gating the analysis stages. ## encode_frame(pcm: &[f32], nb_bytes: usize) -> Vec Encodes one fullband frame of pcm (interleaved f32 in [-1, 1]; 120, 240, 480 or 960 samples per channel at 48 kHz) into nb_bytes. Panics on invalid frame sizes or byte budgets outside 2..=1275. ## encode_frame_bw(pcm: &[f32], nb_bytes: usize, end: usize) -> Vec Encodes one frame coding bands 0..end. Panics on invalid frame sizes, byte budgets outside 2..=1275, or end outside 1..=21. ## final_range() -> u32 The range state after the last encoded frame. ## set_target_bitrate(bitrate: Option) Sets the VBR target bitrate in bits/s. None restores CBR. ## last_transient() -> bool Whether the last frame was detected as a transient and coded with short blocks. ## last_pitch() -> (usize, f32) The pitch period (samples) and gain the pre-filter analysis chose for the last frame. ``` -------------------------------- ### PageReader::new Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.PageReader.html Creates a new PageReader instance to iterate over a complete physical Ogg bitstream provided as a byte slice. ```APIDOC ## pub const fn new(data: &'a [u8]) -> Self ### Description Creates a reader over a complete physical bitstream. ### Parameters - **data** (&[u8]) - Required - The byte slice containing the Ogg bitstream data. ``` -------------------------------- ### OggOpusReader::new Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.OggOpusReader.html Creates a new OggOpusReader by parsing the headers of the first Opus logical bitstream in the provided data. ```APIDOC ## fn new(data: &[u8]) -> Result ### Description Parses the headers of the first Opus logical bitstream in the provided byte slice. ### Parameters - **data** (&[u8]) - Required - The raw Ogg data containing the Opus bitstream. ### Errors - Returns `OggOpusError::NoOpusStream` if no BOS page carries an `OpusHead` packet. - Propagates header errors from `OpusHead::parse` and `OpusTags::parse`. ``` -------------------------------- ### Push a packet to the writer Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.PageWriter.html Appends a packet to the bitstream and emits full pages into the provided output buffer. ```rust pub fn push( &mut self, out: &mut Vec, packet: &[u8], granule_position: u64, end_of_stream: bool, ) ``` -------------------------------- ### CeltDecoder::new Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/decoder/struct.CeltDecoder.html Creates a new CELT decoder instance for a specified number of channels. ```APIDOC ## pub fn new(channels: usize) -> Self ### Description Creates a decoder producing `channels` output channels (1 or 2). ### Parameters - **channels** (usize) - Required - Number of output channels (1 or 2). ### Panics Panics if `channels` is not 1 or 2. ``` -------------------------------- ### OggOpusReader Methods Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.OggOpusReader.html Methods for accessing stream metadata and iterating through audio packets. ```APIDOC ## OggOpusReader Methods ### head() Returns the identification header (`OpusHead`). ### tags() Returns the comment header (`OpusTags`). ### serial() Returns the serial number of the Opus logical bitstream (u32). ### pcm_duration_48k() Returns the total PCM duration in 48 kHz samples as an `Option`. Returns `None` if the stream has no audio page with a granule position. ### next() Advances to the next audio data packet, returning an `Option`. Resolves granule positions per packet. ``` -------------------------------- ### OpusEncoder::new Source: https://docs.rs/ruopus/0.1.2/ruopus/struct.OpusEncoder.html Creates a new OpusEncoder instance for a specified number of channels. ```APIDOC ## pub fn new(channels: usize) -> Self ### Description Creates an encoder for 1 or 2 channels at 48 kHz, fullband. ### Parameters - **channels** (usize) - Required - The number of channels (1 or 2). ### Panics Panics unless channels is 1 or 2. ``` -------------------------------- ### OpusHead::family0 Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.OpusHead.html Creates a standard family-0 header for mono or stereo streams. ```APIDOC ## pub fn family0(channels: u8, pre_skip: u16, input_sample_rate: u32) -> Self ### Description Creates a standard family-0 header for mono or stereo configurations. ### Panics Panics if `channels` is not 1 or 2. ``` -------------------------------- ### OpusDecoder::new Source: https://docs.rs/ruopus/0.1.2/ruopus/struct.OpusDecoder.html Creates a new Opus decoder instance configured for a specific number of channels at 48 kHz. ```APIDOC ## pub fn new(channels: usize) -> Self ### Description Creates a decoder producing `channels` (1 or 2) at 48 kHz. ### Parameters - **channels** (usize) - Required - The number of audio channels (must be 1 or 2). ``` -------------------------------- ### SilkEncoder::new Source: https://docs.rs/ruopus/0.1.2/ruopus/struct.SilkEncoder.html Creates a new instance of the SilkEncoder with a specified internal sampling rate and subframe count. ```APIDOC ## pub fn new(fs_khz: i32, nb_subfr: usize) -> Self ### Description Initializes a new SILK encoder for a mono stream. ### Parameters - **fs_khz** (i32) - The internal sampling rate in kHz (must be 8, 12, or 16). - **nb_subfr** (usize) - The number of subframes (4 for 20ms, 2 for 10ms). ``` -------------------------------- ### pub fn pvq_codebook_size(n: usize, k: usize) -> u32 Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/cwrs/fn.pvq_codebook_size.html Calculates the size of the PVQ codebook using the formula V(N, K) = U(N, K) + U(N, K + 1). Requires n >= 2 and k >= 1. ```APIDOC ## Function: pvq_codebook_size ### Description Calculates the size of the PVQ codebook, which is the number of N-dimensional vectors of K signed pulses. The result is guaranteed to fit in 32 bits for all (N, K) pairs produced by CELT's bit allocation. ### Signature `pub fn pvq_codebook_size(n: usize, k: usize) -> u32` ### Parameters - **n** (usize) - The dimension of the vector. Must be >= 2. - **k** (usize) - The number of pulses. Must be >= 1. ### Returns - **u32** - The calculated size of the codebook. ``` -------------------------------- ### pub fn pulses2bits(band: usize, lm: i32, pulses: i32) -> i32 Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/rate/fn.pulses2bits.html Calculates the cost in 1/8 bits of pulses pseudo-pulses in the specified band and lm. ```APIDOC ## Function: pulses2bits ### Description Calculates the cost in 1/8 bits of `pulses` pseudo-pulses in `(band, lm)`. ### Signature `pub fn pulses2bits(band: usize, lm: i32, pulses: i32) -> i32` ### Parameters - **band** (usize) - The band index. - **lm** (i32) - The lm parameter. - **pulses** (i32) - The number of pseudo-pulses. ### Returns - **i32** - The cost in 1/8 bits. ``` -------------------------------- ### Iterator::next Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.PageReader.html Advances the iterator and returns the next Ogg page in the stream. ```APIDOC ## fn next(&mut self) -> Option> ### Description Advances the iterator and returns the next value. If the stream is exhausted or corrupted beyond recovery, it returns None. ``` -------------------------------- ### pub fn decode_fine_energy Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/energy/fn.decode_fine_energy.html Decodes the fine energy refinement (RFC 6716 §4.3.2.2, unquant_fine_energy). The refinement maps to (f + 1/2) / 2^B_i - 1/2, where fine_quant[i] is the bit count B_i from the allocation. ```APIDOC ## Function: decode_fine_energy ### Signature `pub fn decode_fine_energy(dec: &mut RangeDecoder<'_>, state: &mut EnergyState, start: usize, end: usize, fine_quant: &[i32], channels: usize)` ### Description Decodes the fine energy refinement as defined in RFC 6716 §4.3.2.2 (unquant_fine_energy). The refinement maps to (f + 1/2) / 2^B_i - 1/2, where `fine_quant[i]` represents the bit count B_i from the allocation. ### Parameters - **dec** (&mut RangeDecoder<'_>) - The range decoder instance. - **state** (&mut EnergyState) - The current energy state. - **start** (usize) - The start index. - **end** (usize) - The end index. - **fine_quant** (&[i32]) - The bit count array from the allocation. - **channels** (usize) - The number of channels. ``` -------------------------------- ### MdctLookup::new Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/mdct/struct.MdctLookup.html Builds a new lookup table for a transform family of size n. ```APIDOC ## pub fn new(n: usize) -> Self ### Description Builds the lookup for transform family size `n` (clt_mdct_init). ### Parameters - **n** (usize) - The transform family size. ``` -------------------------------- ### PageWriter::push Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.PageWriter.html Appends a packet to the bitstream and emits full pages into the provided buffer. ```APIDOC ## pub fn push(&mut self, out: &mut Vec, packet: &[u8], granule_position: u64, end_of_stream: bool) ### Description Appends one packet, emitting full pages into `out` as needed. The `granule_position` is recorded on the page where the packet completes. ### Parameters - **out** (&mut Vec) - Required - The output buffer for emitted pages. - **packet** (&[u8]) - Required - The packet data to append. - **granule_position** (u64) - Required - The codec-defined position as of the end of this packet. - **end_of_stream** (bool) - Required - Flag indicating if this is the end of the stream. ``` -------------------------------- ### PageWriter::new Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.PageWriter.html Creates a new PageWriter instance for a logical bitstream with a specified serial number. ```APIDOC ## pub const fn new(serial: u32) -> Self ### Description Creates a writer for a logical bitstream with the given serial number. ### Parameters - **serial** (u32) - Required - The serial number for the logical bitstream. ``` -------------------------------- ### CeltDecoder::with_rate Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/decoder/struct.CeltDecoder.html Creates a new CELT decoder instance with a specific sample rate. ```APIDOC ## pub fn with_rate(channels: usize, fs_hz: u32) -> Self ### Description Creates a decoder producing output at `fs_hz` (48/24/16/12/8 kHz). ### Parameters - **channels** (usize) - Required - Number of output channels. - **fs_hz** (u32) - Required - Sample rate in Hz. ### Panics Panics on unsupported rates or channel counts. ``` -------------------------------- ### Flush the current page Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.PageWriter.html Forces the emission of any partially filled page currently held by the writer. ```rust pub fn flush(&mut self, out: &mut Vec) ``` -------------------------------- ### encode Source: https://docs.rs/ruopus/0.1.2/ruopus/struct.OpusEncoder.html Encodes one frame of interleaved 48 kHz f32 PCM audio into an Opus packet. ```APIDOC ## encode(pcm: &[f32], max_bytes: usize) -> Result, EncodeError> ### Description Encodes one frame of interleaved 48 kHz f32 PCM audio (in the range [-1, 1]) into an Opus packet with a maximum size defined by max_bytes. ### Parameters - **pcm** (&[f32]) - Required - Interleaved 48 kHz f32 PCM samples. - **max_bytes** (usize) - Required - Maximum size of the resulting Opus packet in bytes. ### Returns - **Result, EncodeError>** - The encoded Opus packet or an error if the frame size is invalid or the budget is out of range. ``` -------------------------------- ### pub fn bitexact_log2tan(isin: i32, icos: i32) -> i32 Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/bands/fn.bitexact_log2tan.html Calculates a bit-exact log2(tan) approximation using the provided sine and cosine inputs. ```APIDOC ## Function: bitexact_log2tan ### Description Computes a bit-exact approximation of log2(tan) based on input sine and cosine values. ### Signature `pub fn bitexact_log2tan(isin: i32, icos: i32) -> i32` ### Parameters - **isin** (i32) - The sine input value. - **icos** (i32) - The cosine input value. ### Returns - **i32** - The calculated bit-exact log2(tan) approximation. ``` -------------------------------- ### SilkEncoder::set_bitrate Source: https://docs.rs/ruopus/0.1.2/ruopus/struct.SilkEncoder.html Configures the target bitrate for the encoder. ```APIDOC ## pub fn set_bitrate(&mut self, bps: i32) ### Description Sets the target bitrate in bits per second, which influences the per-frame coding SNR. ``` -------------------------------- ### encode_auto Source: https://docs.rs/ruopus/0.1.2/ruopus/struct.OpusEncoder.html Encodes one frame of audio, automatically selecting the optimal mode (SILK, hybrid, or CELT) based on signal analysis, application profile, and target bitrate. ```APIDOC ## encode_auto(pcm: &[f32], max_bytes: usize) -> Result, EncodeError> ### Description Encodes one frame of audio, automatically choosing between SILK, hybrid, or CELT modes based on signal analysis, the configured signal hint, application profile, and target bitrate. It includes cross-frame hysteresis to prevent mode flipping. ### Parameters - **pcm** (&[f32]) - Required - Interleaved 48 kHz f32 PCM samples. - **max_bytes** (usize) - Required - Maximum size of the resulting Opus packet in bytes. ### Returns - **Result, EncodeError>** - The encoded Opus packet or an error if encoding fails. ``` -------------------------------- ### PacketReader::new Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.PacketReader.html Creates a new instance of PacketReader for a specific logical bitstream identified by its serial number. ```APIDOC ## pub fn new(data: &'a [u8], serial: u32) -> Self ### Description Creates a reader for the logical bitstream identified by `serial` from the provided byte slice `data`. ### Parameters - **data** (&'a [u8]) - The raw Ogg stream data. - **serial** (u32) - The serial number of the logical bitstream to extract. ``` -------------------------------- ### OpusTags::push Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.OpusTags.html Appends a new tag-value pair to the comments. ```APIDOC ## pub fn push(&mut self, tag: &str, value: &str) ### Description Appends a new `TAG=value` comment to the existing list of comments. ``` -------------------------------- ### compute_allocation Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/rate/fn.compute_allocation.html Computes the allocation, reading the skip/intensity/dual-stereo decisions from the bitstream (RFC 6716 §4.3.3, decoder side of compute_allocation). ```APIDOC ## Function: compute_allocation ### Description Computes the allocation, reading the skip/intensity/dual-stereo decisions from the bitstream (RFC 6716 §4.3.3, decoder side of compute_allocation). ### Signature ```rust pub fn compute_allocation( ec: &mut AllocEc<'_, '_>, start: usize, end: usize, offsets: &[i32; 21], cap: &[i32; 21], alloc_trim: i32, total: i32, channels: usize, lm: usize ) -> Allocation ``` ### Parameters - **ec** (&mut AllocEc<'_, '_>) - The allocation entropy coder. - **start** (usize) - The starting band index. - **end** (usize) - The ending band index. - **offsets** (&[i32; 21]) - The per-band boosts in 1/8 bits decoded by the caller (dynalloc). - **cap** (&[i32; 21]) - The per-band capacity limits. - **alloc_trim** (i32) - The decoded trim parameter (0..=10, default 5). - **total** (i32) - The bits available for the remainder of the frame in 1/8 bits. - **channels** (usize) - The number of channels. - **lm** (usize) - The log-frame size (frame length index). ### Returns - **Allocation** - The computed allocation structure. ``` -------------------------------- ### OggPacket Struct Definition Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.OggPacket.html The structure definition for OggPacket, detailing its fields for data storage and stream context. ```rust pub struct OggPacket { pub data: Vec, pub granule_position: u64, pub eos: bool, pub completes_page: bool, } ``` -------------------------------- ### AudioPacket Struct Definition Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.AudioPacket.html The structure definition for AudioPacket, containing the raw data, granule position, and end-of-stream flag. ```rust pub struct AudioPacket { pub data: Vec, pub granule_position: u64, pub eos: bool, } ``` -------------------------------- ### MultistreamDecoder::with_rate Source: https://docs.rs/ruopus/0.1.2/ruopus/struct.MultistreamDecoder.html Creates a new instance of a MultistreamDecoder with a specified sample rate, number of streams, coupled streams, and channel mapping. ```APIDOC ## pub fn with_rate(fs_hz: u32, streams: usize, coupled: usize, mapping: &[u8]) -> Self ### Description Creates a decoder for `streams` elementary streams (the first `coupled` stereo) mapped onto `mapping.len()` output channels. The `mapping[ch]` parameter selects a decoded channel index or 255 for silence. ### Parameters - **fs_hz** (u32) - Required - The sample rate in Hz. - **streams** (usize) - Required - The number of elementary streams. - **coupled** (usize) - Required - The number of coupled stereo streams. - **mapping** (&[u8]) - Required - The channel mapping array. ``` -------------------------------- ### Parse Ogg Page Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.Page.html Parses an Ogg page from a byte slice, verifying the CRC and returning the page along with the number of bytes consumed. ```rust pub fn parse(data: &'a [u8]) -> Result<(Self, usize), OggError> ``` -------------------------------- ### pvq_codebook_size function signature Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/cwrs/fn.pvq_codebook_size.html The function calculates the codebook size based on dimensions N and pulse count K, requiring n >= 2 and k >= 1. ```rust pub fn pvq_codebook_size(n: usize, k: usize) -> u32 ``` -------------------------------- ### Page Struct Definition Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.Page.html The definition of the Page struct, containing header flags and borrowed slices for segments and body data. ```rust pub struct Page<'a> { pub continued: bool, pub bos: bool, pub eos: bool, pub granule_position: u64, pub serial: u32, pub sequence: u32, pub segments: &'a [u8], pub body: &'a [u8], } ``` -------------------------------- ### Define EBANDS constant Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/modes/constant.EBANDS.html Represents the band boundaries in MDCT bins for the shortest frame size. ```rust pub const EBANDS: [i16; 22]; ``` -------------------------------- ### OpusDecoder::with_rate Source: https://docs.rs/ruopus/0.1.2/ruopus/struct.OpusDecoder.html Creates a new Opus decoder instance with a custom sample rate and channel count. ```APIDOC ## pub fn with_rate(fs_hz: u32, channels: usize) -> Self ### Description Creates a decoder producing `channels` at `fs_hz` (supported rates: 48, 24, 16, 12, or 8 kHz). ### Parameters - **fs_hz** (u32) - Required - The sample rate in Hz. - **channels** (usize) - Required - The number of audio channels. ``` -------------------------------- ### OggOpusWriter::finish Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.OggOpusWriter.html Finalizes the Ogg stream and returns the serialized file data. ```APIDOC ## pub fn finish(self) -> Vec ### Description Finishes the stream, emitting an empty EOS page if no packet was marked as last, and returns the complete serialized file as a byte vector. ``` -------------------------------- ### LOG2_FRAC_TABLE definition Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/tables/constant.LOG2_FRAC_TABLE.html The constant is defined as an array of 24 unsigned 8-bit integers. ```rust pub const LOG2_FRAC_TABLE: [u8; 24]; ``` -------------------------------- ### bitexact_log2tan function signature Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/bands/fn.bitexact_log2tan.html The function signature for the bit-exact log2(tan) approximation. ```rust pub fn bitexact_log2tan(isin: i32, icos: i32) -> i32 ``` -------------------------------- ### Packet Accessor Methods Source: https://docs.rs/ruopus/0.1.2/ruopus/packet/struct.Packet.html Methods to retrieve metadata and content from a parsed Packet. ```APIDOC ## Packet Accessors - **toc() -> Toc**: Returns the packet’s TOC byte. - **frames() -> &[&'a [u8]]**: Returns the compressed frames in order. - **padding() -> usize**: Returns the bytes of Opus padding the packet carried (code 3 only). - **duration() -> Duration**: Returns the total audio duration of the packet. ``` -------------------------------- ### pub fn bitexact_cos(x: i16) -> i16 Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/bands/fn.bitexact_cos.html Calculates a bit-exact cosine approximation for the given input value. ```APIDOC ## bitexact_cos ### Description Performs a bit-exact cosine approximation used for steering the allocation. ### Signature `pub fn bitexact_cos(x: i16) -> i16` ### Parameters - **x** (i16) - The input value for the cosine approximation. ### Returns - **i16** - The bit-exact cosine approximation result. ``` -------------------------------- ### SilkStereoEncoder::set_bitrate Source: https://docs.rs/ruopus/0.1.2/ruopus/struct.SilkStereoEncoder.html Configures the target bitrate for the stereo encoder. ```APIDOC ## pub fn set_bitrate(&mut self, bps: i32) ### Description Sets the total target bitrate (for both channels) in bits per second (bps). ``` -------------------------------- ### CACHE_CAPS Constant Definition Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/tables/constant.CACHE_CAPS.html Represents the maximum allocation per band, scaled by init_caps. ```rust pub const CACHE_CAPS: [u8; 168]; ``` -------------------------------- ### OpusHead::parse Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.OpusHead.html Parses a byte slice into an OpusHead struct. ```APIDOC ## pub fn parse(data: &[u8]) -> Result ### Description Parses an `OpusHead` packet from the provided byte slice. ### Errors - `OggOpusError::InvalidIdHeader`: Returned for structural problems. - `OggOpusError::UnsupportedVersion`: Returned when the major version is not 0. ``` -------------------------------- ### SilkEncoder::encode Source: https://docs.rs/ruopus/0.1.2/ruopus/struct.SilkEncoder.html Encodes PCM input data into a SILK payload. ```APIDOC ## pub fn encode(&mut self, input: &[i16]) -> Vec ### Description Encodes i16 PCM input at the internal rate into a SILK payload. The number of frames is inferred from the input length. ### Parameters - **input** (&[i16]) - The PCM audio data to encode. ``` -------------------------------- ### OpusTags::get Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.OpusTags.html Looks up the value of a specific tag in the comments. ```APIDOC ## pub fn get(&self, tag: &str) -> Option ### Description Looks up the value of a given `tag` (case-insensitive, per Vorbis-comment convention). Returns the value as a lossily decoded string if found. ``` -------------------------------- ### Accessing CAPTURE_PATTERN Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/constant.CAPTURE_PATTERN.html The constant is defined as a four-byte array representing the Ogg page header pattern. ```rust pub const CAPTURE_PATTERN: [u8; 4]; ``` -------------------------------- ### encode_hybrid Source: https://docs.rs/ruopus/0.1.2/ruopus/struct.OpusEncoder.html Encodes one frame as a hybrid Opus packet using SILK for the low band and CELT for the high band. ```APIDOC ## pub fn encode_hybrid(&mut self, pcm: &[f32], max_bytes: usize) -> Result, EncodeError> ### Description Encodes one frame as a hybrid Opus packet (mono or stereo, 10/20 ms, super-wideband or fullband). SILK codes the wideband low band and CELT the high band in a single shared range coder. ### Parameters - **pcm** (&[f32]) - The interleaved 48 kHz f32 PCM audio data. - **max_bytes** (usize) - The maximum size of the resulting packet (3..=1275). ### Errors - **EncodeError::InvalidFrameSize** - Unless a 10/20 ms frame and the bandwidth is super-wideband or fullband. - **EncodeError::InvalidBudget** - If max_bytes is outside 3..=1275. ``` -------------------------------- ### encode_ogg_opus Source: https://docs.rs/ruopus/0.1.2/ruopus/index.html Encodes interleaved 48 kHz f32 PCM into a complete Ogg Opus file. ```APIDOC ## encode_ogg_opus ### Description Encodes interleaved 48 kHz f32 PCM into a complete Ogg Opus file (RFC 7845): the OpusHead/OpusTags headers followed by the audio page stream, fullband and 20 ms per packet via OpusEncoder::encode_auto. The final partial frame is zero-padded. ``` -------------------------------- ### MultistreamDecoder::channels Source: https://docs.rs/ruopus/0.1.2/ruopus/struct.MultistreamDecoder.html Returns the number of output channels configured for the decoder. ```APIDOC ## pub fn channels(&self) -> usize ### Description Returns the output channel count for the decoder instance. ``` -------------------------------- ### Define NB_ALLOC_VECTORS constant Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/tables/constant.NB_ALLOC_VECTORS.html Represents the number of quality levels for band allocation interpolation. ```rust pub const NB_ALLOC_VECTORS: usize = 11; ``` -------------------------------- ### OggOpusWriter::push Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.OggOpusWriter.html Appends an Opus packet to the stream, managing granule positions and optional stream closure. ```APIDOC ## pub fn push(&mut self, packet: &[u8], last: bool) ### Description Appends one Opus packet to the stream. Granule positions are advanced based on the packet's TOC duration. ### Parameters - **packet** (&[u8]) - Required - The Opus packet data. - **last** (bool) - Required - If true, marks the final packet and closes the stream with the EOS flag. ``` -------------------------------- ### encode_silk Source: https://docs.rs/ruopus/0.1.2/ruopus/struct.OpusEncoder.html Encodes one frame of interleaved 48 kHz f32 PCM as a SILK-mode Opus packet. ```APIDOC ## pub fn encode_silk(&mut self, pcm: &[f32], max_bytes: usize) -> Result, EncodeError> ### Description Encodes one frame of interleaved 48 kHz f32 PCM in [-1, 1] as a SILK-mode Opus packet (mono or stereo). The frame must be 10, 20, 40 or 60 ms (480/960/1920/2880 samples per channel). ### Parameters - **pcm** (&[f32]) - The interleaved 48 kHz f32 PCM audio data. - **max_bytes** (usize) - The maximum size of the resulting packet (3..=1275). ### Errors - **EncodeError::InvalidFrameSize** - If pcm is not a valid SILK frame size. - **EncodeError::InvalidBudget** - If the packet would exceed max_bytes. ``` -------------------------------- ### anti_collapse Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/bands/fn.anti_collapse.html Injects noise into MDCT blocks that received no pulses, at a level tied to the band’s recent energy history, then renormalises the band. ```APIDOC ## pub fn anti_collapse ### Description Anti-collapse for transient frames (RFC 6716 §4.3.5): injects noise into MDCT blocks that received no pulses, at a level tied to the band’s recent energy history, then renormalises the band. ### Signature ```rust pub fn anti_collapse( x: &mut [f32], collapse_masks: &[u8], lm: usize, channels: usize, size: usize, start: usize, end: usize, log_e: &[[f32; 21]; 2], prev1_log_e: &[[f32; 21]; 2], prev2_log_e: &[[f32; 21]; 2], pulses: &[i32; 21], seed: u32, ) ``` ### Parameters - **x** (&mut [f32]) - The per-channel concatenated spectrum (channels * size). - **collapse_masks** (&[u8]) - Masks indicating collapse status. - **lm** (usize) - Logarithm of the MDCT size. - **channels** (usize) - Number of channels. - **size** (usize) - Size of the spectrum. - **start** (usize) - Start index. - **end** (usize) - End index. - **log_e** (&[[f32; 21]; 2]) - Current frame's band energies. - **prev1_log_e** (&[[f32; 21]; 2]) - First previous frame's band energies. - **prev2_log_e** (&[[f32; 21]; 2]) - Second previous frame's band energies. - **pulses** (&[i32; 21]) - The allocation’s shape budget (1/8 bits). - **seed** (u32) - Random seed for noise generation. ``` -------------------------------- ### WINDOW120 Constant Definition Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/tables/constant.WINDOW120.html Represents the low-overlap MDCT window as an array of 120 floating-point samples. ```rust pub const WINDOW120: [f32; 120]; ``` -------------------------------- ### OpusHead Struct Definition Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.OpusHead.html The structure definition for the Ogg Opus identification header. ```rust pub struct OpusHead { pub version: u8, pub channel_count: u8, pub pre_skip: u16, pub input_sample_rate: u32, pub output_gain_q8: i16, pub channel_mapping: ChannelMapping, } ``` -------------------------------- ### SilkStereoEncoder::new Source: https://docs.rs/ruopus/0.1.2/ruopus/struct.SilkStereoEncoder.html Creates a new stereo encoder instance with a specified internal rate and subframe count. ```APIDOC ## pub fn new(fs_khz: i32, nb_subfr: usize) -> Self ### Description Initializes a new stereo encoder at the given internal rate and subframe count. ### Parameters - **fs_khz** (i32) - The internal sampling rate in kHz. - **nb_subfr** (usize) - The number of subframes. ``` -------------------------------- ### PageWriter::flush Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.PageWriter.html Emits any partially filled page currently held by the writer. ```APIDOC ## pub fn flush(&mut self, out: &mut Vec) ### Description Emits the partially filled page, if any. This should be called after headers like the ID header or comment header. ### Parameters - **out** (&mut Vec) - Required - The output buffer for the flushed page. ``` -------------------------------- ### anti_collapse function signature Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/bands/fn.anti_collapse.html The function signature for anti_collapse, which handles noise injection for MDCT blocks based on band energy history. ```rust pub fn anti_collapse( x: &mut [f32], collapse_masks: &[u8], lm: usize, channels: usize, size: usize, start: usize, end: usize, log_e: &[[f32; 21]; 2], prev1_log_e: &[[f32; 21]; 2], prev2_log_e: &[[f32; 21]; 2], pulses: &[i32; 21], seed: u32, ) ``` -------------------------------- ### quant_all_bands function signature Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/bands/fn.quant_all_bands.html The function signature for decoding band shapes. It requires a mutable reference to a RangeDecoder and various parameters for spectral data and allocation budgets. ```rust pub fn quant_all_bands( dec: &mut RangeDecoder<'_>, start: usize, end: usize, x: &mut [f32], y: Option<&mut [f32]>, collapse_masks: &mut [u8], shape_bits: &[i32; 21], short_blocks: bool, spread: Spread, dual_stereo: bool, intensity: usize, tf_res: &[i32; 21], total_bits: i32, balance: i32, lm: usize, coded_bands: usize, seed: &mut u32, ) ``` -------------------------------- ### DecControl Struct Definition Source: https://docs.rs/ruopus/0.1.2/ruopus/silk/api/struct.DecControl.html The structure definition containing fields for configuring the SILK decoder. ```rust pub struct DecControl { pub channels_internal: usize, pub channels_api: usize, pub internal_sample_rate: i32, pub api_sample_rate: i32, pub payload_size_ms: usize, } ``` -------------------------------- ### Define Bandwidth Enum Source: https://docs.rs/ruopus/0.1.2/ruopus/packet/enum.Bandwidth.html The Bandwidth enum variants representing different audio bandwidths. ```rust pub enum Bandwidth { NarrowBand, MediumBand, WideBand, SuperWideBand, FullBand, } ``` -------------------------------- ### pvq_codebook_size Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/cwrs/index.html Calculates the size of the PVQ codebook, representing the number of N-dimensional vectors of K signed pulses. ```APIDOC ## pvq_codebook_size ### Description Returns the size of the PVQ codebook, calculated as V(N, K) = U(N, K) + U(N, K + 1). ### Signature `fn pvq_codebook_size(N: i32, K: i32) -> u32` ``` -------------------------------- ### Iterator Implementation Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.PacketReader.html PacketReader implements the Iterator trait, allowing users to iterate over OggPacket items. ```APIDOC ## fn next(&mut self) -> Option ### Description Advances the iterator and returns the next reassembled OggPacket from the stream. ### Returns - **Option** - The next packet if available, otherwise None. ``` -------------------------------- ### renormalise_vector Function Signature Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/vq/fn.renormalise_vector.html The function signature for renormalising a vector to a specified gain. ```rust pub fn renormalise_vector(x: &mut [f32], gain: f32) ``` -------------------------------- ### compute_allocation function signature Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/rate/fn.compute_allocation.html The function signature for computing bit allocation, requiring an AllocEc context and various frame parameters. ```rust pub fn compute_allocation( ec: &mut AllocEc<'_, '_>, start: usize, end: usize, offsets: &[i32; 21], cap: &[i32; 21], alloc_trim: i32, total: i32, channels: usize, lm: usize, ) -> Allocation ``` -------------------------------- ### BETA_INTRA Constant Definition Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/modes/constant.BETA_INTRA.html The constant is defined as a 32-bit floating-point value representing the intra frame prediction feedback factor. ```rust pub const BETA_INTRA: f32 = _; // 0.149993896f32 ``` -------------------------------- ### Define EnergyState struct Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/energy/struct.EnergyState.html The structure definition for EnergyState, containing a 2x21 array of f32 values representing log energies. ```rust pub struct EnergyState { pub old_ebands: [[f32; 21]; 2], } ``` -------------------------------- ### LOG_N constant definition Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/modes/constant.LOG_N.html Represents log2(EBANDS[i+1] - EBANDS[i]) in 1/8-bit units at the shortest frame size. ```rust pub const LOG_N: [i16; 21]; ``` -------------------------------- ### E_PROB_MODEL Constant Definition Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/modes/constant.E_PROB_MODEL.html Represents the Laplace probability model for coarse energy deltas, stored as a 4D array in Q8 format. ```rust pub const E_PROB_MODEL: [[[u8; 42]; 2]; 4]; ``` -------------------------------- ### Define NB_EBANDS constant Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/modes/constant.NB_EBANDS.html Represents the fixed number of energy bands used in the CELT codec configuration. ```rust pub const NB_EBANDS: usize = 21; ``` -------------------------------- ### alg_unquant Function Signature Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/vq/fn.alg_unquant.html The function signature for decoding a PVQ-coded band shape. ```rust pub fn alg_unquant( dec: &mut RangeDecoder<'_>, x: &mut [f32], k: usize, spread: Spread, b: usize, gain: f32, ) -> Option ``` -------------------------------- ### Define Application Enum Source: https://docs.rs/ruopus/0.1.2/ruopus/enum.Application.html The Application enum represents the coding application or latency profile used by libopus. ```rust pub enum Application { Voip, Audio, RestrictedLowDelay, } ``` -------------------------------- ### Define Packet Struct Source: https://docs.rs/ruopus/0.1.2/ruopus/packet/struct.Packet.html The internal structure of the Packet type. ```rust pub struct Packet<'a> { /* private fields */ } ``` -------------------------------- ### decode_energy_finalise function signature Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/energy/fn.decode_energy_finalise.html The function signature for final energy refinement in CELT decoding. ```rust pub fn decode_energy_finalise( dec: &mut RangeDecoder<'_>, state: &mut EnergyState, start: usize, end: usize, fine_quant: &[i32], fine_priority: &[bool], bits_left: i32, channels: usize, ) ``` -------------------------------- ### OpusTags Struct Definition Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.OpusTags.html The structure definition for OpusTags, containing the vendor identification string and user comments as raw byte vectors. ```rust pub struct OpusTags { pub vendor: Vec, pub comments: Vec>, } ``` -------------------------------- ### Define FrameSize Enum Source: https://docs.rs/ruopus/0.1.2/ruopus/packet/enum.FrameSize.html The enumeration of supported Opus frame durations. ```rust pub enum FrameSize { Ms2_5, Ms5, Ms10, Ms20, Ms40, Ms60, } ``` -------------------------------- ### decode_fine_energy function signature Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/energy/fn.decode_fine_energy.html The function signature for decoding fine energy refinement using a range decoder and energy state. ```rust pub fn decode_fine_energy( dec: &mut RangeDecoder<'_>, state: &mut EnergyState, start: usize, end: usize, fine_quant: &[i32], channels: usize, ) ``` -------------------------------- ### Define the Toc struct Source: https://docs.rs/ruopus/0.1.2/ruopus/packet/struct.Toc.html The internal structure of the Toc type. ```rust pub struct Toc(/* private fields */); ``` -------------------------------- ### OpusDecoder::decode_packet Source: https://docs.rs/ruopus/0.1.2/ruopus/struct.OpusDecoder.html Decodes an Opus packet into f32 audio samples. ```APIDOC ## pub fn decode_packet(&mut self, data: &[u8]) -> Result, PacketError> ### Description Decodes one Opus packet to interleaved 48 kHz f32 samples. ### Parameters - **data** (&[u8]) - Required - The encoded Opus packet data. ### Response - **Result, PacketError>** - Returns a vector of decoded f32 samples or a PacketError if the packet is malformed. ``` -------------------------------- ### BAND_ALLOCATION Constant Definition Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/tables/constant.BAND_ALLOCATION.html The constant is defined as a fixed-size array of 231 bytes. ```rust pub const BAND_ALLOCATION: [u8; 231]; ``` -------------------------------- ### PageWriter struct definition Source: https://docs.rs/ruopus/0.1.2/ruopus/ogg/struct.PageWriter.html The internal structure definition for PageWriter. ```rust pub struct PageWriter { /* private fields */ } ``` -------------------------------- ### bitexact_cos function signature Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/bands/fn.bitexact_cos.html The function signature for the bit-exact cosine approximation. ```rust pub fn bitexact_cos(x: i16) -> i16 ``` -------------------------------- ### Define MAX_FINE_BITS constant Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/modes/constant.MAX_FINE_BITS.html Represents the maximum number of fine energy bits per band. ```rust pub const MAX_FINE_BITS: i32 = 8; ``` -------------------------------- ### Define MAX_FRAME_LEN constant Source: https://docs.rs/ruopus/0.1.2/ruopus/packet/constant.MAX_FRAME_LEN.html Represents the maximum byte length for an Opus frame, constrained by one/two-byte length coding limits. ```rust pub const MAX_FRAME_LEN: usize = 1275; ``` -------------------------------- ### OpusEncoder Struct Definition Source: https://docs.rs/ruopus/0.1.2/ruopus/struct.OpusEncoder.html The internal structure definition for the OpusEncoder. ```rust pub struct OpusEncoder { /* private fields */ } ``` -------------------------------- ### pub fn ec_laplace_decode(dec: &mut RangeDecoder<'_>, fs: u32, decay: u32) -> i32 Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/laplace/fn.ec_laplace_decode.html Decodes one Laplace-coded value from the provided range decoder. ```APIDOC ## ec_laplace_decode ### Description Decodes one Laplace-coded value. This function is the mirror of `ec_laplace_encode`. ### Signature `pub fn ec_laplace_decode(dec: &mut RangeDecoder<'_>, fs: u32, decay: u32) -> i32` ### Parameters - **dec** (&mut RangeDecoder<'_>) - The range decoder instance used for decoding. - **fs** (u32) - The frequency scale parameter. - **decay** (u32) - The decay parameter for the Laplace distribution. ### Returns - **i32** - The decoded Laplace-coded value. ``` -------------------------------- ### BITRES Constant Definition Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/rate/constant.BITRES.html The constant represents the fractional-bit resolution used for budget calculations. ```rust pub const BITRES: u32 = 3; ``` -------------------------------- ### Define CeltEncoder struct Source: https://docs.rs/ruopus/0.1.2/ruopus/celt/encoder/struct.CeltEncoder.html The internal structure definition for the CELT encoder. ```rust pub struct CeltEncoder { /* private fields */ } ```