0

I do:

var hitsound = context.createOscillator()
var gn       = context.createGain()
hitsound.connect(gn)
gn.connect(context.destination)

function restart() {
    gn.disconnect(context.destination)
    gn.connect(context.destination)
}
function buttonpush() {
    hitsound.start(0)
    setTimeout(250)
    var currentTime = 0;
    gn.gain.exponentialRampToValueAtTime(0.00001, currentTime + 0.04)
    restart()
}

and I get:

InvalidStateError: Failed to execute 'start' on 'AudioScheduledSourceNode': cannot call start more than once.
Error: Failed to execute 'start' on 'AudioScheduledSourceNode': cannot call start more than once.
    at buttonpush (/script.js:12:14)
    at HTMLButtonElement.onclick (/:11:54)

Its linked up to an html site. Also, I looked everywhere in the internet but it wasnt what I was looking for. Is there any way to fix this issue?

  • Does this help ? https://stackoverflow.com/questions/32161832/web-audio-api-oscillator-node-error-cannot-call-start-more-than-once – Bilel Jan 06 '20 at 00:15
  • @Bilel where do i put the `$(document)` lines? in the functions or something? – Blueberry Tech Jan 06 '20 at 00:30
  • $(document) lines are for jQuery... You better define your functions out of that block. And put your buttons events there! But I'd like to understand your expected result first because after trying to simulate your functions... I had a gain variation when I click a button ! But something doesn't fit when trying to stop the sound :/ If we click once it works great but when we change the gain it keeps making noise :) Any explanation? – Bilel Jan 06 '20 at 00:51
  • I made you this Fiddle it uses jQuery : https://jsfiddle.net/kq7cmvyu/ . I'll be back tomorrow if you explain better especially what do you mean by your restart() is it a Loop? Notice that I also changed some values near exponentialRampToValueAtTime – Bilel Jan 06 '20 at 01:35

0 Answers0