mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
audio/vorbis: Remove Stream interface
This commit is contained in:
parent
a3b5b283e4
commit
3b35e6c253
@ -16,29 +16,23 @@ package vorbis
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Stream interface {
|
||||
io.ReadSeeker
|
||||
Len() time.Duration
|
||||
}
|
||||
|
||||
type stream struct {
|
||||
type Stream struct {
|
||||
buf *bytes.Reader
|
||||
sampleRate int
|
||||
}
|
||||
|
||||
func (s *stream) Read(p []byte) (int, error) {
|
||||
func (s *Stream) Read(p []byte) (int, error) {
|
||||
return s.buf.Read(p)
|
||||
}
|
||||
|
||||
func (s *stream) Seek(offset int64, whence int) (int64, error) {
|
||||
func (s *Stream) Seek(offset int64, whence int) (int64, error) {
|
||||
return s.buf.Seek(offset, whence)
|
||||
}
|
||||
|
||||
func (s *stream) Len() time.Duration {
|
||||
func (s *Stream) Len() time.Duration {
|
||||
const bytesPerSample = 4
|
||||
return time.Duration(s.buf.Len()/bytesPerSample) * time.Second / time.Duration(s.sampleRate)
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ import (
|
||||
"github.com/hajimehoshi/go-vorbis"
|
||||
)
|
||||
|
||||
func Decode(context *audio.Context, src io.Reader) (Stream, error) {
|
||||
func Decode(context *audio.Context, src io.Reader) (*Stream, error) {
|
||||
decoded, channels, sampleRate, err := vorbis.Decode(src)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -44,7 +44,7 @@ func Decode(context *audio.Context, src io.Reader) (Stream, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s := &stream{
|
||||
s := &Stream{
|
||||
buf: bytes.NewReader(b),
|
||||
sampleRate: sampleRate,
|
||||
}
|
||||
|
@ -29,12 +29,12 @@ import (
|
||||
// TODO: This just uses decodeAudioData can treat audio files other than Ogg/Vorbis.
|
||||
// TODO: This doesn't work on iOS which doesn't have Ogg/Vorbis decoder.
|
||||
|
||||
func Decode(context *audio.Context, src io.Reader) (Stream, error) {
|
||||
func Decode(context *audio.Context, src io.Reader) (*Stream, error) {
|
||||
b, err := ioutil.ReadAll(src)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s := &stream{
|
||||
s := &Stream{
|
||||
sampleRate: context.SampleRate(),
|
||||
}
|
||||
ch := make(chan struct{})
|
||||
|
Loading…
Reference in New Issue
Block a user