mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
audio/internal/convert: Refactoring
This commit is contained in:
parent
b7abde7f00
commit
3fb304e5a8
@ -32,6 +32,13 @@ type f32Reader struct {
|
|||||||
buf *byte
|
buf *byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func max(a, b int) int {
|
||||||
|
if a < b {
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
func (f *f32Reader) Read(buf []byte) (int, error) {
|
func (f *f32Reader) Read(buf []byte) (int, error) {
|
||||||
if f.eof {
|
if f.eof {
|
||||||
return 0, io.EOF
|
return 0, io.EOF
|
||||||
@ -45,10 +52,7 @@ func (f *f32Reader) Read(buf []byte) (int, error) {
|
|||||||
return 1, nil
|
return 1, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
bf := make([]float32, len(buf)/2)
|
bf := make([]float32, max(len(buf)/2, 1))
|
||||||
if len(buf) == 1 {
|
|
||||||
bf = make([]float32, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
n, err := f.r.Read(bf)
|
n, err := f.r.Read(bf)
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && err != io.EOF {
|
||||||
|
Loading…
Reference in New Issue
Block a user