@k13engineering/rubberband 0.0.4 → 0.0.6

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/dist/lib/index.js CHANGED
@@ -55,6 +55,10 @@ const createRubberbandWrapper = ({
55
55
  throw new Error("plane length exceeds max buffer size");
56
56
  }
57
57
 
58
+ if (plane.length !== sampleCount) {
59
+ throw new Error("all planes must have the same length");
60
+ }
61
+
58
62
  const channelDataPtr = channelDataPtrs[channelIndex];
59
63
  rubberbandApi.memWrite(channelDataPtr, plane);
60
64
  });
@@ -94,7 +98,12 @@ const createRubberbandWrapper = ({
94
98
  let planes/*: Float32Array[]*/ = [];
95
99
 
96
100
  channelDataPtrs.forEach((channelDataPtr) => {
97
- const plane = rubberbandApi.memReadF32(channelDataPtr, samplesReceived);
101
+ // memReadF32 returns a view of the WASM memory, so we need to copy it out
102
+ const stolenPlane = rubberbandApi.memReadF32(channelDataPtr, samplesReceived);
103
+
104
+ const plane = new Float32Array(samplesReceived);
105
+ plane.set(stolenPlane);
106
+
98
107
  planes = [...planes, plane];
99
108
  });
100
109
 
@@ -1,14 +1,25 @@
1
- /* c8 ignore start */
2
- import { loadAsBlob } from "esm-resource";
1
+ const isNode = typeof globalThis.process !== "undefined" &&
2
+ globalThis.process.versions !== null &&
3
+ globalThis.process.versions.node !== null;
4
+
5
+ const loadRubberbandWasmNodeJs = async () => {
6
+ const nodeFs = await import("fs");
7
+ const nodeUrl = await import("url");
8
+ const rubberbandWasmUrl = import.meta.resolve("rubberband-wasm/dist/rubberband.wasm");
9
+ const rubberbandWasmPath = nodeUrl.fileURLToPath(rubberbandWasmUrl);
10
+ const rubberbandWasm = await nodeFs.promises.readFile(rubberbandWasmPath);
11
+ return new Uint8Array(rubberbandWasm);
12
+ };
3
13
 
4
14
  const loadRubberbandWasm = async () => {
5
- const rubberbandBlob = await loadAsBlob({ importMeta: import.meta, filepath: "../../node_modules/rubberband-wasm/dist/rubberband.wasm" });
6
- const rubberbandWasmArrayBuffer = await rubberbandBlob.arrayBuffer();
7
- const rubberbandWasm = new Uint8Array(rubberbandWasmArrayBuffer);
8
- return rubberbandWasm;
15
+
16
+ if (isNode) {
17
+ return await loadRubberbandWasmNodeJs();
18
+ }
19
+
20
+ throw Error("browser environment not implemented yet");
9
21
  };
10
22
 
11
23
  export {
12
24
  loadRubberbandWasm
13
25
  };
14
- /* c8 ignore end */
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.4",
2
+ "version": "0.0.6",
3
3
  "name": "@k13engineering/rubberband",
4
4
  "type": "module",
5
5
  "description": "Rubberband wrapper for Node.js",