mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-13 03:23:14 +01:00
audio/vorbis: bug fix: an int16Stream with io.Reader didn't work
Closes #3192
This commit is contained in:
parent
6cdc2a693b
commit
4df5d02c36
@ -113,14 +113,7 @@ func (s *i16Stream) Read(b []byte) (int, error) {
|
||||
s.i16Reader = newInt16BytesReaderFromFloat32Reader(s.vorbisReader)
|
||||
}
|
||||
|
||||
l := s.totalBytes() - s.posInBytes
|
||||
if l > int64(len(b)) {
|
||||
l = int64(len(b))
|
||||
}
|
||||
if l < 0 {
|
||||
return 0, io.EOF
|
||||
}
|
||||
|
||||
l := int64(len(b))
|
||||
retry:
|
||||
n, err := s.i16Reader.Read(b[:l])
|
||||
if err != nil && err != io.EOF {
|
||||
@ -130,12 +123,8 @@ retry:
|
||||
// When l is too small, decoder's Read might return 0 for a while. Let's retry.
|
||||
goto retry
|
||||
}
|
||||
|
||||
s.posInBytes += int64(n)
|
||||
if s.posInBytes == s.totalBytes() || err == io.EOF {
|
||||
return n, io.EOF
|
||||
}
|
||||
return n, nil
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (s *i16Stream) Seek(offset int64, whence int) (int64, error) {
|
||||
|
@ -138,7 +138,13 @@ func TestNonSeeker(t *testing.T) {
|
||||
t.Errorf("s.SampleRate(): got: %d, want: %d", got, want)
|
||||
}
|
||||
|
||||
// TODO: Check the result of io.ReadAll (#3192).
|
||||
buf, err := io.ReadAll(s)
|
||||
if err != nil {
|
||||
t.Errorf("io.ReadAll: %v", err)
|
||||
}
|
||||
if len(buf) == 0 {
|
||||
t.Errorf("len(buf): got: %d, want: > 0", len(buf))
|
||||
}
|
||||
}
|
||||
|
||||
func TestNonSeekerF32(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user