diff --git a/audio/internal/convert/seeker.go b/audio/internal/convert/seeker.go deleted file mode 100644 index 5583c52cc..000000000 --- a/audio/internal/convert/seeker.go +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2017 The Ebiten Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package convert - -import ( - "io" - - "github.com/hajimehoshi/ebiten/audio" -) - -// A Seeker is io.Seeker and io.ReadSeekCloser. -type Seeker struct { - rc io.ReadCloser - data []uint8 - pos int64 - eof bool -} - -// Read is implementation of io.Reader's Read. -func (s *Seeker) Read(buf []byte) (int, error) { - for int64(len(s.data)) <= s.pos && !s.eof { - buf := make([]uint8, 4096) - n, err := s.rc.Read(buf) - s.data = append(s.data, buf[:n]...) - if err != nil { - if err == io.EOF { - s.eof = true - break - } - return 0, err - } - } - if int64(len(s.data)) <= s.pos && s.eof { - return 0, io.EOF - } - n := copy(buf, s.data[s.pos:]) - s.pos += int64(n) - return n, nil -} - -// Seek is implementation of io.Seeker's Seek. -func (s *Seeker) Seek(offset int64, whence int) (int64, error) { - switch whence { - case io.SeekStart: - s.pos = offset - case io.SeekCurrent: - s.pos += offset - case io.SeekEnd: - panic("not implemented") - } - return s.pos, nil -} - -// Read is implementation of io.Closer's Close. -func (s *Seeker) Close() error { - return s.rc.Close() -} - -// NewSeeker creates audio.ReadSeekCloser from io.ReadSeeker. -func NewSeeker(rc io.ReadCloser) audio.ReadSeekCloser { - return &Seeker{ - rc: rc, - } -} diff --git a/audio/mp3/decode_notjs.go b/audio/mp3/decode_notjs.go index 7ef4e7c59..d23a0cf71 100644 --- a/audio/mp3/decode_notjs.go +++ b/audio/mp3/decode_notjs.go @@ -55,7 +55,7 @@ func Decode(context *audio.Context, src audio.ReadSeekCloser) (*Stream, error) { return nil, err } // TODO: Resampling - var s audio.ReadSeekCloser = convert.NewSeeker(d) + var s audio.ReadSeekCloser = d size := d.Length() if d.SampleRate() != context.SampleRate() { s = convert.NewResampling(s, d.Length(), d.SampleRate(), context.SampleRate()) diff --git a/examples/audio/main.go b/examples/audio/main.go index 554ad8e73..8250465dd 100644 --- a/examples/audio/main.go +++ b/examples/audio/main.go @@ -34,7 +34,7 @@ const ( screenWidth = 320 screenHeight = 240 - // This sample rate doesn't match with wav/ogg's sample rate, + // This sample rate doesn't match with wav/mp3's sample rate, // but decoders adjust them. sampleRate = 48000 )