Skip to content

Commit c0920a6

Browse files
committed
Improve timing of short fades
Fixes goldfire#884
1 parent dc0a2cf commit c0920a6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/howler.core.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,11 +1170,13 @@
11701170
var diff = Math.abs(from - to);
11711171
var steps = diff / 0.01;
11721172
var stepLen = (steps > 0) ? len / steps : len;
1173+
var stepVol = diff / steps;
11731174

11741175
// Since browsers clamp timeouts to 4ms, we need to clamp our steps to that too.
11751176
if (stepLen < 4) {
1176-
steps = Math.ceil(steps / (4 / stepLen));
1177+
steps = Math.ceil(steps * stepLen * 0.25);
11771178
stepLen = 4;
1179+
stepVol = diff / steps;
11781180
}
11791181

11801182
// Store the value being faded to.
@@ -1184,7 +1186,7 @@
11841186
sound._interval = setInterval(function() {
11851187
// Update the volume amount, but only if the volume should change.
11861188
if (steps > 0) {
1187-
vol += (dir === 'in' ? 0.01 : -0.01);
1189+
vol += (dir === 'in' ? stepVol : -stepVol);
11881190
}
11891191

11901192
// Make sure the volume is in the right bounds.

0 commit comments

Comments
 (0)