working
This commit is contained in:
parent
dd64bf0fc9
commit
1416a0de53
2 changed files with 47 additions and 66 deletions
|
|
@ -452,7 +452,8 @@ export const superdough = async (value, deadline, hapDuration) => {
|
||||||
// effects
|
// effects
|
||||||
coarse !== undefined && chain.push(getWorklet(ac, 'coarse-processor', { coarse }));
|
coarse !== undefined && chain.push(getWorklet(ac, 'coarse-processor', { coarse }));
|
||||||
crush !== undefined && chain.push(getWorklet(ac, 'crush-processor', { crush }));
|
crush !== undefined && chain.push(getWorklet(ac, 'crush-processor', { crush }));
|
||||||
shape !== undefined && chain.push(getWorklet(ac, 'shape-processor', { shape }));
|
const shapeInput = Array.isArray(shape) ? { shape: shape[0], postgain: shape[1] } : { shape };
|
||||||
|
shape !== undefined && chain.push(getWorklet(ac, 'shape-processor', shapeInput));
|
||||||
|
|
||||||
compressorThreshold !== undefined &&
|
compressorThreshold !== undefined &&
|
||||||
chain.push(
|
chain.push(
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,23 @@
|
||||||
// LICENSE GNU General Public License v3.0 see https://github.com/dktr0/WebDirt/blob/main/LICENSE
|
const processSample = (inputs, outputs, processBlock) => {
|
||||||
// all the credit goes to dktr0's webdirt: https://github.com/dktr0/WebDirt/blob/5ce3d698362c54d6e1b68acc47eb2955ac62c793/dist/AudioWorklets.js
|
const input = inputs[0];
|
||||||
// <3
|
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
|
||||||
|
// 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 }];
|
||||||
|
|
@ -9,25 +25,15 @@ class CoarseProcessor extends AudioWorkletProcessor {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.notStarted = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
process(inputs, outputs, parameters) {
|
process(inputs, outputs, parameters) {
|
||||||
const input = inputs[0];
|
let coarse = parameters.coarse[0] ?? 0;
|
||||||
const output = outputs[0];
|
coarse = Math.min(128, Math.max(1, Math.round(coarse * 128)));
|
||||||
const coarse = parameters.coarse;
|
return processSample(inputs, outputs, (block, n, inChannel, outChannel) => {
|
||||||
const blockSize = 128;
|
const value = n % coarse === 0 ? block : outChannel[n - 1];
|
||||||
const hasInput = !(input[0] === undefined);
|
return value;
|
||||||
if (hasInput) {
|
});
|
||||||
this.notStarted = false;
|
|
||||||
output[0][0] = input[0][0];
|
|
||||||
for (let n = 1; n < blockSize; n++) {
|
|
||||||
for (let o = 0; o < output.length; o++) {
|
|
||||||
output[o][n] = n % coarse == 0 ? input[0][n] : output[o][n - 1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this.notStarted || hasInput;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,68 +46,42 @@ class CrushProcessor extends AudioWorkletProcessor {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.notStarted = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
process(inputs, outputs, parameters) {
|
process(inputs, outputs, parameters) {
|
||||||
const input = inputs[0];
|
const bitMax = 16;
|
||||||
const output = outputs[0];
|
const bitMin = 1;
|
||||||
const crush = parameters.crush;
|
let crush = parameters.crush[0] ?? 8;
|
||||||
const blockSize = 128;
|
crush = Math.max(bitMin, bitMax - crush * bitMax);
|
||||||
const hasInput = !(input[0] === undefined);
|
|
||||||
if (hasInput) {
|
return processSample(inputs, outputs, (block) => {
|
||||||
this.notStarted = false;
|
const x = Math.pow(2, crush - 1);
|
||||||
if (crush.length === 1) {
|
return Math.round(block * x) / x;
|
||||||
const x = Math.pow(2, crush[0] - 1);
|
});
|
||||||
for (let n = 0; n < blockSize; n++) {
|
|
||||||
const value = Math.round(input[0][n] * x) / x;
|
|
||||||
for (let o = 0; o < output.length; o++) {
|
|
||||||
output[o][n] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (let n = 0; n < blockSize; n++) {
|
|
||||||
let x = Math.pow(2, crush[n] - 1);
|
|
||||||
const value = Math.round(input[0][n] * x) / x;
|
|
||||||
for (let o = 0; o < output.length; o++) {
|
|
||||||
output[o][n] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this.notStarted || hasInput;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
registerProcessor('crush-processor', CrushProcessor);
|
registerProcessor('crush-processor', CrushProcessor);
|
||||||
|
|
||||||
class ShapeProcessor extends AudioWorkletProcessor {
|
class ShapeProcessor extends AudioWorkletProcessor {
|
||||||
static get parameterDescriptors() {
|
static get parameterDescriptors() {
|
||||||
return [{ name: 'shape', defaultValue: 0 }];
|
return [
|
||||||
|
{ name: 'shape', defaultValue: 0 },
|
||||||
|
{ name: 'postgain', defaultValue: 1 },
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.notStarted = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
process(inputs, outputs, parameters) {
|
process(inputs, outputs, parameters) {
|
||||||
const input = inputs[0];
|
let shape_param = parameters.shape[0];
|
||||||
const output = outputs[0];
|
const postgain = Math.max(0.001, Math.min(1, parameters.postgain[0]));
|
||||||
const shape0 = parameters.shape[0];
|
const shape = shape_param * 100;
|
||||||
const shape1 = shape0 < 1 ? shape0 : 1.0 - 4e-10;
|
return processSample(inputs, outputs, (block, n) => {
|
||||||
const shape = (2.0 * shape1) / (1.0 - shape1);
|
const val = ((1 + shape) * block) / (1 + shape * Math.abs(block));
|
||||||
const blockSize = 128;
|
return val * postgain;
|
||||||
const hasInput = !(input[0] === undefined);
|
});
|
||||||
if (hasInput) {
|
|
||||||
this.notStarted = false;
|
|
||||||
for (let n = 0; n < blockSize; n++) {
|
|
||||||
const value = ((1 + shape) * input[0][n]) / (1 + shape * Math.abs(input[0][n]));
|
|
||||||
for (let o = 0; o < output.length; o++) {
|
|
||||||
output[o][n] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this.notStarted || hasInput;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue