wurble-rs 0.4.0 → 0.5.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
@@ -62,6 +62,8 @@ Got your own noises? Hand them over as mono `f32` clips at the voice's `sample_r
62
62
  let mine = Voice::new(vec![my_grunt]);
63
63
  ```
64
64
 
65
+ From JavaScript, upload the whole bank at once with `voice.set_clips(flat, lengths)` (a `Float32Array` plus a `Uint32Array`), and read it back with `clips_flat()` / `clip_lengths()`.
66
+
65
67
  `wave` grows one cycle of sound from the loudness of each harmonic.
66
68
 
67
69
  ```rust
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wurble-rs",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Dialogue voice synthesis for games, from procedural blips or your own sample banks",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "type": "module",
package/wurble.d.ts CHANGED
@@ -8,9 +8,12 @@ export class Voice {
8
8
  static babble(): Voice;
9
9
  static blip(): Voice;
10
10
  static chitter(): Voice;
11
+ clip_lengths(): Uint32Array;
12
+ clips_flat(): Float32Array;
11
13
  cues(text: string): Float32Array;
12
14
  constructor();
13
15
  static grumble(): Voice;
16
+ set_clips(samples: Float32Array, lengths: Uint32Array): void;
14
17
  speak(text: string): Float32Array;
15
18
  wav(text: string): Uint8Array;
16
19
  hiss: number;
@@ -54,15 +57,18 @@ export interface InitOutput {
54
57
  readonly voice_babble: () => number;
55
58
  readonly voice_blip: () => number;
56
59
  readonly voice_chitter: () => number;
60
+ readonly voice_clip_lengths: (a: number) => [number, number];
61
+ readonly voice_clips_flat: (a: number) => [number, number];
57
62
  readonly voice_cues: (a: number, b: number, c: number) => [number, number];
58
63
  readonly voice_empty: () => number;
59
64
  readonly voice_grumble: () => number;
65
+ readonly voice_set_clips: (a: number, b: number, c: number, d: number, e: number) => void;
60
66
  readonly voice_speak: (a: number, b: number, c: number) => [number, number];
61
67
  readonly voice_wav: (a: number, b: number, c: number) => [number, number];
62
68
  readonly __wbindgen_externrefs: WebAssembly.Table;
63
69
  readonly __wbindgen_malloc: (a: number, b: number) => number;
64
- readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
65
70
  readonly __wbindgen_free: (a: number, b: number, c: number) => void;
71
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
66
72
  readonly __wbindgen_start: () => void;
67
73
  }
68
74
 
package/wurble.js CHANGED
@@ -176,6 +176,24 @@ export class Voice {
176
176
  const ret = wasm.voice_chitter();
177
177
  return Voice.__wrap(ret);
178
178
  }
179
+ /**
180
+ * @returns {Uint32Array}
181
+ */
182
+ clip_lengths() {
183
+ const ret = wasm.voice_clip_lengths(this.__wbg_ptr);
184
+ var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
185
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
186
+ return v1;
187
+ }
188
+ /**
189
+ * @returns {Float32Array}
190
+ */
191
+ clips_flat() {
192
+ const ret = wasm.voice_clips_flat(this.__wbg_ptr);
193
+ var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
194
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
195
+ return v1;
196
+ }
179
197
  /**
180
198
  * @param {string} text
181
199
  * @returns {Float32Array}
@@ -201,6 +219,17 @@ export class Voice {
201
219
  const ret = wasm.voice_grumble();
202
220
  return Voice.__wrap(ret);
203
221
  }
222
+ /**
223
+ * @param {Float32Array} samples
224
+ * @param {Uint32Array} lengths
225
+ */
226
+ set_clips(samples, lengths) {
227
+ const ptr0 = passArrayF32ToWasm0(samples, wasm.__wbindgen_malloc);
228
+ const len0 = WASM_VECTOR_LEN;
229
+ const ptr1 = passArray32ToWasm0(lengths, wasm.__wbindgen_malloc);
230
+ const len1 = WASM_VECTOR_LEN;
231
+ wasm.voice_set_clips(this.__wbg_ptr, ptr0, len0, ptr1, len1);
232
+ }
204
233
  /**
205
234
  * @param {string} text
206
235
  * @returns {Float32Array}
@@ -258,6 +287,11 @@ function getArrayF32FromWasm0(ptr, len) {
258
287
  return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
259
288
  }
260
289
 
290
+ function getArrayU32FromWasm0(ptr, len) {
291
+ ptr = ptr >>> 0;
292
+ return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
293
+ }
294
+
261
295
  function getArrayU8FromWasm0(ptr, len) {
262
296
  ptr = ptr >>> 0;
263
297
  return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
@@ -275,6 +309,14 @@ function getStringFromWasm0(ptr, len) {
275
309
  return decodeText(ptr >>> 0, len);
276
310
  }
277
311
 
312
+ let cachedUint32ArrayMemory0 = null;
313
+ function getUint32ArrayMemory0() {
314
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
315
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
316
+ }
317
+ return cachedUint32ArrayMemory0;
318
+ }
319
+
278
320
  let cachedUint8ArrayMemory0 = null;
279
321
  function getUint8ArrayMemory0() {
280
322
  if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
@@ -283,6 +325,13 @@ function getUint8ArrayMemory0() {
283
325
  return cachedUint8ArrayMemory0;
284
326
  }
285
327
 
328
+ function passArray32ToWasm0(arg, malloc) {
329
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
330
+ getUint32ArrayMemory0().set(arg, ptr / 4);
331
+ WASM_VECTOR_LEN = arg.length;
332
+ return ptr;
333
+ }
334
+
286
335
  function passArrayF32ToWasm0(arg, malloc) {
287
336
  const ptr = malloc(arg.length * 4, 4) >>> 0;
288
337
  getFloat32ArrayMemory0().set(arg, ptr / 4);
@@ -362,6 +411,7 @@ function __wbg_finalize_init(instance, module) {
362
411
  wasm = instance.exports;
363
412
  wasmModule = module;
364
413
  cachedFloat32ArrayMemory0 = null;
414
+ cachedUint32ArrayMemory0 = null;
365
415
  cachedUint8ArrayMemory0 = null;
366
416
  wasm.__wbindgen_start();
367
417
  return wasm;
package/wurble_bg.wasm CHANGED
Binary file