From 2e6cb3527463830274c98aae82f12cd3bb597772 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 1 Apr 2019 00:01:41 +0900 Subject: [PATCH] audio/mp3: Bug fix: Accept non-io.Closer at Resampling --- audio/internal/convert/resampling.go | 11 ++++++----- audio/mp3/decode_notjs.go | 4 +--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/audio/internal/convert/resampling.go b/audio/internal/convert/resampling.go index b92cb7881..51655a0ad 100644 --- a/audio/internal/convert/resampling.go +++ b/audio/internal/convert/resampling.go @@ -17,8 +17,6 @@ package convert import ( "io" "math" - - "github.com/hajimehoshi/ebiten/audio" ) var cosTable = [65536]float64{} @@ -67,7 +65,7 @@ func sinc01(x float64) float64 { } type Resampling struct { - source audio.ReadSeekCloser + source io.ReadSeeker size int64 from int to int @@ -78,7 +76,7 @@ type Resampling struct { lruSrcBlocks []int64 } -func NewResampling(source audio.ReadSeekCloser, size int64, from, to int) *Resampling { +func NewResampling(source io.ReadSeeker, size int64, from, to int) *Resampling { r := &Resampling{ source: source, size: size, @@ -246,5 +244,8 @@ func (r *Resampling) Seek(offset int64, whence int) (int64, error) { } func (r *Resampling) Close() error { - return r.source.Close() + if closer, ok := r.source.(io.Closer); ok { + return closer.Close() + } + panic("audio/internal/convert: r.source must be io.Closer") } diff --git a/audio/mp3/decode_notjs.go b/audio/mp3/decode_notjs.go index aa59cc527..5f42e6cf0 100644 --- a/audio/mp3/decode_notjs.go +++ b/audio/mp3/decode_notjs.go @@ -82,17 +82,15 @@ func Decode(context *audio.Context, src audio.ReadSeekCloser) (*Stream, error) { if err != nil { return nil, err } - var toClose io.Closer = src var r *convert.Resampling if d.SampleRate() != context.SampleRate() { r = convert.NewResampling(d, d.Length(), d.SampleRate(), context.SampleRate()) - toClose = r } s := &Stream{ orig: d, resampling: r, - toClose: toClose, + toClose: src, } runtime.SetFinalizer(s, (*Stream).Close) return s, nil