@ainsej/rubberband-wasm 4.0.0 → 4.0.1
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/index.esm.js +463 -0
- package/dist/index.esm.min.js +7 -0
- package/dist/index.umd.js +475 -0
- package/dist/index.umd.min.js +7 -0
- package/dist/rubberband-processor.js +689 -0
- package/dist/rubberband-processor.min.js +7 -0
- package/dist/rubberband.wasm +0 -0
- package/dist/types/RubberBandInterface.d.ts +101 -0
- package/dist/types/RubberBandNode.d.ts +84 -0
- package/dist/types/RubberBandProcessor.d.ts +1 -0
- package/dist/types/index.d.ts +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* rubberband-wasm v4.0.1 (https://www.npmjs.com/package/rubberband-wasm)
|
|
3
|
+
* (c) Dani Biro
|
|
4
|
+
* @license GPLv2
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
!function(){"use strict";var e,t,s;!function(e){e[e.RubberBandOptionProcessOffline=0]="RubberBandOptionProcessOffline",e[e.RubberBandOptionProcessRealTime=1]="RubberBandOptionProcessRealTime",e[e.RubberBandOptionStretchElastic=0]="RubberBandOptionStretchElastic",e[e.RubberBandOptionStretchPrecise=16]="RubberBandOptionStretchPrecise",e[e.RubberBandOptionTransientsCrisp=0]="RubberBandOptionTransientsCrisp",e[e.RubberBandOptionTransientsMixed=256]="RubberBandOptionTransientsMixed",e[e.RubberBandOptionTransientsSmooth=512]="RubberBandOptionTransientsSmooth",e[e.RubberBandOptionDetectorCompound=0]="RubberBandOptionDetectorCompound",e[e.RubberBandOptionDetectorPercussive=1024]="RubberBandOptionDetectorPercussive",e[e.RubberBandOptionDetectorSoft=2048]="RubberBandOptionDetectorSoft",e[e.RubberBandOptionPhaseLaminar=0]="RubberBandOptionPhaseLaminar",e[e.RubberBandOptionPhaseIndependent=8192]="RubberBandOptionPhaseIndependent",e[e.RubberBandOptionThreadingAuto=0]="RubberBandOptionThreadingAuto",e[e.RubberBandOptionThreadingNever=65536]="RubberBandOptionThreadingNever",e[e.RubberBandOptionThreadingAlways=131072]="RubberBandOptionThreadingAlways",e[e.RubberBandOptionWindowStandard=0]="RubberBandOptionWindowStandard",e[e.RubberBandOptionWindowShort=1048576]="RubberBandOptionWindowShort",e[e.RubberBandOptionWindowLong=2097152]="RubberBandOptionWindowLong",e[e.RubberBandOptionSmoothingOff=0]="RubberBandOptionSmoothingOff",e[e.RubberBandOptionSmoothingOn=8388608]="RubberBandOptionSmoothingOn",e[e.RubberBandOptionFormantShifted=0]="RubberBandOptionFormantShifted",e[e.RubberBandOptionFormantPreserved=16777216]="RubberBandOptionFormantPreserved",e[e.RubberBandOptionPitchHighSpeed=0]="RubberBandOptionPitchHighSpeed",e[e.RubberBandOptionPitchHighQuality=33554432]="RubberBandOptionPitchHighQuality",e[e.RubberBandOptionPitchHighConsistency=67108864]="RubberBandOptionPitchHighConsistency",e[e.RubberBandOptionChannelsApart=0]="RubberBandOptionChannelsApart",e[e.RubberBandOptionChannelsTogether=268435456]="RubberBandOptionChannelsTogether",e[e.RubberBandOptionEngineFaster=0]="RubberBandOptionEngineFaster",e[e.RubberBandOptionEngineFiner=536870912]="RubberBandOptionEngineFiner"}(e||(e={})),function(e){e[e.DefaultOptions=0]="DefaultOptions",e[e.PercussiveOptions=1056768]="PercussiveOptions"}(t||(t={})),function(e){e[e.RubberBandLiveOptionWindowShort=0]="RubberBandLiveOptionWindowShort",e[e.RubberBandLiveOptionWindowMedium=1048576]="RubberBandLiveOptionWindowMedium",e[e.RubberBandLiveOptionFormantShifted=0]="RubberBandLiveOptionFormantShifted",e[e.RubberBandLiveOptionFormantPreserved=16777216]="RubberBandLiveOptionFormantPreserved",e[e.RubberBandLiveOptionChannelsApart=0]="RubberBandLiveOptionChannelsApart",e[e.RubberBandLiveOptionChannelsTogether=268435456]="RubberBandLiveOptionChannelsTogether"}(s||(s={}));class r{constructor(){}static async initialize(e){if("undefined"==typeof WebAssembly)throw new Error("WebAssembly is not supported in this environment!");let t={};const s=(...e)=>(console.error("WASI called with params",e),52);let i=[];const n=await WebAssembly.instantiate(e,{env:{emscripten_notify_memory_growth:()=>{t.HEAP8=new Uint8Array(n.exports.memory.buffer),t.HEAP32=new Uint32Array(n.exports.memory.buffer)}},wasi_snapshot_preview1:{proc_exit:(...e)=>s("proc_exit",e),fd_read:(...e)=>s("fd_read",e),fd_write:(e,s,r,n)=>{if(e>2)return 52;let a=0;for(let e=0;e<r;e++){const e=t.HEAP32[s>>2],r=t.HEAP32[s+4>>2];s+=8;for(let s=0;s<r;s++){const r=t.HEAP8[e+s];0===r||10===r?(console.log(i.join("")),i.length=0):i.push(String.fromCharCode(r))}a+=r}return t.HEAP32[n>>2]=a,0},fd_seek:(...e)=>s("fd_seek",e),fd_close:(...e)=>s("fd_close",e),environ_sizes_get:(e,t)=>52,environ_get:(...e)=>s("environ_get",e),clock_time_get:(...e)=>s("clock_time_get",e)}}),a=n.exports;t.HEAP8=new Uint8Array(n.exports.memory.buffer),t.HEAP32=new Uint32Array(n.exports.memory.buffer),a._initialize();const o={heap:t,exports:a},b=new r;return b.wasm=o,b}malloc(e){return this.wasm.exports.wasm_malloc(e)}memWrite(e,t){const s=t instanceof Uint8Array?t:new Uint8Array(t.buffer,t.byteOffset,t.byteLength);this.wasm.heap.HEAP8.set(s,e)}memWritePtr(e,t){const s=new Uint8Array(4);new DataView(s.buffer).setUint32(0,t,!0),this.wasm.heap.HEAP8.set(s,e)}memReadU8(e,t){return this.wasm.heap.HEAP8.subarray(e,e+t)}memReadF32(e,t){const s=this.memReadU8(e,4*t);return new Float32Array(s.buffer,s.byteOffset,t)}free(e){this.wasm.exports.wasm_free(e)}rubberband_new(e,t,s,r,i){return this.wasm.exports.rb_new(e,t,s,r,i)}rubberband_delete(e){this.wasm.exports.rb_delete(e)}rubberband_reset(e){this.wasm.exports.rb_reset(e)}rubberband_get_engine_version(e){return this.wasm.exports.rb_get_engine_version(e)}rubberband_set_time_ratio(e,t){this.wasm.exports.rb_set_time_ratio(e,t)}rubberband_set_pitch_scale(e,t){this.wasm.exports.rb_set_pitch_scale(e,t)}rubberband_set_formant_scale(e,t){this.wasm.exports.rb_set_formant_scale(e,t)}rubberband_get_time_ratio(e){return this.wasm.exports.rb_get_time_ratio(e)}rubberband_get_pitch_scale(e){return this.wasm.exports.rb_get_pitch_scale(e)}rubberband_get_formant_scale(e){return this.wasm.exports.rb_get_formant_scale(e)}rubberband_get_preferred_start_pad(e){return this.wasm.exports.rb_get_preferred_start_pad(e)}rubberband_get_start_delay(e){return this.wasm.exports.rb_get_start_delay(e)}rubberband_get_latency(e){return this.wasm.exports.rb_get_latency(e)}rubberband_set_transients_option(e,t){this.wasm.exports.rb_set_transients_option(e,t)}rubberband_set_detector_option(e,t){this.wasm.exports.rb_set_detector_option(e,t)}rubberband_set_phase_option(e,t){this.wasm.exports.rb_set_phase_option(e,t)}rubberband_set_formant_option(e,t){this.wasm.exports.rb_set_formant_option(e,t)}rubberband_set_pitch_option(e,t){this.wasm.exports.rb_set_pitch_option(e,t)}rubberband_set_expected_input_duration(e,t){this.wasm.exports.rb_set_expected_input_duration(e,t)}rubberband_get_samples_required(e){return this.wasm.exports.rb_get_samples_required(e)}rubberband_set_max_process_size(e,t){this.wasm.exports.rb_set_max_process_size(e,t)}rubberband_get_process_size_limit(e){return this.wasm.exports.rb_get_process_size_limit(e)}rubberband_set_key_frame_map(e,t,s,r){this.wasm.exports.rb_set_key_frame_map(e,t,s,r)}rubberband_study(e,t,s,r){this.wasm.exports.rb_study(e,t,s,r)}rubberband_process(e,t,s,r){this.wasm.exports.rb_process(e,t,s,r)}rubberband_available(e){return this.wasm.exports.rb_available(e)}rubberband_retrieve(e,t,s){return this.wasm.exports.rb_retrieve(e,t,s)}rubberband_get_channel_count(e){return this.wasm.exports.rb_get_channel_count(e)}rubberband_calculate_stretch(e){this.wasm.exports.rb_calculate_stretch(e)}rubberband_set_debug_level(e,t){this.wasm.exports.rb_set_debug_level(e,t)}rubberband_set_default_debug_level(e){this.wasm.exports.rb_set_default_debug_level(e)}rubberband_live_new(e,t,s){return this.wasm.exports.rb_live_new(e,t,s)}rubberband_live_delete(e){this.wasm.exports.rb_live_delete(e)}rubberband_live_reset(e){this.wasm.exports.rb_live_reset(e)}rubberband_live_set_pitch_scale(e,t){this.wasm.exports.rb_live_set_pitch_scale(e,t)}rubberband_live_get_pitch_scale(e){return this.wasm.exports.rb_live_get_pitch_scale(e)}rubberband_live_set_formant_scale(e,t){this.wasm.exports.rb_live_set_formant_scale(e,t)}rubberband_live_get_formant_scale(e){return this.wasm.exports.rb_live_get_formant_scale(e)}rubberband_live_get_start_delay(e){return this.wasm.exports.rb_live_get_start_delay(e)}rubberband_live_set_formant_option(e,t){this.wasm.exports.rb_live_set_formant_option(e,t)}rubberband_live_get_block_size(e){return this.wasm.exports.rb_live_get_block_size(e)}rubberband_live_shift(e,t,s){this.wasm.exports.rb_live_shift(e,t,s)}rubberband_live_get_channel_count(e){return this.wasm.exports.rb_live_get_channel_count(e)}rubberband_live_set_debug_level(e,t){this.wasm.exports.rb_live_set_debug_level(e,t)}rubberband_live_set_default_debug_level(e){this.wasm.exports.rb_live_set_default_debug_level(e)}}const i=8192,n=65536,a=e.RubberBandOptionProcessRealTime|e.RubberBandOptionEngineFaster|e.RubberBandOptionPitchHighConsistency;class o extends AudioWorkletProcessor{constructor(){super(),this.rb=null,this.state=0,this.channels=0,this.options=a,this.closed=!1,this.inPtr=0,this.outPtr=0,this.inChan=[],this.outChan=[],this.source=[],this.sourceLen=0,this.sourceSampleRate=sampleRate,this.rateFactor=1,this.readPos=0,this.playing=!1,this.loop=!1,this.finished=!1,this.sentFinal=!1,this.endedPosted=!1,this.startPad=0,this.toDrop=0,this.needStart=!0,this.speed=1,this.pitchScale=1,this.ring=[],this.ringRead=0,this.ringWrite=0,this.ringCount=0,this.framesSinceReport=0,this.port.onmessage=e=>this.onMessage(e.data)}async onMessage(e){if(!this.closed)switch(e&&e.type){case"initialise":await this.initialise(e);break;case"buffer":this.setBuffer(e);break;case"play":this.finished&&this.resetTransport(0),this.endedPosted=!1,this.preroll(),this.playing=!0;break;case"pause":this.playing=!1;break;case"stop":this.playing=!1,this.resetTransport(0);break;case"seek":{const t=Math.max(0,Math.round((e.seconds||0)*this.sourceSampleRate));this.resetTransport(Math.min(t,this.sourceLen)),this.playing&&this.preroll();break}case"loop":this.loop=!!e.value;break;case"speed":this.speed=e.value>0?e.value:1,this.applyRatios();break;case"pitch":this.pitchScale=e.value>0?e.value:1,this.applyRatios();break;case"close":this.dispose()}}async initialise(e){try{this.channels=e.channels,"number"==typeof e.options&&(this.options=e.options);const t=e.wasm,s=t instanceof WebAssembly.Module?t:await WebAssembly.compile(t);if(this.closed)return;if(this.rb=await r.initialize(s),this.closed)return void(this.rb=null);this.allocate(),this.createState(),this.port.postMessage({type:"ready"})}catch(e){this.port.postMessage({type:"error",error:String(e&&e.message||e)})}}allocate(){const e=this.rb;this.inPtr=e.malloc(4*this.channels),this.outPtr=e.malloc(4*this.channels),this.inChan=[],this.outChan=[],this.ring=[];for(let t=0;t<this.channels;t++){const s=e.malloc(32768),r=e.malloc(32768);this.inChan.push(s),this.outChan.push(r),e.memWritePtr(this.inPtr+4*t,s),e.memWritePtr(this.outPtr+4*t,r),this.ring.push(new Float32Array(n))}}createState(){const e=this.rb;this.state&&(e.rubberband_delete(this.state),this.state=0),this.state=e.rubberband_new(sampleRate,this.channels,this.options,1,1),e.rubberband_set_max_process_size(this.state,i),this.applyRatios()}applyRatios(){if(!this.rb||!this.state)return;const e=this.rateFactor/this.speed,t=this.pitchScale/this.rateFactor;this.rb.rubberband_set_time_ratio(this.state,e),this.rb.rubberband_set_pitch_scale(this.state,t)}setBuffer(e){this.source=e.channels||[],this.sourceLen=this.source[0]?this.source[0].length:0,this.sourceSampleRate=e.sampleRate||sampleRate,this.rateFactor=sampleRate/this.sourceSampleRate,this.playing=!1,this.resetTransport(0)}resetTransport(e){this.readPos=e,this.ringRead=0,this.ringWrite=0,this.ringCount=0,this.finished=!1,this.sentFinal=!1,this.endedPosted=!1,this.startPad=0,this.toDrop=0,this.needStart=!0;const t=this.rb,s=this.state;t&&s&&(t.rubberband_reset(s),this.applyRatios())}preroll(){this.pump(4096,1<<20)}pump(e,t){const s=this.rb,r=this.state;if(s&&r&&!this.finished)for(this.needStart&&(this.applyRatios(),this.startPad=s.rubberband_get_preferred_start_pad(r),this.toDrop=s.rubberband_get_start_delay(r),this.needStart=!1);this.ringCount<e&&!this.finished&&t-- >0;){const e=s.rubberband_available(r);if(e<0){this.finished=!0;break}if(e>0){this.drain(e);continue}if(this.sentFinal)break;let t=s.rubberband_get_samples_required(r);t<=0&&(t=1),t>i&&(t=i);const n=this.assembleInput(t);s.rubberband_process(r,this.inPtr,t,n?1:0),n&&(this.sentFinal=!0)}}assembleInput(e){const t=this.rb,s=this.channels,r=[];for(let i=0;i<s;i++)r.push(t.memReadF32(this.inChan[i],e));let i=!1;for(let t=0;t<e;t++){if(this.startPad>0){for(let e=0;e<s;e++)r[e][t]=0;this.startPad--;continue}if(this.readPos>=this.sourceLen){if(!(this.loop&&this.sourceLen>0)){for(let e=0;e<s;e++)r[e][t]=0;i=!0;continue}this.readPos=0}const e=this.readPos;for(let i=0;i<s;i++){const s=this.source[i];r[i][t]=s?s[e]:0}this.readPos++}return i}drain(e){const t=this.rb,s=this.state;let r=e;for(;r>0;){const e=n-this.ringCount;if(e<=0)break;const a=Math.min(r,i,e),o=t.rubberband_retrieve(s,this.outPtr,a);if(o<=0)break;let b=0;if(this.toDrop>0){const e=Math.min(this.toDrop,o);this.toDrop-=e,b=e}const h=o-b;if(h>0){const e=[];for(let s=0;s<this.channels;s++)e.push(t.memReadF32(this.outChan[s],o));this.push(e,b,h)}r-=o}}push(e,t,s){const r=this.ringWrite,i=Math.min(s,65536-r),n=s-i;for(let a=0;a<this.channels;a++){const o=e[a];this.ring[a].set(o.subarray(t,t+i),r),n>0&&this.ring[a].set(o.subarray(t+i,t+s),0)}this.ringWrite=(r+s)%65536,this.ringCount+=s}pop(e,t){const s=this.ringRead,r=Math.min(t,65536-s),i=t-r;for(let t=0;t<this.channels;t++){const n=e[t];n&&(n.set(this.ring[t].subarray(s,s+r),0),i>0&&n.set(this.ring[t].subarray(0,i),r))}this.ringRead=(s+t)%65536,this.ringCount-=t}dispose(){this.closed=!0;const e=this.rb;if(e){this.state&&e.rubberband_delete(this.state);for(const t of this.inChan)e.free(t);for(const t of this.outChan)e.free(t);this.inPtr&&e.free(this.inPtr),this.outPtr&&e.free(this.outPtr)}this.state=0,this.rb=null,this.port.onmessage=null}process(e,t){if(this.closed)return!1;const s=t[0];if(!s||0===s.length)return!0;const r=s[0].length;if(!this.rb||!this.state||!this.playing){for(let e=0;e<s.length;e++)s[e].fill(0);return!0}this.pump(4096,256);const i=Math.min(r,this.ringCount);i>0&&this.pop(s,i);for(let e=0;e<s.length;e++)e>=this.channels?s[e].fill(0):i<r&&s[e].fill(0,i);return this.finished&&0===this.ringCount&&!this.endedPosted&&(this.endedPosted=!0,this.playing=!1,this.port.postMessage({type:"ended"})),this.framesSinceReport+=r,this.framesSinceReport>=sampleRate/30&&(this.framesSinceReport=0,this.port.postMessage({type:"position",seconds:this.audiblePositionSeconds()})),!0}audiblePositionSeconds(){const e=this.ringCount*this.speed*this.sourceSampleRate/sampleRate;let t=this.readPos-e;return t<0&&(t=this.loop&&this.sourceLen?t+this.sourceLen:0),t<0&&(t=0),t/this.sourceSampleRate}}registerProcessor("rubberband-processor",o)}();
|
|
Binary file
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export declare enum RubberBandOption {
|
|
2
|
+
RubberBandOptionProcessOffline = 0,
|
|
3
|
+
RubberBandOptionProcessRealTime = 1,
|
|
4
|
+
RubberBandOptionStretchElastic = 0,
|
|
5
|
+
RubberBandOptionStretchPrecise = 16,
|
|
6
|
+
RubberBandOptionTransientsCrisp = 0,
|
|
7
|
+
RubberBandOptionTransientsMixed = 256,
|
|
8
|
+
RubberBandOptionTransientsSmooth = 512,
|
|
9
|
+
RubberBandOptionDetectorCompound = 0,
|
|
10
|
+
RubberBandOptionDetectorPercussive = 1024,
|
|
11
|
+
RubberBandOptionDetectorSoft = 2048,
|
|
12
|
+
RubberBandOptionPhaseLaminar = 0,
|
|
13
|
+
RubberBandOptionPhaseIndependent = 8192,
|
|
14
|
+
RubberBandOptionThreadingAuto = 0,
|
|
15
|
+
RubberBandOptionThreadingNever = 65536,
|
|
16
|
+
RubberBandOptionThreadingAlways = 131072,
|
|
17
|
+
RubberBandOptionWindowStandard = 0,
|
|
18
|
+
RubberBandOptionWindowShort = 1048576,
|
|
19
|
+
RubberBandOptionWindowLong = 2097152,
|
|
20
|
+
RubberBandOptionSmoothingOff = 0,
|
|
21
|
+
RubberBandOptionSmoothingOn = 8388608,
|
|
22
|
+
RubberBandOptionFormantShifted = 0,
|
|
23
|
+
RubberBandOptionFormantPreserved = 16777216,
|
|
24
|
+
RubberBandOptionPitchHighSpeed = 0,
|
|
25
|
+
RubberBandOptionPitchHighQuality = 33554432,
|
|
26
|
+
RubberBandOptionPitchHighConsistency = 67108864,
|
|
27
|
+
RubberBandOptionChannelsApart = 0,
|
|
28
|
+
RubberBandOptionChannelsTogether = 268435456,
|
|
29
|
+
RubberBandOptionEngineFaster = 0,
|
|
30
|
+
RubberBandOptionEngineFiner = 536870912
|
|
31
|
+
}
|
|
32
|
+
export declare enum RubberBandPresetOption {
|
|
33
|
+
DefaultOptions = 0,
|
|
34
|
+
PercussiveOptions = 1056768
|
|
35
|
+
}
|
|
36
|
+
export declare enum RubberBandLiveOption {
|
|
37
|
+
RubberBandLiveOptionWindowShort = 0,
|
|
38
|
+
RubberBandLiveOptionWindowMedium = 1048576,
|
|
39
|
+
RubberBandLiveOptionFormantShifted = 0,
|
|
40
|
+
RubberBandLiveOptionFormantPreserved = 16777216,
|
|
41
|
+
RubberBandLiveOptionChannelsApart = 0,
|
|
42
|
+
RubberBandLiveOptionChannelsTogether = 268435456
|
|
43
|
+
}
|
|
44
|
+
export declare type RubberBandState = number;
|
|
45
|
+
export declare type RubberBandLiveState = number;
|
|
46
|
+
export declare class RubberBandInterface {
|
|
47
|
+
private wasm;
|
|
48
|
+
private constructor();
|
|
49
|
+
static initialize(module: WebAssembly.Module): Promise<RubberBandInterface>;
|
|
50
|
+
malloc(size: number): number;
|
|
51
|
+
memWrite(destPtr: number, data: Uint8Array | Float32Array): void;
|
|
52
|
+
memWritePtr(destPtr: number, srcPtr: number): void;
|
|
53
|
+
memReadU8(srcPtr: number, length: number): Uint8Array;
|
|
54
|
+
memReadF32(srcPtr: number, length: number): Float32Array;
|
|
55
|
+
free(ptr: number): void;
|
|
56
|
+
rubberband_new(sampleRate: number, channels: number, options: RubberBandOption, initialTimeRatio: number, initialPitchScale: number): RubberBandState;
|
|
57
|
+
rubberband_delete(state: RubberBandState): void;
|
|
58
|
+
rubberband_reset(state: RubberBandState): void;
|
|
59
|
+
rubberband_get_engine_version(state: RubberBandState): number;
|
|
60
|
+
rubberband_set_time_ratio(state: RubberBandState, ratio: number): void;
|
|
61
|
+
rubberband_set_pitch_scale(state: RubberBandState, scale: number): void;
|
|
62
|
+
rubberband_set_formant_scale(state: RubberBandState, scale: number): void;
|
|
63
|
+
rubberband_get_time_ratio(state: RubberBandState): number;
|
|
64
|
+
rubberband_get_pitch_scale(state: RubberBandState): number;
|
|
65
|
+
rubberband_get_formant_scale(state: RubberBandState): number;
|
|
66
|
+
rubberband_get_preferred_start_pad(state: RubberBandState): number;
|
|
67
|
+
rubberband_get_start_delay(state: RubberBandState): number;
|
|
68
|
+
rubberband_get_latency(state: RubberBandState): number;
|
|
69
|
+
rubberband_set_transients_option(state: RubberBandState, options: RubberBandOption): void;
|
|
70
|
+
rubberband_set_detector_option(state: RubberBandState, options: RubberBandOption): void;
|
|
71
|
+
rubberband_set_phase_option(state: RubberBandState, options: RubberBandOption): void;
|
|
72
|
+
rubberband_set_formant_option(state: RubberBandState, options: RubberBandOption): void;
|
|
73
|
+
rubberband_set_pitch_option(state: RubberBandState, options: RubberBandOption): void;
|
|
74
|
+
rubberband_set_expected_input_duration(state: RubberBandState, samples: number): void;
|
|
75
|
+
rubberband_get_samples_required(state: RubberBandState): number;
|
|
76
|
+
rubberband_set_max_process_size(state: RubberBandState, samples: number): void;
|
|
77
|
+
rubberband_get_process_size_limit(state: RubberBandState): number;
|
|
78
|
+
rubberband_set_key_frame_map(state: RubberBandState, keyframecount: number, from: number, to: number): void;
|
|
79
|
+
rubberband_study(state: RubberBandState, input: number, samples: number, final: number): void;
|
|
80
|
+
rubberband_process(state: RubberBandState, input: number, samples: number, final: number): void;
|
|
81
|
+
rubberband_available(state: RubberBandState): number;
|
|
82
|
+
rubberband_retrieve(state: RubberBandState, output: number, samples: number): number;
|
|
83
|
+
rubberband_get_channel_count(state: RubberBandState): number;
|
|
84
|
+
rubberband_calculate_stretch(state: RubberBandState): void;
|
|
85
|
+
rubberband_set_debug_level(state: RubberBandState, level: number): void;
|
|
86
|
+
rubberband_set_default_debug_level(level: number): void;
|
|
87
|
+
rubberband_live_new(sampleRate: number, channels: number, options: RubberBandLiveOption): RubberBandLiveState;
|
|
88
|
+
rubberband_live_delete(state: RubberBandLiveState): void;
|
|
89
|
+
rubberband_live_reset(state: RubberBandLiveState): void;
|
|
90
|
+
rubberband_live_set_pitch_scale(state: RubberBandLiveState, scale: number): void;
|
|
91
|
+
rubberband_live_get_pitch_scale(state: RubberBandLiveState): number;
|
|
92
|
+
rubberband_live_set_formant_scale(state: RubberBandLiveState, scale: number): void;
|
|
93
|
+
rubberband_live_get_formant_scale(state: RubberBandLiveState): number;
|
|
94
|
+
rubberband_live_get_start_delay(state: RubberBandLiveState): number;
|
|
95
|
+
rubberband_live_set_formant_option(state: RubberBandLiveState, options: RubberBandLiveOption): void;
|
|
96
|
+
rubberband_live_get_block_size(state: RubberBandLiveState): number;
|
|
97
|
+
rubberband_live_shift(state: RubberBandLiveState, input: number, output: number): void;
|
|
98
|
+
rubberband_live_get_channel_count(state: RubberBandLiveState): number;
|
|
99
|
+
rubberband_live_set_debug_level(state: RubberBandLiveState, level: number): void;
|
|
100
|
+
rubberband_live_set_default_debug_level(level: number): void;
|
|
101
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export interface RubberBandNodeOptions {
|
|
2
|
+
/** URL of the bundled worklet processor (dist/rubberband-processor.js). */
|
|
3
|
+
processorUrl?: string;
|
|
4
|
+
/** URL to fetch the rubberband.wasm binary from. */
|
|
5
|
+
wasmUrl?: string;
|
|
6
|
+
/** Pre-fetched wasm binary (compiled inside the worklet). */
|
|
7
|
+
wasmBinary?: ArrayBuffer | Uint8Array;
|
|
8
|
+
/**
|
|
9
|
+
* Number of output channels (default 2). A source with fewer channels is
|
|
10
|
+
* duplicated up to this count; a source with more has its extra channels
|
|
11
|
+
* dropped (the first `channelCount` are kept).
|
|
12
|
+
*/
|
|
13
|
+
channelCount?: number;
|
|
14
|
+
/** RubberBand options bitmask (advanced; defaults to a real-time, glitch-free preset). */
|
|
15
|
+
options?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* RubberBandNode — a Web Audio source node that plays a buffer through Rubber
|
|
19
|
+
* Band Library with live, real-time control over tempo (time-stretch) and pitch.
|
|
20
|
+
*
|
|
21
|
+
* It has no inputs and one output; connect it to the graph like an
|
|
22
|
+
* AudioBufferSourceNode:
|
|
23
|
+
*
|
|
24
|
+
* ```js
|
|
25
|
+
* const node = await RubberBandNode.create(ctx, {
|
|
26
|
+
* processorUrl: "rubberband-processor.js",
|
|
27
|
+
* wasmUrl: "rubberband.wasm",
|
|
28
|
+
* channelCount: audioBuffer.numberOfChannels,
|
|
29
|
+
* });
|
|
30
|
+
* node.connect(ctx.destination);
|
|
31
|
+
* node.setBuffer(audioBuffer);
|
|
32
|
+
* node.setTempo(1.5); // 1.5x speed, pitch unchanged
|
|
33
|
+
* node.setPitchSemitones(-3); // down a minor third, speed unchanged
|
|
34
|
+
* node.play();
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare class RubberBandNode extends AudioWorkletNode {
|
|
38
|
+
private readonly _channels;
|
|
39
|
+
private readonly _sourceSampleRate;
|
|
40
|
+
private _ready;
|
|
41
|
+
private _readyResolve;
|
|
42
|
+
private _readyReject;
|
|
43
|
+
/** Fired once when playback reaches the end (re-armed on every play/seek/stop). */
|
|
44
|
+
onended: (() => void) | null;
|
|
45
|
+
/** Fired periodically with the current playback position, in seconds of source time. */
|
|
46
|
+
onposition: ((seconds: number) => void) | null;
|
|
47
|
+
private constructor();
|
|
48
|
+
/** Number of output channels the node was created with. */
|
|
49
|
+
get sourceChannels(): number;
|
|
50
|
+
/** Resolves once the worklet has compiled the wasm and is ready to play. */
|
|
51
|
+
get ready(): Promise<void>;
|
|
52
|
+
/** Register the worklet module on a context (idempotent per context). */
|
|
53
|
+
static addModule(context: BaseAudioContext, processorUrl: string): Promise<void>;
|
|
54
|
+
/** Create a ready-to-use RubberBandNode. */
|
|
55
|
+
static create(context: BaseAudioContext, opts?: RubberBandNodeOptions): Promise<RubberBandNode>;
|
|
56
|
+
/**
|
|
57
|
+
* Load source audio. Channel data is copied before transfer, so the supplied
|
|
58
|
+
* AudioBuffer/arrays are left intact. Resets the transport to the start.
|
|
59
|
+
*/
|
|
60
|
+
setBuffer(buffer: AudioBuffer | Float32Array[]): void;
|
|
61
|
+
private _normalizeChannels;
|
|
62
|
+
/** Start (or restart, if previously ended) playback. */
|
|
63
|
+
play(): void;
|
|
64
|
+
/** Pause, keeping the current position. */
|
|
65
|
+
pause(): void;
|
|
66
|
+
/** Stop and rewind to the start. */
|
|
67
|
+
stop(): void;
|
|
68
|
+
/** Seek to a position in seconds of source time. */
|
|
69
|
+
seek(seconds: number): void;
|
|
70
|
+
/** Enable/disable looping. */
|
|
71
|
+
set loop(value: boolean);
|
|
72
|
+
/** Set playback speed (1 = normal, 2 = double speed) without changing pitch. */
|
|
73
|
+
setTempo(speed: number): void;
|
|
74
|
+
/** Set the time ratio directly (output duration / input duration). */
|
|
75
|
+
setTimeRatio(ratio: number): void;
|
|
76
|
+
/** Set the pitch scale directly (1 = no shift, 2 = up one octave). */
|
|
77
|
+
setPitchScale(scale: number): void;
|
|
78
|
+
/** Set the pitch shift in semitones (without changing tempo). */
|
|
79
|
+
setPitchSemitones(semitones: number): void;
|
|
80
|
+
/** Free wasm resources in the worklet and disconnect the node. */
|
|
81
|
+
close(): void;
|
|
82
|
+
}
|
|
83
|
+
/** Default RubberBand options used by the real-time node (exported for reference/override). */
|
|
84
|
+
export declare const RUBBERBAND_REALTIME_DEFAULT_OPTIONS: number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ainsej/rubberband-wasm",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "WebAssembly version of the Rubber Band Library (high quality software library for audio time-stretching and pitch-shifting)",
|
|
5
5
|
"main": "dist/index.umd.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|