mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
audio/internal/cbackend: adjust the defalut buffer size to Oto's
This commit is contained in:
parent
e2de758160
commit
d74a627f41
@ -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]
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user