Skip to content

Decoder

Decodes Opus packets back into raw PCM audio frames.

The decoder state is an opaque libopus pointer that persists across calls - do not create a new Decoder per packet. One Decoder instance per audio stream is the correct usage.

Call destroy when the decoder is no longer needed to free the native state.

Decoder.handle  :: FFIPointer
Decoder.sampleRate  :: number
Decoder.channels  :: number
Decoder : decode ( opusBuffer )  -> buffer

Decodes an Opus packet into a raw s16le PCM frame.

Parameters

opusBuffer: buffer

Returns

buffer
Decoder : decodeFec ( nextPacket )  -> buffer

Recovers the lost frame preceding nextPacket using the FEC data embedded in that packet. Use when a packet is missing but the following packet has already arrived.

Parameters

nextPacket: buffer

Returns

buffer
Decoder : decodePLC ( )  -> buffer

Synthesises a comfort-noise frame for a lost packet when no FEC data is available (packet loss concealment).

Returns

buffer
Decoder : destroy ( )  -> ()

Frees the native decoder state. No-op if already destroyed.

Decoder . new ( sampleRate channels )  -> Decoder

Responsible for constructing this class.

Parameters

sampleRate: number
channels: number

Returns

Decoder