mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-13 22:47:26 +01:00
audio: Bug fix: Noise on Safari because of performance issue (#307)
This commit is contained in:
parent
6e897d1479
commit
7201015d02
@ -91,9 +91,13 @@ func toLR(data []byte) ([]int16, []int16) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) Proceed(data []byte) error {
|
func (p *Player) Proceed(data []byte) error {
|
||||||
|
// delay is buffer in sample numbers for p.positionInSamples.
|
||||||
|
// Without this, adjusting p.positionInSamples with the context's currenTime
|
||||||
|
// much more often especially on Safari, which is the cause of noise (#307).
|
||||||
|
const delay = 256
|
||||||
p.bufferedData = append(p.bufferedData, data...)
|
p.bufferedData = append(p.bufferedData, data...)
|
||||||
c := int64(p.context.Get("currentTime").Float() * float64(p.sampleRate))
|
c := int64(p.context.Get("currentTime").Float() * float64(p.sampleRate))
|
||||||
if p.positionInSamples < c {
|
if p.positionInSamples+delay < c {
|
||||||
p.positionInSamples = c
|
p.positionInSamples = c
|
||||||
}
|
}
|
||||||
// Heuristic data size which doesn't cause too much noise and too much delay (#299)
|
// Heuristic data size which doesn't cause too much noise and too much delay (#299)
|
||||||
@ -114,7 +118,7 @@ func (p *Player) Proceed(data []byte) error {
|
|||||||
s := p.context.Call("createBufferSource")
|
s := p.context.Call("createBufferSource")
|
||||||
s.Set("buffer", buf)
|
s.Set("buffer", buf)
|
||||||
s.Call("connect", p.context.Get("destination"))
|
s.Call("connect", p.context.Get("destination"))
|
||||||
s.Call("start", float64(p.positionInSamples)/float64(p.sampleRate))
|
s.Call("start", float64(p.positionInSamples+delay)/float64(p.sampleRate))
|
||||||
p.positionInSamples += int64(len(il))
|
p.positionInSamples += int64(len(il))
|
||||||
p.bufferedData = p.bufferedData[dataSize:]
|
p.bufferedData = p.bufferedData[dataSize:]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user