diff --git a/templates/sonar_demo.html b/templates/sonar_demo.html index 41b1776..f821d33 100644 --- a/templates/sonar_demo.html +++ b/templates/sonar_demo.html @@ -21,6 +21,10 @@

Settings

+ + + + @@ -49,20 +53,36 @@ app.push(fft_magnitudes, {z_scale: 500000}); } }); - const osc = new Tone.Oscillator(0, 'sine').toDestination(); + const osc = new Tone.Oscillator().toDestination(); + osc.type = 'sine'; let playing = false; document.getElementById('play_sound_button').addEventListener('click', (e) => { - playing = !playing; - if (playing) { + playing = !playing; + let secs = document.getElementById('time').value; + secs = parseFloat(secs); + let intervalId = window.setInterval(function(){ + if (playing) { + playSound(); + } else { + document.getElementById('play_sound_button').innerHTML="PLAY"; + osc.stop(); + clearInterval(intervalId); + } + }, secs * 1000); + }) + function playSound(){ let freq = document.getElementById('frequency').value; + let inc = document.getElementById('increase').value; + let secs = document.getElementById('time').value; + freq = parseFloat(freq); + inc = parseFloat(inc); + secs = parseFloat(secs); osc.frequency.value = freq; document.getElementById('play_sound_button').innerHTML="PAUSE"; osc.start(); - } else { - document.getElementById('play_sound_button').innerHTML="PLAY"; - osc.stop(); - } - }) + osc.frequency.linearRampTo(freq + inc, secs); + console.log(osc.frequency.value); + } \ No newline at end of file