mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-11 13:48:40 +00:00
gain curve func
This commit is contained in:
parent
b192c6823c
commit
5ed28d6168
@ -1,9 +1,9 @@
|
|||||||
import { getAudioContext } from './superdough.mjs';
|
import { getAudioContext } from './superdough.mjs';
|
||||||
import { clamp, nanFallback } from './util.mjs';
|
import { clamp, nanFallback } from './util.mjs';
|
||||||
|
|
||||||
export function gainNode(value) {
|
export function gainNode(value) {
|
||||||
const node = getAudioContext().createGain();
|
const node = getAudioContext().createGain();
|
||||||
node.gain.value = value;
|
node.gain.value = value
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,6 +20,16 @@ export function registerSound(key, onTrigger, data = {}) {
|
|||||||
soundMap.setKey(key.toLowerCase(), { 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) {
|
function aliasBankMap(aliasMap) {
|
||||||
// Make all bank keys lower case for case insensitivity
|
// Make all bank keys lower case for case insensitivity
|
||||||
for (const key in aliasMap) {
|
for (const key in aliasMap) {
|
||||||
@ -87,7 +97,7 @@ export function getSound(s) {
|
|||||||
|
|
||||||
const defaultDefaultValues = {
|
const defaultDefaultValues = {
|
||||||
s: 'triangle',
|
s: 'triangle',
|
||||||
gain: 0.8,
|
gain: 1,
|
||||||
postgain: 1,
|
postgain: 1,
|
||||||
density: '.03',
|
density: '.03',
|
||||||
ftype: '12db',
|
ftype: '12db',
|
||||||
@ -471,12 +481,17 @@ export const superdough = async (value, t, hapDuration) => {
|
|||||||
compressorRelease,
|
compressorRelease,
|
||||||
} = value;
|
} = 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
|
//music programs/audio gear usually increments inputs/outputs from 1, so imitate that behavior
|
||||||
channels = (Array.isArray(channels) ? channels : [channels]).map((ch) => ch - 1);
|
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
|
let toDisconnect = []; // audio nodes that will be disconnected when the source has ended
|
||||||
const onended = () => {
|
const onended = () => {
|
||||||
toDisconnect.forEach((n) => n?.disconnect());
|
toDisconnect.forEach((n) => n?.disconnect());
|
||||||
@ -516,6 +531,7 @@ export const superdough = async (value, t, hapDuration) => {
|
|||||||
|
|
||||||
// gain stage
|
// gain stage
|
||||||
chain.push(gainNode(gain));
|
chain.push(gainNode(gain));
|
||||||
|
chain.push(gainNode(.8 * velocity))
|
||||||
|
|
||||||
//filter
|
//filter
|
||||||
const ftype = getFilterType(value.ftype);
|
const ftype = getFilterType(value.ftype);
|
||||||
@ -616,7 +632,7 @@ export const superdough = async (value, t, hapDuration) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// last gain
|
// last gain
|
||||||
const post = new GainNode(ac, { gain: postgain });
|
const post = new GainNode(ac, { gain:postgain });
|
||||||
chain.push(post);
|
chain.push(post);
|
||||||
connectToDestination(post, channels);
|
connectToDestination(post, channels);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user