Added Decoder.ReadStereo() / Decoder.ReadStereoFloat32() using stereo decoding API
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
88633d8444
commit
dcd55d6b5c
46
stream.go
46
stream.go
|
@ -171,6 +171,52 @@ func (s *Stream) ReadFloat32(pcm []float32) (int, error) {
|
|||
return int(n), nil
|
||||
}
|
||||
|
||||
// ReadStereo is the same as Read, but decodes to always two channels
|
||||
func (s *Stream) ReadStereo(pcm []int16) (int, error) {
|
||||
if s.oggfile == nil {
|
||||
return 0, fmt.Errorf("opus stream is uninitialized or already closed")
|
||||
}
|
||||
if len(pcm) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
streams.Save(s)
|
||||
defer streams.Del(s)
|
||||
n := C.op_read_stereo(
|
||||
s.oggfile,
|
||||
(*C.opus_int16)(&pcm[0]),
|
||||
C.int(len(pcm)))
|
||||
if n < 0 {
|
||||
return 0, StreamError(n)
|
||||
}
|
||||
if n == 0 {
|
||||
return 0, io.EOF
|
||||
}
|
||||
return int(n), nil
|
||||
}
|
||||
|
||||
// ReadStereoFloat32 is the same as ReadStereo, but decodes to float32 instead of int16.
|
||||
func (s *Stream) ReadStereoFloat32(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
|
||||
}
|
||||
streams.Save(s)
|
||||
defer streams.Del(s)
|
||||
n := C.op_read_float_stereo(
|
||||
s.oggfile,
|
||||
(*C.float)(&pcm[0]),
|
||||
C.int(len(pcm)))
|
||||
if n < 0 {
|
||||
return 0, StreamError(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")
|
||||
|
|
Loading…
Reference in a new issue