audio/internal/cbackend: adjust the defalut buffer size to Oto's

This commit is contained in:
Hajime Hoshi 2022-03-25 03:47:21 +09:00
parent e2de758160
commit d74a627f41
2 changed files with 6 additions and 6 deletions

View File

@ -62,6 +62,6 @@ func (c *Context) Err() error {
return nil
}
func (c *Context) bufferSize() int {
return c.sampleRate * c.channelNum * c.bitDepthInBytes / 4 // 0.25[s]
func (c *Context) defaultBufferSize() int {
return c.sampleRate * c.channelNum * c.bitDepthInBytes / 2 // 0.5[s]
}

View File

@ -178,7 +178,7 @@ func (p *playerImpl) Play() {
func (p *playerImpl) ensureTmpBuf() []byte {
if p.tmpbuf == nil {
p.tmpbuf = make([]byte, p.context.bufferSize())
p.tmpbuf = make([]byte, p.context.defaultBufferSize())
}
return p.tmpbuf
}
@ -193,7 +193,7 @@ func (p *playerImpl) playImpl() {
if !p.eof {
buf := p.ensureTmpBuf()
for len(p.buf) < p.context.bufferSize() {
for len(p.buf) < p.context.defaultBufferSize() {
n, err := p.src.Read(buf)
if err != nil && err != io.EOF {
p.setErrorImpl(err)
@ -360,7 +360,7 @@ func (p *playerImpl) canReadSourceToBuffer() bool {
if p.eof {
return false
}
return len(p.buf) < p.context.bufferSize()
return len(p.buf) < p.context.defaultBufferSize()
}
func (p *playerImpl) readSourceToBuffer() {
@ -374,7 +374,7 @@ func (p *playerImpl) readSourceToBuffer() {
return
}
if len(p.buf) >= p.context.bufferSize() {
if len(p.buf) >= p.context.defaultBufferSize() {
return
}