mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 03:58:55 +01:00
audio/mp3: Bug fix: Accept non-io.Closer at Resampling
This commit is contained in:
parent
49c0b64b60
commit
cba109ebee
@ -17,8 +17,6 @@ package convert
|
|||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/audio"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var cosTable = [65536]float64{}
|
var cosTable = [65536]float64{}
|
||||||
@ -67,7 +65,7 @@ func sinc01(x float64) float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Resampling struct {
|
type Resampling struct {
|
||||||
source audio.ReadSeekCloser
|
source io.ReadSeeker
|
||||||
size int64
|
size int64
|
||||||
from int
|
from int
|
||||||
to int
|
to int
|
||||||
@ -78,7 +76,7 @@ type Resampling struct {
|
|||||||
lruSrcBlocks []int64
|
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{
|
r := &Resampling{
|
||||||
source: source,
|
source: source,
|
||||||
size: size,
|
size: size,
|
||||||
@ -246,5 +244,8 @@ func (r *Resampling) Seek(offset int64, whence int) (int64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Resampling) Close() 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")
|
||||||
}
|
}
|
||||||
|
@ -82,17 +82,15 @@ func Decode(context *audio.Context, src audio.ReadSeekCloser) (*Stream, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var toClose io.Closer = src
|
|
||||||
|
|
||||||
var r *convert.Resampling
|
var r *convert.Resampling
|
||||||
if d.SampleRate() != context.SampleRate() {
|
if d.SampleRate() != context.SampleRate() {
|
||||||
r = convert.NewResampling(d, d.Length(), d.SampleRate(), context.SampleRate())
|
r = convert.NewResampling(d, d.Length(), d.SampleRate(), context.SampleRate())
|
||||||
toClose = r
|
|
||||||
}
|
}
|
||||||
s := &Stream{
|
s := &Stream{
|
||||||
orig: d,
|
orig: d,
|
||||||
resampling: r,
|
resampling: r,
|
||||||
toClose: toClose,
|
toClose: src,
|
||||||
}
|
}
|
||||||
runtime.SetFinalizer(s, (*Stream).Close)
|
runtime.SetFinalizer(s, (*Stream).Close)
|
||||||
return s, nil
|
return s, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user