From ebeaac3c5ff20efa2879bbd393a4dee4572da0c3 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Tue, 29 Aug 2023 12:54:17 +0200 Subject: [PATCH] adding fm wave choice --- packages/superdough/synth.mjs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/superdough/synth.mjs b/packages/superdough/synth.mjs index 57317133..ee863192 100644 --- a/packages/superdough/synth.mjs +++ b/packages/superdough/synth.mjs @@ -2,7 +2,8 @@ import { midiToFreq, noteToMidi } from './util.mjs'; import { registerSound, getAudioContext } from './superdough.mjs'; import { getOscillator, gainNode, getEnvelope } from './helpers.mjs'; -const mod = (freq, range = 1, type = 'sine') => { +const mod = (freq, range = 1, type) => { + console.log(type) const ctx = getAudioContext(); const osc = ctx.createOscillator(); osc.type = type; @@ -13,7 +14,7 @@ const mod = (freq, range = 1, type = 'sine') => { return { node: g, stop: (t) => osc.stop(t) }; }; -const fm = (osc, harmonicityRatio, modulationIndex, wave = 'sine') => { +const fm = (osc, harmonicityRatio, modulationIndex, wave) => { const carrfreq = osc.frequency.value; const modfreq = carrfreq * harmonicityRatio; const modgain = modfreq * modulationIndex; @@ -33,6 +34,7 @@ export function registerSynthSounds() { release = 0.01, fmh: fmHarmonicity = 1, fmi: fmModulationIndex, + fmwave: fmWaveform = 'sine' } = value; let { n, note, freq } = value; // with synths, n and note are the same thing @@ -50,7 +52,11 @@ export function registerSynthSounds() { let stopFm; if (fmModulationIndex) { - const { node: modulator, stop } = fm(o, fmHarmonicity, fmModulationIndex); + const { node: modulator, stop } = fm( + o, fmHarmonicity, + fmModulationIndex, + fmWaveform + ); modulator.connect(o.frequency); stopFm = stop; }