mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
audio: Remove convert.Seeker: mp3.Decoded is now io.Seeker
This commit is contained in:
parent
addde5ee6d
commit
9130c490c2
@ -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,
|
|
||||||
}
|
|
||||||
}
|
|
@ -55,7 +55,7 @@ func Decode(context *audio.Context, src audio.ReadSeekCloser) (*Stream, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// TODO: Resampling
|
// TODO: Resampling
|
||||||
var s audio.ReadSeekCloser = convert.NewSeeker(d)
|
var s audio.ReadSeekCloser = d
|
||||||
size := d.Length()
|
size := d.Length()
|
||||||
if d.SampleRate() != context.SampleRate() {
|
if d.SampleRate() != context.SampleRate() {
|
||||||
s = convert.NewResampling(s, d.Length(), d.SampleRate(), context.SampleRate())
|
s = convert.NewResampling(s, d.Length(), d.SampleRate(), context.SampleRate())
|
||||||
|
@ -34,7 +34,7 @@ const (
|
|||||||
screenWidth = 320
|
screenWidth = 320
|
||||||
screenHeight = 240
|
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.
|
// but decoders adjust them.
|
||||||
sampleRate = 48000
|
sampleRate = 48000
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user