geedback_dsp.js (7260B)
1 /* @ts-self-types="./geedback_dsp.d.ts" */ 2 3 export class GeedbackProcessor { 4 __destroy_into_raw() { 5 const ptr = this.__wbg_ptr; 6 this.__wbg_ptr = 0; 7 GeedbackProcessorFinalization.unregister(this); 8 return ptr; 9 } 10 free() { 11 const ptr = this.__destroy_into_raw(); 12 wasm.__wbg_geedbackprocessor_free(ptr, 0); 13 } 14 /** 15 * @returns {number} 16 */ 17 get_latest_output() { 18 const ret = wasm.geedbackprocessor_get_latest_output(this.__wbg_ptr); 19 return ret; 20 } 21 constructor() { 22 const ret = wasm.geedbackprocessor_new(); 23 this.__wbg_ptr = ret; 24 GeedbackProcessorFinalization.register(this, this.__wbg_ptr, this); 25 return this; 26 } 27 /** 28 * @returns {number} 29 */ 30 process() { 31 const ret = wasm.geedbackprocessor_process(this.__wbg_ptr); 32 return ret; 33 } 34 /** 35 * @param {number} x 36 * @param {number} y 37 * @param {number} z 38 */ 39 set_linear_accel(x, y, z) { 40 wasm.geedbackprocessor_set_linear_accel(this.__wbg_ptr, x, y, z); 41 } 42 /** 43 * @param {number} a 44 * @param {number} b 45 * @param {number} g 46 */ 47 set_orient(a, b, g) { 48 wasm.geedbackprocessor_set_orient(this.__wbg_ptr, a, b, g); 49 } 50 /** 51 * @param {number} sample_rate 52 */ 53 set_sample_rate(sample_rate) { 54 wasm.geedbackprocessor_set_sample_rate(this.__wbg_ptr, sample_rate); 55 } 56 /** 57 * @param {number} x 58 * @param {number} y 59 */ 60 set_touch(x, y) { 61 wasm.geedbackprocessor_set_touch(this.__wbg_ptr, x, y); 62 } 63 /** 64 * @param {number} index 65 * @param {Waveform} wave 66 */ 67 set_waveform(index, wave) { 68 wasm.geedbackprocessor_set_waveform(this.__wbg_ptr, index, wave); 69 } 70 } 71 if (Symbol.dispose) GeedbackProcessor.prototype[Symbol.dispose] = GeedbackProcessor.prototype.free; 72 73 /** 74 * @enum {0 | 1 | 2 | 3 | 4 | 5 | 6 | 7} 75 */ 76 export const Waveform = Object.freeze({ 77 Sine: 0, "0": "Sine", 78 Triangle: 1, "1": "Triangle", 79 TriangleSawtooth: 2, "2": "TriangleSawtooth", 80 Sawtooth: 3, "3": "Sawtooth", 81 ReverseSawtooth: 4, "4": "ReverseSawtooth", 82 Square: 5, "5": "Square", 83 WidePulse: 6, "6": "WidePulse", 84 NarrowPulse: 7, "7": "NarrowPulse", 85 }); 86 function __wbg_get_imports() { 87 const import0 = { 88 __proto__: null, 89 __wbg___wbindgen_throw_9c75d47bf9e7731e: function(arg0, arg1) { 90 throw new Error(getStringFromWasm0(arg0, arg1)); 91 }, 92 __wbindgen_init_externref_table: function() { 93 const table = wasm.__wbindgen_externrefs; 94 const offset = table.grow(4); 95 table.set(0, undefined); 96 table.set(offset + 0, undefined); 97 table.set(offset + 1, null); 98 table.set(offset + 2, true); 99 table.set(offset + 3, false); 100 }, 101 }; 102 return { 103 __proto__: null, 104 "./geedback_dsp_bg.js": import0, 105 }; 106 } 107 108 const GeedbackProcessorFinalization = (typeof FinalizationRegistry === 'undefined') 109 ? { register: () => {}, unregister: () => {} } 110 : new FinalizationRegistry(ptr => wasm.__wbg_geedbackprocessor_free(ptr, 1)); 111 112 function getStringFromWasm0(ptr, len) { 113 return decodeText(ptr >>> 0, len); 114 } 115 116 let cachedUint8ArrayMemory0 = null; 117 function getUint8ArrayMemory0() { 118 if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { 119 cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); 120 } 121 return cachedUint8ArrayMemory0; 122 } 123 124 let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); 125 cachedTextDecoder.decode(); 126 const MAX_SAFARI_DECODE_BYTES = 2146435072; 127 let numBytesDecoded = 0; 128 function decodeText(ptr, len) { 129 numBytesDecoded += len; 130 if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) { 131 cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); 132 cachedTextDecoder.decode(); 133 numBytesDecoded = len; 134 } 135 return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); 136 } 137 138 let wasmModule, wasmInstance, wasm; 139 function __wbg_finalize_init(instance, module) { 140 wasmInstance = instance; 141 wasm = instance.exports; 142 wasmModule = module; 143 cachedUint8ArrayMemory0 = null; 144 wasm.__wbindgen_start(); 145 return wasm; 146 } 147 148 async function __wbg_load(module, imports) { 149 if (typeof Response === 'function' && module instanceof Response) { 150 if (typeof WebAssembly.instantiateStreaming === 'function') { 151 try { 152 return await WebAssembly.instantiateStreaming(module, imports); 153 } catch (e) { 154 const validResponse = module.ok && expectedResponseType(module.type); 155 156 if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') { 157 console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e); 158 159 } else { throw e; } 160 } 161 } 162 163 const bytes = await module.arrayBuffer(); 164 return await WebAssembly.instantiate(bytes, imports); 165 } else { 166 const instance = await WebAssembly.instantiate(module, imports); 167 168 if (instance instanceof WebAssembly.Instance) { 169 return { instance, module }; 170 } else { 171 return instance; 172 } 173 } 174 175 function expectedResponseType(type) { 176 switch (type) { 177 case 'basic': case 'cors': case 'default': return true; 178 } 179 return false; 180 } 181 } 182 183 function initSync(module) { 184 if (wasm !== undefined) return wasm; 185 186 187 if (module !== undefined) { 188 if (Object.getPrototypeOf(module) === Object.prototype) { 189 ({module} = module) 190 } else { 191 console.warn('using deprecated parameters for `initSync()`; pass a single object instead') 192 } 193 } 194 195 const imports = __wbg_get_imports(); 196 if (!(module instanceof WebAssembly.Module)) { 197 module = new WebAssembly.Module(module); 198 } 199 const instance = new WebAssembly.Instance(module, imports); 200 return __wbg_finalize_init(instance, module); 201 } 202 203 async function __wbg_init(module_or_path) { 204 if (wasm !== undefined) return wasm; 205 206 207 if (module_or_path !== undefined) { 208 if (Object.getPrototypeOf(module_or_path) === Object.prototype) { 209 ({module_or_path} = module_or_path) 210 } else { 211 console.warn('using deprecated parameters for the initialization function; pass a single object instead') 212 } 213 } 214 215 if (module_or_path === undefined) { 216 module_or_path = new URL('geedback_dsp_bg.wasm', import.meta.url); 217 } 218 const imports = __wbg_get_imports(); 219 220 if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) { 221 module_or_path = fetch(module_or_path); 222 } 223 224 const { instance, module } = await __wbg_load(await module_or_path, imports); 225 226 return __wbg_finalize_init(instance, module); 227 } 228 229 export { initSync, __wbg_init as default };