fixes not connected to destination issue

This commit is contained in:
Emanuel Rodriguez 2024-02-08 00:00:13 -08:00
parent 3cb0784e39
commit dc1bc9df2d
1 changed files with 13 additions and 0 deletions

View File

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