mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
audio: Use samller window for resampling on browsers
This commit is contained in:
parent
2c6f6e605e
commit
b4e3e9375c
@ -19,6 +19,7 @@ import (
|
||||
"math"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/audio"
|
||||
"github.com/hajimehoshi/ebiten/internal/web"
|
||||
)
|
||||
|
||||
func sinc(x float64) float64 {
|
||||
@ -126,16 +127,19 @@ func (r *Resampling) src(i int) (float64, float64, error) {
|
||||
}
|
||||
|
||||
func (r *Resampling) at(t int64) (float64, float64, error) {
|
||||
const windowSize = 8
|
||||
windowSize := 8
|
||||
if web.IsBrowser() {
|
||||
windowSize = 4
|
||||
}
|
||||
tInSrc := float64(t) * float64(r.from) / float64(r.to)
|
||||
startN := int64(tInSrc) - windowSize
|
||||
startN := int64(tInSrc) - int64(windowSize)
|
||||
if startN < 0 {
|
||||
startN = 0
|
||||
}
|
||||
if r.size/4 <= startN {
|
||||
startN = r.size/4 - 1
|
||||
}
|
||||
endN := int64(tInSrc) + windowSize + 1
|
||||
endN := int64(tInSrc) + int64(windowSize) + 1
|
||||
if r.size/4 <= endN {
|
||||
endN = r.size/4 - 1
|
||||
}
|
||||
@ -146,7 +150,7 @@ func (r *Resampling) at(t int64) (float64, float64, error) {
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
w := 0.5 + 0.5*math.Cos(2*math.Pi*(tInSrc-float64(n))/(windowSize*2+1))
|
||||
w := 0.5 + 0.5*math.Cos(2*math.Pi*(tInSrc-float64(n))/(float64(windowSize)*2+1))
|
||||
s := sinc(math.Pi*(tInSrc-float64(n))) * w
|
||||
lv += srcL * s
|
||||
rv += srcR * s
|
||||
|
Loading…
Reference in New Issue
Block a user