lanczos-resampler 0.1.1 → 0.2.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/lanczos_resampler.d.ts +20 -4
- package/lanczos_resampler_bg.js +66 -6
- package/lanczos_resampler_bg.wasm +0 -0
- package/package.json +2 -2
package/lanczos_resampler.d.ts
CHANGED
|
@@ -34,7 +34,8 @@ export class ChunkedInterleavedResampler {
|
|
|
34
34
|
* Resamples input signal chunk from the source to the target sample rate and appends the
|
|
35
35
|
* resulting signal to the output.
|
|
36
36
|
*
|
|
37
|
-
* Returns the number of processed input samples
|
|
37
|
+
* Returns the number of processed input samples and the number of produced output samples.
|
|
38
|
+
* The output is clamped to _[-1; 1]_.
|
|
38
39
|
*
|
|
39
40
|
* For each {@link ChunkedInterleavedResampler.inputSampleRate} input samples this method produces exactly
|
|
40
41
|
* {@link ChunkedInterleavedResampler.outputSampleRate} output samples even if it is called multiple times with a smaller
|
|
@@ -52,7 +53,7 @@ export class ChunkedInterleavedResampler {
|
|
|
52
53
|
* isn't an interpolation function, but a filter. To minimize such discrepancies chunk size should
|
|
53
54
|
* be much larger than _2⋅A + 1_.
|
|
54
55
|
*/
|
|
55
|
-
resample(chunk: Float32Array, output: Float32Array):
|
|
56
|
+
resample(chunk: Float32Array, output: Float32Array): ResampleOutcome;
|
|
56
57
|
/**
|
|
57
58
|
* Get the number of channels.
|
|
58
59
|
*/
|
|
@@ -101,7 +102,8 @@ export class ChunkedResampler {
|
|
|
101
102
|
* Resamples input signal chunk from the source to the target sample rate and appends the
|
|
102
103
|
* resulting signal to the output.
|
|
103
104
|
*
|
|
104
|
-
* Returns the number of processed input samples
|
|
105
|
+
* Returns the number of processed input samples and the number of produced output samples.
|
|
106
|
+
* The output is clamped to _[-1; 1]_.
|
|
105
107
|
*
|
|
106
108
|
* For each {@link ChunkedResampler.inputSampleRate} input samples this method produces exactly
|
|
107
109
|
* {@link ChunkedResampler.outputSampleRate} output samples even if it is called multiple times with a smaller
|
|
@@ -119,7 +121,7 @@ export class ChunkedResampler {
|
|
|
119
121
|
* isn't an interpolation function, but a filter. To minimize such discrepancies chunk size should
|
|
120
122
|
* be much larger than _2⋅A + 1_.
|
|
121
123
|
*/
|
|
122
|
-
resample(chunk: Float32Array, output: Float32Array):
|
|
124
|
+
resample(chunk: Float32Array, output: Float32Array): ResampleOutcome;
|
|
123
125
|
/**
|
|
124
126
|
* Get input sample rate in Hz.
|
|
125
127
|
*/
|
|
@@ -133,6 +135,20 @@ export class ChunkedResampler {
|
|
|
133
135
|
outputSampleRate: number;
|
|
134
136
|
}
|
|
135
137
|
|
|
138
|
+
export class ResampleOutcome {
|
|
139
|
+
private constructor();
|
|
140
|
+
free(): void;
|
|
141
|
+
[Symbol.dispose](): void;
|
|
142
|
+
/**
|
|
143
|
+
* How many samples were read from the input.
|
|
144
|
+
*/
|
|
145
|
+
numRead: number;
|
|
146
|
+
/**
|
|
147
|
+
* How many samples were wrtten to the output.
|
|
148
|
+
*/
|
|
149
|
+
numWritten: number;
|
|
150
|
+
}
|
|
151
|
+
|
|
136
152
|
export class WholeResampler {
|
|
137
153
|
free(): void;
|
|
138
154
|
[Symbol.dispose](): void;
|
package/lanczos_resampler_bg.js
CHANGED
|
@@ -91,6 +91,10 @@ const ChunkedResamplerFinalization = (typeof FinalizationRegistry === 'undefined
|
|
|
91
91
|
? { register: () => {}, unregister: () => {} }
|
|
92
92
|
: new FinalizationRegistry(ptr => wasm.__wbg_chunkedresampler_free(ptr >>> 0, 1));
|
|
93
93
|
|
|
94
|
+
const ResampleOutcomeFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
95
|
+
? { register: () => {}, unregister: () => {} }
|
|
96
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_resampleoutcome_free(ptr >>> 0, 1));
|
|
97
|
+
|
|
94
98
|
const WholeResamplerFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
95
99
|
? { register: () => {}, unregister: () => {} }
|
|
96
100
|
: new FinalizationRegistry(ptr => wasm.__wbg_wholeresampler_free(ptr >>> 0, 1));
|
|
@@ -195,7 +199,8 @@ export class ChunkedInterleavedResampler {
|
|
|
195
199
|
* Resamples input signal chunk from the source to the target sample rate and appends the
|
|
196
200
|
* resulting signal to the output.
|
|
197
201
|
*
|
|
198
|
-
* Returns the number of processed input samples
|
|
202
|
+
* Returns the number of processed input samples and the number of produced output samples.
|
|
203
|
+
* The output is clamped to _[-1; 1]_.
|
|
199
204
|
*
|
|
200
205
|
* For each {@link ChunkedInterleavedResampler.inputSampleRate} input samples this method produces exactly
|
|
201
206
|
* {@link ChunkedInterleavedResampler.outputSampleRate} output samples even if it is called multiple times with a smaller
|
|
@@ -214,13 +219,13 @@ export class ChunkedInterleavedResampler {
|
|
|
214
219
|
* be much larger than _2⋅A + 1_.
|
|
215
220
|
* @param {Float32Array} chunk
|
|
216
221
|
* @param {Float32Array} output
|
|
217
|
-
* @returns {
|
|
222
|
+
* @returns {ResampleOutcome}
|
|
218
223
|
*/
|
|
219
224
|
resample(chunk, output) {
|
|
220
225
|
const ptr0 = passArrayF32ToWasm0(chunk, wasm.__wbindgen_export);
|
|
221
226
|
const len0 = WASM_VECTOR_LEN;
|
|
222
227
|
const ret = wasm.chunkedinterleavedresampler_resample(this.__wbg_ptr, ptr0, len0, addHeapObject(output));
|
|
223
|
-
return ret
|
|
228
|
+
return ResampleOutcome.__wrap(ret);
|
|
224
229
|
}
|
|
225
230
|
}
|
|
226
231
|
if (Symbol.dispose) ChunkedInterleavedResampler.prototype[Symbol.dispose] = ChunkedInterleavedResampler.prototype.free;
|
|
@@ -315,7 +320,8 @@ export class ChunkedResampler {
|
|
|
315
320
|
* Resamples input signal chunk from the source to the target sample rate and appends the
|
|
316
321
|
* resulting signal to the output.
|
|
317
322
|
*
|
|
318
|
-
* Returns the number of processed input samples
|
|
323
|
+
* Returns the number of processed input samples and the number of produced output samples.
|
|
324
|
+
* The output is clamped to _[-1; 1]_.
|
|
319
325
|
*
|
|
320
326
|
* For each {@link ChunkedResampler.inputSampleRate} input samples this method produces exactly
|
|
321
327
|
* {@link ChunkedResampler.outputSampleRate} output samples even if it is called multiple times with a smaller
|
|
@@ -334,17 +340,71 @@ export class ChunkedResampler {
|
|
|
334
340
|
* be much larger than _2⋅A + 1_.
|
|
335
341
|
* @param {Float32Array} chunk
|
|
336
342
|
* @param {Float32Array} output
|
|
337
|
-
* @returns {
|
|
343
|
+
* @returns {ResampleOutcome}
|
|
338
344
|
*/
|
|
339
345
|
resample(chunk, output) {
|
|
340
346
|
const ptr0 = passArrayF32ToWasm0(chunk, wasm.__wbindgen_export);
|
|
341
347
|
const len0 = WASM_VECTOR_LEN;
|
|
342
348
|
const ret = wasm.chunkedresampler_resample(this.__wbg_ptr, ptr0, len0, addHeapObject(output));
|
|
343
|
-
return ret
|
|
349
|
+
return ResampleOutcome.__wrap(ret);
|
|
344
350
|
}
|
|
345
351
|
}
|
|
346
352
|
if (Symbol.dispose) ChunkedResampler.prototype[Symbol.dispose] = ChunkedResampler.prototype.free;
|
|
347
353
|
|
|
354
|
+
/**
|
|
355
|
+
* Resampling outcome.
|
|
356
|
+
*/
|
|
357
|
+
export class ResampleOutcome {
|
|
358
|
+
static __wrap(ptr) {
|
|
359
|
+
ptr = ptr >>> 0;
|
|
360
|
+
const obj = Object.create(ResampleOutcome.prototype);
|
|
361
|
+
obj.__wbg_ptr = ptr;
|
|
362
|
+
ResampleOutcomeFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
363
|
+
return obj;
|
|
364
|
+
}
|
|
365
|
+
__destroy_into_raw() {
|
|
366
|
+
const ptr = this.__wbg_ptr;
|
|
367
|
+
this.__wbg_ptr = 0;
|
|
368
|
+
ResampleOutcomeFinalization.unregister(this);
|
|
369
|
+
return ptr;
|
|
370
|
+
}
|
|
371
|
+
free() {
|
|
372
|
+
const ptr = this.__destroy_into_raw();
|
|
373
|
+
wasm.__wbg_resampleoutcome_free(ptr, 0);
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* How many samples were read from the input.
|
|
377
|
+
* @returns {number}
|
|
378
|
+
*/
|
|
379
|
+
get numRead() {
|
|
380
|
+
const ret = wasm.__wbg_get_resampleoutcome_numRead(this.__wbg_ptr);
|
|
381
|
+
return ret >>> 0;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* How many samples were read from the input.
|
|
385
|
+
* @param {number} arg0
|
|
386
|
+
*/
|
|
387
|
+
set numRead(arg0) {
|
|
388
|
+
wasm.__wbg_set_resampleoutcome_numRead(this.__wbg_ptr, arg0);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* How many samples were wrtten to the output.
|
|
392
|
+
* @returns {number}
|
|
393
|
+
*/
|
|
394
|
+
get numWritten() {
|
|
395
|
+
const ret = wasm.__wbg_get_resampleoutcome_numWritten(this.__wbg_ptr);
|
|
396
|
+
return ret >>> 0;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* How many samples were wrtten to the output.
|
|
400
|
+
* @param {number} arg0
|
|
401
|
+
*/
|
|
402
|
+
set numWritten(arg0) {
|
|
403
|
+
wasm.__wbg_set_resampleoutcome_numWritten(this.__wbg_ptr, arg0);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
if (Symbol.dispose) ResampleOutcome.prototype[Symbol.dispose] = ResampleOutcome.prototype.free;
|
|
407
|
+
|
|
348
408
|
/**
|
|
349
409
|
* A resampler that processes audio input as a whole.
|
|
350
410
|
*
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "lanczos-resampler",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "Audio resampler for Rust/JS that uses Lanczos filter.",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.2.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"lanczos_resampler.d.ts"
|
|
16
16
|
],
|
|
17
17
|
"main": "lanczos_resampler.js",
|
|
18
|
-
"homepage": "https://github.
|
|
18
|
+
"homepage": "https://igankevich.github.io/lanczos-resampler/",
|
|
19
19
|
"types": "lanczos_resampler.d.ts",
|
|
20
20
|
"sideEffects": [
|
|
21
21
|
"./lanczos_resampler.js",
|