mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
audio: Adjust buffer size to reduce noise
This commit is contained in:
parent
f2173f8f75
commit
77b62615b2
@ -75,11 +75,13 @@ func max64(a, b int64) int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *player) proceed() error {
|
func (p *player) proceed() error {
|
||||||
const bufferSize = 2048
|
const channelNum = 2
|
||||||
|
const bytesPerSample = channelNum * 16 / 8
|
||||||
|
bufferSize := p.sampleRate * bytesPerSample / 60
|
||||||
c := int64(p.context.Get("currentTime").Float() * float64(p.sampleRate))
|
c := int64(p.context.Get("currentTime").Float() * float64(p.sampleRate))
|
||||||
// Buffer size is relatively big and it is needed to check that c.positionInSample doesn't
|
// Buffer size is relatively big and it is needed to check that c.positionInSample doesn't
|
||||||
// proceed too far away (#180).
|
// proceed too far away (#180).
|
||||||
if c+bufferSize < p.positionInSamples {
|
if c+int64(bufferSize) < p.positionInSamples {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if p.positionInSamples < c {
|
if p.positionInSamples < c {
|
||||||
@ -88,8 +90,6 @@ func (p *player) proceed() error {
|
|||||||
b := make([]byte, bufferSize)
|
b := make([]byte, bufferSize)
|
||||||
n, err := p.src.Read(b)
|
n, err := p.src.Read(b)
|
||||||
if 0 < n {
|
if 0 < n {
|
||||||
const channelNum = 2
|
|
||||||
const bytesPerSample = channelNum * 16 / 8
|
|
||||||
buf := p.context.Call("createBuffer", channelNum, n/bytesPerSample, p.sampleRate)
|
buf := p.context.Call("createBuffer", channelNum, n/bytesPerSample, p.sampleRate)
|
||||||
l := buf.Call("getChannelData", 0)
|
l := buf.Call("getChannelData", 0)
|
||||||
r := buf.Call("getChannelData", 1)
|
r := buf.Call("getChannelData", 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user