From 252fee56d3ae9a15f9fe664c15c2820f0fe26ec6 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 9 Mar 2016 01:36:19 +0900 Subject: [PATCH] audio: Rename OggStream -> VorbisStream --- examples/audio/main.go | 2 +- exp/audio/{ogg.go => vorbis.go} | 10 +++++----- exp/audio/{ogg_js.go => vorbis_js.go} | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) rename exp/audio/{ogg.go => vorbis.go} (84%) rename exp/audio/{ogg_js.go => vorbis_js.go} (86%) diff --git a/examples/audio/main.go b/examples/audio/main.go index 2a4ddaa58..f8cbf12e6 100644 --- a/examples/audio/main.go +++ b/examples/audio/main.go @@ -43,7 +43,7 @@ func main() { } // TODO: sampleRate should be obtained from the ogg file. audioContext = audio.NewContext(22050) - s, err := audioContext.NewOggStream(f) + s, err := audioContext.NewVorbisStream(f) if err != nil { log.Fatal(err) } diff --git a/exp/audio/ogg.go b/exp/audio/vorbis.go similarity index 84% rename from exp/audio/ogg.go rename to exp/audio/vorbis.go index b2b880546..6ecd7f35d 100644 --- a/exp/audio/ogg.go +++ b/exp/audio/vorbis.go @@ -26,11 +26,11 @@ import ( "github.com/hajimehoshi/go-vorbis" ) -type OggStream struct { +type VorbisStream struct { buf *bytes.Reader } -func (c *Context) NewOggStream(src io.Reader) (*OggStream, error) { +func (c *Context) NewVorbisStream(src io.Reader) (*VorbisStream, error) { decoded, channels, sampleRate, err := vorbis.Decode(src) if err != nil { return nil, err @@ -47,16 +47,16 @@ func (c *Context) NewOggStream(src io.Reader) (*OggStream, error) { if err != nil { return nil, err } - s := &OggStream{ + s := &VorbisStream{ buf: bytes.NewReader(b), } return s, nil } -func (s *OggStream) Read(p []byte) (int, error) { +func (s *VorbisStream) Read(p []byte) (int, error) { return s.buf.Read(p) } -func (s *OggStream) Seek(offset int64, whence int) (int64, error) { +func (s *VorbisStream) Seek(offset int64, whence int) (int64, error) { return s.buf.Seek(offset, whence) } diff --git a/exp/audio/ogg_js.go b/exp/audio/vorbis_js.go similarity index 86% rename from exp/audio/ogg_js.go rename to exp/audio/vorbis_js.go index 318268d79..7ddfa537b 100644 --- a/exp/audio/ogg_js.go +++ b/exp/audio/vorbis_js.go @@ -24,24 +24,24 @@ import ( "github.com/gopherjs/gopherjs/js" ) -type OggStream struct { +type VorbisStream struct { buf *bytes.Reader } // 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 (c *Context) NewOggStream(src io.Reader) (*OggStream, error) { +func (c *Context) NewVorbisStream(src io.Reader) (*VorbisStream, error) { b, err := ioutil.ReadAll(src) if err != nil { return nil, err } - s := &OggStream{} + s := &VorbisStream{} ch := make(chan struct{}) // TODO: 1 is a correct second argument? oc := js.Global.Get("OfflineAudioContext").New(2, 1, c.sampleRate) - oc.Call("decodeAudioData", js.NewArrayBuffer(b), func(buf *js.Obbmaiject) { + oc.Call("decodeAudioData", js.NewArrayBuffer(b), func(buf *js.Object) { defer close(ch) il := buf.Call("getChannelData", 0).Interface().([]float32) ir := buf.Call("getChannelData", 1).Interface().([]float32) @@ -60,10 +60,10 @@ func (c *Context) NewOggStream(src io.Reader) (*OggStream, error) { return s, nil } -func (s *OggStream) Read(p []byte) (int, error) { +func (s *VorbisStream) Read(p []byte) (int, error) { return s.buf.Read(p) } -func (s *OggStream) Seek(offset int64, whence int) (int64, error) { +func (s *VorbisStream) Seek(offset int64, whence int) (int64, error) { return s.buf.Seek(offset, whence) }