mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-25 12:38:35 +00:00
support negative fenv
This commit is contained in:
parent
9d5f919023
commit
828e475921
@ -1,4 +1,5 @@
|
|||||||
import { getAudioContext } from './superdough.mjs';
|
import { getAudioContext } from './superdough.mjs';
|
||||||
|
import { clamp } from './util.mjs';
|
||||||
|
|
||||||
export function gainNode(value) {
|
export function gainNode(value) {
|
||||||
const node = getAudioContext().createGain();
|
const node = getAudioContext().createGain();
|
||||||
@ -85,9 +86,19 @@ export function createFilter(context, type, frequency, Q, attack, decay, sustain
|
|||||||
filter.frequency.value = frequency;
|
filter.frequency.value = frequency;
|
||||||
|
|
||||||
// Apply ADSR to filter frequency
|
// Apply ADSR to filter frequency
|
||||||
if (fenv > 0) {
|
if (fenv !== 0) {
|
||||||
const min = frequency;
|
let min = 0;
|
||||||
const max = Math.min(frequency + 200 * 2 ** fenv, 20000);
|
let max = Math.sign(fenv) * 200 * 2 ** Math.abs(fenv);
|
||||||
|
if (max < min) {
|
||||||
|
// offset by max: keep range when *penv sign is flipped
|
||||||
|
// comment those lines out to center around cutoff instead peak
|
||||||
|
min += Math.abs(max);
|
||||||
|
max += Math.abs(max);
|
||||||
|
}
|
||||||
|
|
||||||
|
min = clamp(min + frequency, 0, 20000);
|
||||||
|
max = clamp(max + frequency, 0, 20000);
|
||||||
|
// console.log('min', min, 'max', max);
|
||||||
getParamADSR(filter.frequency, attack, decay, sustain, release, min, max, start, end);
|
getParamADSR(filter.frequency, attack, decay, sustain, release, min, max, start, end);
|
||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user