trying to get the radio oscillator wave to be seletable by
the radiobuttons
This commit is contained in:
2023-10-01 00:10:28 -07:00
parent aa0f8686f6
commit 93f3ae3fda
2 changed files with 28 additions and 2 deletions

View File

@@ -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);
});
};