Support decoding into Float

This commit is contained in:
DataHoarder 2022-10-04 10:43:29 +02:00
parent 27b0cc9a06
commit a2e2148b78
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
2 changed files with 23 additions and 7 deletions

View file

@ -21,8 +21,7 @@ func NewDecoder() Decoder {
}
}
// Decode decodes the Opus bitstream into PCM
func (d *Decoder) Decode(in []byte, out []byte) (bandwidth Bandwidth, isStereo bool, err error) {
func (d *Decoder) decode(in []byte) (bandwidth Bandwidth, isStereo bool, err error) {
if len(in) < 1 {
return 0, false, errTooShortForTableOfContentsHeader
}
@ -49,9 +48,27 @@ func (d *Decoder) Decode(in []byte, out []byte) (bandwidth Bandwidth, isStereo b
}
}
if err := bitdepth.ConvertFloat32LittleEndianToSigned16LittleEndian(d.silkBuffer, out, 3); err != nil {
return 0, false, err
}
return cfg.bandwidth(), tocHeader.isStereo(), nil
}
// Decode decodes the Opus bitstream into PCM
func (d *Decoder) Decode(in []byte, out []byte) (bandwidth Bandwidth, isStereo bool, err error) {
if bandwidth, isStereo, err = d.decode(in); err != nil {
return
} else {
if err := bitdepth.ConvertFloat32LittleEndianToSigned16LittleEndian(d.silkBuffer, out, 3); err != nil {
return 0, false, err
}
return
}
}
// DecodeFloat decodes the Opus bitstream into native float
func (d *Decoder) DecodeFloat(in []byte, out []float32) (bandwidth Bandwidth, isStereo bool, err error) {
if bandwidth, isStereo, err = d.decode(in); err != nil {
return
} else {
copy(out, d.silkBuffer)
return
}
}

View file

@ -32,7 +32,6 @@ func main() {
}
decoder := opus.NewDecoder()
x := 0
for {
segments, _, err := ogg.ParseNextPage()