Documentation
¶
Overview ¶
Package opus wraps the Opus codec for jargo's audio path: it decodes Opus packets to PCM on the way in and encodes PCM to Opus packets on the way out.
The codec runs at 48 kHz — the rate WebRTC negotiates for Opus — so audio crosses the transport without resampling. Encoding produces 20 ms frames, the standard WebRTC packetization.
The decoder is pure Go. The Encoder has two builds selected by the `libopus` build tag (see encoder_pion.go / encoder_libopus.go): the default is the pure-Go encoder; `-tags libopus` links the C library for higher speech quality. Both expose the same NewEncoder/Encode API.
Index ¶
Constants ¶
const ( // SampleRate is the codec sample rate in Hz. Opus runs at 48 kHz. SampleRate = 48000 // FrameDuration is the duration of one encoded packet. FrameDuration = 20 * time.Millisecond // FrameSamples is the number of samples per channel in one 20 ms frame. FrameSamples = SampleRate / 1000 * 20 // 960 )
Variables ¶
This section is empty.
Functions ¶
func FrameBytes ¶
FrameBytes is the size in bytes of one 20 ms S16LE frame for channels.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder decodes Opus packets into signed 16-bit little-endian PCM.
func NewDecoder ¶
NewDecoder builds a Decoder that outputs channels-channel 48 kHz PCM. It decodes all Opus modes (SILK, CELT and hybrid).
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder encodes 48 kHz S16LE PCM into Opus packets using the pure-Go pion encoder. This is the default build. The encoder is currently CELT-only, which is weaker on speech than libopus; build with `-tags libopus` for the C library instead (see encoder_libopus.go).
func NewEncoder ¶
NewEncoder builds an Encoder for channels-channel 48 kHz audio at the given bitrate in bits per second; pass 0 for the codec default.