opus-go/decoder.go
Sean DuBois 0c432b922c Only support CELT for now
Assert that Hybrid or Silk wasn't selected
2022-06-12 16:02:47 -04:00

31 lines
805 B
Go

package opus
import "fmt"
// Decoder decodes the Opus bitstream into PCM
type Decoder struct {
}
// Decode decodes the Opus bitstream into PCM
func (d *Decoder) Decode(in []byte) (bandwidth Bandwidth, isStereo bool, frames [][]byte, err error) {
if len(in) < 1 {
return 0, false, nil, errTooShortForTableOfContentsHeader
}
tocHeader := tableOfContentsHeader(in[0])
cfg := tocHeader.configuration()
switch tocHeader.frameCode() {
case frameCodeOneFrame:
frames = append(frames, in[1:])
default:
return 0, false, nil, fmt.Errorf("%w: %d", errUnsupportedFrameCode, tocHeader.frameCode())
}
if cfg.mode() != configurationModeCELTOnly {
return 0, false, nil, fmt.Errorf("%w: %d", errUnsupportedConfigurationMode, cfg.mode())
}
return cfg.bandwidth(), tocHeader.isStereo(), nil, nil
}