audio/internal/convert: Use float64 for positions

This commit is contained in:
Hajime Hoshi 2017-12-27 18:55:17 +09:00
parent 6d6504085c
commit e2a026138a

View File

@ -127,21 +127,21 @@ func (r *Resampling) src(i int) (float64, float64, error) {
} }
func (r *Resampling) at(t int64) (float64, float64, error) { func (r *Resampling) at(t int64) (float64, float64, error) {
windowSize := 8 windowSize := 8.0
if web.IsBrowser() { if web.IsBrowser() {
windowSize = 4 windowSize = 4.0
} }
tInSrc := float64(t) * float64(r.from) / float64(r.to) tInSrc := float64(t) * float64(r.from) / float64(r.to)
startN := int64(tInSrc) - int64(windowSize) startN := tInSrc - windowSize
if startN < 0 { if startN < 0 {
startN = 0 startN = 0
} }
if r.size/4 <= startN { if float64(r.size/4) <= startN {
startN = r.size/4 - 1 startN = float64(r.size/4) - 1
} }
endN := int64(tInSrc) + int64(windowSize) + 1 endN := tInSrc + windowSize + 1
if r.size/4 <= endN { if float64(r.size/4) <= endN {
endN = r.size/4 - 1 endN = float64(r.size/4) - 1
} }
lv := 0.0 lv := 0.0
rv := 0.0 rv := 0.0
@ -150,8 +150,8 @@ func (r *Resampling) at(t int64) (float64, float64, error) {
if err != nil { if err != nil {
return 0, 0, err return 0, 0, err
} }
w := 0.5 + 0.5*math.Cos(2*math.Pi*(tInSrc-float64(n))/(float64(windowSize)*2+1)) w := 0.5 + 0.5*math.Cos(2*math.Pi*(tInSrc-n)/(windowSize*2+1))
s := sinc(math.Pi*(tInSrc-float64(n))) * w s := sinc(math.Pi*(tInSrc-n)) * w
lv += srcL * s lv += srcL * s
rv += srcR * s rv += srcR * s
} }