1 | import "../core/worklet/SingleIOProcessor.worklet.js";
|
2 | import { registerProcessor } from "../core/worklet/WorkletGlobalScope.js";
|
3 |
|
4 | export const workletName = "bit-crusher";
|
5 |
|
6 | export const bitCrusherWorklet = `
|
7 | class BitCrusherWorklet extends SingleIOProcessor {
|
8 |
|
9 | static get parameterDescriptors() {
|
10 | return [{
|
11 | name: "bits",
|
12 | defaultValue: 12,
|
13 | minValue: 1,
|
14 | maxValue: 16,
|
15 | automationRate: 'k-rate'
|
16 | }];
|
17 | }
|
18 |
|
19 | generate(input, _channel, parameters) {
|
20 | const step = Math.pow(0.5, parameters.bits - 1);
|
21 | const val = step * Math.floor(input / step + 0.5);
|
22 | return val;
|
23 | }
|
24 | }
|
25 | `;
|
26 |
|
27 | registerProcessor(workletName, bitCrusherWorklet);
|