From 5ed28d6168b8d323ed64efa049c0feb285d73678 Mon Sep 17 00:00:00 2001 From: "Jade (Rose) Rowland" Date: Mon, 31 Mar 2025 00:17:26 -0400 Subject: [PATCH 1/5] gain curve func --- packages/superdough/helpers.mjs | 4 ++-- packages/superdough/superdough.mjs | 24 ++++++++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/superdough/helpers.mjs b/packages/superdough/helpers.mjs index e51156fe..2ad1567c 100644 --- a/packages/superdough/helpers.mjs +++ b/packages/superdough/helpers.mjs @@ -1,9 +1,9 @@ -import { getAudioContext } from './superdough.mjs'; +import { getAudioContext } from './superdough.mjs'; import { clamp, nanFallback } from './util.mjs'; export function gainNode(value) { const node = getAudioContext().createGain(); - node.gain.value = value; + node.gain.value = value return node; } diff --git a/packages/superdough/superdough.mjs b/packages/superdough/superdough.mjs index fc81f565..a9372ca1 100644 --- a/packages/superdough/superdough.mjs +++ b/packages/superdough/superdough.mjs @@ -20,6 +20,16 @@ export function registerSound(key, onTrigger, data = {}) { soundMap.setKey(key.toLowerCase(), { onTrigger, data }); } +let gainCurveFunc = (val) => Math.pow(val,2) + +export function applyGainCurve(val) { + return gainCurveFunc(val) +} + +export function setGainCurve(newGainCurveFunc) { + gainCurveFunc = newGainCurveFunc +} + function aliasBankMap(aliasMap) { // Make all bank keys lower case for case insensitivity for (const key in aliasMap) { @@ -87,7 +97,7 @@ export function getSound(s) { const defaultDefaultValues = { s: 'triangle', - gain: 0.8, + gain: 1, postgain: 1, density: '.03', ftype: '12db', @@ -471,12 +481,17 @@ export const superdough = async (value, t, hapDuration) => { compressorRelease, } = value; - gain = nanFallback(gain, 1); + gain = applyGainCurve(nanFallback(gain, 1)); + postgain = applyGainCurve(postgain) + shapevol = applyGainCurve(shapevol) + distortvol = applyGainCurve(distortvol) + delay = applyGainCurve(delay) + velocity = applyGainCurve(velocity) + //music programs/audio gear usually increments inputs/outputs from 1, so imitate that behavior channels = (Array.isArray(channels) ? channels : [channels]).map((ch) => ch - 1); - gain *= velocity; // velocity currently only multiplies with gain. it might do other things in the future let toDisconnect = []; // audio nodes that will be disconnected when the source has ended const onended = () => { toDisconnect.forEach((n) => n?.disconnect()); @@ -516,6 +531,7 @@ export const superdough = async (value, t, hapDuration) => { // gain stage chain.push(gainNode(gain)); + chain.push(gainNode(.8 * velocity)) //filter const ftype = getFilterType(value.ftype); @@ -616,7 +632,7 @@ export const superdough = async (value, t, hapDuration) => { } // last gain - const post = new GainNode(ac, { gain: postgain }); + const post = new GainNode(ac, { gain:postgain }); chain.push(post); connectToDestination(post, channels); From 999c0b23495583a96c89cea6d787390a8d40ad0b Mon Sep 17 00:00:00 2001 From: "Jade (Rose) Rowland" Date: Mon, 31 Mar 2025 00:21:01 -0400 Subject: [PATCH 2/5] lint --- packages/superdough/helpers.mjs | 4 ++-- packages/superdough/superdough.mjs | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/superdough/helpers.mjs b/packages/superdough/helpers.mjs index 2ad1567c..e51156fe 100644 --- a/packages/superdough/helpers.mjs +++ b/packages/superdough/helpers.mjs @@ -1,9 +1,9 @@ -import { getAudioContext } from './superdough.mjs'; +import { getAudioContext } from './superdough.mjs'; import { clamp, nanFallback } from './util.mjs'; export function gainNode(value) { const node = getAudioContext().createGain(); - node.gain.value = value + node.gain.value = value; return node; } diff --git a/packages/superdough/superdough.mjs b/packages/superdough/superdough.mjs index a9372ca1..d2c825ab 100644 --- a/packages/superdough/superdough.mjs +++ b/packages/superdough/superdough.mjs @@ -20,14 +20,14 @@ export function registerSound(key, onTrigger, data = {}) { soundMap.setKey(key.toLowerCase(), { onTrigger, data }); } -let gainCurveFunc = (val) => Math.pow(val,2) +let gainCurveFunc = (val) => Math.pow(val, 2); export function applyGainCurve(val) { - return gainCurveFunc(val) + return gainCurveFunc(val); } export function setGainCurve(newGainCurveFunc) { - gainCurveFunc = newGainCurveFunc + gainCurveFunc = newGainCurveFunc; } function aliasBankMap(aliasMap) { @@ -482,12 +482,11 @@ export const superdough = async (value, t, hapDuration) => { } = value; gain = applyGainCurve(nanFallback(gain, 1)); - postgain = applyGainCurve(postgain) - shapevol = applyGainCurve(shapevol) - distortvol = applyGainCurve(distortvol) - delay = applyGainCurve(delay) - velocity = applyGainCurve(velocity) - + postgain = applyGainCurve(postgain); + shapevol = applyGainCurve(shapevol); + distortvol = applyGainCurve(distortvol); + delay = applyGainCurve(delay); + velocity = applyGainCurve(velocity); //music programs/audio gear usually increments inputs/outputs from 1, so imitate that behavior channels = (Array.isArray(channels) ? channels : [channels]).map((ch) => ch - 1); @@ -531,7 +530,7 @@ export const superdough = async (value, t, hapDuration) => { // gain stage chain.push(gainNode(gain)); - chain.push(gainNode(.8 * velocity)) + chain.push(gainNode(0.8 * velocity)); //filter const ftype = getFilterType(value.ftype); @@ -632,7 +631,7 @@ export const superdough = async (value, t, hapDuration) => { } // last gain - const post = new GainNode(ac, { gain:postgain }); + const post = new GainNode(ac, { gain: postgain }); chain.push(post); connectToDestination(post, channels); From f32abac06f7b1d45dba47bfb729e45f53b771b89 Mon Sep 17 00:00:00 2001 From: "Jade (Rose) Rowland" Date: Sun, 27 Apr 2025 02:20:53 -0400 Subject: [PATCH 3/5] reset gaincurve --- packages/superdough/superdough.mjs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/superdough/superdough.mjs b/packages/superdough/superdough.mjs index d3c9e49f..8e766b65 100644 --- a/packages/superdough/superdough.mjs +++ b/packages/superdough/superdough.mjs @@ -18,6 +18,7 @@ export const DEFAULT_MAX_POLYPHONY = 128; const DEFAULT_AUDIO_DEVICE_NAME = 'System Standard'; let maxPolyphony = DEFAULT_MAX_POLYPHONY; + export function setMaxPolyphony(polyphony) { maxPolyphony = parseInt(polyphony) ?? DEFAULT_MAX_POLYPHONY; } @@ -117,7 +118,7 @@ export const getAudioDevices = async () => { const defaultDefaultValues = { s: 'triangle', - gain: .8, + gain: 0.8, postgain: 1, density: '.03', ftype: '12db', @@ -548,7 +549,7 @@ export const superdough = async (value, t, hapDuration) => { //music programs/audio gear usually increments inputs/outputs from 1, so imitate that behavior channels = (Array.isArray(channels) ? channels : [channels]).map((ch) => ch - 1); - + let audioNodes = []; if (bank && s) { From c088c0c9d2b832a6eb26274369cc3f7ad601b66e Mon Sep 17 00:00:00 2001 From: "Jade (Rose) Rowland" Date: Sun, 27 Apr 2025 02:21:49 -0400 Subject: [PATCH 4/5] def --- packages/superdough/superdough.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/superdough/superdough.mjs b/packages/superdough/superdough.mjs index 8e766b65..34c22e72 100644 --- a/packages/superdough/superdough.mjs +++ b/packages/superdough/superdough.mjs @@ -29,7 +29,7 @@ export function registerSound(key, onTrigger, data = {}) { soundMap.setKey(key, { onTrigger, data }); } -let gainCurveFunc = (val) => Math.pow(val, 1); +let gainCurveFunc = (val) => val; export function applyGainCurve(val) { return gainCurveFunc(val); From 480b5ff58bf9636b11791fd00340d0d17d1ca6a1 Mon Sep 17 00:00:00 2001 From: "Jade (Rose) Rowland" Date: Sun, 27 Apr 2025 02:38:10 -0400 Subject: [PATCH 5/5] fix vel --- packages/superdough/superdough.mjs | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/superdough/superdough.mjs b/packages/superdough/superdough.mjs index 34c22e72..0c4d2395 100644 --- a/packages/superdough/superdough.mjs +++ b/packages/superdough/superdough.mjs @@ -592,7 +592,6 @@ export const superdough = async (value, t, hapDuration) => { // gain stage chain.push(gainNode(gain)); - chain.push(gainNode(0.8 * velocity)); //filter const ftype = getFilterType(value.ftype);