mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +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 {
|
||||
v js.Value
|
||||
sampleRate int
|
||||
channelNum int
|
||||
bitDepthInBytes int
|
||||
v js.Value
|
||||
}
|
||||
|
||||
func NewContext(sampleRate int, channelNum, bitDepthInBytes int) *Context {
|
||||
v := js.Global().Get("go2cpp").Call("createAudio", sampleRate, channelNum, bitDepthInBytes)
|
||||
return &Context{
|
||||
v: v,
|
||||
sampleRate: sampleRate,
|
||||
channelNum: channelNum,
|
||||
bitDepthInBytes: bitDepthInBytes,
|
||||
v: v,
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,22 +103,7 @@ func (p *Player) Play() {
|
||||
p.v.Set("volume", p.volume)
|
||||
runloop = true
|
||||
}
|
||||
|
||||
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 {
|
||||
go p.loop()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user