mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +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 {
|
||||
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) {
|
||||
|
@ -188,8 +188,9 @@ func Decode(context *audio.Context, src audio.ReadSeekCloser) (*Stream, error) {
|
||||
size *= 2
|
||||
}
|
||||
if sampleRate != context.SampleRate() {
|
||||
s = convert.NewResampling(s, size, sampleRate, context.SampleRate())
|
||||
size = size * int64(context.SampleRate()) / int64(sampleRate)
|
||||
r := convert.NewResampling(s, size, sampleRate, context.SampleRate())
|
||||
s = r
|
||||
size = r.Size()
|
||||
}
|
||||
return &Stream{decoded: s, size: size}, nil
|
||||
}
|
||||
|
@ -219,8 +219,9 @@ chunks:
|
||||
}
|
||||
}
|
||||
if sampleRateFrom != sampleRateTo {
|
||||
s = convert.NewResampling(s, dataSize, sampleRateFrom, sampleRateTo)
|
||||
dataSize = dataSize * int64(sampleRateTo) / int64(sampleRateFrom)
|
||||
r := convert.NewResampling(s, dataSize, sampleRateFrom, sampleRateTo)
|
||||
s = r
|
||||
dataSize = r.Size()
|
||||
}
|
||||
return &Stream{inner: s, size: dataSize}, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user