work on synth class

This commit is contained in:
Emanuel Rodriguez 2024-02-07 23:41:04 -08:00
parent 37eabc79ca
commit 3cb0784e39
1 changed files with 20 additions and 1 deletions

View File

@ -3,15 +3,34 @@ class Synth {
this.audioContext = audioContext;
this.oscWaveType = waveType;
this.oscFrequency = frequency;
// osc setup
this.osc = this.audioContext.createOscillator();
this.osc.type = this.oscWaveType;
this.osc.frequency.setValueAtTime(this.oscFrequency, this.audioContext.currentTime);
this.osc.connect(this.audioContext.destination);
}
setOscWaveType(type) {
this.oscWaveType = type;
this.osc.type = this.oscWaveType;
}
startOsc() {
this.osc.start();
}
stopOsc() {
// first get all the parameters for this osc
let currentFreq = this.osc.frequency.value;
let currentType = this.osc.type;
this.osc.stop();
this.osc = this.audioContext.createOscillator();
console.log(this.osc);
this.osc.type = currentType;
this.osc.frequency.setValueAtTime(currentFreq, this.audioContext.currentTime);
}
}