From 93f3ae3fda5bf9045362f21a4fed0f2ad0ea9708 Mon Sep 17 00:00:00 2001 From: ergz Date: Sun, 1 Oct 2023 00:10:28 -0700 Subject: [PATCH] wip trying to get the radio oscillator wave to be seletable by the radiobuttons --- basic.html | 13 ++++++++++++- basic.js | 17 ++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/basic.html b/basic.html index e245c0f..75c418a 100644 --- a/basic.html +++ b/basic.html @@ -5,9 +5,20 @@ - HTML 5 Boilerplate + simple-synth +
+ + + + + + + + + +
diff --git a/basic.js b/basic.js index 2706c18..a8d3a8b 100644 --- a/basic.js +++ b/basic.js @@ -2,6 +2,10 @@ let osc = null; let gain = null; window.onload = function () { + let selectedWave = document.querySelector( + "input[name='wavechoice']:checked" + ).value; + const audioContext = new AudioContext(); // this gets the node for the start butten and adds to it an even listener for click, when clicked the synth will play @@ -31,7 +35,7 @@ window.onload = function () { gain = audioContext.createGain(); } - osc.type = "sine"; + osc.type = "" + selectedWave; osc.frequency.setValueAtTime( parseFloat(freq.value), audioContext.currentTime @@ -51,4 +55,15 @@ window.onload = function () { osc.stop(); osc = null; }); + + function handleSelectionChange() { + let selectedValue = document.querySelector( + 'input[name="choice"]:checked' + ).value; + console.log(selectedValue); + } + + document.querySelectorAll("input[name='wavechoice']").forEach((rb) => { + rb.addEventListener("change", handleSelectionChange); + }); };