mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 11:48:55 +01:00
audio: Make sure to fill 4096 bytes
This commit is contained in:
parent
e69b44e327
commit
c090805021
@ -89,26 +89,33 @@ func (p *player) proceed() error {
|
|||||||
p.position = c
|
p.position = c
|
||||||
}
|
}
|
||||||
b := make([]byte, bufferSize)
|
b := make([]byte, bufferSize)
|
||||||
n, err := p.src.Read(b)
|
for 0 < len(b) {
|
||||||
if 0 < n {
|
print(len(b))
|
||||||
const channelNum = 2
|
n, err := p.src.Read(b)
|
||||||
const bytesPerSample = channelNum * 16 / 8
|
if 0 < n {
|
||||||
buf := p.context.Call("createBuffer", channelNum, n/bytesPerSample, p.sampleRate)
|
const channelNum = 2
|
||||||
l := buf.Call("getChannelData", 0)
|
const bytesPerSample = channelNum * 16 / 8
|
||||||
r := buf.Call("getChannelData", 1)
|
buf := p.context.Call("createBuffer", channelNum, n/bytesPerSample, p.sampleRate)
|
||||||
il, ir := toLR(b[:n])
|
l := buf.Call("getChannelData", 0)
|
||||||
const max = 1 << 15
|
r := buf.Call("getChannelData", 1)
|
||||||
for i := 0; i < len(il); i++ {
|
il, ir := toLR(b[:n])
|
||||||
l.SetIndex(i, float64(il[i])/max)
|
const max = 1 << 15
|
||||||
r.SetIndex(i, float64(ir[i])/max)
|
for i := 0; i < len(il); i++ {
|
||||||
|
l.SetIndex(i, float64(il[i])/max)
|
||||||
|
r.SetIndex(i, float64(ir[i])/max)
|
||||||
|
}
|
||||||
|
p.bufferSource = p.context.Call("createBufferSource")
|
||||||
|
p.bufferSource.Set("buffer", buf)
|
||||||
|
p.bufferSource.Call("connect", p.context.Get("destination"))
|
||||||
|
p.bufferSource.Call("start", maxF(p.position, c))
|
||||||
|
p.position += buf.Get("duration").Float()
|
||||||
|
b = b[n:]
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
p.bufferSource = p.context.Call("createBufferSource")
|
|
||||||
p.bufferSource.Set("buffer", buf)
|
|
||||||
p.bufferSource.Call("connect", p.context.Get("destination"))
|
|
||||||
p.bufferSource.Call("start", maxF(p.position, c))
|
|
||||||
p.position += buf.Get("duration").Float()
|
|
||||||
}
|
}
|
||||||
return err
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *player) start() error {
|
func (p *player) start() error {
|
||||||
|
Loading…
Reference in New Issue
Block a user