@libredsp/core 0.1.7 → 0.2.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.
package/README.md CHANGED
@@ -1,20 +1,7 @@
1
- # LibreDSP
1
+ # LibreDSP Library
2
2
 
3
- This package contains the WebAssembly (WASM) build of **libredsp** for use in JavaScript and TypeScript projects.
4
-
5
- > **Note:** This repository/package only contains the compiled WASM artifacts generated by `wasm-pack`. The Rust source code, documentation, examples, and issue tracker are maintained in the main GitHub repository.
6
-
7
- ## Source Code
8
-
9
- The complete source code is available at:
10
-
11
- **https://github.com/libredsp/libredsp**
12
-
13
- ## Installation
14
-
15
- ```bash
16
- npm install @libredsp/core
17
- ```
3
+ This is the WASM output of LibreDSP project written in Rust.
4
+ To view the source code of LibreDSP visit [github.com/libredsp/libredsp](https://www.github.com/libredsp/libredsp).
18
5
 
19
6
  ## License
20
- Apache 2.0
7
+ Apache-2.0. See the LICENSE file for more info.
package/libredsp.d.ts CHANGED
@@ -1,14 +1,26 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
 
4
+ export class DoaEstimator {
5
+ free(): void;
6
+ [Symbol.dispose](): void;
7
+ constructor(sample_rate: number, mic_distance: number, speed_of_sound: number, frame_size: number, hop_size: number, activation_threshold_dbfs: number, calibration_delay_samples: number);
8
+ push(left: Float64Array, right: Float64Array): Float64Array;
9
+ push_interleaved_i16(samples: Int16Array): Float64Array;
10
+ }
11
+
4
12
  export class TransferFunction {
5
- private constructor();
6
13
  free(): void;
7
14
  [Symbol.dispose](): void;
15
+ constructor(num: Float64Array, den: Float64Array);
8
16
  readonly den: Float64Array;
9
17
  readonly num: Float64Array;
10
18
  }
11
19
 
20
+ export function doa_estimate_delay_wasm(left: Float64Array, right: Float64Array, sample_rate: number, mic_distance: number, speed_of_sound: number, calibration_delay_samples: number): number;
21
+
22
+ export function doa_estimate_wasm(left: Float64Array, right: Float64Array, sample_rate: number, mic_distance: number, speed_of_sound: number, calibration_delay_samples: number): number;
23
+
12
24
  export function iir_filter_analog_to_digital_wasm(design_type_code: number, filter_type_code: number, w1: number, w2: number, n: number, chebyshev_coef: number): TransferFunction;
13
25
 
14
26
  export function least_squares_linear_phase_fir_wasm(f: Float64Array, a: Float64Array, weights: Float64Array, n: number): TransferFunction;
@@ -25,6 +37,12 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
25
37
 
26
38
  export interface InitOutput {
27
39
  readonly memory: WebAssembly.Memory;
40
+ readonly __wbg_doaestimator_free: (a: number, b: number) => void;
41
+ readonly doa_estimate_delay_wasm: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => number;
42
+ readonly doa_estimate_wasm: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => number;
43
+ readonly doaestimator_new: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => number;
44
+ readonly doaestimator_push: (a: number, b: number, c: number, d: number, e: number) => [number, number];
45
+ readonly doaestimator_push_interleaved_i16: (a: number, b: number, c: number) => [number, number];
28
46
  readonly iir_filter_analog_to_digital_wasm: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
29
47
  readonly least_squares_linear_phase_fir_wasm: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => number;
30
48
  readonly parks_mcclellan_wasm: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => number;
@@ -33,14 +51,15 @@ export interface InitOutput {
33
51
  readonly zero_pole_placement_iir_filter_design_wasm: (a: number, b: number, c: number, d: number) => number;
34
52
  readonly __wbg_transferfunction_free: (a: number, b: number) => void;
35
53
  readonly transferfunction_den: (a: number) => [number, number];
54
+ readonly transferfunction_new: (a: number, b: number, c: number, d: number) => number;
36
55
  readonly transferfunction_num: (a: number) => [number, number];
37
56
  readonly __wbindgen_malloc: (a: number, b: number) => number;
38
57
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
39
58
  readonly __wbindgen_exn_store: (a: number) => void;
40
59
  readonly __externref_table_alloc: () => number;
41
60
  readonly __wbindgen_externrefs: WebAssembly.Table;
42
- readonly __externref_table_dealloc: (a: number) => void;
43
61
  readonly __wbindgen_free: (a: number, b: number, c: number) => void;
62
+ readonly __externref_table_dealloc: (a: number) => void;
44
63
  readonly __wbindgen_start: () => void;
45
64
  }
46
65
 
package/libredsp.js CHANGED
@@ -1,5 +1,61 @@
1
1
  /* @ts-self-types="./libredsp.d.ts" */
2
2
 
3
+ export class DoaEstimator {
4
+ __destroy_into_raw() {
5
+ const ptr = this.__wbg_ptr;
6
+ this.__wbg_ptr = 0;
7
+ DoaEstimatorFinalization.unregister(this);
8
+ return ptr;
9
+ }
10
+ free() {
11
+ const ptr = this.__destroy_into_raw();
12
+ wasm.__wbg_doaestimator_free(ptr, 0);
13
+ }
14
+ /**
15
+ * @param {number} sample_rate
16
+ * @param {number} mic_distance
17
+ * @param {number} speed_of_sound
18
+ * @param {number} frame_size
19
+ * @param {number} hop_size
20
+ * @param {number} activation_threshold_dbfs
21
+ * @param {number} calibration_delay_samples
22
+ */
23
+ constructor(sample_rate, mic_distance, speed_of_sound, frame_size, hop_size, activation_threshold_dbfs, calibration_delay_samples) {
24
+ const ret = wasm.doaestimator_new(sample_rate, mic_distance, speed_of_sound, frame_size, hop_size, activation_threshold_dbfs, calibration_delay_samples);
25
+ this.__wbg_ptr = ret;
26
+ DoaEstimatorFinalization.register(this, this.__wbg_ptr, this);
27
+ return this;
28
+ }
29
+ /**
30
+ * @param {Float64Array} left
31
+ * @param {Float64Array} right
32
+ * @returns {Float64Array}
33
+ */
34
+ push(left, right) {
35
+ const ptr0 = passArrayF64ToWasm0(left, wasm.__wbindgen_malloc);
36
+ const len0 = WASM_VECTOR_LEN;
37
+ const ptr1 = passArrayF64ToWasm0(right, wasm.__wbindgen_malloc);
38
+ const len1 = WASM_VECTOR_LEN;
39
+ const ret = wasm.doaestimator_push(this.__wbg_ptr, ptr0, len0, ptr1, len1);
40
+ var v3 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
41
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
42
+ return v3;
43
+ }
44
+ /**
45
+ * @param {Int16Array} samples
46
+ * @returns {Float64Array}
47
+ */
48
+ push_interleaved_i16(samples) {
49
+ const ptr0 = passArray16ToWasm0(samples, wasm.__wbindgen_malloc);
50
+ const len0 = WASM_VECTOR_LEN;
51
+ const ret = wasm.doaestimator_push_interleaved_i16(this.__wbg_ptr, ptr0, len0);
52
+ var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
53
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
54
+ return v2;
55
+ }
56
+ }
57
+ if (Symbol.dispose) DoaEstimator.prototype[Symbol.dispose] = DoaEstimator.prototype.free;
58
+
3
59
  export class TransferFunction {
4
60
  static __wrap(ptr) {
5
61
  const obj = Object.create(TransferFunction.prototype);
@@ -26,6 +82,20 @@ export class TransferFunction {
26
82
  wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
27
83
  return v1;
28
84
  }
85
+ /**
86
+ * @param {Float64Array} num
87
+ * @param {Float64Array} den
88
+ */
89
+ constructor(num, den) {
90
+ const ptr0 = passArrayF64ToWasm0(num, wasm.__wbindgen_malloc);
91
+ const len0 = WASM_VECTOR_LEN;
92
+ const ptr1 = passArrayF64ToWasm0(den, wasm.__wbindgen_malloc);
93
+ const len1 = WASM_VECTOR_LEN;
94
+ const ret = wasm.transferfunction_new(ptr0, len0, ptr1, len1);
95
+ this.__wbg_ptr = ret;
96
+ TransferFunctionFinalization.register(this, this.__wbg_ptr, this);
97
+ return this;
98
+ }
29
99
  /**
30
100
  * @returns {Float64Array}
31
101
  */
@@ -38,6 +108,42 @@ export class TransferFunction {
38
108
  }
39
109
  if (Symbol.dispose) TransferFunction.prototype[Symbol.dispose] = TransferFunction.prototype.free;
40
110
 
111
+ /**
112
+ * @param {Float64Array} left
113
+ * @param {Float64Array} right
114
+ * @param {number} sample_rate
115
+ * @param {number} mic_distance
116
+ * @param {number} speed_of_sound
117
+ * @param {number} calibration_delay_samples
118
+ * @returns {number}
119
+ */
120
+ export function doa_estimate_delay_wasm(left, right, sample_rate, mic_distance, speed_of_sound, calibration_delay_samples) {
121
+ const ptr0 = passArrayF64ToWasm0(left, wasm.__wbindgen_malloc);
122
+ const len0 = WASM_VECTOR_LEN;
123
+ const ptr1 = passArrayF64ToWasm0(right, wasm.__wbindgen_malloc);
124
+ const len1 = WASM_VECTOR_LEN;
125
+ const ret = wasm.doa_estimate_delay_wasm(ptr0, len0, ptr1, len1, sample_rate, mic_distance, speed_of_sound, calibration_delay_samples);
126
+ return ret;
127
+ }
128
+
129
+ /**
130
+ * @param {Float64Array} left
131
+ * @param {Float64Array} right
132
+ * @param {number} sample_rate
133
+ * @param {number} mic_distance
134
+ * @param {number} speed_of_sound
135
+ * @param {number} calibration_delay_samples
136
+ * @returns {number}
137
+ */
138
+ export function doa_estimate_wasm(left, right, sample_rate, mic_distance, speed_of_sound, calibration_delay_samples) {
139
+ const ptr0 = passArrayF64ToWasm0(left, wasm.__wbindgen_malloc);
140
+ const len0 = WASM_VECTOR_LEN;
141
+ const ptr1 = passArrayF64ToWasm0(right, wasm.__wbindgen_malloc);
142
+ const len1 = WASM_VECTOR_LEN;
143
+ const ret = wasm.doa_estimate_wasm(ptr0, len0, ptr1, len1, sample_rate, mic_distance, speed_of_sound, calibration_delay_samples);
144
+ return ret;
145
+ }
146
+
41
147
  /**
42
148
  * @param {number} design_type_code
43
149
  * @param {number} filter_type_code
@@ -201,6 +307,9 @@ function __wbg_get_imports() {
201
307
  };
202
308
  }
203
309
 
310
+ const DoaEstimatorFinalization = (typeof FinalizationRegistry === 'undefined')
311
+ ? { register: () => {}, unregister: () => {} }
312
+ : new FinalizationRegistry(ptr => wasm.__wbg_doaestimator_free(ptr, 1));
204
313
  const TransferFunctionFinalization = (typeof FinalizationRegistry === 'undefined')
205
314
  ? { register: () => {}, unregister: () => {} }
206
315
  : new FinalizationRegistry(ptr => wasm.__wbg_transferfunction_free(ptr, 1));
@@ -241,6 +350,14 @@ function getStringFromWasm0(ptr, len) {
241
350
  return decodeText(ptr >>> 0, len);
242
351
  }
243
352
 
353
+ let cachedUint16ArrayMemory0 = null;
354
+ function getUint16ArrayMemory0() {
355
+ if (cachedUint16ArrayMemory0 === null || cachedUint16ArrayMemory0.byteLength === 0) {
356
+ cachedUint16ArrayMemory0 = new Uint16Array(wasm.memory.buffer);
357
+ }
358
+ return cachedUint16ArrayMemory0;
359
+ }
360
+
244
361
  let cachedUint8ArrayMemory0 = null;
245
362
  function getUint8ArrayMemory0() {
246
363
  if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
@@ -258,6 +375,13 @@ function handleError(f, args) {
258
375
  }
259
376
  }
260
377
 
378
+ function passArray16ToWasm0(arg, malloc) {
379
+ const ptr = malloc(arg.length * 2, 2) >>> 0;
380
+ getUint16ArrayMemory0().set(arg, ptr / 2);
381
+ WASM_VECTOR_LEN = arg.length;
382
+ return ptr;
383
+ }
384
+
261
385
  function passArrayF64ToWasm0(arg, malloc) {
262
386
  const ptr = malloc(arg.length * 8, 8) >>> 0;
263
387
  getFloat64ArrayMemory0().set(arg, ptr / 8);
@@ -344,6 +468,7 @@ function __wbg_finalize_init(instance, module) {
344
468
  wasmModule = module;
345
469
  cachedDataViewMemory0 = null;
346
470
  cachedFloat64ArrayMemory0 = null;
471
+ cachedUint16ArrayMemory0 = null;
347
472
  cachedUint8ArrayMemory0 = null;
348
473
  wasm.__wbindgen_start();
349
474
  return wasm;
package/libredsp_bg.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -2,11 +2,11 @@
2
2
  "name": "@libredsp/core",
3
3
  "type": "module",
4
4
  "description": "DSP library in Rust",
5
- "version": "0.1.7",
5
+ "version": "0.2.0",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/libredsp/libredsp"
9
+ "url": "https://github.com/libredsp/libredsp-rs"
10
10
  },
11
11
  "files": [
12
12
  "libredsp_bg.wasm",