mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +01:00
audio: Rename OggStream -> VorbisStream
This commit is contained in:
parent
b964df4f0f
commit
252fee56d3
@ -43,7 +43,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
// TODO: sampleRate should be obtained from the ogg file.
|
// TODO: sampleRate should be obtained from the ogg file.
|
||||||
audioContext = audio.NewContext(22050)
|
audioContext = audio.NewContext(22050)
|
||||||
s, err := audioContext.NewOggStream(f)
|
s, err := audioContext.NewVorbisStream(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -26,11 +26,11 @@ import (
|
|||||||
"github.com/hajimehoshi/go-vorbis"
|
"github.com/hajimehoshi/go-vorbis"
|
||||||
)
|
)
|
||||||
|
|
||||||
type OggStream struct {
|
type VorbisStream struct {
|
||||||
buf *bytes.Reader
|
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)
|
decoded, channels, sampleRate, err := vorbis.Decode(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -47,16 +47,16 @@ func (c *Context) NewOggStream(src io.Reader) (*OggStream, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
s := &OggStream{
|
s := &VorbisStream{
|
||||||
buf: bytes.NewReader(b),
|
buf: bytes.NewReader(b),
|
||||||
}
|
}
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *OggStream) Read(p []byte) (int, error) {
|
func (s *VorbisStream) Read(p []byte) (int, error) {
|
||||||
return s.buf.Read(p)
|
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)
|
return s.buf.Seek(offset, whence)
|
||||||
}
|
}
|
@ -24,24 +24,24 @@ import (
|
|||||||
"github.com/gopherjs/gopherjs/js"
|
"github.com/gopherjs/gopherjs/js"
|
||||||
)
|
)
|
||||||
|
|
||||||
type OggStream struct {
|
type VorbisStream struct {
|
||||||
buf *bytes.Reader
|
buf *bytes.Reader
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This just uses decodeAudioData can treat audio files other than Ogg/Vorbis.
|
// 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.
|
// 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)
|
b, err := ioutil.ReadAll(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
s := &OggStream{}
|
s := &VorbisStream{}
|
||||||
ch := make(chan struct{})
|
ch := make(chan struct{})
|
||||||
|
|
||||||
// TODO: 1 is a correct second argument?
|
// TODO: 1 is a correct second argument?
|
||||||
oc := js.Global.Get("OfflineAudioContext").New(2, 1, c.sampleRate)
|
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)
|
defer close(ch)
|
||||||
il := buf.Call("getChannelData", 0).Interface().([]float32)
|
il := buf.Call("getChannelData", 0).Interface().([]float32)
|
||||||
ir := buf.Call("getChannelData", 1).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
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *OggStream) Read(p []byte) (int, error) {
|
func (s *VorbisStream) Read(p []byte) (int, error) {
|
||||||
return s.buf.Read(p)
|
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)
|
return s.buf.Seek(offset, whence)
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user