Skip to content

Encoder

Encodes raw PCM audio frames into Opus packets.

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

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

Encoder.handle  :: FFIPointer
Encoder.sampleRate  :: number
Encoder.channels  :: number
Encoder.application  :: number
Encoder : encode ( pcmFrame )  -> buffer

Encodes a raw PCM frame into an Opus packet. The frame must be exactly one Opus frame duration of samples.

Parameters

pcmFrame: buffer

Returns

buffer
Encoder : destroy ( )  -> ()

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

Encoder . new ( sampleRate channels application )  -> Encoder

Responsible for constructing this class.

Parameters

sampleRate: number
channels: number
application: number

Returns

Encoder