Opus decoder backed by the opus-rs codec through Rustler.
Decodes raw Opus packets into PCM (the little-endian f32 binary contract,
interleaved for stereo). A 1-byte (ToC-only) packet is treated as a lost/DTX frame
and concealed (packet-loss concealment) rather than rejected.
Example
{:ok, decoder} = RustyOpus.Decoder.new(16_000, 1)
{:ok, pcm} = RustyOpus.Decoder.decode(decoder, packet, 320)
:ok = RustyOpus.Decoder.close(decoder)frame_size is the number of samples per channel in the decoded frame (for
example 320 samples at 16 kHz is a 20 ms frame) and must match the frame duration of
the encoded packets.
Summary
Functions
Closes the decoder idempotently. Further calls return {:error, %Error{reason: :closed}}.
Decodes one Opus packet into PCM using frame_size samples per channel.
Decodes a list of Opus packets into one concatenated PCM binary.
Creates a new decoder for a supported sampling rate and channel count.
Types
@type t() :: %RustyOpus.Decoder{ channels: 1 | 2, rate: 8000 | 12000 | 16000 | 24000 | 48000, resource: reference() }
Functions
@spec close(t()) :: :ok
Closes the decoder idempotently. Further calls return {:error, %Error{reason: :closed}}.
@spec decode(t(), binary(), pos_integer()) :: {:ok, binary()} | {:error, RustyOpus.Error.t()}
Decodes one Opus packet into PCM using frame_size samples per channel.
Returns {:ok, pcm} where pcm is the little-endian f32 binary with
written_samples * channels samples.
@spec decode_many(t(), [binary()], keyword()) :: {:ok, binary()} | {:error, RustyOpus.Error.t()}
Decodes a list of Opus packets into one concatenated PCM binary.
Packets share decoder state (including 1-byte DTX concealment). Defaults
frame_size to div(rate, 50) (20 ms). An empty list returns an empty PCM binary.
@spec new(pos_integer(), 1 | 2) :: {:ok, t()} | {:error, RustyOpus.Error.t()}
Creates a new decoder for a supported sampling rate and channel count.