mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
audio: Bug fix: stream size must be multiple of 4 (#384)
This commit is contained in:
parent
1828830b4a
commit
db902dbbee
@ -56,7 +56,8 @@ func NewResampling(source audio.ReadSeekCloser, size int64, from, to int) *Resam
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Resampling) Size() int64 {
|
func (r *Resampling) Size() int64 {
|
||||||
return int64(float64(r.size) * float64(r.to) / float64(r.from))
|
s := int64(float64(r.size) * float64(r.to) / float64(r.from))
|
||||||
|
return s / 4 * 4
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Resampling) src(i int) (float64, float64, error) {
|
func (r *Resampling) src(i int) (float64, float64, error) {
|
||||||
|
@ -188,8 +188,9 @@ func Decode(context *audio.Context, src audio.ReadSeekCloser) (*Stream, error) {
|
|||||||
size *= 2
|
size *= 2
|
||||||
}
|
}
|
||||||
if sampleRate != context.SampleRate() {
|
if sampleRate != context.SampleRate() {
|
||||||
s = convert.NewResampling(s, size, sampleRate, context.SampleRate())
|
r := convert.NewResampling(s, size, sampleRate, context.SampleRate())
|
||||||
size = size * int64(context.SampleRate()) / int64(sampleRate)
|
s = r
|
||||||
|
size = r.Size()
|
||||||
}
|
}
|
||||||
return &Stream{decoded: s, size: size}, nil
|
return &Stream{decoded: s, size: size}, nil
|
||||||
}
|
}
|
||||||
|
@ -219,8 +219,9 @@ chunks:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if sampleRateFrom != sampleRateTo {
|
if sampleRateFrom != sampleRateTo {
|
||||||
s = convert.NewResampling(s, dataSize, sampleRateFrom, sampleRateTo)
|
r := convert.NewResampling(s, dataSize, sampleRateFrom, sampleRateTo)
|
||||||
dataSize = dataSize * int64(sampleRateTo) / int64(sampleRateFrom)
|
s = r
|
||||||
|
dataSize = r.Size()
|
||||||
}
|
}
|
||||||
return &Stream{inner: s, size: dataSize}, nil
|
return &Stream{inner: s, size: dataSize}, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user