mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-11 13:48:34 +00:00
fileter envelopes
This commit is contained in:
parent
7da7554493
commit
9663c2ec85
@ -88,21 +88,16 @@ export function getCompressor(ac, threshold, ratio, knee, attack, release) {
|
||||
};
|
||||
return new DynamicsCompressorNode(ac, options);
|
||||
}
|
||||
|
||||
const adsrmin = 0.001;
|
||||
export const getADSRDefaults = (
|
||||
a,
|
||||
d,
|
||||
s,
|
||||
r,
|
||||
def = { attack: adsrmin, decay: adsrmin, sustain: 1, release: adsrmin },
|
||||
) => {
|
||||
const envmin = 0.001;
|
||||
export const getADSRValues = (params, defaultValues = [envmin, envmin, 1, envmin]) => {
|
||||
const [a, d, s, r] = params;
|
||||
const [defA, defD, defS, defR] = defaultValues;
|
||||
console.log(a, d, s, r);
|
||||
if (a == null && d == null && s == null && r == null) {
|
||||
return def;
|
||||
return defaultValues;
|
||||
}
|
||||
const sustain = s ?? ((a != null && d == null) || (a == null && d == null)) ? def.sustain : adsrmin;
|
||||
return { attack: a ?? adsrmin, decay: d ?? adsrmin, sustain, release: r ?? adsrmin };
|
||||
const sustain = s != null ? s : (a != null && d == null) || (a == null && d == null) ? defS : envmin;
|
||||
return [a ?? envmin, d ?? envmin, sustain, r ?? envmin];
|
||||
};
|
||||
|
||||
export function createFilter(
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { noteToMidi, valueToMidi, nanFallback } from './util.mjs';
|
||||
import { getAudioContext, registerSound } from './index.mjs';
|
||||
import { getADSRDefaults, getEnvelope } from './helpers.mjs';
|
||||
import { getADSRValues, getEnvelope } from './helpers.mjs';
|
||||
import { logger } from './logger.mjs';
|
||||
|
||||
const bufferCache = {}; // string: Promise<ArrayBuffer>
|
||||
@ -252,7 +252,7 @@ export async function onTriggerSample(t, value, onended, bank, resolveUrl) {
|
||||
const ac = getAudioContext();
|
||||
// destructure adsr here, because the default should be different for synths and samples
|
||||
|
||||
const { attack, decay, sustain, release } = getADSRDefaults(value.attack, value.decay, value.sustain, value.release);
|
||||
const [attack, decay, sustain, release] = getADSRValues([value.attack, value.decay, value.sustain, value.release]);
|
||||
//const soundfont = getSoundfontKey(s);
|
||||
const time = t + nudge;
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ import './reverb.mjs';
|
||||
import './vowel.mjs';
|
||||
import { clamp, nanFallback } from './util.mjs';
|
||||
import workletsUrl from './worklets.mjs?url';
|
||||
import { createFilter, gainNode, getCompressor } from './helpers.mjs';
|
||||
import { createFilter, gainNode, getADSRValues, getCompressor } from './helpers.mjs';
|
||||
import { map } from 'nanostores';
|
||||
import { logger } from './logger.mjs';
|
||||
import { loadBuffer } from './sampler.mjs';
|
||||
@ -269,26 +269,16 @@ export const superdough = async (value, deadline, hapDuration) => {
|
||||
// low pass
|
||||
cutoff,
|
||||
lpenv,
|
||||
lpattack = 0.01,
|
||||
lpdecay = 0.01,
|
||||
lpsustain = 1,
|
||||
lprelease = 0.01,
|
||||
resonance = 1,
|
||||
// high pass
|
||||
hpenv,
|
||||
hcutoff,
|
||||
hpattack = 0.01,
|
||||
hpdecay = 0.01,
|
||||
hpsustain = 1,
|
||||
hprelease = 0.01,
|
||||
|
||||
hresonance = 1,
|
||||
// band pass
|
||||
bpenv,
|
||||
bandf,
|
||||
bpattack = 0.01,
|
||||
bpdecay = 0.01,
|
||||
bpsustain = 1,
|
||||
bprelease = 0.01,
|
||||
|
||||
bandq = 1,
|
||||
channels = [1, 2],
|
||||
//phaser
|
||||
@ -322,6 +312,7 @@ export const superdough = async (value, deadline, hapDuration) => {
|
||||
compressorAttack,
|
||||
compressorRelease,
|
||||
} = value;
|
||||
|
||||
gain = nanFallback(gain, 1);
|
||||
|
||||
//music programs/audio gear usually increments inputs/outputs from 1, so imitate that behavior
|
||||
@ -366,7 +357,15 @@ export const superdough = async (value, deadline, hapDuration) => {
|
||||
// gain stage
|
||||
chain.push(gainNode(gain));
|
||||
|
||||
const filterEnvDefaults = [0.01, 0.01, 1, 0.01];
|
||||
|
||||
if (cutoff !== undefined) {
|
||||
const [lpattack, lpdecay, lpsustain, lprelease] = getADSRValues(
|
||||
[value.lpattack, value.lpdecay, value.lpsustain, value.lprelease],
|
||||
filterEnvDefaults,
|
||||
);
|
||||
console.log(lpattack, 'atta');
|
||||
|
||||
let lp = () =>
|
||||
createFilter(
|
||||
ac,
|
||||
@ -389,6 +388,10 @@ export const superdough = async (value, deadline, hapDuration) => {
|
||||
}
|
||||
|
||||
if (hcutoff !== undefined) {
|
||||
const [hpattack, hpdecay, hpsustain, hprelease] = getADSRValues(
|
||||
[value.hpattack, value.hpdecay, value.hpsustain, value.hprelease],
|
||||
filterEnvDefaults,
|
||||
);
|
||||
let hp = () =>
|
||||
createFilter(
|
||||
ac,
|
||||
@ -411,6 +414,10 @@ export const superdough = async (value, deadline, hapDuration) => {
|
||||
}
|
||||
|
||||
if (bandf !== undefined) {
|
||||
const [bpattack, bpdecay, bpsustain, bprelease] = getADSRValues(
|
||||
[value.bpattack, value.bpdecay, value.bpsustain, value.bprelease],
|
||||
filterEnvDefaults,
|
||||
);
|
||||
let bp = () =>
|
||||
createFilter(
|
||||
ac,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { midiToFreq, noteToMidi } from './util.mjs';
|
||||
import { registerSound, getAudioContext } from './superdough.mjs';
|
||||
import { gainNode, getADSRDefaults, getEnvelope, getExpEnvelope } from './helpers.mjs';
|
||||
import { gainNode, getADSRValues, getEnvelope, getExpEnvelope } from './helpers.mjs';
|
||||
import { getNoiseMix, getNoiseOscillator } from './noise.mjs';
|
||||
|
||||
const mod = (freq, range = 1, type = 'sine') => {
|
||||
@ -29,15 +29,11 @@ export function registerSynthSounds() {
|
||||
registerSound(
|
||||
s,
|
||||
(t, value, onended) => {
|
||||
// destructure adsr here, because the default should be different for synths and samples
|
||||
const { attack, decay, sustain, release } = getADSRDefaults(
|
||||
value.attack,
|
||||
value.decay,
|
||||
value.sustain,
|
||||
value.release,
|
||||
{ attack: 0.001, decay: 0.05, sustain: 0.6, release: 0.01 },
|
||||
const defaultADSRValues = [0.001, 0.05, 0.6, 0.01];
|
||||
const [attack, decay, sustain, release] = getADSRValues(
|
||||
[value.attack, value.decay, value.sustain, value.release],
|
||||
defaultADSRValues,
|
||||
);
|
||||
console.log({ attack, decay, sustain, release });
|
||||
|
||||
let sound;
|
||||
if (waveforms.includes(s)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user