Move algorithm into constructor
This commit is contained in:
parent
69b034349a
commit
f0669ce3ba
2 changed files with 10 additions and 6 deletions
|
|
@ -403,6 +403,11 @@ export const getDistortionAlgorithm = (algo) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getDistortion = (distort, postgain, algorithm) => {
|
export const getDistortion = (distort, postgain, algorithm) => {
|
||||||
const { _algorithm, index } = getDistortionAlgorithm(algorithm);
|
const { index } = getDistortionAlgorithm(algorithm);
|
||||||
return getWorklet(getAudioContext(), 'distort-processor', { distort, postgain, algorithm: index });
|
return getWorklet(
|
||||||
|
getAudioContext(),
|
||||||
|
'distort-processor',
|
||||||
|
{ distort, postgain },
|
||||||
|
{ processorOptions: { algorithm: index } },
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -348,13 +348,13 @@ class DistortProcessor extends AudioWorkletProcessor {
|
||||||
return [
|
return [
|
||||||
{ name: 'distort', defaultValue: 0 },
|
{ name: 'distort', defaultValue: 0 },
|
||||||
{ name: 'postgain', defaultValue: 1 },
|
{ name: 'postgain', defaultValue: 1 },
|
||||||
{ name: 'algorithm', defaultValue: 0, min: 0 },
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor({ processorOptions }) {
|
||||||
super();
|
super();
|
||||||
this.started = false;
|
this.started = false;
|
||||||
|
this.algorithm = getDistortionAlgorithm(processorOptions.algorithm).algorithm;
|
||||||
}
|
}
|
||||||
|
|
||||||
process(inputs, outputs, parameters) {
|
process(inputs, outputs, parameters) {
|
||||||
|
|
@ -366,13 +366,12 @@ class DistortProcessor extends AudioWorkletProcessor {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.started = hasInput;
|
this.started = hasInput;
|
||||||
const { algorithm } = getDistortionAlgorithm(pv(parameters.algorithm, 0)); // do not allow audio rate algo changes
|
|
||||||
for (let n = 0; n < blockSize; n++) {
|
for (let n = 0; n < blockSize; n++) {
|
||||||
const postgain = clamp(pv(parameters.postgain, n), 0.001, 1);
|
const postgain = clamp(pv(parameters.postgain, n), 0.001, 1);
|
||||||
const shape = Math.expm1(pv(parameters.distort, n));
|
const shape = Math.expm1(pv(parameters.distort, n));
|
||||||
for (let ch = 0; ch < input.length; ch++) {
|
for (let ch = 0; ch < input.length; ch++) {
|
||||||
const x = input[ch][n];
|
const x = input[ch][n];
|
||||||
output[ch][n] = postgain * algorithm(x, shape);
|
output[ch][n] = postgain * this.algorithm(x, shape);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue