From 18c6890d96f6edfb3fadab9f529878669ae0b62c Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 24 Dec 2017 00:58:14 +0900 Subject: [PATCH] audio: More often reading (decoding) audio source to reduce noise --- audio/audio.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/audio/audio.go b/audio/audio.go index 438a262e4..92367e3c0 100644 --- a/audio/audio.go +++ b/audio/audio.go @@ -488,8 +488,8 @@ func (p *Player) readLoop() { break } - // Try to read the buffer for 1/15[s]. - l := p.sampleRate * bytesPerSample * channelNum / 15 + // Try to read the buffer for 1/60[s]. + l := p.sampleRate * bytesPerSample * channelNum / 60 l &= mask buf := make([]byte, l) n, err := p.src.Read(buf) @@ -507,7 +507,7 @@ func (p *Player) readLoop() { t = nil break } - t = time.After(10 * time.Millisecond) + t = time.After(time.Millisecond) case buf := <-p.proceedCh: if readErr != nil { @@ -518,9 +518,7 @@ func (p *Player) readLoop() { lengthInBytes := len(buf) * 2 l := lengthInBytes - // Buffer size needs to be much more than the actual required length - // so that noise caused by empty buffer can be avoided. - if len(p.buf) < lengthInBytes*8 && !p.srcEOF { + if len(p.buf) < lengthInBytes && !p.srcEOF { p.proceededCh <- proceededValues{buf, nil} break }