Expand description
opus1: the Opus audio codec (RFC 6716) in Rust, ported from libopus 1.6.1, the reference implementation in C.
OpusEncoderandOpusDecodercode one stream of mono or stereo audio, at 8, 12, 16, 24 or 48 kHz (SampleRate,Channels).- The module
multistreamcodes several streams in one packet, for example 5.1 surround sound (featurealloc, which the default featurestdturns on). - The module
packetreads, splits and joins Opus packets without decoding them, andextensionsreads and writes the extensions in their padding. - With the feature
dred, the encoder adds deep redundancy (DRED) to its packets, andOpusDredDecoderreads it back to rebuild lost audio.
Every call that can fail returns Error, whose ErrorKind is the
error code libopus returns in the same case.
use opus1::{Application, Channels, OpusDecoder, OpusEncoder, SampleRate};
let mut encoder = OpusEncoder::new(SampleRate::Hz48000, Channels::Mono, Application::Audio)?;
let mut decoder = OpusDecoder::new(SampleRate::Hz48000, Channels::Mono)?;
let pcm: Vec<f32> = (0..960).map(|i| (i as f32 * 0.05).sin() * 0.5).collect();
let mut packet = [0u8; 1275];
let len = encoder.encode(&pcm, 960, &mut packet)?;
let mut out = [0.0f32; 960];
assert_eq!(decoder.decode(&packet[..len], 960, &mut out)?, 960);opus1 follows libopus 1.6.1. The tests of the repository
compare its packets and its decoded audio with that release. The docs
folder of the repository explains the codec, the library and where
opus1 differs from libopus.
Modules§
- extensions
- Packet extensions: extra data stored in the padding of an Opus packet.
- multistream
alloc - Multichannel encoding and decoding (several Opus streams in one packet).
It allocates in its constructors, so it needs the
allocfeature, whichstdandheap(both on by default) turn on. It works withoutstdwhen the application has a global allocator. The constructors build each stream codec in place in that memory, so they need little stack, also withoutheap. The single-stream codec staysno_stdwithoutalloc. - packet
- Opus packet framing (RFC 6716 section 3 and appendix B): reading the frames out of a packet, writing frames into a packet, and padding.
Structs§
- DnnBlob
deep-plcanddnn - A validated weight blob in the libopus format (
OPUS_SET_DNN_BLOB). Cloning is cheap: the bytes are not copied. - DnnModels
deep-plcanddnn - A set of model groups, as returned by every
set_dnn_blob(OpusDecoder,OpusEncoder,OpusDredDecoderandmultistream::MultistreamDecoder): the groups that the call loaded. - Dred
Parse dnnanddred - What
OpusDredDecoder::parsefound in a packet. - Error
- An error of opus1: its kind and a message that says what was wrong.
- Opus
Decoder - A decoder of one Opus stream to mono or stereo audio: libopus
OpusDecoder. - Opus
Dred dnnanddred - The DRED data of one packet (libopus
OpusDRED, 11,236 bytes). - Opus
Dred Decoder dnnanddred - The DRED decoder (libopus
OpusDREDDecoder): the RDOVAE decoder’s weights and the kernel variant. It keeps no state between packets, so one decoder can serve any number of streams. - Opus
Encoder - An encoder of one Opus stream of mono or stereo audio: libopus
OpusEncoder.
Enums§
- Application
- What an encoder is tuned for: libopus
OPUS_APPLICATION_*, theapplicationargument ofOpusEncoder::new. - Bandwidth
- An audio bandwidth: libopus
OPUS_BANDWIDTH_*. Each value says up to which frequency a packet carries audio. - Bitrate
- The bitrate setting of an encoder: libopus
OPUS_SET_BITRATE. SeeOpusEncoder::set_bitrate;MultistreamEncoder::set_bitratetakes it too. - Channels
- The number of channels of the audio that an encoder takes or a decoder
writes. A single Opus stream has one or two channels. For more, use the
multistreammodule, which counts channels with ausize. - Dred
Processing dnnanddred - When
OpusDredDecoder::parseruns the RDOVAE decoder: libopus’sdefer_processingflag ofopus_dred_parse. - Error
Kind - What kind of error happened: one per libopus error code.
- Forced
Mode - A coding mode the caller asks the encoder to use: libopus
MODE_SILK_ONLY,MODE_HYBRIDandMODE_CELT_ONLYforOPUS_SET_FORCE_MODE. SeeOpusEncoder::set_force_mode. - Frame
Duration - The frame duration setting of an encoder: libopus
OPUS_SET_EXPERT_FRAME_DURATION. SeeOpusEncoder::set_expert_frame_duration;MultistreamEncoder::set_expert_frame_durationtakes it too. - Inband
Fec - In-band forward error correction (FEC): libopus
OPUS_SET_INBAND_FEC. SeeOpusEncoder::set_inband_fec. - Sample
Rate - A sampling rate of the audio that an encoder takes or a decoder writes. Opus supports these five rates and no others.
- Signal
- What the input of an encoder is: libopus
OPUS_SET_SIGNAL. SeeOpusEncoder::set_signal.
Constants§
- VERSION
- The version of this crate, for example
"0.3.0": theversionof itsCargo.toml.
Functions§
- pcm_
soft_ clip - libopus
opus_pcm_soft_clip(opus.c): bring a float signal into [-1, 1] without hard clipping.