From 7a5254f48f1545085b59205abc7400cc4c6ba1f2 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 22 Aug 2021 00:36:28 +0900 Subject: [PATCH] audio: Refactoring --- audio/internal/go2cpp/player_js.go | 14 +++++++++++++- audio/player_js.go | 22 +--------------------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/audio/internal/go2cpp/player_js.go b/audio/internal/go2cpp/player_js.go index 1b7fd4e0f..de6867df5 100644 --- a/audio/internal/go2cpp/player_js.go +++ b/audio/internal/go2cpp/player_js.go @@ -19,6 +19,8 @@ import ( "runtime" "sync" "syscall/js" + + "github.com/hajimehoshi/ebiten/v2/audio/internal/readerdriver" ) type Context struct { @@ -38,7 +40,7 @@ func NewContext(sampleRate int, channelNum, bitDepthInBytes int) *Context { } } -func (c *Context) NewPlayer(r io.Reader) *Player { +func (c *Context) NewPlayer(r io.Reader) readerdriver.Player { cond := sync.NewCond(&sync.Mutex{}) onwritten := js.FuncOf(func(this js.Value, args []js.Value) interface{} { cond.Signal() @@ -55,6 +57,16 @@ func (c *Context) NewPlayer(r io.Reader) *Player { return p } +func (c *Context) Suspend() error { + // Do nothing so far. + return nil +} + +func (c *Context) Resume() error { + // Do nothing so far. + return nil +} + func (c *Context) oneBufferSize() int { // TODO: This must be audio.oneBufferSize(p.context.sampleRate). Avoid the duplication. return c.sampleRate * c.channelNum * c.bitDepthInBytes / 4 diff --git a/audio/player_js.go b/audio/player_js.go index 74aff9526..b155c0e2e 100644 --- a/audio/player_js.go +++ b/audio/player_js.go @@ -15,7 +15,6 @@ package audio import ( - "io" "syscall/js" "github.com/hajimehoshi/ebiten/v2/audio/internal/go2cpp" @@ -26,27 +25,8 @@ func newContext(sampleRate, channelNum, bitDepthInBytes int) (context, chan stru if js.Global().Get("go2cpp").Truthy() { ready := make(chan struct{}) close(ready) - ctx := go2cpp.NewContext(sampleRate, channelNum, bitDepthInBytes) - return &go2cppDriverWrapper{ctx}, ready, nil + return go2cpp.NewContext(sampleRate, channelNum, bitDepthInBytes), ready, nil } return readerdriver.NewContext(sampleRate, channelNum, bitDepthInBytes) } - -type go2cppDriverWrapper struct { - c *go2cpp.Context -} - -func (w *go2cppDriverWrapper) NewPlayer(r io.Reader) readerdriver.Player { - return w.c.NewPlayer(r) -} - -func (w *go2cppDriverWrapper) Suspend() error { - // Do nothing so far. - return nil -} - -func (w *go2cppDriverWrapper) Resume() error { - // Do nothing so far. - return nil -}