mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-27 21:48:27 +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;
|
return gainNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getFilter = (type, frequency, Q) => {
|
export function createFilter(context, type, frequency, Q, curve, to, over, t) {
|
||||||
const filter = getAudioContext().createBiquadFilter();
|
const filter = context.createBiquadFilter();
|
||||||
filter.type = type;
|
filter.type = type;
|
||||||
filter.frequency.value = frequency;
|
filter.frequency.value = frequency;
|
||||||
filter.Q.value = Q;
|
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;
|
return filter;
|
||||||
};
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import './reverb.mjs';
|
|||||||
import './vowel.mjs';
|
import './vowel.mjs';
|
||||||
import { clamp } from './util.mjs';
|
import { clamp } from './util.mjs';
|
||||||
import workletsUrl from './worklets.mjs?url';
|
import workletsUrl from './worklets.mjs?url';
|
||||||
import { getFilter, gainNode } from './helpers.mjs';
|
import { createFilter, gainNode } from './helpers.mjs';
|
||||||
import { map } from 'nanostores';
|
import { map } from 'nanostores';
|
||||||
import { logger } from './logger.mjs';
|
import { logger } from './logger.mjs';
|
||||||
|
|
||||||
@ -177,6 +177,11 @@ export const superdough = async (value, deadline, hapDuration) => {
|
|||||||
bank,
|
bank,
|
||||||
source,
|
source,
|
||||||
gain = 0.8,
|
gain = 0.8,
|
||||||
|
// filters
|
||||||
|
order = 12,
|
||||||
|
to,
|
||||||
|
filtenv = 'lin',
|
||||||
|
over,
|
||||||
// low pass
|
// low pass
|
||||||
cutoff,
|
cutoff,
|
||||||
resonance = 1,
|
resonance = 1,
|
||||||
@ -239,11 +244,37 @@ export const superdough = async (value, deadline, hapDuration) => {
|
|||||||
// gain stage
|
// gain stage
|
||||||
chain.push(gainNode(gain));
|
chain.push(gainNode(gain));
|
||||||
|
|
||||||
// filters
|
if (cutoff !== undefined) {
|
||||||
cutoff !== undefined && chain.push(getFilter('lowpass', cutoff, resonance));
|
const filter1 = createFilter(ac, 'lowpass', cutoff, resonance, filtenv, to || cutoff, over || hapDuration, t);
|
||||||
hcutoff !== undefined && chain.push(getFilter('highpass', hcutoff, hresonance));
|
chain.push(filter1);
|
||||||
bandf !== undefined && chain.push(getFilter('bandpass', bandf, bandq));
|
if (order === 24) {
|
||||||
vowel !== undefined && chain.push(ac.createVowelFilter(vowel));
|
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
|
// effects
|
||||||
coarse !== undefined && chain.push(getWorklet(ac, 'coarse-processor', { coarse }));
|
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);
|
analyserSend = effectSend(post, analyserNode, analyze);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(chain);
|
||||||
// connect chain elements together
|
// connect chain elements together
|
||||||
chain.slice(1).reduce((last, current) => last.connect(current), chain[0]);
|
chain.slice(1).reduce((last, current) => last.connect(current), chain[0]);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user