audio/internal/readerdriver: Experimental increase of buffers

Also, this change reduces goroutine uses for efficiency.

Updates #1768
This commit is contained in:
Hajime Hoshi 2021-08-18 23:19:14 +09:00
parent 045b14ba21
commit ded679c071
2 changed files with 15 additions and 7 deletions

View File

@ -22,7 +22,7 @@ import (
"golang.org/x/sys/windows"
)
const headerBufferSize = 4096
const headerBufferSize = 8192
func IsAvailable() bool {
return true
@ -117,7 +117,7 @@ func NewContext(sampleRate, channelNum, bitDepthInBytes int) (Context, chan stru
}
c.waveOut = w
c.headers = make([]*header, 0, 4)
c.headers = make([]*header, 0, 3)
for len(c.headers) < cap(c.headers) {
h, err := newHeader(c.waveOut, headerBufferSize)
if err != nil {

View File

@ -156,15 +156,23 @@ func (p *player) Play() {
}
func (p *playerImpl) Play() {
ch := make(chan struct{})
go func() {
// Goroutines don't work effiently on Windows. Avoid using them (#1768).
if runtime.GOOS == "windows" {
p.m.Lock()
defer p.m.Unlock()
close(ch)
p.playImpl()
}()
<-ch
} else {
ch := make(chan struct{})
go func() {
p.m.Lock()
defer p.m.Unlock()
close(ch)
p.playImpl()
}()
<-ch
}
}
func (p *playerImpl) playImpl() {