From dc1bc9df2dc4853d896f7a5436b749a154ffa4f8 Mon Sep 17 00:00:00 2001 From: ergz Date: Thu, 8 Feb 2024 00:00:13 -0800 Subject: [PATCH] fixes not connected to destination issue --- single-voice-synth.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/single-voice-synth.js b/single-voice-synth.js index ab74064..b849b93 100644 --- a/single-voice-synth.js +++ b/single-voice-synth.js @@ -3,6 +3,7 @@ class Synth { this.audioContext = audioContext; this.oscWaveType = waveType; this.oscFrequency = frequency; + this.isPlaying = false; // osc setup this.osc = this.audioContext.createOscillator(); @@ -18,6 +19,7 @@ class Synth { startOsc() { this.osc.start(); + this.isPlaying = true; } stopOsc() { @@ -30,6 +32,17 @@ class Synth { console.log(this.osc); this.osc.type = currentType; this.osc.frequency.setValueAtTime(currentFreq, this.audioContext.currentTime); + this.osc.connect(this.audioContext.destination); + this.isPlaying = false; + } + + toggleOsc() { + + if (this.isPlaying === false) { + this.startOsc(); + } else { + this.stopOsc(); + } } }