@k13engineering/rubberband 0.0.5 → 0.0.7
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.d.ts +1 -0
- package/dist/lib/index.js +26 -1
- package/package.json +1 -1
package/dist/lib/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ declare const createRubberbandWrapper: ({ sampleRate, channelCount, maxBufferSiz
|
|
|
16
16
|
process: ({ audioData }: {
|
|
17
17
|
audioData: TRubberbandAudioData;
|
|
18
18
|
}) => void;
|
|
19
|
+
end: () => void;
|
|
19
20
|
available: () => number;
|
|
20
21
|
latencyInSamples: () => number;
|
|
21
22
|
retrieve: ({ sampleCount }: {
|
package/dist/lib/index.js
CHANGED
|
@@ -12,6 +12,7 @@ const rubberbandApi = await RubberBandInterface.initialize(wasm);
|
|
|
12
12
|
|
|
13
13
|
const OptionProcessRealTime = 1;
|
|
14
14
|
|
|
15
|
+
// eslint-disable-next-line max-statements
|
|
15
16
|
const createRubberbandWrapper = ({
|
|
16
17
|
sampleRate,
|
|
17
18
|
channelCount,
|
|
@@ -22,6 +23,8 @@ const createRubberbandWrapper = ({
|
|
|
22
23
|
maxBufferSizeInFrames: number;
|
|
23
24
|
}*/) => {
|
|
24
25
|
|
|
26
|
+
let ended = false;
|
|
27
|
+
|
|
25
28
|
const channelArrayPtr = rubberbandApi.malloc(channelCount * 4);
|
|
26
29
|
const channelDataPtrs/*: number[]*/ = [];
|
|
27
30
|
for (let channel = 0; channel < channelCount; channel += 1) {
|
|
@@ -45,6 +48,9 @@ const createRubberbandWrapper = ({
|
|
|
45
48
|
};
|
|
46
49
|
|
|
47
50
|
const process = ({ audioData }/*: { audioData: TRubberbandAudioData }*/) => {
|
|
51
|
+
if (ended) {
|
|
52
|
+
throw Error("already ended");
|
|
53
|
+
}
|
|
48
54
|
|
|
49
55
|
const firstPlane = audioData.planes[0];
|
|
50
56
|
const sampleCount = firstPlane.length;
|
|
@@ -55,6 +61,10 @@ const createRubberbandWrapper = ({
|
|
|
55
61
|
throw new Error("plane length exceeds max buffer size");
|
|
56
62
|
}
|
|
57
63
|
|
|
64
|
+
if (plane.length !== sampleCount) {
|
|
65
|
+
throw new Error("all planes must have the same length");
|
|
66
|
+
}
|
|
67
|
+
|
|
58
68
|
const channelDataPtr = channelDataPtrs[channelIndex];
|
|
59
69
|
rubberbandApi.memWrite(channelDataPtr, plane);
|
|
60
70
|
});
|
|
@@ -62,6 +72,15 @@ const createRubberbandWrapper = ({
|
|
|
62
72
|
rubberbandApi.rubberband_process(rb, channelArrayPtr, sampleCount, 0);
|
|
63
73
|
};
|
|
64
74
|
|
|
75
|
+
const end = () => {
|
|
76
|
+
if (ended) {
|
|
77
|
+
throw Error("already ended");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
ended = true;
|
|
81
|
+
rubberbandApi.rubberband_process(rb, channelArrayPtr, 0, 1);
|
|
82
|
+
};
|
|
83
|
+
|
|
65
84
|
const available = ()/*: number*/ => {
|
|
66
85
|
return rubberbandApi.rubberband_available(rb);
|
|
67
86
|
};
|
|
@@ -94,7 +113,12 @@ const createRubberbandWrapper = ({
|
|
|
94
113
|
let planes/*: Float32Array[]*/ = [];
|
|
95
114
|
|
|
96
115
|
channelDataPtrs.forEach((channelDataPtr) => {
|
|
97
|
-
|
|
116
|
+
// memReadF32 returns a view of the WASM memory, so we need to copy it out
|
|
117
|
+
const stolenPlane = rubberbandApi.memReadF32(channelDataPtr, samplesReceived);
|
|
118
|
+
|
|
119
|
+
const plane = new Float32Array(samplesReceived);
|
|
120
|
+
plane.set(stolenPlane);
|
|
121
|
+
|
|
98
122
|
planes = [...planes, plane];
|
|
99
123
|
});
|
|
100
124
|
|
|
@@ -108,6 +132,7 @@ const createRubberbandWrapper = ({
|
|
|
108
132
|
requestTimeRatio,
|
|
109
133
|
samplesRequired,
|
|
110
134
|
process,
|
|
135
|
+
end,
|
|
111
136
|
available,
|
|
112
137
|
latencyInSamples,
|
|
113
138
|
retrieve
|
package/package.json
CHANGED