Unify lfo functions
This commit is contained in:
parent
11e3da0552
commit
4b08dd8447
2 changed files with 30 additions and 25 deletions
|
|
@ -109,36 +109,39 @@ export function getEnvelope(audioContext, properties = {}) {
|
||||||
return getWorklet(audioContext, 'envelope-processor', properties);
|
return getWorklet(audioContext, 'envelope-processor', properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getLfo(audioContext, begin, end, properties = {}) {
|
export function getLfo(audioContext, properties = {}) {
|
||||||
const { shape = 0, ...props } = properties;
|
const {
|
||||||
const { dcoffset = -0.5, depth = 1 } = properties;
|
shape = 0,
|
||||||
|
begin = 0,
|
||||||
|
end = 0,
|
||||||
|
time,
|
||||||
|
depth = 1,
|
||||||
|
dcoffset = -0.5,
|
||||||
|
frequency = 1,
|
||||||
|
skew = 0.5,
|
||||||
|
phaseoffset = 0,
|
||||||
|
curve = 1,
|
||||||
|
min,
|
||||||
|
max,
|
||||||
|
...props
|
||||||
|
} = properties;
|
||||||
|
|
||||||
const lfoprops = {
|
const lfoprops = {
|
||||||
frequency: 1,
|
|
||||||
depth,
|
|
||||||
skew: 0.5,
|
|
||||||
phaseoffset: 0,
|
|
||||||
time: begin,
|
|
||||||
begin,
|
begin,
|
||||||
end,
|
end,
|
||||||
shape: getModulationShapeInput(shape),
|
time: time ?? begin,
|
||||||
|
depth,
|
||||||
dcoffset,
|
dcoffset,
|
||||||
min: dcoffset * depth,
|
frequency,
|
||||||
max: dcoffset * depth + depth,
|
skew,
|
||||||
curve: 1,
|
phaseoffset,
|
||||||
...props,
|
curve,
|
||||||
};
|
|
||||||
|
|
||||||
return getWorklet(audioContext, 'lfo-processor', lfoprops);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getCustomLfo(audioContext, properties = {}) {
|
|
||||||
// Default / process certain params
|
|
||||||
const { shape = 0, ...props } = properties;
|
|
||||||
const lfoprops = {
|
|
||||||
shape: getModulationShapeInput(shape),
|
shape: getModulationShapeInput(shape),
|
||||||
dcoffset: -0.5,
|
min: min ?? dcoffset * depth,
|
||||||
|
max: max ?? dcoffset * depth + depth,
|
||||||
...props,
|
...props,
|
||||||
};
|
};
|
||||||
|
|
||||||
return getWorklet(audioContext, 'lfo-processor', lfoprops);
|
return getWorklet(audioContext, 'lfo-processor', lfoprops);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -177,7 +180,9 @@ export function getParamLfo(audioContext, param, start, end, lfoValues) {
|
||||||
}
|
}
|
||||||
let lfo;
|
let lfo;
|
||||||
if (depth) {
|
if (depth) {
|
||||||
lfo = getLfo(audioContext, start, end, {
|
lfo = getLfo(audioContext, {
|
||||||
|
begin: start,
|
||||||
|
end,
|
||||||
depth,
|
depth,
|
||||||
dcoffset,
|
dcoffset,
|
||||||
...getLfoInputs,
|
...getLfoInputs,
|
||||||
|
|
|
||||||
|
|
@ -457,7 +457,7 @@ function connectLFO(idx, params, nodeTracker) {
|
||||||
min,
|
min,
|
||||||
max,
|
max,
|
||||||
};
|
};
|
||||||
const lfoNode = getCustomLfo(getAudioContext(), modParams);
|
const lfoNode = getLfo(getAudioContext(), modParams);
|
||||||
nodeTracker[`lfo${idx}`] = [lfoNode];
|
nodeTracker[`lfo${idx}`] = [lfoNode];
|
||||||
targetParams.forEach((t) => lfoNode.connect(t));
|
targetParams.forEach((t) => lfoNode.connect(t));
|
||||||
return lfoNode;
|
return lfoNode;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue