From 3b35e6c253066926a99a86dfc652858edce30b7b Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 27 Mar 2016 01:15:28 +0900 Subject: [PATCH] audio/vorbis: Remove Stream interface --- exp/audio/vorbis/stream.go | 14 ++++---------- exp/audio/vorbis/vorbis.go | 4 ++-- exp/audio/vorbis/vorbis_js.go | 4 ++-- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/exp/audio/vorbis/stream.go b/exp/audio/vorbis/stream.go index bd381fb1c..00c0ff0d3 100644 --- a/exp/audio/vorbis/stream.go +++ b/exp/audio/vorbis/stream.go @@ -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) } diff --git a/exp/audio/vorbis/vorbis.go b/exp/audio/vorbis/vorbis.go index b83ef77cf..57e36fc57 100644 --- a/exp/audio/vorbis/vorbis.go +++ b/exp/audio/vorbis/vorbis.go @@ -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, } diff --git a/exp/audio/vorbis/vorbis_js.go b/exp/audio/vorbis/vorbis_js.go index ae8259b57..58131bfea 100644 --- a/exp/audio/vorbis/vorbis_js.go +++ b/exp/audio/vorbis/vorbis_js.go @@ -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{})