Compare commits
5 commits
dbc1ce8df2
...
a2e2148b78
Author | SHA1 | Date | |
---|---|---|---|
DataHoarder | a2e2148b78 | ||
27b0cc9a06 | |||
a9917652d9 | |||
2d6fc47384 | |||
5777c86e20 |
|
@ -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.
|
||||
|
|
29
decoder.go
29
decoder.go
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ func main() {
|
|||
}
|
||||
|
||||
decoder := opus.NewDecoder()
|
||||
x := 0
|
||||
for {
|
||||
segments, _, err := ogg.ParseNextPage()
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue