Compare commits

...

5 commits

Author SHA1 Message Date
DataHoarder a2e2148b78
Support decoding into Float 2022-10-04 10:43:29 +02:00
Sean DuBois 27b0cc9a06 Fix README for examples/playback
URL to faiface was poorly formatted
2022-10-03 23:17:57 -04:00
Sean DuBois a9917652d9 Add blogpost to README 2022-10-03 00:03:54 -04:00
Sean DuBois 2d6fc47384 Panic on decode error in examples/playback
Error wasn't returned to user before
2022-10-02 21:11:11 -04:00
Sean DuBois 5777c86e20 Update README 2022-10-01 23:37:17 -04:00
5 changed files with 29 additions and 10 deletions

View file

@ -30,7 +30,10 @@ This package provides a Pure Go implementation of the [Opus Codec](https://opus-
* **learning** - This project was written to be read by others. It includes excerpts and links to [RFC 6716](https://datatracker.ietf.org/doc/rfc6716/)
* **safety** - Go provides memory safety. Avoids a class of bugs that are devastating in sensitive environments.
* **maintainability** - Go was designed to build simple, reliable, and efficient software.
* **portability** - A Pure Go implementation makes it easier to build for other platforms. Using libopus from Go prevents cross compilation.
* **inspire** - Go is a power language, but lacking in media libraries. We hope this project inspires the next generation to build
* more media libraries for Go.
You can read more [here](https://pion.ly/blog/pion-opus/)
### Running
See our [examples](examples) for demonstrations of how to use this package.

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()

View file

@ -1,5 +1,5 @@
# playback
playback demonstrates decoding a ogg file and then playing using the [faiface/beep](github.com/faiface/beep) library
playback demonstrates decoding a ogg file and then playing using the [faiface/beep](https://github.com/faiface/beep) library
## Instructions
### Install playback

View file

@ -42,7 +42,7 @@ func (o *opusReader) Read(p []byte) (n int, err error) {
o.decodeBufferOffset = 0
if _, _, err = o.opusDecoder.Decode(segment, o.decodeBuffer); err != nil {
return 0, err
panic(err)
}
}