diff --git a/gumble/opus/opus.go b/gumble/opus/opus.go index 39eb8c4..a183e35 100644 --- a/gumble/opus/opus.go +++ b/gumble/opus/opus.go @@ -97,17 +97,21 @@ func (*Decoder) ID() int { } func (d *Decoder) Decode(data []byte, frameSize int) ([]int16, error) { - // Allocate buffer for stereo - frameSize is per channel - pcm := make([]int16, frameSize*gumble.AudioChannels) + // frameSize is the maximum number of PCM samples (all channels + // combined). The underlying Opus decoder output is interleaved + // stereo, so the buffer holds left+right pairs. + pcm := make([]int16, frameSize) - // Decode the data + // Decode the data. If data is nil/empty, the decoder performs + // Packet Loss Concealment and produces a concealed frame. n, err := d.Decoder.Decode(data, pcm) if err != nil { return []int16{}, err } - // Return the exact number of samples decoded - return pcm[:n*gumble.AudioChannels], nil + // n is the number of samples per channel; stereo interleaved + // output means total samples = n * channels. + return pcm[:n*d.channels], nil } func (d *Decoder) Reset() {