mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
audio/internal/convert: bug fix: Read never returned io.EOF when seeked
This commit is contained in:
parent
c03ece2671
commit
91cdaa9f11
@ -68,7 +68,11 @@ func (r *float32BytesReader) Read(buf []byte) (int, error) {
|
||||
copy(r.i16Buf, r.i16Buf[samplesToFill*2:])
|
||||
r.i16Buf = r.i16Buf[:len(r.i16Buf)-samplesToFill*2]
|
||||
|
||||
return samplesToFill * 4, nil
|
||||
n := samplesToFill * 4
|
||||
if r.eof {
|
||||
return n, io.EOF
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (r *float32BytesReader) Seek(offset int64, whence int) (int64, error) {
|
||||
|
@ -66,6 +66,13 @@ func TestFloat32(t *testing.T) {
|
||||
for _, c := range cases {
|
||||
c := c
|
||||
t.Run(c.Name, func(t *testing.T) {
|
||||
for _, seek := range []bool{false, true} {
|
||||
seek := seek
|
||||
name := "nonseek"
|
||||
if seek {
|
||||
name = "seek"
|
||||
}
|
||||
t.Run(name, func(t *testing.T) {
|
||||
// Note that unsafe.SliceData is available as of Go 1.20.
|
||||
var in, out []byte
|
||||
if len(c.In) > 0 {
|
||||
@ -76,7 +83,7 @@ func TestFloat32(t *testing.T) {
|
||||
in = unsafe.Slice((*byte)(unsafe.Pointer(&c.In[0])), len(c.In)*2)
|
||||
out = unsafe.Slice((*byte)(unsafe.Pointer(&outF32[0])), len(outF32)*4)
|
||||
}
|
||||
r := convert.NewFloat32BytesReaderFromInt16BytesReader(bytes.NewReader(in))
|
||||
r := convert.NewFloat32BytesReaderFromInt16BytesReader(bytes.NewReader(in)).(io.ReadSeeker)
|
||||
var got []byte
|
||||
for {
|
||||
var buf [97]byte
|
||||
@ -88,6 +95,14 @@ func TestFloat32(t *testing.T) {
|
||||
}
|
||||
break
|
||||
}
|
||||
if seek {
|
||||
if _, err := r.Seek(0, io.SeekCurrent); err != nil {
|
||||
if err != io.EOF {
|
||||
t.Fatal(err)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
want := out
|
||||
if !bytes.Equal(got, want) {
|
||||
@ -95,4 +110,6 @@ func TestFloat32(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user