@libreaudio/la-call 0.0.1-g → 0.0.1-h
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/LICENSE +674 -0
- package/dist/BBBA-mapi.js +21 -0
- package/dist/BBBA-mapi.wasm +0 -0
- package/dist/BBBA-nosimd-mapi.js +21 -0
- package/dist/BBBA-nosimd-mapi.wasm +0 -0
- package/dist/mapi-proc.js +173 -0
- package/package.json +4 -8
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// Copyright 2025-2026 Filipe Coelho <falktx@falktx.com>
|
|
2
|
+
// SPDX-License-Identifier: ISC
|
|
3
|
+
|
|
4
|
+
// known constants
|
|
5
|
+
const maxSymbolLength = 255;
|
|
6
|
+
const nominalBufferSize = 128;
|
|
7
|
+
|
|
8
|
+
// function to setup wasm + emscripten module options for offline fetch
|
|
9
|
+
const createWasmOpts = (wasmBlob, postRunCallback, errorCallback) => {
|
|
10
|
+
return {
|
|
11
|
+
// override to use previously retrieved blob data, as `fetch` is not allowed in worklets
|
|
12
|
+
instantiateWasm: (imports, successCallback) => {
|
|
13
|
+
WebAssembly.instantiate(wasmBlob, imports).then(output => {
|
|
14
|
+
successCallback(output.instance, output.module);
|
|
15
|
+
}).catch(error => {
|
|
16
|
+
errorCallback(error);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
return {};
|
|
20
|
+
},
|
|
21
|
+
postRun: postRunCallback,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// class that holds a mono audio plugin instance
|
|
26
|
+
// see https://github.com/DISTRHO/MAPI for the API used here
|
|
27
|
+
class MapiProcessorInstance {
|
|
28
|
+
constructor(port, module) {
|
|
29
|
+
this.port = port;
|
|
30
|
+
this.module = module;
|
|
31
|
+
this.handle = module._mapi_create(sampleRate, nominalBufferSize);
|
|
32
|
+
this.enabled = true;
|
|
33
|
+
|
|
34
|
+
this.audioData = module._malloc(module.HEAPF32.BYTES_PER_ELEMENT * nominalBufferSize);
|
|
35
|
+
this.audioPtrs = module._malloc(module.HEAPU32.BYTES_PER_ELEMENT);
|
|
36
|
+
module.HEAPU32[this.audioPtrs + (0 << 2) >> 2] = this.audioData;
|
|
37
|
+
|
|
38
|
+
this.csymbolData = module._malloc(maxSymbolLength);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
csymbol(symbol) {
|
|
42
|
+
const len = Math.min(maxSymbolLength, this.module.lengthBytesUTF8(symbol) + 1);
|
|
43
|
+
this.module.stringToUTF8(symbol, this.csymbolData, len);
|
|
44
|
+
return this.csymbolData;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
param(symbol, value) {
|
|
48
|
+
this.module._mapi_set_parameter(this.handle, this.csymbol(symbol), value);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
process(buffer, bufferSize, bufferOffset) {
|
|
52
|
+
if (! this.enabled)
|
|
53
|
+
return;
|
|
54
|
+
|
|
55
|
+
for (let i = 0; i < bufferSize; ++i)
|
|
56
|
+
this.module.HEAPF32[this.audioData + (i << 2) >> 2] = buffer[bufferOffset + i];
|
|
57
|
+
|
|
58
|
+
this.module._mapi_process(this.handle, this.audioPtrs, this.audioPtrs, bufferSize);
|
|
59
|
+
|
|
60
|
+
for (let i = 0; i < bufferSize; ++i)
|
|
61
|
+
buffer[bufferOffset + i] = this.module.HEAPF32[this.audioData + (i << 2) >> 2];
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// worklet processor implementation
|
|
66
|
+
class MapiWorkletProcessor extends AudioWorkletProcessor {
|
|
67
|
+
constructor(options) {
|
|
68
|
+
super(options);
|
|
69
|
+
|
|
70
|
+
// validity checks
|
|
71
|
+
if (options.numberOfInputs != options.numberOfOutputs)
|
|
72
|
+
throw Error('Mis-matching IO, number of inputs must match outputs');
|
|
73
|
+
if (options.numberOfInputs != 1)
|
|
74
|
+
throw Error('Invalid IO, must be mono');
|
|
75
|
+
|
|
76
|
+
// workaround for Chromium-based browsers, return true in `process` until disconnected
|
|
77
|
+
this.disconnected = false;
|
|
78
|
+
|
|
79
|
+
// MAPI processor instance
|
|
80
|
+
this.bbba = null;
|
|
81
|
+
|
|
82
|
+
// bi-directional port communication
|
|
83
|
+
this.port.onmessage = event => {
|
|
84
|
+
switch (event.data.type)
|
|
85
|
+
{
|
|
86
|
+
case 'init':
|
|
87
|
+
this.init(event.data);
|
|
88
|
+
break;
|
|
89
|
+
case 'enable':
|
|
90
|
+
this.enable(event.data);
|
|
91
|
+
break;
|
|
92
|
+
case 'param':
|
|
93
|
+
this.param(event.data);
|
|
94
|
+
break;
|
|
95
|
+
case 'destroy':
|
|
96
|
+
this.destroy();
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
init(data) {
|
|
103
|
+
// execute JS to expose the emscripten load module function
|
|
104
|
+
const jsfn_bbba = new Function(data.js + 'return mapi_bbba;');
|
|
105
|
+
const create_module_bbba = jsfn_bbba.call();
|
|
106
|
+
|
|
107
|
+
// create wasm opts for offline loading
|
|
108
|
+
const opts = createWasmOpts(data.wasm,
|
|
109
|
+
(module) => {
|
|
110
|
+
this.bbba = new MapiProcessorInstance(this.port, module);
|
|
111
|
+
this.port.postMessage({ type: 'loaded' });
|
|
112
|
+
},
|
|
113
|
+
(error) => {
|
|
114
|
+
this.port.postMessage({ type: 'error', error: error });
|
|
115
|
+
},
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
// create the wasm module and instance
|
|
119
|
+
create_module_bbba(opts);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
enable(data) {
|
|
123
|
+
if (!this.bbba) {
|
|
124
|
+
console.error('BBBA wasm is not loaded yet!');
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
this.bbba.enabled = !!data.enable;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
param(data) {
|
|
132
|
+
if (!this.bbba) {
|
|
133
|
+
console.error('BBBA wasm is not loaded yet!');
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
this.bbba.param(data.symbol, data.value);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
destroy() {
|
|
141
|
+
this.disconnected = true;
|
|
142
|
+
this.bbba = null;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
process(inputs, outputs, parameters) {
|
|
146
|
+
if (this.disconnected)
|
|
147
|
+
return false;
|
|
148
|
+
if (!this.bbba)
|
|
149
|
+
return true;
|
|
150
|
+
|
|
151
|
+
const input = inputs[0];
|
|
152
|
+
const output = outputs[0];
|
|
153
|
+
|
|
154
|
+
// IO check, can be zero if stream is not connected yet
|
|
155
|
+
if (input.length == 0 || output.length == 0)
|
|
156
|
+
return true;
|
|
157
|
+
|
|
158
|
+
// use in-place processing
|
|
159
|
+
const buffer = output[0];
|
|
160
|
+
buffer.set(input[0]);
|
|
161
|
+
|
|
162
|
+
for (let offset = 0; offset < buffer.length; offset += nominalBufferSize)
|
|
163
|
+
this.bbba.process(buffer, Math.min(nominalBufferSize, buffer.length - offset), offset);
|
|
164
|
+
|
|
165
|
+
// reuse mono buffer if stereo
|
|
166
|
+
if (output.length == 2)
|
|
167
|
+
output[1].set(buffer);
|
|
168
|
+
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
registerProcessor("mapi-proc", MapiWorkletProcessor);
|
package/package.json
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libreaudio/la-call",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1h",
|
|
4
4
|
"description": "Voice isolation and optimization AudioWorklet/WASM module for web conferencing",
|
|
5
5
|
"license": "GPL-3.0+",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"files": [
|
|
9
|
-
"dist/
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"dist/BBBA-nosimd-mapi.wasm",
|
|
13
|
-
"dist/mapi-proc.js",
|
|
14
|
-
"dist/index.js",
|
|
15
|
-
"dist/index.d.ts"
|
|
9
|
+
"dist/",
|
|
10
|
+
"package.json",
|
|
11
|
+
"LICENSE"
|
|
16
12
|
],
|
|
17
13
|
"repository": {
|
|
18
14
|
"type": "git",
|