@libreaudio/la-call 0.0.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.
@@ -0,0 +1,4 @@
1
+ // Copyright 2026 Filipe Coelho <falktx@falktx.com>
2
+ // SPDX-License-Identifier: GPL-3.0-or-later
3
+
4
+ export declare const createWasmProcessor: (audioContext: AudioContext) => Promise<AudioNode>;
package/dist/index.js ADDED
@@ -0,0 +1,138 @@
1
+ // Copyright 2026 Filipe Coelho <falktx@falktx.com>
2
+ // SPDX-License-Identifier: GPL-3.0-or-later
3
+
4
+ // These imports get resolved by Vite/webpack as asset URLs at build time
5
+ export { default as mapiWasm } from './BBBA-mapi.wasm';
6
+ // export { default as mapiNosimdWasm } from './BBBA-nosimd-mapi.wasm';
7
+ export { default as mapiJs } from './BBBA-mapi.js';
8
+ // export { default as mapiNosimdJs } from './BBBA-nosimd-mapi.js';
9
+ export { default as mapiProcJs } from './mapi-proc.js';
10
+
11
+ // create audio worklet or script processor
12
+ // we rely on script processor because worklets must run at 128 block size, which is not possible on low-spec machines
13
+ const createWasmProcessor = (audioContext) => {
14
+ return new Promise((resolve, reject) => {
15
+ if (typeof(WebAssembly) === 'undefined') {
16
+ reject('WebAssembly unsupported');
17
+ return;
18
+ }
19
+ if (! WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,2,8,1,1,97,1,98,3,127,1,6,6,1,127,1,65,0,11,7,5,1,1,97,3,1]))) {
20
+ reject('Importable/Exportable mutable globals unsupported');
21
+ return;
22
+ }
23
+
24
+ if (! navigator.userAgent.match(/Android/i)) {
25
+ console.log("Using Audio Worklet");
26
+
27
+ const processorBlob = new Blob([mapiProcJs], { type: 'text/javascript' });
28
+ const processorURL = URL.createObjectURL(processorBlob);
29
+
30
+ audioContext.audioWorklet.addModule(processorURL)
31
+ .then(() => {
32
+ const options = {
33
+ channelCount: 1,
34
+ numberOfInputs: 1,
35
+ numberOfOutputs: 1,
36
+ outputChannelCount: [1],
37
+ };
38
+ const processor = new AudioWorkletNode(audioContext, 'mapi-proc', options);
39
+ processor.port.onmessage = event => {
40
+ if (event.data.type == 'loaded') {
41
+ processor.port.postMessage({ type: 'param', symbol: "intensity", value: 100 });
42
+ processor.port.postMessage({ type: 'param', symbol: "leveler_target", value: -18 });
43
+ processor.port.postMessage({ type: 'param', symbol: "sb_strength", value: 60 });
44
+ processor.port.postMessage({ type: 'param', symbol: "mb_strength", value: 60 });
45
+ processor.port.postMessage({ type: 'param', symbol: "pre_gain", value: 2 });
46
+ processor.port.postMessage({ type: 'param', symbol: "post_gain", value: 0 });
47
+ resolve(processor);
48
+ }
49
+ else if (event.data.type == 'error') {
50
+ reject(event.data.error);
51
+ }
52
+ };
53
+ processor.port.postMessage({ type: 'init', wasm: mapiWasm, js: mapiJs });
54
+ })
55
+ .catch(reject);
56
+ return;
57
+ }
58
+
59
+ // NOTE fallback with createScriptProcessor follows here
60
+ console.log("Using Script Processor");
61
+
62
+ // execute JS to expose the emscripten load module function
63
+ const jsfn_bbba = new Function(mapiJs + 'return mapi_bbba;');
64
+ const create_module_bbba = jsfn_bbba.call();
65
+
66
+ const bufferSize = 4096;
67
+ const numberOfInputs = 1;
68
+ const numberOfOutputs = 1;
69
+ const processor = audioContext.createScriptProcessor(bufferSize, numberOfInputs, numberOfOutputs);
70
+
71
+ // create the wasm module and instance
72
+ create_module_bbba({
73
+ instantiateWasm: (imports, successCallback) => {
74
+ WebAssembly.instantiate(mapiWasm, imports)
75
+ .then(output => {
76
+ successCallback(output.instance, output.module);
77
+ })
78
+ .catch(reject);
79
+ return {};
80
+ },
81
+ postRun: function(module) {
82
+ const handle = module._mapi_create(audioContext.sampleRate, bufferSize);
83
+
84
+ const audioData = module._malloc(module.HEAPF32.BYTES_PER_ELEMENT * bufferSize);
85
+ const audioPtrs = module._malloc(module.HEAPU32.BYTES_PER_ELEMENT);
86
+ module.HEAPU32[audioPtrs + (0 << 2) >> 2] = audioData;
87
+
88
+ const maxSymbolLength = 255;
89
+ const csymbolData = module._malloc(maxSymbolLength);
90
+ const csymbol = (symbol) => {
91
+ const len = Math.min(maxSymbolLength, module.lengthBytesUTF8(symbol) + 1);
92
+ module.stringToUTF8(symbol, csymbolData, len);
93
+ return csymbolData;
94
+ }
95
+
96
+ let enabled = true;
97
+ processor.onaudioprocess = function (e) {
98
+ if (! enabled) {
99
+ e.outputBuffer.copyToChannel(e.inputBuffer.getChannelData(0), 0);
100
+ return;
101
+ }
102
+
103
+ let buffer = e.inputBuffer.getChannelData(0);
104
+
105
+ for (let i = 0; i < bufferSize; ++i)
106
+ module.HEAPF32[audioData + (i << 2) >> 2] = buffer[i];
107
+
108
+ module._mapi_process(handle, audioPtrs, audioPtrs, bufferSize);
109
+
110
+ buffer = e.outputBuffer.getChannelData(0);
111
+ for (let i = 0; i < bufferSize; ++i)
112
+ buffer[i] = module.HEAPF32[audioData + (i << 2) >> 2];
113
+ };
114
+
115
+ // use same API as worklet for pushing changes
116
+ processor.port = {
117
+ postMessage: (data) => {
118
+ switch (data.type)
119
+ {
120
+ case 'enable':
121
+ enabled = !!data.enable;
122
+ break;
123
+ case 'param':
124
+ module._mapi_set_parameter(handle, csymbol(data.symbol), data.value);
125
+ break;
126
+ case 'destroy':
127
+ break;
128
+ }
129
+ },
130
+ };
131
+
132
+ resolve(processor);
133
+ },
134
+ });
135
+ });
136
+ };
137
+
138
+ export default createWasmProcessor;
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@libreaudio/la-call",
3
+ "version": "0.0.1",
4
+ "description": "Voice isolation and optimization AudioWorklet/WASM module for web conferencing",
5
+ "license": "GPL-3.0+",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist/",
10
+ "package.json",
11
+ "../LICENSE"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/trummerschlunk/BigBlueBetterAudio"
16
+ }
17
+ }