Crates.io | mousiki |
lib.rs | mousiki |
version | 0.1.0 |
created_at | 2025-09-23 12:03:30.201903+00 |
updated_at | 2025-09-23 12:03:30.201903+00 |
description | Pure Rust Opus decoder. |
homepage | https://github.com/cijiugechu/mousiki |
repository | https://github.com/cijiugechu/mousiki |
max_upload_size | |
id | 1851360 |
size | 320,845 |
An Opus decoder library in Rust, ported from the Go implementation in pion/opus
. The core crate is #![no_std]
and performs zero heap allocations.
Either i16
little-endian (LE) or f32
, depending on the API you call.
A 20 ms frame yields 960 samples (mono), i.e., 1920 bytes for i16
output.
cargo run --example decode -- testdata/tiny.ogg output_mono.pcm
cpal
):cargo run --example playback -- testdata/tiny.ogg
The snippet below decodes a single Opus packet into i16
PCM (mono, 48 kHz):
use mousiki::decoder::Decoder;
// `packet` is a single Opus SILK-only, mono packet (already decontainerized; not an Ogg page).
let packet: &[u8] = /* your Opus packet */;
// Output buffer (20 ms -> 960 samples, each sample is 2 bytes for i16)
let mut pcm_bytes = [0u8; 1920];
let mut decoder = Decoder::new();
let (_bandwidth, stereo) = decoder.decode(packet, &mut pcm_bytes)?;
assert!(!stereo, "mono only for now");
// `pcm_bytes` now contains 48 kHz i16 little-endian PCM data
For f32
output, use decode_float32
and a buffer of length 960 for a 20 ms frame:
use mousiki::decoder::Decoder;
let packet: &[u8] = /* your Opus packet */;
let mut pcm_f32 = [0.0f32; 960];
let mut decoder = Decoder::new();
let (_bandwidth, stereo) = decoder.decode_float32(packet, &mut pcm_f32)?;
assert!(!stereo);
Tip: If your input is an Ogg-encapsulated Opus stream, see the example oggreader
usage to extract raw Opus packets before decoding.
LICENSE
).pion/opus
(Go) implementation and the community.