mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
audio: Refactoring
This commit is contained in:
parent
88da1bb23f
commit
7a5254f48f
@ -19,6 +19,8 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall/js"
|
"syscall/js"
|
||||||
|
|
||||||
|
"github.com/hajimehoshi/ebiten/v2/audio/internal/readerdriver"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Context struct {
|
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{})
|
cond := sync.NewCond(&sync.Mutex{})
|
||||||
onwritten := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
onwritten := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||||
cond.Signal()
|
cond.Signal()
|
||||||
@ -55,6 +57,16 @@ func (c *Context) NewPlayer(r io.Reader) *Player {
|
|||||||
return p
|
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 {
|
func (c *Context) oneBufferSize() int {
|
||||||
// TODO: This must be audio.oneBufferSize(p.context.sampleRate). Avoid the duplication.
|
// TODO: This must be audio.oneBufferSize(p.context.sampleRate). Avoid the duplication.
|
||||||
return c.sampleRate * c.channelNum * c.bitDepthInBytes / 4
|
return c.sampleRate * c.channelNum * c.bitDepthInBytes / 4
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
package audio
|
package audio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"syscall/js"
|
"syscall/js"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/audio/internal/go2cpp"
|
"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() {
|
if js.Global().Get("go2cpp").Truthy() {
|
||||||
ready := make(chan struct{})
|
ready := make(chan struct{})
|
||||||
close(ready)
|
close(ready)
|
||||||
ctx := go2cpp.NewContext(sampleRate, channelNum, bitDepthInBytes)
|
return go2cpp.NewContext(sampleRate, channelNum, bitDepthInBytes), ready, nil
|
||||||
return &go2cppDriverWrapper{ctx}, ready, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return readerdriver.NewContext(sampleRate, channelNum, bitDepthInBytes)
|
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
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user