mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-11 21:58:37 +00:00
Envelope filter and filter order
This commit is contained in:
parent
abaeb52b7c
commit
ec8616a515
@ -66,10 +66,18 @@ export const getADSR = (attack, decay, sustain, release, velocity, begin, end) =
|
||||
return gainNode;
|
||||
};
|
||||
|
||||
export const getFilter = (type, frequency, Q) => {
|
||||
const filter = getAudioContext().createBiquadFilter();
|
||||
export function createFilter(context, type, frequency, Q, curve, to, over, t) {
|
||||
const filter = context.createBiquadFilter();
|
||||
filter.type = type;
|
||||
filter.frequency.value = frequency;
|
||||
filter.Q.value = Q;
|
||||
|
||||
if (to !== null && over !== null) {
|
||||
if (curve === 'lin') {
|
||||
filter.frequency.linearRampToValueAtTime(to, t + over);
|
||||
} else {
|
||||
filter.frequency.exponentialRampToValueAtTime(to, t + over);
|
||||
}
|
||||
}
|
||||
return filter;
|
||||
};
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ import './reverb.mjs';
|
||||
import './vowel.mjs';
|
||||
import { clamp } from './util.mjs';
|
||||
import workletsUrl from './worklets.mjs?url';
|
||||
import { getFilter, gainNode } from './helpers.mjs';
|
||||
import { createFilter, gainNode } from './helpers.mjs';
|
||||
import { map } from 'nanostores';
|
||||
import { logger } from './logger.mjs';
|
||||
|
||||
@ -177,6 +177,11 @@ export const superdough = async (value, deadline, hapDuration) => {
|
||||
bank,
|
||||
source,
|
||||
gain = 0.8,
|
||||
// filters
|
||||
order = 12,
|
||||
to,
|
||||
filtenv = 'lin',
|
||||
over,
|
||||
// low pass
|
||||
cutoff,
|
||||
resonance = 1,
|
||||
@ -239,11 +244,37 @@ export const superdough = async (value, deadline, hapDuration) => {
|
||||
// gain stage
|
||||
chain.push(gainNode(gain));
|
||||
|
||||
// filters
|
||||
cutoff !== undefined && chain.push(getFilter('lowpass', cutoff, resonance));
|
||||
hcutoff !== undefined && chain.push(getFilter('highpass', hcutoff, hresonance));
|
||||
bandf !== undefined && chain.push(getFilter('bandpass', bandf, bandq));
|
||||
vowel !== undefined && chain.push(ac.createVowelFilter(vowel));
|
||||
if (cutoff !== undefined) {
|
||||
const filter1 = createFilter(ac, 'lowpass', cutoff, resonance, filtenv, to || cutoff, over || hapDuration, t);
|
||||
chain.push(filter1);
|
||||
if (order === 24) {
|
||||
const filter2 = createFilter(ac, 'lowpass', cutoff, resonance, filtenv, to || cutoff, over || hapDuration, t);
|
||||
chain.push(filter2);
|
||||
}
|
||||
}
|
||||
|
||||
if (hcutoff !== undefined) {
|
||||
const filter1 = createFilter(ac, 'highpass', hcutoff, hresonance, filtenv, to || hcutoff, over || hapDuration, t);
|
||||
chain.push(filter1);
|
||||
if (order === 24) {
|
||||
const filter2 = createFilter(ac, 'highpass', hcutoff, hresonance, filtenv, to || hcutoff, over || hapDuration, t);
|
||||
chain.push(filter2);
|
||||
}
|
||||
}
|
||||
|
||||
if (bandf !== undefined) {
|
||||
const filter1 = createFilter(ac, 'bandpass', bandf, bandq, filtenv, to || bandf, over || hapDuration, t);
|
||||
chain.push(filter1);
|
||||
if (order === 24) {
|
||||
const filter2 = createFilter(ac, 'bandpass', bandf, bandq, filtenv, to || bandf, over || hapDuration, t);
|
||||
chain.push(filter2);
|
||||
}
|
||||
}
|
||||
|
||||
if (vowel !== undefined) {
|
||||
const vowelFilter = ac.createVowelFilter(vowel);
|
||||
chain.push(vowelFilter);
|
||||
}
|
||||
|
||||
// effects
|
||||
coarse !== undefined && chain.push(getWorklet(ac, 'coarse-processor', { coarse }));
|
||||
@ -282,6 +313,7 @@ export const superdough = async (value, deadline, hapDuration) => {
|
||||
analyserSend = effectSend(post, analyserNode, analyze);
|
||||
}
|
||||
|
||||
console.log(chain);
|
||||
// connect chain elements together
|
||||
chain.slice(1).reduce((last, current) => last.connect(current), chain[0]);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user