mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-13 12:32:05 +01:00
audio/internal/go2cpp: Fix C++ side and remove the preparation
This commit is contained in:
parent
ed7d7e8976
commit
65f974588c
@ -22,19 +22,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Context struct {
|
type Context struct {
|
||||||
v js.Value
|
v js.Value
|
||||||
sampleRate int
|
|
||||||
channelNum int
|
|
||||||
bitDepthInBytes int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewContext(sampleRate int, channelNum, bitDepthInBytes int) *Context {
|
func NewContext(sampleRate int, channelNum, bitDepthInBytes int) *Context {
|
||||||
v := js.Global().Get("go2cpp").Call("createAudio", sampleRate, channelNum, bitDepthInBytes)
|
v := js.Global().Get("go2cpp").Call("createAudio", sampleRate, channelNum, bitDepthInBytes)
|
||||||
return &Context{
|
return &Context{
|
||||||
v: v,
|
v: v,
|
||||||
sampleRate: sampleRate,
|
|
||||||
channelNum: channelNum,
|
|
||||||
bitDepthInBytes: bitDepthInBytes,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,22 +103,7 @@ func (p *Player) Play() {
|
|||||||
p.v.Set("volume", p.volume)
|
p.v.Set("volume", p.volume)
|
||||||
runloop = true
|
runloop = true
|
||||||
}
|
}
|
||||||
|
|
||||||
p.v.Call("play")
|
p.v.Call("play")
|
||||||
|
|
||||||
// Prepare the first data as soon as possible, or the audio can get stuck.
|
|
||||||
// TODO: Get the appropriate buffer size from the C++ side.
|
|
||||||
buf := make([]byte, p.context.sampleRate*p.context.channelNum*p.context.bitDepthInBytes/4)
|
|
||||||
n, err := p.src.Read(buf)
|
|
||||||
if err != nil && err != io.EOF {
|
|
||||||
p.setError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if n > 0 {
|
|
||||||
dst := js.Global().Get("Uint8Array").New(n)
|
|
||||||
p.writeImpl(dst, buf[:n])
|
|
||||||
}
|
|
||||||
|
|
||||||
if runloop {
|
if runloop {
|
||||||
go p.loop()
|
go p.loop()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user