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 return nil
} }
func (c *Context) bufferSize() int { func (c *Context) defaultBufferSize() int {
return c.sampleRate * c.channelNum * c.bitDepthInBytes / 4 // 0.25[s] 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 { func (p *playerImpl) ensureTmpBuf() []byte {
if p.tmpbuf == nil { if p.tmpbuf == nil {
p.tmpbuf = make([]byte, p.context.bufferSize()) p.tmpbuf = make([]byte, p.context.defaultBufferSize())
} }
return p.tmpbuf return p.tmpbuf
} }
@ -193,7 +193,7 @@ func (p *playerImpl) playImpl() {
if !p.eof { if !p.eof {
buf := p.ensureTmpBuf() buf := p.ensureTmpBuf()
for len(p.buf) < p.context.bufferSize() { for len(p.buf) < p.context.defaultBufferSize() {
n, err := p.src.Read(buf) n, err := p.src.Read(buf)
if err != nil && err != io.EOF { if err != nil && err != io.EOF {
p.setErrorImpl(err) p.setErrorImpl(err)
@ -360,7 +360,7 @@ func (p *playerImpl) canReadSourceToBuffer() bool {
if p.eof { if p.eof {
return false return false
} }
return len(p.buf) < p.context.bufferSize() return len(p.buf) < p.context.defaultBufferSize()
} }
func (p *playerImpl) readSourceToBuffer() { func (p *playerImpl) readSourceToBuffer() {
@ -374,7 +374,7 @@ func (p *playerImpl) readSourceToBuffer() {
return return
} }
if len(p.buf) >= p.context.bufferSize() { if len(p.buf) >= p.context.defaultBufferSize() {
return return
} }