mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
audio/internal/readerdriver: Refactoring
This commit is contained in:
parent
7f8c3a13b3
commit
08c3025560
@ -182,17 +182,15 @@ func (p *playerImpl) appendBuffer(this js.Value, args []js.Value) interface{} {
|
||||
}
|
||||
|
||||
tmp := make([]byte, 4096)
|
||||
need := p.context.oneBufferSize()
|
||||
bs := make([]byte, 0, need)
|
||||
for need > 0 {
|
||||
bs := make([]byte, 0, p.context.oneBufferSize())
|
||||
for cap(bs)-len(bs) > 0 {
|
||||
if len(p.buf) > 0 {
|
||||
n := len(p.buf)
|
||||
if n > need {
|
||||
if need := cap(bs) - len(bs); n > need {
|
||||
n = need
|
||||
}
|
||||
bs = append(bs, p.buf[:n]...)
|
||||
p.buf = p.buf[n:]
|
||||
need -= n
|
||||
continue
|
||||
}
|
||||
n, err := p.src.Read(tmp)
|
||||
@ -201,12 +199,11 @@ func (p *playerImpl) appendBuffer(this js.Value, args []js.Value) interface{} {
|
||||
p.Pause()
|
||||
return nil
|
||||
}
|
||||
if n > need {
|
||||
if need := cap(bs) - len(bs); n > need {
|
||||
p.buf = append(p.buf, tmp[need:]...)
|
||||
n = need
|
||||
}
|
||||
bs = append(bs, tmp[:n]...)
|
||||
need -= n
|
||||
if err == io.EOF {
|
||||
p.eof = true
|
||||
break
|
||||
|
Loading…
Reference in New Issue
Block a user