audio: Bug fix: stream size must be multiple of 4 (#384)

This commit is contained in:
Hajime Hoshi 2017-07-12 00:51:36 +09:00
parent 1828830b4a
commit db902dbbee
3 changed files with 8 additions and 5 deletions

View File

@ -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) {

View File

@ -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
}

View File

@ -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
}