From 7f60a9e52b37c420b211e52368f53fb22a5822a1 Mon Sep 17 00:00:00 2001 From: "Jade (Rose) Rowland" Date: Sun, 3 Mar 2024 01:23:08 -0500 Subject: [PATCH] yay --- packages/superdough/worklets.mjs | 34 +++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/packages/superdough/worklets.mjs b/packages/superdough/worklets.mjs index 94dd6cce..b7505da1 100644 --- a/packages/superdough/worklets.mjs +++ b/packages/superdough/worklets.mjs @@ -145,9 +145,10 @@ const polySaw = (t, dt) => { class BetterOscillatorProcessor extends AudioWorkletProcessor { constructor() { super(); - this.phase = 0; + this.phase = []; this.sync_phase = 0; this.prev_sync_phase = 0; + this.adj = []; } static get parameterDescriptors() { return [ @@ -204,18 +205,37 @@ class BetterOscillatorProcessor extends AudioWorkletProcessor { return false; } const frequency = params.frequency[0]; - const dt = frequency / sampleRate; + const output = outputs[0]; + const numSaws = 7; + const detune = 0.5; + const spread = 0.5; + + for (let n = 0; n < numSaws; n++) { + this.adj[n] = 0; + + if (n > 0) { + this.adj[n] = n % 2 === 1 ? n * detune : -((n - 1) * detune); + } + } for (let i = 0; i < output[0].length; i++) { - const out = polySaw(this.phase, frequency / sampleRate); - output[0][i] = out; + let out = 0; + for (let n = 0; n < numSaws; n++) { + const freq = frequency + this.adj[n]; + const dt = freq / sampleRate; - this.phase += dt; + out = out + polySaw(this.phase[n], freq / sampleRate); - if (this.phase > 1.0) { - this.phase = this.phase - 1; + this.phase[n] = this.phase[n] ?? Math.random(); + + this.phase[n] += dt; + + if (this.phase[n] > 1.0) { + this.phase[n] = this.phase[n] - 1; + } } + output[0][i] = out; } return true;