dspx 1.2.4 → 1.3.1

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 (74) hide show
  1. package/README.md +40 -78
  2. package/binding.gyp +10 -0
  3. package/dist/FilterBankDesign.d.ts +233 -0
  4. package/dist/FilterBankDesign.d.ts.map +1 -0
  5. package/dist/FilterBankDesign.js +247 -0
  6. package/dist/FilterBankDesign.js.map +1 -0
  7. package/dist/advanced-dsp.d.ts +6 -6
  8. package/dist/advanced-dsp.d.ts.map +1 -1
  9. package/dist/advanced-dsp.js +35 -12
  10. package/dist/advanced-dsp.js.map +1 -1
  11. package/dist/backends.d.ts +0 -103
  12. package/dist/backends.d.ts.map +1 -1
  13. package/dist/backends.js +0 -217
  14. package/dist/backends.js.map +1 -1
  15. package/dist/bindings.d.ts +270 -17
  16. package/dist/bindings.d.ts.map +1 -1
  17. package/dist/bindings.js +566 -43
  18. package/dist/bindings.js.map +1 -1
  19. package/dist/index.d.ts +4 -2
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +2 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/types.d.ts +67 -8
  24. package/dist/types.d.ts.map +1 -1
  25. package/dist/utils.d.ts +38 -8
  26. package/dist/utils.d.ts.map +1 -1
  27. package/dist/utils.js +84 -26
  28. package/dist/utils.js.map +1 -1
  29. package/package.json +1 -2
  30. package/prebuilds/win32-x64/dspx.node +0 -0
  31. package/scripts/add-dispose-to-tests.js +145 -0
  32. package/src/native/DspPipeline.cc +699 -126
  33. package/src/native/DspPipeline.h +13 -0
  34. package/src/native/FilterBankDesignBindings.cc +241 -0
  35. package/src/native/IDspStage.h +24 -0
  36. package/src/native/UtilityBindings.cc +130 -0
  37. package/src/native/adapters/AmplifyStage.h +148 -0
  38. package/src/native/adapters/ClipDetectionStage.h +15 -4
  39. package/src/native/adapters/ConvolutionStage.h +101 -0
  40. package/src/native/adapters/CumulativeMovingAverageStage.h +264 -0
  41. package/src/native/adapters/DecimatorStage.h +80 -0
  42. package/src/native/adapters/DifferentiatorStage.h +13 -0
  43. package/src/native/adapters/ExponentialMovingAverageStage.h +290 -0
  44. package/src/native/adapters/FilterBankStage.cc +336 -0
  45. package/src/native/adapters/FilterBankStage.h +170 -0
  46. package/src/native/adapters/FilterStage.cc +122 -0
  47. package/src/native/adapters/FilterStage.h +4 -0
  48. package/src/native/adapters/HilbertEnvelopeStage.h +55 -0
  49. package/src/native/adapters/IntegratorStage.h +15 -0
  50. package/src/native/adapters/InterpolatorStage.h +51 -0
  51. package/src/native/adapters/LinearRegressionStage.h +40 -0
  52. package/src/native/adapters/LmsStage.h +63 -0
  53. package/src/native/adapters/MeanAbsoluteValueStage.h +76 -0
  54. package/src/native/adapters/MovingAverageStage.h +119 -0
  55. package/src/native/adapters/PeakDetectionStage.h +53 -0
  56. package/src/native/adapters/RectifyStage.h +14 -0
  57. package/src/native/adapters/ResamplerStage.h +67 -0
  58. package/src/native/adapters/RlsStage.h +76 -0
  59. package/src/native/adapters/RmsStage.h +72 -0
  60. package/src/native/adapters/SnrStage.h +45 -0
  61. package/src/native/adapters/SquareStage.h +78 -0
  62. package/src/native/adapters/SscStage.h +65 -0
  63. package/src/native/adapters/StftStage.h +62 -0
  64. package/src/native/adapters/VarianceStage.h +59 -0
  65. package/src/native/adapters/WampStage.h +59 -0
  66. package/src/native/adapters/WaveformLengthStage.h +51 -0
  67. package/src/native/adapters/ZScoreNormalizeStage.h +64 -0
  68. package/src/native/core/CumulativeMovingAverageFilter.h +123 -0
  69. package/src/native/core/ExponentialMovingAverageFilter.h +129 -0
  70. package/src/native/core/FilterBankDesign.h +266 -0
  71. package/src/native/core/Policies.h +124 -0
  72. package/src/native/utils/CircularBufferArray.cc +2 -1
  73. package/src/native/utils/SimdOps.h +67 -0
  74. package/src/native/utils/Toon.h +195 -0
package/dist/utils.js CHANGED
@@ -352,36 +352,94 @@ export function crossCorrelation(x, y, options) {
352
352
  *
353
353
  * @namespace DspUtils
354
354
  */
355
- export const DspUtils = {
355
+ export class DspUtils {
356
356
  /**
357
- * Computes the dot product of two vectors using SIMD-accelerated native code.
358
- * @see {@link dotProduct} for detailed documentation
357
+ * Converts an array of planar (separate) Float32Array channels into a single interleaved Float32Array.
358
+ * This version uses the high-performance native C++ binding.
359
+ *
360
+ * @param planar an array of Float32Arrays, where each array represents a single channel.
361
+ * @returns A single Float32Array with samples interleaved.
362
+ * @throws An error if the input is not a valid array of Float32Arrays or if channel lengths are inconsistent.
359
363
  */
360
- dotProduct,
361
- /**
362
- * Computes the sum of array elements using SIMD-accelerated native code.
363
- * @see {@link sum} for detailed documentation
364
- */
365
- sum,
366
- /**
367
- * Computes the sum of squared elements using SIMD-accelerated native code.
368
- * @see {@link sumOfSquares} for detailed documentation
369
- */
370
- sumOfSquares,
371
- /**
372
- * Removes linear trend or constant offset from signals.
373
- * @see {@link detrend} for detailed documentation
374
- */
375
- detrend,
364
+ static interleave(planar) {
365
+ if (!Array.isArray(planar)) {
366
+ throw new Error("Input must be an array of Float32Arrays.");
367
+ }
368
+ // Delegate to the native addon for high-performance interleaving
369
+ return DspAddon.interleave(planar);
370
+ }
376
371
  /**
377
- * Computes FFT-based autocorrelation for pitch and periodicity detection.
378
- * @see {@link autocorrelation} for detailed documentation
372
+ * Converts a single interleaved Float32Array into an array of planar (separate) Float32Array channels.
373
+ * This version uses the high-performance native C++ binding.
374
+ *
375
+ * @param interleaved The interleaved Float32Array.
376
+ * @param numChannels The number of channels to deinterleave.
377
+ * @returns An array of Float32Arrays, where each array is a channel.
378
+ * @throws An error if the interleaved array length is not divisible by the number of channels.
379
379
  */
380
- autocorrelation,
380
+ static deinterleave(interleaved, numChannels) {
381
+ if (!(interleaved instanceof Float32Array)) {
382
+ throw new TypeError("Input must be a Float32Array.");
383
+ }
384
+ if (typeof numChannels !== "number" || numChannels <= 0) {
385
+ throw new TypeError("Number of channels must be a positive number.");
386
+ }
387
+ // Delegate to the native addon for high-performance deinterleaving
388
+ return DspAddon.deinterleave(interleaved, numChannels);
389
+ }
381
390
  /**
382
- * Computes FFT-based cross-correlation for time delay estimation and pattern matching.
383
- * @see {@link crossCorrelation} for detailed documentation
391
+ * Extracts a single channel from an interleaved Float32Array as a new Float32Array.
392
+ * This is a zero-copy view into the original buffer if possible, but currently creates a copy.
393
+ *
394
+ * @param interleaved The interleaved Float32Array.
395
+ * @param numChannels The total number of channels in the interleaved data.
396
+ * @param channelIndex The index of the channel to extract (0-based).
397
+ * @returns A new Float32Array containing only the data for the specified channel.
398
+ * @throws An error if the channel index is out of bounds.
384
399
  */
385
- crossCorrelation,
386
- };
400
+ static getChannel(interleaved, numChannels, channelIndex) {
401
+ if (channelIndex < 0 || channelIndex >= numChannels) {
402
+ throw new Error("Channel index is out of bounds.");
403
+ }
404
+ if (interleaved.length % numChannels !== 0) {
405
+ throw new Error("Interleaved array length must be divisible by the number of channels.");
406
+ }
407
+ const numSamples = interleaved.length / numChannels;
408
+ const channelData = new Float32Array(numSamples);
409
+ for (let i = 0; i < numSamples; i++) {
410
+ channelData[i] = interleaved[i * numChannels + channelIndex];
411
+ }
412
+ return channelData;
413
+ }
414
+ }
415
+ /**
416
+ * Computes the dot product of two vectors using SIMD-accelerated native code.
417
+ * @see {@link dotProduct} for detailed documentation
418
+ */
419
+ DspUtils.dotProduct = dotProduct;
420
+ /**
421
+ * Computes the sum of array elements using SIMD-accelerated native code.
422
+ * @see {@link sum} for detailed documentation
423
+ */
424
+ DspUtils.sum = sum;
425
+ /**
426
+ * Computes the sum of squared elements using SIMD-accelerated native code.
427
+ * @see {@link sumOfSquares} for detailed documentation
428
+ */
429
+ DspUtils.sumOfSquares = sumOfSquares;
430
+ /**
431
+ * Removes linear trend or constant offset from signals.
432
+ * @see {@link detrend} for detailed documentation
433
+ */
434
+ DspUtils.detrend = detrend;
435
+ /**
436
+ * Computes FFT-based autocorrelation for pitch and periodicity detection.
437
+ * @see {@link autocorrelation} for detailed documentation
438
+ */
439
+ DspUtils.autocorrelation = autocorrelation;
440
+ /**
441
+ * Computes FFT-based cross-correlation for time delay estimation and pattern matching.
442
+ * @see {@link crossCorrelation} for detailed documentation
443
+ */
444
+ DspUtils.crossCorrelation = crossCorrelation;
387
445
  //# sourceMappingURL=utils.js.map
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/ts/utils.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAO1C,wCAAwC;AACxC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC,IAAI,QAAa,CAAC;AAClB,sCAAsC;AACtC,IAAI,CAAC;IACH,gDAAgD;IAChD,QAAQ,GAAG,YAAY,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;AACjD,CAAC;AAAC,OAAO,CAAC,EAAE,CAAC;IACX,IAAI,CAAC;QACH,oEAAoE;QACpE,QAAQ,GAAG,YAAY,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IACvD,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC;QAClB,+CAA+C;QAC/C,MAAM,IAAI,KAAK,CACb,oCAAoC,GAAG,EAAE,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE,CAClE,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,UAAU,UAAU,CAAC,CAAe,EAAE,CAAe;IACzD,IAAI,CAAC,CAAC,CAAC,YAAY,YAAY,CAAC,EAAE,CAAC;QACjC,MAAM,IAA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,GAAG,YAAY,CAAC;AAEnC;;;GAGG;AACI,gBAAO,GAAG,OAAO,CAAC;AAEzB;;;GAGG;AACI,wBAAe,GAAG,eAAe,CAAC;AAEzC;;;GAGG;AACI,yBAAgB,GAAG,gBAAgB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dspx",
3
- "version": "1.2.4",
3
+ "version": "1.3.1",
4
4
  "description": "High-performance DSP library with native C++ acceleration and Redis state persistence",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -59,7 +59,6 @@
59
59
  "@types/jest": "^30.0.0",
60
60
  "@types/node": "^24.9.1",
61
61
  "jest": "^30.2.0",
62
- "kafkajs": "^2.2.4",
63
62
  "prebuildify": "^6.0.1",
64
63
  "redis": "^5.9.0",
65
64
  "ts-jest": "^29.4.5",
Binary file
@@ -0,0 +1,145 @@
1
+ /**
2
+ * Script to add dispose() calls to all DspProcessor/Pipeline instances in test files
3
+ */
4
+
5
+ import fs from "fs";
6
+ import path from "path";
7
+ import { fileURLToPath } from "url";
8
+
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = path.dirname(__filename);
11
+
12
+ const testsDir = path.join(__dirname, "../src/ts/__tests__");
13
+
14
+ // Files that already have dispose() implemented
15
+ const filesWithDispose = [
16
+ "MovingAverage.test.ts",
17
+ "Chaining.test.ts",
18
+ "ChannelMerge.test.ts",
19
+ "WillisonAmplitude.test.ts",
20
+ "WaveformLength.test.ts",
21
+ "WaveletHilbert.test.ts",
22
+ ];
23
+
24
+ function addDisposeToFile(filePath) {
25
+ const filename = path.basename(filePath);
26
+
27
+ // Skip files that already have dispose
28
+ if (filesWithDispose.includes(filename)) {
29
+ console.log(`✓ Skipping ${filename} (already has dispose)`);
30
+ return;
31
+ }
32
+
33
+ let content = fs.readFileSync(filePath, "utf-8");
34
+ let modified = false;
35
+
36
+ // Pattern 1: Files with beforeEach creating processor variable
37
+ // Look for: let processor: DspProcessor; with beforeEach
38
+ if (
39
+ content.includes("let processor: DspProcessor") ||
40
+ content.includes("let pipeline: DspProcessor")
41
+ ) {
42
+ const processorName = content.includes("let processor:")
43
+ ? "processor"
44
+ : "pipeline";
45
+
46
+ // Check if afterEach already exists
47
+ if (!content.includes("afterEach(")) {
48
+ // Find the beforeEach block
49
+ const beforeEachMatch = content.match(
50
+ /beforeEach\(\(\) => \{[\s\S]*?\}\);/
51
+ );
52
+ if (beforeEachMatch) {
53
+ const insertPos = beforeEachMatch.index + beforeEachMatch[0].length;
54
+ const afterEachBlock = `\n\n afterEach(() => {\n ${processorName}.dispose();\n });`;
55
+ content =
56
+ content.slice(0, insertPos) +
57
+ afterEachBlock +
58
+ content.slice(insertPos);
59
+ modified = true;
60
+ console.log(`✓ Added afterEach dispose() to ${filename}`);
61
+ }
62
+ }
63
+ }
64
+
65
+ // Pattern 2: Individual test cases creating pipeline inline
66
+ // Look for: const pipeline = createDspPipeline()
67
+ if (
68
+ content.includes("const pipeline = createDspPipeline()") ||
69
+ content.includes("const processor = createDspPipeline()")
70
+ ) {
71
+ // Find all test cases
72
+ const testRegex = /(test|it)\([^{]+\{[\s\S]*?\n \}\);/g;
73
+ let match;
74
+ const replacements = [];
75
+
76
+ while ((match = testRegex.exec(content)) !== null) {
77
+ const testBody = match[0];
78
+
79
+ // Check if this test creates a pipeline
80
+ const pipelineMatches = testBody.match(
81
+ /const (pipeline|processor\d*) = createDspPipeline\(\)/g
82
+ );
83
+
84
+ if (pipelineMatches && !testBody.includes(".dispose()")) {
85
+ // Extract pipeline variable names
86
+ const varNames = pipelineMatches
87
+ .map((m) => {
88
+ const nameMatch = m.match(/const (\w+) =/);
89
+ return nameMatch ? nameMatch[1] : null;
90
+ })
91
+ .filter(Boolean);
92
+
93
+ // Find the closing brace of the test
94
+ const closingBraceMatch = testBody.match(/\n \}\);$/);
95
+ if (closingBraceMatch) {
96
+ const disposeStatements = varNames
97
+ .map((name) => ` ${name}.dispose();`)
98
+ .join("\n");
99
+ const newTestBody = testBody.replace(
100
+ /\n \}\);$/,
101
+ `\n\n${disposeStatements}\n });`
102
+ );
103
+ replacements.push({ old: testBody, new: newTestBody });
104
+ }
105
+ }
106
+ }
107
+
108
+ // Apply replacements
109
+ for (const { old, new: newText } of replacements) {
110
+ content = content.replace(old, newText);
111
+ modified = true;
112
+ }
113
+
114
+ if (replacements.length > 0) {
115
+ console.log(
116
+ `✓ Added inline dispose() calls to ${replacements.length} tests in ${filename}`
117
+ );
118
+ }
119
+ }
120
+
121
+ if (modified) {
122
+ fs.writeFileSync(filePath, content);
123
+ console.log(`✓ Modified ${filename}`);
124
+ } else {
125
+ console.log(` No changes needed for ${filename}`);
126
+ }
127
+ }
128
+
129
+ // Process all test files
130
+ const testFiles = fs
131
+ .readdirSync(testsDir)
132
+ .filter((f) => f.endsWith(".test.ts"))
133
+ .map((f) => path.join(testsDir, f));
134
+
135
+ console.log(`Processing ${testFiles.length} test files...\n`);
136
+
137
+ for (const file of testFiles) {
138
+ try {
139
+ addDisposeToFile(file);
140
+ } catch (error) {
141
+ console.error(`✗ Error processing ${path.basename(file)}:`, error.message);
142
+ }
143
+ }
144
+
145
+ console.log("\n✅ Done!");