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(); + } } }