From: Hraban Luyat Date: Sun, 5 Jul 2015 20:07:29 +0000 (+0100) Subject: float routines for stream reader X-Git-Tag: v2.0.0~95 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=6b3d9bb2da863c5a52693d0f8807a7655541f65d;p=go-opus.git float routines for stream reader --- diff --git a/stream.go b/stream.go index de8dbae..07a5743 100644 --- a/stream.go +++ b/stream.go @@ -105,6 +105,27 @@ func (s *Stream) Read(pcm []int16) (int, error) { return int(n), nil } +func (s *Stream) ReadFloat32(pcm []float32) (int, error) { + if s.oggfile == nil { + return 0, fmt.Errorf("opus stream is uninitialized or already closed") + } + if len(pcm) == 0 { + return 0, nil + } + n := C.op_read_float( + s.oggfile, + (*C.float)(&pcm[0]), + C.int(len(pcm)), + nil) + if n < 0 { + return 0, opusfileerr(n) + } + if n == 0 { + return 0, io.EOF + } + return int(n), nil +} + func (s *Stream) Close() error { if s.oggfile == nil { return fmt.Errorf("opus stream is uninitialized or already closed")