Bug 97290
Summary: | Loud sounds turning up when using Web Audio API where no sound expected | ||
---|---|---|---|
Product: | WebKit | Reporter: | Srikumar K. Subramanian <srikumarks> |
Component: | Web Audio | Assignee: | Nobody <webkit-unassigned> |
Status: | UNCONFIRMED | ||
Severity: | Normal | CC: | crogers, eric.carlson, jer.noble |
Priority: | P2 | ||
Version: | 528+ (Nightly build) | ||
Hardware: | Other | ||
OS: | Other |
Srikumar K. Subramanian
OS: iOS6
Device Type: iPhone4
Steps to reproduce:
The following code is not expected to produce any sound since the volume set is 0, but once in a while you get a loud "ping" if you keep reloading the page in Mobile Safari on iOS6. Less than 10 attempts are needed to produce this effect.
{{{
<script>
var ac = new webkitAudioContext();
var attack = 0.01;
var decay = 0.5;
function note(t, f, v) {
var osc = ac.createOscillator();
osc.frequency.value = f;
var gain = ac.createGainNode();
gain.gain.setValueAtTime(0, t);
gain.gain.linearRampToValueAtTime(v, t + attack);
gain.gain.setTargetValueAtTime(0, t + attack, decay);
osc.connect(gain);
gain.connect(ac.destination);
osc.noteOn(t);
osc.noteOff(t + 12 * decay);
}
note(ac.currentTime, 880, 0);
</script>
}}}
I've occasionally heard such loud sounds in Chrome 21.0.1180.89 and Safari 6 on MacOS 10.8.1 and so I believe it might be present in the WebKit implementation across the board.
Some other observations -
1. Changing the line "gain.gain.setValueAtTime(0, t);" to "gain.gain.value = 0;" seems to result in the code doing the right thing - i.e. I never got the loud ping on several attempts.
2. Changing the line "note(ac.currentTime, 880, 0);" to "note(ac.currentTime + 0.01, 880, 0);" also seems to resolve this issue.
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Srikumar K. Subramanian
Btw with either of the changes (1) and (2), if I give a non-zero gain value, the note is played at that level correctly upon page load.