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