@codexo/exojs-audio-fx 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/esm/BeatDetector.d.ts +55 -9
  2. package/dist/esm/BeatDetector.js +19 -9
  3. package/dist/esm/BeatDetector.js.map +1 -1
  4. package/dist/esm/dsp/tempogram.d.ts +122 -21
  5. package/dist/esm/effects/AutoWahEffect.d.ts +127 -0
  6. package/dist/esm/effects/AutoWahEffect.js +241 -0
  7. package/dist/esm/effects/AutoWahEffect.js.map +1 -0
  8. package/dist/esm/effects/BitCrusherEffect.d.ts +63 -0
  9. package/dist/esm/effects/BitCrusherEffect.js +74 -0
  10. package/dist/esm/effects/BitCrusherEffect.js.map +1 -0
  11. package/dist/esm/effects/ConvolutionEffect.d.ts +114 -0
  12. package/dist/esm/effects/ConvolutionEffect.js +193 -0
  13. package/dist/esm/effects/ConvolutionEffect.js.map +1 -0
  14. package/dist/esm/effects/DistortionEffect.d.ts +119 -0
  15. package/dist/esm/effects/DistortionEffect.js +199 -0
  16. package/dist/esm/effects/DistortionEffect.js.map +1 -0
  17. package/dist/esm/effects/DuckingEffect.js +6 -2
  18. package/dist/esm/effects/DuckingEffect.js.map +1 -1
  19. package/dist/esm/effects/FlangerEffect.d.ts +98 -0
  20. package/dist/esm/effects/FlangerEffect.js +205 -0
  21. package/dist/esm/effects/FlangerEffect.js.map +1 -0
  22. package/dist/esm/effects/GranularEffect.d.ts +8 -4
  23. package/dist/esm/effects/GranularEffect.js +4 -12
  24. package/dist/esm/effects/GranularEffect.js.map +1 -1
  25. package/dist/esm/effects/LimiterEffect.d.ts +124 -0
  26. package/dist/esm/effects/LimiterEffect.js +198 -0
  27. package/dist/esm/effects/LimiterEffect.js.map +1 -0
  28. package/dist/esm/effects/PhaserEffect.d.ts +126 -0
  29. package/dist/esm/effects/PhaserEffect.js +258 -0
  30. package/dist/esm/effects/PhaserEffect.js.map +1 -0
  31. package/dist/esm/effects/PingPongDelayEffect.d.ts +83 -0
  32. package/dist/esm/effects/PingPongDelayEffect.js +189 -0
  33. package/dist/esm/effects/PingPongDelayEffect.js.map +1 -0
  34. package/dist/esm/effects/PitchShiftEffect.d.ts +14 -13
  35. package/dist/esm/effects/PitchShiftEffect.js +16 -18
  36. package/dist/esm/effects/PitchShiftEffect.js.map +1 -1
  37. package/dist/esm/effects/RingModulatorEffect.d.ts +95 -0
  38. package/dist/esm/effects/RingModulatorEffect.js +165 -0
  39. package/dist/esm/effects/RingModulatorEffect.js.map +1 -0
  40. package/dist/esm/effects/TremoloEffect.d.ts +110 -0
  41. package/dist/esm/effects/TremoloEffect.js +205 -0
  42. package/dist/esm/effects/TremoloEffect.js.map +1 -0
  43. package/dist/esm/effects/VocoderEffect.d.ts +0 -4
  44. package/dist/esm/effects/VocoderEffect.js +1 -11
  45. package/dist/esm/effects/VocoderEffect.js.map +1 -1
  46. package/dist/esm/index.d.ts +10 -0
  47. package/dist/esm/index.js +10 -0
  48. package/dist/esm/index.js.map +1 -1
  49. package/dist/esm/worklets/beat-detector.worklet.d.ts +1 -1
  50. package/dist/esm/worklets/beat-detector.worklet.js +628 -112
  51. package/dist/esm/worklets/beat-detector.worklet.js.map +1 -1
  52. package/dist/esm/worklets/bit-crusher.worklet.d.ts +1 -0
  53. package/dist/esm/worklets/bit-crusher.worklet.js +45 -0
  54. package/dist/esm/worklets/bit-crusher.worklet.js.map +1 -0
  55. package/dist/esm/worklets/granular.worklet.d.ts +1 -1
  56. package/dist/esm/worklets/granular.worklet.js +13 -4
  57. package/dist/esm/worklets/granular.worklet.js.map +1 -1
  58. package/dist/esm/worklets/pitch-shift.worklet.d.ts +1 -1
  59. package/dist/esm/worklets/pitch-shift.worklet.js +87 -32
  60. package/dist/esm/worklets/pitch-shift.worklet.js.map +1 -1
  61. package/dist/esm/worklets/vocoder.worklet.d.ts +1 -1
  62. package/dist/esm/worklets/vocoder.worklet.js +5 -3
  63. package/dist/esm/worklets/vocoder.worklet.js.map +1 -1
  64. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"beat-detector.worklet.js","sources":["../../../../src/worklets/beat-detector.worklet.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAO,MAAM,yBAAyB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"beat-detector.worklet.js","sources":["../../../../src/worklets/beat-detector.worklet.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACO,MAAM,yBAAyB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1 @@
1
+ export declare const bitCrusherWorkletSource = "\nclass BitCrusherProcessor extends AudioWorkletProcessor {\n static get parameterDescriptors() {\n return [\n { name: 'bits', defaultValue: 8, minValue: 1, maxValue: 16, automationRate: 'k-rate' },\n { name: 'normFreq', defaultValue: 0.5, minValue: 0, maxValue: 1, automationRate: 'k-rate' },\n ];\n }\n\n constructor() {\n super();\n // Phase accumulator for sample-and-hold; held keeps the last latched value.\n this._phase = 0;\n this._held = 0;\n }\n\n process(inputs, outputs, parameters) {\n const input = inputs[0]?.[0];\n const output = outputs[0]?.[0];\n if (!input || !output) return true;\n\n const bits = Math.round(Math.max(1, Math.min(16, parameters.bits[0])));\n const normFreq = Math.max(0, Math.min(1, parameters.normFreq[0]));\n // Quantization step: 2 / 2^bits (maps [-1, 1] onto 2^bits levels)\n const step = 2 / Math.pow(2, bits);\n\n for (let i = 0; i < input.length; i++) {\n // Advance the sample-and-hold phase accumulator.\n this._phase += normFreq;\n if (this._phase >= 1) {\n // Wrap phase and latch a fresh, quantized sample.\n this._phase -= 1;\n this._held = step * Math.round(input[i] / step);\n }\n // Emit the held (quantized) sample \u2014 pure wet, no dry mixing here.\n output[i] = this._held;\n }\n return true;\n }\n}\nregisterProcessor('exojs-bit-crusher', BitCrusherProcessor);\n";
@@ -0,0 +1,45 @@
1
+ const bitCrusherWorkletSource = `
2
+ class BitCrusherProcessor extends AudioWorkletProcessor {
3
+ static get parameterDescriptors() {
4
+ return [
5
+ { name: 'bits', defaultValue: 8, minValue: 1, maxValue: 16, automationRate: 'k-rate' },
6
+ { name: 'normFreq', defaultValue: 0.5, minValue: 0, maxValue: 1, automationRate: 'k-rate' },
7
+ ];
8
+ }
9
+
10
+ constructor() {
11
+ super();
12
+ // Phase accumulator for sample-and-hold; held keeps the last latched value.
13
+ this._phase = 0;
14
+ this._held = 0;
15
+ }
16
+
17
+ process(inputs, outputs, parameters) {
18
+ const input = inputs[0]?.[0];
19
+ const output = outputs[0]?.[0];
20
+ if (!input || !output) return true;
21
+
22
+ const bits = Math.round(Math.max(1, Math.min(16, parameters.bits[0])));
23
+ const normFreq = Math.max(0, Math.min(1, parameters.normFreq[0]));
24
+ // Quantization step: 2 / 2^bits (maps [-1, 1] onto 2^bits levels)
25
+ const step = 2 / Math.pow(2, bits);
26
+
27
+ for (let i = 0; i < input.length; i++) {
28
+ // Advance the sample-and-hold phase accumulator.
29
+ this._phase += normFreq;
30
+ if (this._phase >= 1) {
31
+ // Wrap phase and latch a fresh, quantized sample.
32
+ this._phase -= 1;
33
+ this._held = step * Math.round(input[i] / step);
34
+ }
35
+ // Emit the held (quantized) sample — pure wet, no dry mixing here.
36
+ output[i] = this._held;
37
+ }
38
+ return true;
39
+ }
40
+ }
41
+ registerProcessor('exojs-bit-crusher', BitCrusherProcessor);
42
+ `;
43
+
44
+ export { bitCrusherWorkletSource };
45
+ //# sourceMappingURL=bit-crusher.worklet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bit-crusher.worklet.js","sources":["../../../../src/worklets/bit-crusher.worklet.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAO,MAAM,uBAAuB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1 +1 @@
1
- export declare const granularWorkletSource = "\nconst sampleRate = globalThis.sampleRate;\n\nclass GranularProcessor extends AudioWorkletProcessor {\n static get parameterDescriptors() {\n return [\n { name: 'grainSize', defaultValue: 0.05, minValue: 0.005, maxValue: 0.5, automationRate: 'k-rate' },\n { name: 'density', defaultValue: 50, minValue: 1, maxValue: 500, automationRate: 'k-rate' },\n { name: 'spread', defaultValue: 0.5, minValue: 0, maxValue: 1.0, automationRate: 'k-rate' },\n { name: 'pitchMin', defaultValue: 1.0, minValue: 0.25, maxValue: 4.0, automationRate: 'k-rate' },\n { name: 'pitchMax', defaultValue: 1.0, minValue: 0.25, maxValue: 4.0, automationRate: 'k-rate' },\n { name: 'wet', defaultValue: 1.0, minValue: 0, maxValue: 1.0, automationRate: 'k-rate' },\n ];\n }\n\n constructor(options) {\n super();\n const opts = options.processorOptions ?? {};\n const bufferSeconds = opts.bufferSeconds ?? 2;\n this._bufferLength = Math.floor(bufferSeconds * sampleRate);\n this._buffer = new Float32Array(this._bufferLength);\n this._writePos = 0;\n this._timeUntilNextGrainSamples = 0;\n this._grains = []; // { startPos, ageSamples, lengthSamples, pitch }\n }\n\n process(inputs, outputs, parameters) {\n const input = inputs[0]?.[0];\n const output = outputs[0]?.[0];\n if (!input || !output) return true;\n\n const grainSize = parameters.grainSize[0];\n const density = parameters.density[0];\n const spread = parameters.spread[0];\n const pitchMin = parameters.pitchMin[0];\n const pitchMax = parameters.pitchMax[0];\n const wet = parameters.wet[0];\n\n const grainSizeSamples = Math.max(8, Math.floor(grainSize * sampleRate));\n const samplesPerGrain = sampleRate / Math.max(1, density);\n\n for (let i = 0; i < input.length; i++) {\n // Write input to circular buffer\n this._buffer[this._writePos] = input[i];\n this._writePos = (this._writePos + 1) % this._bufferLength;\n\n // Spawn new grain if scheduled\n this._timeUntilNextGrainSamples -= 1;\n if (this._timeUntilNextGrainSamples <= 0) {\n // Random offset into recent past, biased by spread\n const maxOffset = Math.floor(spread * this._bufferLength);\n const offset = Math.floor(Math.random() * Math.max(1, maxOffset));\n const startPos = (this._writePos - offset - grainSizeSamples + this._bufferLength) % this._bufferLength;\n // Random pitch in [pitchMin, pitchMax]\n const pitch = pitchMin + Math.random() * Math.max(0, pitchMax - pitchMin);\n\n this._grains.push({ startPos, ageSamples: 0, lengthSamples: grainSizeSamples, pitch });\n this._timeUntilNextGrainSamples = samplesPerGrain;\n }\n\n // Mix all active grains (apply Hann window)\n let grainSum = 0;\n for (let g = this._grains.length - 1; g >= 0; g--) {\n const grain = this._grains[g];\n if (grain.ageSamples >= grain.lengthSamples) {\n this._grains.splice(g, 1);\n continue;\n }\n\n const phase = grain.ageSamples / grain.lengthSamples;\n const window = 0.5 * (1 - Math.cos(2 * Math.PI * phase));\n const readPos = grain.startPos + grain.ageSamples * grain.pitch;\n const sampleIndex = Math.floor(readPos) % this._bufferLength;\n const safeIndex = (sampleIndex + this._bufferLength) % this._bufferLength;\n grainSum += this._buffer[safeIndex] * window;\n\n grain.ageSamples++;\n }\n\n output[i] = (1 - wet) * input[i] + wet * grainSum;\n }\n return true;\n }\n}\nregisterProcessor('exojs-granular', GranularProcessor);\n";
1
+ export declare const granularWorkletSource = "\nconst sampleRate = globalThis.sampleRate;\n\nclass GranularProcessor extends AudioWorkletProcessor {\n static get parameterDescriptors() {\n return [\n { name: 'grainSize', defaultValue: 0.05, minValue: 0.005, maxValue: 0.5, automationRate: 'k-rate' },\n { name: 'density', defaultValue: 50, minValue: 1, maxValue: 500, automationRate: 'k-rate' },\n { name: 'spread', defaultValue: 0.5, minValue: 0, maxValue: 1.0, automationRate: 'k-rate' },\n { name: 'pitchMin', defaultValue: 1.0, minValue: 0.25, maxValue: 4.0, automationRate: 'k-rate' },\n { name: 'pitchMax', defaultValue: 1.0, minValue: 0.25, maxValue: 4.0, automationRate: 'k-rate' },\n ];\n }\n\n constructor(options) {\n super();\n const opts = options.processorOptions ?? {};\n const bufferSeconds = opts.bufferSeconds ?? 2;\n this._bufferLength = Math.floor(bufferSeconds * sampleRate);\n this._buffer = new Float32Array(this._bufferLength);\n this._writePos = 0;\n this._timeUntilNextGrainSamples = 0;\n this._grains = []; // { startPos, ageSamples, lengthSamples, pitch }\n this._normalizeGain = opts.normalizeGain ?? false;\n }\n\n process(inputs, outputs, parameters) {\n const input = inputs[0]?.[0];\n const output = outputs[0]?.[0];\n if (!input || !output) return true;\n\n const grainSize = parameters.grainSize[0];\n const density = parameters.density[0];\n const spread = parameters.spread[0];\n const pitchMin = parameters.pitchMin[0];\n const pitchMax = parameters.pitchMax[0];\n const grainSizeSamples = Math.max(8, Math.floor(grainSize * sampleRate));\n const samplesPerGrain = sampleRate / Math.max(1, density);\n\n // Optional level normalization. Output RMS scales as sqrt(3/8) (the Hann\n // window RMS) times sqrt(density * grainSize) \u2014 overlapping uncorrelated\n // grains add in power. Dividing by that factor holds the wet level near\n // unity regardless of density/grainSize. Default off keeps the expressive\n // density dynamics that make granular sound the way it does.\n let normFactor = 1;\n if (this._normalizeGain) {\n const expectedGrains = density * grainSize; // simultaneous grains (dimensionless)\n normFactor = 1 / (0.6123724356957945 * Math.sqrt(Math.max(1e-6, expectedGrains)));\n }\n\n for (let i = 0; i < input.length; i++) {\n // Write input to circular buffer\n this._buffer[this._writePos] = input[i];\n this._writePos = (this._writePos + 1) % this._bufferLength;\n\n // Spawn new grain if scheduled\n this._timeUntilNextGrainSamples -= 1;\n if (this._timeUntilNextGrainSamples <= 0) {\n // Random offset into recent past, biased by spread\n const maxOffset = Math.floor(spread * this._bufferLength);\n const offset = Math.floor(Math.random() * Math.max(1, maxOffset));\n const startPos = (this._writePos - offset - grainSizeSamples + this._bufferLength) % this._bufferLength;\n // Random pitch in [pitchMin, pitchMax]\n const pitch = pitchMin + Math.random() * Math.max(0, pitchMax - pitchMin);\n\n this._grains.push({ startPos, ageSamples: 0, lengthSamples: grainSizeSamples, pitch });\n this._timeUntilNextGrainSamples = samplesPerGrain;\n }\n\n // Mix all active grains (apply Hann window)\n let grainSum = 0;\n for (let g = this._grains.length - 1; g >= 0; g--) {\n const grain = this._grains[g];\n if (grain.ageSamples >= grain.lengthSamples) {\n this._grains.splice(g, 1);\n continue;\n }\n\n const phase = grain.ageSamples / grain.lengthSamples;\n const window = 0.5 * (1 - Math.cos(2 * Math.PI * phase));\n const readPos = grain.startPos + grain.ageSamples * grain.pitch;\n const sampleIndex = Math.floor(readPos) % this._bufferLength;\n const safeIndex = (sampleIndex + this._bufferLength) % this._bufferLength;\n grainSum += this._buffer[safeIndex] * window;\n\n grain.ageSamples++;\n }\n\n output[i] = grainSum * normFactor;\n }\n return true;\n }\n}\nregisterProcessor('exojs-granular', GranularProcessor);\n";
@@ -9,7 +9,6 @@ class GranularProcessor extends AudioWorkletProcessor {
9
9
  { name: 'spread', defaultValue: 0.5, minValue: 0, maxValue: 1.0, automationRate: 'k-rate' },
10
10
  { name: 'pitchMin', defaultValue: 1.0, minValue: 0.25, maxValue: 4.0, automationRate: 'k-rate' },
11
11
  { name: 'pitchMax', defaultValue: 1.0, minValue: 0.25, maxValue: 4.0, automationRate: 'k-rate' },
12
- { name: 'wet', defaultValue: 1.0, minValue: 0, maxValue: 1.0, automationRate: 'k-rate' },
13
12
  ];
14
13
  }
15
14
 
@@ -22,6 +21,7 @@ class GranularProcessor extends AudioWorkletProcessor {
22
21
  this._writePos = 0;
23
22
  this._timeUntilNextGrainSamples = 0;
24
23
  this._grains = []; // { startPos, ageSamples, lengthSamples, pitch }
24
+ this._normalizeGain = opts.normalizeGain ?? false;
25
25
  }
26
26
 
27
27
  process(inputs, outputs, parameters) {
@@ -34,11 +34,20 @@ class GranularProcessor extends AudioWorkletProcessor {
34
34
  const spread = parameters.spread[0];
35
35
  const pitchMin = parameters.pitchMin[0];
36
36
  const pitchMax = parameters.pitchMax[0];
37
- const wet = parameters.wet[0];
38
-
39
37
  const grainSizeSamples = Math.max(8, Math.floor(grainSize * sampleRate));
40
38
  const samplesPerGrain = sampleRate / Math.max(1, density);
41
39
 
40
+ // Optional level normalization. Output RMS scales as sqrt(3/8) (the Hann
41
+ // window RMS) times sqrt(density * grainSize) — overlapping uncorrelated
42
+ // grains add in power. Dividing by that factor holds the wet level near
43
+ // unity regardless of density/grainSize. Default off keeps the expressive
44
+ // density dynamics that make granular sound the way it does.
45
+ let normFactor = 1;
46
+ if (this._normalizeGain) {
47
+ const expectedGrains = density * grainSize; // simultaneous grains (dimensionless)
48
+ normFactor = 1 / (0.6123724356957945 * Math.sqrt(Math.max(1e-6, expectedGrains)));
49
+ }
50
+
42
51
  for (let i = 0; i < input.length; i++) {
43
52
  // Write input to circular buffer
44
53
  this._buffer[this._writePos] = input[i];
@@ -77,7 +86,7 @@ class GranularProcessor extends AudioWorkletProcessor {
77
86
  grain.ageSamples++;
78
87
  }
79
88
 
80
- output[i] = (1 - wet) * input[i] + wet * grainSum;
89
+ output[i] = grainSum * normFactor;
81
90
  }
82
91
  return true;
83
92
  }
@@ -1 +1 @@
1
- {"version":3,"file":"granular.worklet.js","sources":["../../../../src/worklets/granular.worklet.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAO,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"granular.worklet.js","sources":["../../../../src/worklets/granular.worklet.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAO,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1 +1 @@
1
- export declare const pitchShiftWorkletSource = "\nclass PitchShiftProcessor extends AudioWorkletProcessor {\n static get parameterDescriptors() {\n return [\n { name: 'pitch', defaultValue: 1.0, minValue: 0.25, maxValue: 4.0, automationRate: 'k-rate' },\n { name: 'wet', defaultValue: 1.0, minValue: 0, maxValue: 1.0, automationRate: 'k-rate' },\n ];\n }\n\n constructor(options) {\n super();\n const grainSize = options.processorOptions?.grainSize ?? 1024;\n this._grainSize = grainSize;\n this._bufferLength = grainSize * 4;\n this._buffer = new Float32Array(this._bufferLength);\n this._writePos = 0;\n // Two staggered read positions for overlap-add\n this._readPosA = 0;\n this._readPosB = grainSize / 2;\n this._hannWindow = this._buildHannWindow(grainSize);\n }\n\n _buildHannWindow(n) {\n const w = new Float32Array(n);\n for (let i = 0; i < n; i++) {\n w[i] = 0.5 * (1 - Math.cos(2 * Math.PI * i / (n - 1)));\n }\n return w;\n }\n\n _readGrain(readPos) {\n const grainSize = this._grainSize;\n const sampleIndex = Math.floor(readPos);\n const phase = sampleIndex % grainSize; // position within the grain envelope\n const win = this._hannWindow[phase];\n const bufferIndex = ((this._writePos - this._bufferLength + sampleIndex) % this._bufferLength + this._bufferLength) % this._bufferLength;\n return this._buffer[bufferIndex] * win;\n }\n\n process(inputs, outputs, parameters) {\n const input = inputs[0]?.[0];\n const output = outputs[0]?.[0];\n if (!input || !output) return true;\n\n const pitch = parameters.pitch[0];\n const wet = parameters.wet[0];\n\n for (let i = 0; i < input.length; i++) {\n // Write to circular buffer\n this._buffer[this._writePos] = input[i];\n this._writePos = (this._writePos + 1) % this._bufferLength;\n\n // Read two grains and sum\n const grainA = this._readGrain(this._readPosA);\n const grainB = this._readGrain(this._readPosB);\n const shifted = grainA + grainB;\n\n // Mix with dry\n output[i] = (1 - wet) * input[i] + wet * shifted;\n\n // Advance read positions at pitch rate\n this._readPosA += pitch;\n this._readPosB += pitch;\n if (this._readPosA >= this._grainSize) this._readPosA -= this._grainSize;\n if (this._readPosB >= this._grainSize) this._readPosB -= this._grainSize;\n }\n return true;\n }\n}\nregisterProcessor('exojs-pitch-shift', PitchShiftProcessor);\n";
1
+ export declare const pitchShiftWorkletSource = "\nclass PitchShiftProcessor extends AudioWorkletProcessor {\n static get parameterDescriptors() {\n return [\n { name: 'pitch', defaultValue: 1.0, minValue: 0.25, maxValue: 4.0, automationRate: 'k-rate' },\n ];\n }\n\n // Pitch shift = SOLA time-stretch by `pitch` followed by resampling by\n // `pitch`. SOLA (synchronized overlap-add) realigns each synthesis grain by\n // cross-correlation so grain restarts stay phase coherent \u2014 this is what\n // keeps the carrier exactly at f_in * pitch. A naive granular delay drifts\n // the pitch because its grain-boundary phase jumps accumulate into a\n // frequency offset.\n constructor(options) {\n super();\n const grainSize = options.processorOptions?.grainSize ?? 1024;\n this._frameLen = grainSize; // analysis/synthesis frame\n this._hop = grainSize >> 1; // synthesis hop (50% overlap)\n this._overlap = grainSize - this._hop;\n this._seek = grainSize >> 2; // correlation search radius (\u00B1)\n this._win = this._buildHannWindow(grainSize);\n\n // Input ring buffer: holds enough past input for the correlation search.\n this._inLen = grainSize * 4 + 2 * this._seek;\n this._inBuf = new Float32Array(this._inLen);\n this._inCount = 0; // total input samples written\n\n // Stretched-stream overlap-add accumulator (also a ring).\n this._outLen = grainSize * 4;\n this._outBuf = new Float32Array(this._outLen);\n this._synthPos = 0; // total stretched samples synthesized\n this._readPos = 0; // fractional resample read position\n this._aPos = 0; // analysis position (absolute input coords)\n this._first = true;\n }\n\n _buildHannWindow(n) {\n // Periodic Hann: w(p) + w(p + n/2) === 1, i.e. constant-overlap-add at\n // 50% overlap, so two adjacent grains reconstruct unity amplitude.\n const w = new Float32Array(n);\n for (let i = 0; i < n; i++) {\n w[i] = 0.5 * (1 - Math.cos(2 * Math.PI * i / n));\n }\n return w;\n }\n\n // Find the input offset (within \u00B1seek of `nominal`) whose grain head best\n // matches the existing output overlap region \u2014 the waveform-similarity step\n // that keeps successive grains in phase.\n _correlate(nominal) {\n const ov = this._overlap;\n const ib = this._inBuf, iL = this._inLen;\n const ob = this._outBuf, oL = this._outLen;\n const sp = this._synthPos, seek = this._seek;\n let bestD = 0, bestC = -Infinity;\n for (let d = -seek; d <= seek; d++) {\n const base = nominal + d;\n if (base < 0 || base + ov > this._inCount) continue;\n let c = 0;\n for (let k = 0; k < ov; k++) c += ob[(sp + k) % oL] * ib[(base + k) % iL];\n if (c > bestC) { bestC = c; bestD = d; }\n }\n return bestD;\n }\n\n // True once the input buffer covers the next analysis frame plus its search.\n _canGenerate() {\n const nominal = Math.round(this._aPos);\n const oldest = this._inCount - this._inLen;\n return nominal >= 0\n && nominal + this._frameLen + this._seek <= this._inCount\n && nominal - this._seek >= oldest;\n }\n\n // Emit one phase-aligned grain into the stretched-stream accumulator.\n _generate(pitch) {\n const F = this._frameLen, H = this._hop, win = this._win;\n const ib = this._inBuf, iL = this._inLen;\n const ob = this._outBuf, oL = this._outLen;\n const nominal = Math.round(this._aPos);\n const d = this._first ? 0 : this._correlate(nominal);\n this._first = false;\n const base = nominal + d;\n // Zero the newly exposed tail, then overlap-add the windowed grain.\n for (let j = H; j < F; j++) ob[(this._synthPos + j) % oL] = 0;\n for (let j = 0; j < F; j++) ob[(this._synthPos + j) % oL] += ib[(base + j) % iL] * win[j];\n this._synthPos += H;\n this._aPos += H / pitch; // analysis hop = synthesis hop / stretch\n }\n\n process(inputs, outputs, parameters) {\n const input = inputs[0]?.[0];\n const output = outputs[0]?.[0];\n if (!input || !output) return true;\n\n const pitch = parameters.pitch[0];\n const ob = this._outBuf, oL = this._outLen;\n\n for (let i = 0; i < input.length; i++) {\n this._inBuf[this._inCount % this._inLen] = input[i];\n this._inCount++;\n\n // Pull-generate stretched samples until the read pointer has a margin.\n let guard = 0;\n while (this._synthPos < this._readPos + 2 && this._canGenerate() && guard++ < 64) {\n this._generate(pitch);\n }\n\n let shifted = 0;\n if (this._readPos + 1 < this._synthPos) {\n const p = this._readPos;\n const i0 = Math.floor(p), frac = p - i0;\n const a = ob[((i0 % oL) + oL) % oL];\n const b = ob[(((i0 + 1) % oL) + oL) % oL];\n shifted = a + (b - a) * frac;\n this._readPos += pitch;\n }\n\n output[i] = shifted;\n }\n return true;\n }\n}\nregisterProcessor('exojs-pitch-shift', PitchShiftProcessor);\n";
@@ -3,38 +3,90 @@ class PitchShiftProcessor extends AudioWorkletProcessor {
3
3
  static get parameterDescriptors() {
4
4
  return [
5
5
  { name: 'pitch', defaultValue: 1.0, minValue: 0.25, maxValue: 4.0, automationRate: 'k-rate' },
6
- { name: 'wet', defaultValue: 1.0, minValue: 0, maxValue: 1.0, automationRate: 'k-rate' },
7
6
  ];
8
7
  }
9
8
 
9
+ // Pitch shift = SOLA time-stretch by \`pitch\` followed by resampling by
10
+ // \`pitch\`. SOLA (synchronized overlap-add) realigns each synthesis grain by
11
+ // cross-correlation so grain restarts stay phase coherent — this is what
12
+ // keeps the carrier exactly at f_in * pitch. A naive granular delay drifts
13
+ // the pitch because its grain-boundary phase jumps accumulate into a
14
+ // frequency offset.
10
15
  constructor(options) {
11
16
  super();
12
17
  const grainSize = options.processorOptions?.grainSize ?? 1024;
13
- this._grainSize = grainSize;
14
- this._bufferLength = grainSize * 4;
15
- this._buffer = new Float32Array(this._bufferLength);
16
- this._writePos = 0;
17
- // Two staggered read positions for overlap-add
18
- this._readPosA = 0;
19
- this._readPosB = grainSize / 2;
20
- this._hannWindow = this._buildHannWindow(grainSize);
18
+ this._frameLen = grainSize; // analysis/synthesis frame
19
+ this._hop = grainSize >> 1; // synthesis hop (50% overlap)
20
+ this._overlap = grainSize - this._hop;
21
+ this._seek = grainSize >> 2; // correlation search radius (±)
22
+ this._win = this._buildHannWindow(grainSize);
23
+
24
+ // Input ring buffer: holds enough past input for the correlation search.
25
+ this._inLen = grainSize * 4 + 2 * this._seek;
26
+ this._inBuf = new Float32Array(this._inLen);
27
+ this._inCount = 0; // total input samples written
28
+
29
+ // Stretched-stream overlap-add accumulator (also a ring).
30
+ this._outLen = grainSize * 4;
31
+ this._outBuf = new Float32Array(this._outLen);
32
+ this._synthPos = 0; // total stretched samples synthesized
33
+ this._readPos = 0; // fractional resample read position
34
+ this._aPos = 0; // analysis position (absolute input coords)
35
+ this._first = true;
21
36
  }
22
37
 
23
38
  _buildHannWindow(n) {
39
+ // Periodic Hann: w(p) + w(p + n/2) === 1, i.e. constant-overlap-add at
40
+ // 50% overlap, so two adjacent grains reconstruct unity amplitude.
24
41
  const w = new Float32Array(n);
25
42
  for (let i = 0; i < n; i++) {
26
- w[i] = 0.5 * (1 - Math.cos(2 * Math.PI * i / (n - 1)));
43
+ w[i] = 0.5 * (1 - Math.cos(2 * Math.PI * i / n));
27
44
  }
28
45
  return w;
29
46
  }
30
47
 
31
- _readGrain(readPos) {
32
- const grainSize = this._grainSize;
33
- const sampleIndex = Math.floor(readPos);
34
- const phase = sampleIndex % grainSize; // position within the grain envelope
35
- const win = this._hannWindow[phase];
36
- const bufferIndex = ((this._writePos - this._bufferLength + sampleIndex) % this._bufferLength + this._bufferLength) % this._bufferLength;
37
- return this._buffer[bufferIndex] * win;
48
+ // Find the input offset (within ±seek of \`nominal\`) whose grain head best
49
+ // matches the existing output overlap region — the waveform-similarity step
50
+ // that keeps successive grains in phase.
51
+ _correlate(nominal) {
52
+ const ov = this._overlap;
53
+ const ib = this._inBuf, iL = this._inLen;
54
+ const ob = this._outBuf, oL = this._outLen;
55
+ const sp = this._synthPos, seek = this._seek;
56
+ let bestD = 0, bestC = -Infinity;
57
+ for (let d = -seek; d <= seek; d++) {
58
+ const base = nominal + d;
59
+ if (base < 0 || base + ov > this._inCount) continue;
60
+ let c = 0;
61
+ for (let k = 0; k < ov; k++) c += ob[(sp + k) % oL] * ib[(base + k) % iL];
62
+ if (c > bestC) { bestC = c; bestD = d; }
63
+ }
64
+ return bestD;
65
+ }
66
+
67
+ // True once the input buffer covers the next analysis frame plus its search.
68
+ _canGenerate() {
69
+ const nominal = Math.round(this._aPos);
70
+ const oldest = this._inCount - this._inLen;
71
+ return nominal >= 0
72
+ && nominal + this._frameLen + this._seek <= this._inCount
73
+ && nominal - this._seek >= oldest;
74
+ }
75
+
76
+ // Emit one phase-aligned grain into the stretched-stream accumulator.
77
+ _generate(pitch) {
78
+ const F = this._frameLen, H = this._hop, win = this._win;
79
+ const ib = this._inBuf, iL = this._inLen;
80
+ const ob = this._outBuf, oL = this._outLen;
81
+ const nominal = Math.round(this._aPos);
82
+ const d = this._first ? 0 : this._correlate(nominal);
83
+ this._first = false;
84
+ const base = nominal + d;
85
+ // Zero the newly exposed tail, then overlap-add the windowed grain.
86
+ for (let j = H; j < F; j++) ob[(this._synthPos + j) % oL] = 0;
87
+ for (let j = 0; j < F; j++) ob[(this._synthPos + j) % oL] += ib[(base + j) % iL] * win[j];
88
+ this._synthPos += H;
89
+ this._aPos += H / pitch; // analysis hop = synthesis hop / stretch
38
90
  }
39
91
 
40
92
  process(inputs, outputs, parameters) {
@@ -43,26 +95,29 @@ class PitchShiftProcessor extends AudioWorkletProcessor {
43
95
  if (!input || !output) return true;
44
96
 
45
97
  const pitch = parameters.pitch[0];
46
- const wet = parameters.wet[0];
98
+ const ob = this._outBuf, oL = this._outLen;
47
99
 
48
100
  for (let i = 0; i < input.length; i++) {
49
- // Write to circular buffer
50
- this._buffer[this._writePos] = input[i];
51
- this._writePos = (this._writePos + 1) % this._bufferLength;
101
+ this._inBuf[this._inCount % this._inLen] = input[i];
102
+ this._inCount++;
52
103
 
53
- // Read two grains and sum
54
- const grainA = this._readGrain(this._readPosA);
55
- const grainB = this._readGrain(this._readPosB);
56
- const shifted = grainA + grainB;
104
+ // Pull-generate stretched samples until the read pointer has a margin.
105
+ let guard = 0;
106
+ while (this._synthPos < this._readPos + 2 && this._canGenerate() && guard++ < 64) {
107
+ this._generate(pitch);
108
+ }
57
109
 
58
- // Mix with dry
59
- output[i] = (1 - wet) * input[i] + wet * shifted;
110
+ let shifted = 0;
111
+ if (this._readPos + 1 < this._synthPos) {
112
+ const p = this._readPos;
113
+ const i0 = Math.floor(p), frac = p - i0;
114
+ const a = ob[((i0 % oL) + oL) % oL];
115
+ const b = ob[(((i0 + 1) % oL) + oL) % oL];
116
+ shifted = a + (b - a) * frac;
117
+ this._readPos += pitch;
118
+ }
60
119
 
61
- // Advance read positions at pitch rate
62
- this._readPosA += pitch;
63
- this._readPosB += pitch;
64
- if (this._readPosA >= this._grainSize) this._readPosA -= this._grainSize;
65
- if (this._readPosB >= this._grainSize) this._readPosB -= this._grainSize;
120
+ output[i] = shifted;
66
121
  }
67
122
  return true;
68
123
  }
@@ -1 +1 @@
1
- {"version":3,"file":"pitch-shift.worklet.js","sources":["../../../../src/worklets/pitch-shift.worklet.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAO,MAAM,uBAAuB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"pitch-shift.worklet.js","sources":["../../../../src/worklets/pitch-shift.worklet.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAO,MAAM,uBAAuB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1 +1 @@
1
- export declare const vocoderWorkletSource = "\nconst sampleRate = globalThis.sampleRate;\n\nclass VocoderProcessor extends AudioWorkletProcessor {\n static get parameterDescriptors() {\n return [\n { name: 'wet', defaultValue: 1.0, minValue: 0, maxValue: 1.0, automationRate: 'k-rate' },\n { name: 'envelopeSmoothing', defaultValue: 0.005, minValue: 0.0001, maxValue: 0.1, automationRate: 'k-rate' },\n ];\n }\n\n constructor(options) {\n super();\n const opts = options.processorOptions ?? {};\n const bandCount = opts.numBands ?? 16;\n const minHz = opts.minHz ?? 80;\n const maxHz = opts.maxHz ?? 8000;\n const Q = opts.bandQ ?? 4;\n\n // Log-spaced band centers + biquad coefficients\n this._bands = [];\n for (let i = 0; i < bandCount; i++) {\n const ratio = bandCount === 1 ? 0 : i / (bandCount - 1);\n const centerHz = minHz * Math.pow(maxHz / minHz, ratio);\n const omega = 2 * Math.PI * centerHz / sampleRate;\n const cos = Math.cos(omega);\n const sin = Math.sin(omega);\n const alpha = sin / (2 * Q);\n\n // Bandpass (constant 0 dB peak) biquad\n const a0 = 1 + alpha;\n const b0 = alpha / a0;\n const b1 = 0;\n const b2 = -alpha / a0;\n const a1 = (-2 * cos) / a0;\n const a2 = (1 - alpha) / a0;\n this._bands.push({ b0, b1, b2, a1, a2 });\n }\n\n // Per-band biquad state (one for carrier, one for modulator)\n this._carrierStates = this._bands.map(() => ({ x1: 0, x2: 0, y1: 0, y2: 0 }));\n this._modulatorStates = this._bands.map(() => ({ x1: 0, x2: 0, y1: 0, y2: 0 }));\n\n // Per-band envelope follower\n this._envelopes = new Float32Array(bandCount);\n }\n\n _processBiquad(state, coef, x) {\n const y = coef.b0 * x + coef.b1 * state.x1 + coef.b2 * state.x2 - coef.a1 * state.y1 - coef.a2 * state.y2;\n state.x2 = state.x1; state.x1 = x;\n state.y2 = state.y1; state.y1 = y;\n return y;\n }\n\n process(inputs, outputs, parameters) {\n const carrier = inputs[0]?.[0];\n const modulator = inputs[1]?.[0];\n const output = outputs[0]?.[0];\n if (!carrier || !output) return true;\n\n const wet = parameters.wet[0];\n const envSmoothing = parameters.envelopeSmoothing[0];\n const bandCount = this._bands.length;\n\n for (let i = 0; i < carrier.length; i++) {\n const carrierSample = carrier[i];\n const modulatorSample = modulator?.[i] ?? 0;\n\n let bandSum = 0;\n for (let b = 0; b < bandCount; b++) {\n const coef = this._bands[b];\n\n // Modulator band \u2192 envelope follower\n const modBand = this._processBiquad(this._modulatorStates[b], coef, modulatorSample);\n const target = Math.abs(modBand);\n this._envelopes[b] += (target - this._envelopes[b]) * envSmoothing;\n\n // Carrier band, scaled by modulator envelope\n const carBand = this._processBiquad(this._carrierStates[b], coef, carrierSample);\n bandSum += carBand * this._envelopes[b];\n }\n\n output[i] = (1 - wet) * carrierSample + wet * bandSum;\n }\n return true;\n }\n}\nregisterProcessor('exojs-vocoder', VocoderProcessor);\n";
1
+ export declare const vocoderWorkletSource = "\nconst sampleRate = globalThis.sampleRate;\n\nclass VocoderProcessor extends AudioWorkletProcessor {\n static get parameterDescriptors() {\n return [\n { name: 'envelopeSmoothing', defaultValue: 0.005, minValue: 0.0001, maxValue: 0.1, automationRate: 'k-rate' },\n ];\n }\n\n constructor(options) {\n super();\n const opts = options.processorOptions ?? {};\n const bandCount = opts.numBands ?? 16;\n const minHz = opts.minHz ?? 80;\n const maxHz = opts.maxHz ?? 8000;\n const Q = opts.bandQ ?? 4;\n\n // Log-spaced band centers + biquad coefficients\n this._bands = [];\n for (let i = 0; i < bandCount; i++) {\n const ratio = bandCount === 1 ? 0 : i / (bandCount - 1);\n const centerHz = minHz * Math.pow(maxHz / minHz, ratio);\n const omega = 2 * Math.PI * centerHz / sampleRate;\n const cos = Math.cos(omega);\n const sin = Math.sin(omega);\n const alpha = sin / (2 * Q);\n\n // Bandpass (constant 0 dB peak) biquad\n const a0 = 1 + alpha;\n const b0 = alpha / a0;\n const b1 = 0;\n const b2 = -alpha / a0;\n const a1 = (-2 * cos) / a0;\n const a2 = (1 - alpha) / a0;\n this._bands.push({ b0, b1, b2, a1, a2 });\n }\n\n // Per-band biquad state (one for carrier, one for modulator)\n this._carrierStates = this._bands.map(() => ({ x1: 0, x2: 0, y1: 0, y2: 0 }));\n this._modulatorStates = this._bands.map(() => ({ x1: 0, x2: 0, y1: 0, y2: 0 }));\n\n // Per-band envelope follower\n this._envelopes = new Float32Array(bandCount);\n }\n\n _processBiquad(state, coef, x) {\n const y = coef.b0 * x + coef.b1 * state.x1 + coef.b2 * state.x2 - coef.a1 * state.y1 - coef.a2 * state.y2;\n state.x2 = state.x1; state.x1 = x;\n state.y2 = state.y1; state.y1 = y;\n return y;\n }\n\n process(inputs, outputs, parameters) {\n const carrier = inputs[0]?.[0];\n const modulator = inputs[1]?.[0];\n const output = outputs[0]?.[0];\n if (!carrier || !output) return true;\n\n const envSmoothing = parameters.envelopeSmoothing[0];\n const bandCount = this._bands.length;\n\n for (let i = 0; i < carrier.length; i++) {\n const carrierSample = carrier[i];\n const modulatorSample = modulator?.[i] ?? 0;\n\n let bandSum = 0;\n for (let b = 0; b < bandCount; b++) {\n const coef = this._bands[b];\n\n // Modulator band \u2192 envelope follower\n const modBand = this._processBiquad(this._modulatorStates[b], coef, modulatorSample);\n const target = Math.abs(modBand);\n this._envelopes[b] += (target - this._envelopes[b]) * envSmoothing;\n\n // Carrier band, scaled by modulator envelope\n const carBand = this._processBiquad(this._carrierStates[b], coef, carrierSample);\n bandSum += carBand * this._envelopes[b];\n }\n\n // Multiply bandSum by bandCount: for a broadband carrier the energy is\n // split across N bands, so the raw product (carBand \u00D7 envelope) is\n // O(1/N) of the carrier amplitude. Scaling by N restores unity gain\n // for typical broadband carrier + voice modulator inputs.\n output[i] = bandSum * bandCount;\n }\n return true;\n }\n}\nregisterProcessor('exojs-vocoder', VocoderProcessor);\n";
@@ -4,7 +4,6 @@ const sampleRate = globalThis.sampleRate;
4
4
  class VocoderProcessor extends AudioWorkletProcessor {
5
5
  static get parameterDescriptors() {
6
6
  return [
7
- { name: 'wet', defaultValue: 1.0, minValue: 0, maxValue: 1.0, automationRate: 'k-rate' },
8
7
  { name: 'envelopeSmoothing', defaultValue: 0.005, minValue: 0.0001, maxValue: 0.1, automationRate: 'k-rate' },
9
8
  ];
10
9
  }
@@ -58,7 +57,6 @@ class VocoderProcessor extends AudioWorkletProcessor {
58
57
  const output = outputs[0]?.[0];
59
58
  if (!carrier || !output) return true;
60
59
 
61
- const wet = parameters.wet[0];
62
60
  const envSmoothing = parameters.envelopeSmoothing[0];
63
61
  const bandCount = this._bands.length;
64
62
 
@@ -80,7 +78,11 @@ class VocoderProcessor extends AudioWorkletProcessor {
80
78
  bandSum += carBand * this._envelopes[b];
81
79
  }
82
80
 
83
- output[i] = (1 - wet) * carrierSample + wet * bandSum;
81
+ // Multiply bandSum by bandCount: for a broadband carrier the energy is
82
+ // split across N bands, so the raw product (carBand × envelope) is
83
+ // O(1/N) of the carrier amplitude. Scaling by N restores unity gain
84
+ // for typical broadband carrier + voice modulator inputs.
85
+ output[i] = bandSum * bandCount;
84
86
  }
85
87
  return true;
86
88
  }
@@ -1 +1 @@
1
- {"version":3,"file":"vocoder.worklet.js","sources":["../../../../src/worklets/vocoder.worklet.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAO,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"vocoder.worklet.js","sources":["../../../../src/worklets/vocoder.worklet.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAO,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codexo/exojs-audio-fx",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "Audio effects, DSP, beat detection and analysis for ExoJS.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,10 +26,10 @@
26
26
  "LICENSE"
27
27
  ],
28
28
  "peerDependencies": {
29
- "@codexo/exojs": "0.14.x"
29
+ "@codexo/exojs": "0.15.x"
30
30
  },
31
31
  "devDependencies": {
32
- "@codexo/exojs": "0.14.0",
32
+ "@codexo/exojs": "0.15.0",
33
33
  "@codexo/exojs-config": "0.0.0"
34
34
  },
35
35
  "license": "MIT",