audio/vorbis: Remove Stream interface

This commit is contained in:
Hajime Hoshi 2016-03-27 01:15:28 +09:00
parent a3b5b283e4
commit 3b35e6c253
3 changed files with 8 additions and 14 deletions

View File

@ -16,29 +16,23 @@ package vorbis
import (
"bytes"
"io"
"time"
)
type Stream interface {
io.ReadSeeker
Len() time.Duration
}
type stream struct {
type Stream struct {
buf *bytes.Reader
sampleRate int
}
func (s *stream) Read(p []byte) (int, error) {
func (s *Stream) Read(p []byte) (int, error) {
return s.buf.Read(p)
}
func (s *stream) Seek(offset int64, whence int) (int64, error) {
func (s *Stream) Seek(offset int64, whence int) (int64, error) {
return s.buf.Seek(offset, whence)
}
func (s *stream) Len() time.Duration {
func (s *Stream) Len() time.Duration {
const bytesPerSample = 4
return time.Duration(s.buf.Len()/bytesPerSample) * time.Second / time.Duration(s.sampleRate)
}

View File

@ -27,7 +27,7 @@ import (
"github.com/hajimehoshi/go-vorbis"
)
func Decode(context *audio.Context, src io.Reader) (Stream, error) {
func Decode(context *audio.Context, src io.Reader) (*Stream, error) {
decoded, channels, sampleRate, err := vorbis.Decode(src)
if err != nil {
return nil, err
@ -44,7 +44,7 @@ func Decode(context *audio.Context, src io.Reader) (Stream, error) {
if err != nil {
return nil, err
}
s := &stream{
s := &Stream{
buf: bytes.NewReader(b),
sampleRate: sampleRate,
}

View File

@ -29,12 +29,12 @@ import (
// TODO: This just uses decodeAudioData can treat audio files other than Ogg/Vorbis.
// TODO: This doesn't work on iOS which doesn't have Ogg/Vorbis decoder.
func Decode(context *audio.Context, src io.Reader) (Stream, error) {
func Decode(context *audio.Context, src io.Reader) (*Stream, error) {
b, err := ioutil.ReadAll(src)
if err != nil {
return nil, err
}
s := &stream{
s := &Stream{
sampleRate: context.SampleRate(),
}
ch := make(chan struct{})