*/
import "C"
+// Stream wraps a io.Reader in a decoding layer. It provides an API similar to
+// io.Reader, but it provides raw PCM data instead of the encoded Opus data.
+//
+// This wraps the libopusfile library.
type Stream struct {
id uintptr
oggfile *C.OggOpusFile
return C.int(n)
}
+// NewStream creates and initializes a new stream. Don't call .Init() on this.
func NewStream(read io.Reader) (*Stream, error) {
var s Stream
err := s.Init(read)
var errno C.int
// Immediately delete the stream after .Init to avoid leaking if the
- // caller forgets to (/ doesn't want to) call .Delete(). No need for that,
+ // caller forgets to (/ doesn't want to) call .Close(). No need for that,
// since the callback is only ever called during a .Read operation; just
// Save and Delete from the map around that every time a reader function is
// called.
return int(n), nil
}
+// ReadFloat32 is the same as Read, but decodes to float32 instead of int16.
func (s *Stream) ReadFloat32(pcm []float32) (int, error) {
if s.oggfile == nil {
return 0, fmt.Errorf("opus stream is uninitialized or already closed")