@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 +10 -1
- package/dist/lib/rubberband.js +18 -7
- package/package.json +1 -1
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
|
-
|
|
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
|
|
package/dist/lib/rubberband.js
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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