diff --git a/single-voice-synth.js b/single-voice-synth.js index b849b93..2127123 100644 --- a/single-voice-synth.js +++ b/single-voice-synth.js @@ -1,5 +1,5 @@ class Synth { - constructor(audioContext, waveType = "sine", frequency = 400) { + constructor(audioContext, waveType = "triangle", frequency = 100) { this.audioContext = audioContext; this.oscWaveType = waveType; this.oscFrequency = frequency; @@ -17,6 +17,15 @@ class Synth { this.osc.type = this.oscWaveType; } + setOscFrequency(freq) { + this.oscFrequency = freq; + this.osc.frequency.setValueAtTime(freq, this.audioContext.currentTime); + } + + setOscDetune(amount) { + this.osc.detune.setValueAtTime(amount, this.audioContext.currentTime); + } + startOsc() { this.osc.start(); this.isPlaying = true; @@ -29,7 +38,6 @@ class Synth { this.osc.stop(); this.osc = this.audioContext.createOscillator(); - console.log(this.osc); this.osc.type = currentType; this.osc.frequency.setValueAtTime(currentFreq, this.audioContext.currentTime); this.osc.connect(this.audioContext.destination); @@ -37,7 +45,6 @@ class Synth { } toggleOsc() { - if (this.isPlaying === false) { this.startOsc(); } else { @@ -53,4 +60,12 @@ let synth = new Synth(globalAudioContext); window.onload = function() { console.log("hello world!"); console.log(synth); + + var detune = document.getElementById("detune"); + detune.addEventListener("input", () => { + synth.setOscDetune(parseFloat(detune.value)) + }) } + + + diff --git a/single-voice.html b/single-voice.html index 1eccd9e..a077adc 100644 --- a/single-voice.html +++ b/single-voice.html @@ -11,5 +11,6 @@
- + +