disable lint for global worklet variables

This commit is contained in:
Jade (Rose) Rowland 2024-03-05 00:34:59 -05:00
parent c0b00339c5
commit 232b9c13d7
2 changed files with 63 additions and 41 deletions

View File

@ -219,7 +219,7 @@ export function applyFM(param, value, begin) {
if (fmModulationIndex) { if (fmModulationIndex) {
const ac = getAudioContext(); const ac = getAudioContext();
const envGain = ac.createGain(); const envGain = ac.createGain();
const { node: modulator } = fm(param, fmHarmonicity, fmModulationIndex, fmWaveform); const { node: modulator, stop } = fm(param, fmHarmonicity, fmModulationIndex, fmWaveform);
if (![fmAttack, fmDecay, fmSustain, fmRelease, fmVelocity].find((v) => v !== undefined)) { if (![fmAttack, fmDecay, fmSustain, fmRelease, fmVelocity].find((v) => v !== undefined)) {
// no envelope by default // no envelope by default
modulator.connect(param); modulator.connect(param);

View File

@ -1,23 +1,6 @@
const processSample = (inputs, outputs, processBlock) => {
const input = inputs[0];
const output = outputs[0];
const blockSize = 128;
if (input == null || output == null) {
return false;
}
for (let n = 0; n < blockSize; n++) {
input.forEach((inChannel, i) => {
const outChannel = output[i % output.length];
const block = inChannel[n];
outChannel[n] = processBlock(block, n, inChannel, outChannel);
});
}
return true;
};
// coarse, crush, and shape processors adapted from dktr0's webdirt: https://github.com/dktr0/WebDirt/blob/5ce3d698362c54d6e1b68acc47eb2955ac62c793/dist/AudioWorklets.js // coarse, crush, and shape processors adapted from dktr0's webdirt: https://github.com/dktr0/WebDirt/blob/5ce3d698362c54d6e1b68acc47eb2955ac62c793/dist/AudioWorklets.js
// LICENSE GNU General Public License v3.0 see https://github.com/dktr0/WebDirt/blob/main/LICENSE // LICENSE GNU General Public License v3.0 see https://github.com/dktr0/WebDirt/blob/main/LICENSE
class CoarseProcessor extends AudioWorkletProcessor { class CoarseProcessor extends AudioWorkletProcessor {
static get parameterDescriptors() { static get parameterDescriptors() {
return [{ name: 'coarse', defaultValue: 1 }]; return [{ name: 'coarse', defaultValue: 1 }];
@ -28,15 +11,24 @@ class CoarseProcessor extends AudioWorkletProcessor {
} }
process(inputs, outputs, parameters) { process(inputs, outputs, parameters) {
const input = inputs[0];
const output = outputs[0];
const blockSize = 128;
let coarse = parameters.coarse[0] ?? 0; let coarse = parameters.coarse[0] ?? 0;
coarse = Math.max(1, coarse); coarse = Math.max(1, coarse);
return processSample(inputs, outputs, (block, n, inChannel, outChannel) => {
const value = n % coarse === 0 ? block : outChannel[n - 1]; if (input[0] == null || output[0] == null) {
return value; return false;
}); }
for (let n = 0; n < blockSize; n++) {
for (let i = 0; i < input.length; i++) {
output[i][n] = n % coarse === 0 ? input[i][n] : output[i][n - 1];
}
}
return true;
} }
} }
registerProcessor('coarse-processor', CoarseProcessor); registerProcessor('coarse-processor', CoarseProcessor);
class CrushProcessor extends AudioWorkletProcessor { class CrushProcessor extends AudioWorkletProcessor {
@ -49,13 +41,23 @@ class CrushProcessor extends AudioWorkletProcessor {
} }
process(inputs, outputs, parameters) { process(inputs, outputs, parameters) {
const input = inputs[0];
const output = outputs[0];
const blockSize = 128;
let crush = parameters.crush[0] ?? 8; let crush = parameters.crush[0] ?? 8;
crush = Math.max(1, crush); crush = Math.max(1, crush);
return processSample(inputs, outputs, (block) => { if (input[0] == null || output[0] == null) {
const x = Math.pow(2, crush - 1); return false;
return Math.round(block * x) / x; }
}); for (let n = 0; n < blockSize; n++) {
for (let i = 0; i < input.length; i++) {
const x = Math.pow(2, crush - 1);
output[i][n] = Math.round(input[i][n] * x) / x;
}
}
return true;
} }
} }
registerProcessor('crush-processor', CrushProcessor); registerProcessor('crush-processor', CrushProcessor);
@ -73,17 +75,26 @@ class ShapeProcessor extends AudioWorkletProcessor {
} }
process(inputs, outputs, parameters) { process(inputs, outputs, parameters) {
const input = inputs[0];
const output = outputs[0];
const blockSize = 128;
let shape = parameters.shape[0]; let shape = parameters.shape[0];
const postgain = Math.max(0.001, Math.min(1, parameters.postgain[0]));
shape = shape < 1 ? shape : 1.0 - 4e-10; shape = shape < 1 ? shape : 1.0 - 4e-10;
shape = (2.0 * shape) / (1.0 - shape); shape = (2.0 * shape) / (1.0 - shape);
return processSample(inputs, outputs, (block) => { const postgain = Math.max(0.001, Math.min(1, parameters.postgain[0]));
const val = ((1 + shape) * block) / (1 + shape * Math.abs(block));
return val * postgain; if (input[0] == null || output[0] == null) {
}); return false;
}
for (let n = 0; n < blockSize; n++) {
for (let i = 0; i < input.length; i++) {
output[i][n] = (((1 + shape) * input[i][n]) / (1 + shape * Math.abs(input[i][n]))) * postgain;
}
}
return true;
} }
} }
registerProcessor('shape-processor', ShapeProcessor); registerProcessor('shape-processor', ShapeProcessor);
class DistortProcessor extends AudioWorkletProcessor { class DistortProcessor extends AudioWorkletProcessor {
@ -99,16 +110,24 @@ class DistortProcessor extends AudioWorkletProcessor {
} }
process(inputs, outputs, parameters) { process(inputs, outputs, parameters) {
let shape = parameters.distort[0]; const input = inputs[0];
const output = outputs[0];
const blockSize = 128;
const shape = Math.expm1(parameters.distort[0]);
const postgain = Math.max(0.001, Math.min(1, parameters.postgain[0])); const postgain = Math.max(0.001, Math.min(1, parameters.postgain[0]));
shape = Math.expm1(shape);
return processSample(inputs, outputs, (block) => { if (input[0] == null || output[0] == null) {
const val = ((1 + shape) * block) / (1 + shape * Math.abs(block)); return false;
return val * postgain; }
}); for (let n = 0; n < blockSize; n++) {
for (let i = 0; i < input.length; i++) {
output[i][n] = (((1 + shape) * input[i][n]) / (1 + shape * Math.abs(input[i][n]))) * postgain;
}
}
return true;
} }
} }
registerProcessor('distort-processor', DistortProcessor); registerProcessor('distort-processor', DistortProcessor);
// adjust waveshape to remove frequencies above nyquist to prevent aliasing // adjust waveshape to remove frequencies above nyquist to prevent aliasing
@ -194,9 +213,11 @@ class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
]; ];
} }
process(input, outputs, params) { process(input, outputs, params) {
// eslint-disable-next-line no-undef
if (currentTime <= params.begin[0]) { if (currentTime <= params.begin[0]) {
return true; return true;
} }
// eslint-disable-next-line no-undef
if (currentTime >= params.end[0]) { if (currentTime >= params.end[0]) {
return false; return false;
} }
@ -219,6 +240,7 @@ class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
} }
const freq = Math.min(16744, Math.max(1, frequency + adj * 0.01 * frequency)); const freq = Math.min(16744, Math.max(1, frequency + adj * 0.01 * frequency));
const balance = isOdd ? 1 - panspread : panspread; const balance = isOdd ? 1 - panspread : panspread;
// eslint-disable-next-line no-undef
const dt = freq / sampleRate; const dt = freq / sampleRate;
for (let i = 0; i < output[0].length; i++) { for (let i = 0; i < output[0].length; i++) {