react-native-audio-api 0.1.0 → 0.3.0-rc1
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/README.md +10 -8
- package/RNAudioAPI.podspec +5 -0
- package/android/CMakeLists.txt +21 -10
- package/android/libs/fftw3/arm64-v8a/libfftw3.a +0 -0
- package/android/libs/fftw3/armeabi-v7a/libfftw3.a +0 -0
- package/android/libs/fftw3/x86/libfftw3.a +0 -0
- package/android/libs/fftw3/x86_64/libfftw3.a +0 -0
- package/android/libs/include/fftw3/fftw3.h +413 -0
- package/android/src/main/cpp/AudioPlayer/AudioPlayer.cpp +32 -2
- package/android/src/main/cpp/AudioPlayer/AudioPlayer.h +6 -2
- package/common/cpp/AudioAPIInstaller/AudioAPIInstallerHostObject.cpp +5 -3
- package/common/cpp/AudioAPIInstaller/AudioAPIInstallerHostObject.h +5 -1
- package/common/cpp/HostObjects/AudioBufferHostObject.cpp +6 -0
- package/common/cpp/HostObjects/AudioBufferSourceNodeHostObject.cpp +13 -1
- package/common/cpp/HostObjects/AudioContextHostObject.cpp +12 -149
- package/common/cpp/HostObjects/AudioContextHostObject.h +8 -14
- package/common/cpp/HostObjects/AudioNodeHostObject.cpp +0 -6
- package/common/cpp/HostObjects/BaseAudioContextHostObject.cpp +240 -0
- package/common/cpp/HostObjects/BaseAudioContextHostObject.h +41 -0
- package/common/cpp/HostObjects/BiquadFilterNodeHostObject.cpp +44 -0
- package/common/cpp/HostObjects/OscillatorNodeHostObject.cpp +21 -0
- package/common/cpp/HostObjects/OscillatorNodeHostObject.h +1 -0
- package/common/cpp/HostObjects/PeriodicWaveHostObject.cpp +33 -0
- package/common/cpp/HostObjects/PeriodicWaveHostObject.h +33 -0
- package/common/cpp/core/AudioArray.cpp +117 -0
- package/common/cpp/core/AudioArray.h +48 -0
- package/common/cpp/core/AudioBuffer.cpp +23 -80
- package/common/cpp/core/AudioBuffer.h +12 -13
- package/common/cpp/core/AudioBufferSourceNode.cpp +112 -25
- package/common/cpp/core/AudioBufferSourceNode.h +10 -6
- package/common/cpp/core/AudioBus.cpp +518 -0
- package/common/cpp/core/AudioBus.h +83 -0
- package/common/cpp/core/AudioContext.cpp +7 -77
- package/common/cpp/core/AudioContext.h +3 -60
- package/common/cpp/core/AudioDestinationNode.cpp +27 -15
- package/common/cpp/core/AudioDestinationNode.h +13 -5
- package/common/cpp/core/AudioNode.cpp +184 -22
- package/common/cpp/core/AudioNode.h +37 -37
- package/common/cpp/core/AudioNodeManager.cpp +75 -0
- package/common/cpp/core/AudioNodeManager.h +42 -0
- package/common/cpp/core/AudioParam.cpp +8 -11
- package/common/cpp/core/AudioParam.h +8 -8
- package/common/cpp/core/AudioScheduledSourceNode.cpp +19 -5
- package/common/cpp/core/AudioScheduledSourceNode.h +6 -2
- package/common/cpp/core/BaseAudioContext.cpp +191 -0
- package/common/cpp/core/BaseAudioContext.h +87 -0
- package/common/cpp/core/BiquadFilterNode.cpp +92 -69
- package/common/cpp/core/BiquadFilterNode.h +53 -57
- package/common/cpp/core/GainNode.cpp +12 -12
- package/common/cpp/core/GainNode.h +5 -3
- package/common/cpp/core/OscillatorNode.cpp +38 -29
- package/common/cpp/core/OscillatorNode.h +29 -69
- package/common/cpp/core/ParamChange.h +6 -6
- package/common/cpp/core/PeriodicWave.cpp +362 -0
- package/common/cpp/core/PeriodicWave.h +119 -0
- package/common/cpp/core/StereoPannerNode.cpp +31 -30
- package/common/cpp/core/StereoPannerNode.h +6 -6
- package/common/cpp/types/BiquadFilterType.h +19 -0
- package/common/cpp/types/ChannelCountMode.h +10 -0
- package/common/cpp/types/ChannelInterpretation.h +10 -0
- package/common/cpp/types/ContextState.h +10 -0
- package/common/cpp/types/OscillatorType.h +11 -0
- package/common/cpp/utils/FFTFrame.h +67 -0
- package/common/cpp/utils/JsiPromise.cpp +59 -0
- package/common/cpp/utils/JsiPromise.h +42 -0
- package/common/cpp/utils/Locker.h +49 -0
- package/common/cpp/utils/VectorMath.cpp +88 -3
- package/common/cpp/utils/VectorMath.h +7 -1
- package/common/cpp/utils/android/FFTFrame.cpp +23 -0
- package/common/cpp/utils/ios/FFTFrame.cpp +29 -0
- package/common/cpp/wrappers/AudioBufferSourceNodeWrapper.cpp +10 -0
- package/common/cpp/wrappers/AudioBufferSourceNodeWrapper.h +3 -2
- package/common/cpp/wrappers/AudioBufferWrapper.h +5 -5
- package/common/cpp/wrappers/AudioContextWrapper.cpp +7 -60
- package/common/cpp/wrappers/AudioContextWrapper.h +5 -26
- package/common/cpp/wrappers/AudioNodeWrapper.h +5 -5
- package/common/cpp/wrappers/AudioParamWrapper.h +4 -4
- package/common/cpp/wrappers/BaseAudioContextWrapper.cpp +83 -0
- package/common/cpp/wrappers/BaseAudioContextWrapper.h +50 -0
- package/common/cpp/wrappers/BiquadFilterNodeWrapper.cpp +9 -0
- package/common/cpp/wrappers/BiquadFilterNodeWrapper.h +9 -4
- package/common/cpp/wrappers/GainNodeWrapper.h +1 -1
- package/common/cpp/wrappers/OscillatorNodeWrapper.cpp +6 -0
- package/common/cpp/wrappers/OscillatorNodeWrapper.h +5 -2
- package/common/cpp/wrappers/PeriodicWaveWrapper.h +17 -0
- package/common/cpp/wrappers/StereoPannerNodeWrapper.h +1 -1
- package/ios/AudioAPIModule.h +20 -1
- package/ios/AudioAPIModule.mm +6 -4
- package/ios/AudioDecoder/AudioDecoder.h +17 -0
- package/ios/AudioDecoder/AudioDecoder.m +167 -0
- package/ios/AudioDecoder/IOSAudioDecoder.h +26 -0
- package/ios/AudioDecoder/IOSAudioDecoder.mm +40 -0
- package/ios/AudioPlayer/AudioPlayer.h +3 -2
- package/ios/AudioPlayer/AudioPlayer.m +14 -17
- package/ios/AudioPlayer/IOSAudioPlayer.h +7 -3
- package/ios/AudioPlayer/IOSAudioPlayer.mm +31 -7
- package/lib/module/core/AudioBuffer.js +37 -0
- package/lib/module/core/AudioBuffer.js.map +1 -0
- package/lib/module/core/AudioBufferSourceNode.js +28 -0
- package/lib/module/core/AudioBufferSourceNode.js.map +1 -0
- package/lib/module/core/AudioContext.js +10 -0
- package/lib/module/core/AudioContext.js.map +1 -0
- package/lib/module/core/AudioDestinationNode.js +7 -0
- package/lib/module/core/AudioDestinationNode.js.map +1 -0
- package/lib/module/core/AudioNode.js +22 -0
- package/lib/module/core/AudioNode.js.map +1 -0
- package/lib/module/core/AudioParam.js +35 -0
- package/lib/module/core/AudioParam.js.map +1 -0
- package/lib/module/core/AudioScheduledSourceNode.js +28 -0
- package/lib/module/core/AudioScheduledSourceNode.js.map +1 -0
- package/lib/module/core/BaseAudioContext.js +62 -0
- package/lib/module/core/BaseAudioContext.js.map +1 -0
- package/lib/module/core/BiquadFilterNode.js +25 -0
- package/lib/module/core/BiquadFilterNode.js.map +1 -0
- package/lib/module/core/GainNode.js +9 -0
- package/lib/module/core/GainNode.js.map +1 -0
- package/lib/module/core/OscillatorNode.js +24 -0
- package/lib/module/core/OscillatorNode.js.map +1 -0
- package/lib/module/core/PeriodicWave.js +8 -0
- package/lib/module/core/PeriodicWave.js.map +1 -0
- package/lib/module/core/StereoPannerNode.js +9 -0
- package/lib/module/core/StereoPannerNode.js.map +1 -0
- package/lib/module/core/types.js.map +1 -0
- package/lib/module/errors/IndexSizeError.js +8 -0
- package/lib/module/errors/IndexSizeError.js.map +1 -0
- package/lib/module/errors/InvalidAccessError.js +8 -0
- package/lib/module/errors/InvalidAccessError.js.map +1 -0
- package/lib/module/errors/InvalidStateError.js +8 -0
- package/lib/module/errors/InvalidStateError.js.map +1 -0
- package/lib/module/errors/RangeError.js +8 -0
- package/lib/module/errors/RangeError.js.map +1 -0
- package/lib/module/errors/index.js +5 -0
- package/lib/module/errors/index.js.map +1 -0
- package/lib/module/index.js +212 -15
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.native.js +18 -0
- package/lib/module/index.native.js.map +1 -0
- package/lib/module/interfaces.js +2 -0
- package/lib/module/interfaces.js.map +1 -0
- package/lib/module/utils/resolveAudioSource.js +10 -0
- package/lib/module/utils/resolveAudioSource.js.map +1 -0
- package/lib/typescript/core/AudioBuffer.d.ts +12 -0
- package/lib/typescript/core/AudioBuffer.d.ts.map +1 -0
- package/lib/typescript/core/AudioBufferSourceNode.d.ts +12 -0
- package/lib/typescript/core/AudioBufferSourceNode.d.ts.map +1 -0
- package/lib/typescript/core/AudioContext.d.ts +6 -0
- package/lib/typescript/core/AudioContext.d.ts.map +1 -0
- package/lib/typescript/core/AudioDestinationNode.d.ts +7 -0
- package/lib/typescript/core/AudioDestinationNode.d.ts.map +1 -0
- package/lib/typescript/core/AudioNode.d.ts +16 -0
- package/lib/typescript/core/AudioNode.d.ts.map +1 -0
- package/lib/typescript/core/AudioParam.d.ts +14 -0
- package/lib/typescript/core/AudioParam.d.ts.map +1 -0
- package/lib/typescript/core/AudioScheduledSourceNode.d.ts +10 -0
- package/lib/typescript/core/AudioScheduledSourceNode.d.ts.map +1 -0
- package/lib/typescript/core/BaseAudioContext.d.ts +27 -0
- package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -0
- package/lib/typescript/core/BiquadFilterNode.d.ts +16 -0
- package/lib/typescript/core/BiquadFilterNode.d.ts.map +1 -0
- package/lib/typescript/core/GainNode.d.ts +9 -0
- package/lib/typescript/core/GainNode.d.ts.map +1 -0
- package/lib/typescript/core/OscillatorNode.d.ts +15 -0
- package/lib/typescript/core/OscillatorNode.d.ts.map +1 -0
- package/lib/typescript/core/PeriodicWave.d.ts +5 -0
- package/lib/typescript/core/PeriodicWave.d.ts.map +1 -0
- package/lib/typescript/core/StereoPannerNode.d.ts +9 -0
- package/lib/typescript/core/StereoPannerNode.d.ts.map +1 -0
- package/lib/typescript/core/types.d.ts +15 -0
- package/lib/typescript/core/types.d.ts.map +1 -0
- package/lib/typescript/errors/IndexSizeError.d.ts +5 -0
- package/lib/typescript/errors/IndexSizeError.d.ts.map +1 -0
- package/lib/typescript/errors/InvalidAccessError.d.ts +5 -0
- package/lib/typescript/errors/InvalidAccessError.d.ts.map +1 -0
- package/lib/typescript/errors/InvalidStateError.d.ts +5 -0
- package/lib/typescript/errors/InvalidStateError.d.ts.map +1 -0
- package/lib/typescript/errors/RangeError.d.ts +5 -0
- package/lib/typescript/errors/RangeError.d.ts.map +1 -0
- package/lib/typescript/errors/index.d.ts +5 -0
- package/lib/typescript/errors/index.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +88 -5
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/index.native.d.ts +14 -0
- package/lib/typescript/index.native.d.ts.map +1 -0
- package/lib/typescript/interfaces.d.ts +79 -0
- package/lib/typescript/interfaces.d.ts.map +1 -0
- package/lib/typescript/utils/resolveAudioSource.d.ts +3 -0
- package/lib/typescript/utils/resolveAudioSource.d.ts.map +1 -0
- package/package.json +4 -2
- package/src/core/AudioBuffer.ts +68 -0
- package/src/core/AudioBufferSourceNode.ts +35 -0
- package/src/core/AudioContext.ts +12 -0
- package/src/core/AudioDestinationNode.ts +9 -0
- package/src/core/AudioNode.ts +38 -0
- package/src/core/AudioParam.ts +55 -0
- package/src/core/AudioScheduledSourceNode.ts +43 -0
- package/src/core/BaseAudioContext.ts +108 -0
- package/src/core/BiquadFilterNode.ts +49 -0
- package/src/core/GainNode.ts +13 -0
- package/src/core/OscillatorNode.ts +37 -0
- package/src/core/PeriodicWave.ts +10 -0
- package/src/core/StereoPannerNode.ts +13 -0
- package/src/core/types.ts +33 -0
- package/src/errors/IndexSizeError.ts +8 -0
- package/src/errors/InvalidAccessError.ts +8 -0
- package/src/errors/InvalidStateError.ts +8 -0
- package/src/errors/RangeError.ts +8 -0
- package/src/errors/index.ts +4 -0
- package/src/index.native.ts +25 -0
- package/src/index.ts +380 -40
- package/src/interfaces.ts +121 -0
- package/src/modules/global.d.ts +3 -3
- package/src/utils/resolveAudioSource.ts +14 -0
- package/lib/module/types.js.map +0 -1
- package/lib/typescript/types.d.ts +0 -76
- package/lib/typescript/types.d.ts.map +0 -1
- package/src/types.ts +0 -108
- /package/lib/module/{types.js → core/types.js} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RangeError.d.ts","sourceRoot":"","sources":["../../../src/errors/RangeError.ts"],"names":[],"mappings":"AAAA,cAAM,UAAW,SAAQ,KAAK;gBAChB,OAAO,EAAE,MAAM;CAI5B;AAED,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as IndexSizeError } from './IndexSizeError';
|
|
2
|
+
export { default as InvalidAccessError } from './InvalidAccessError';
|
|
3
|
+
export { default as InvalidStateError } from './InvalidStateError';
|
|
4
|
+
export { default as RangeError } from './RangeError';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -1,18 +1,101 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare class
|
|
1
|
+
import { AudioSource, ContextState, PeriodicWaveConstraints } from './core/types';
|
|
2
|
+
export declare class AudioBuffer {
|
|
3
|
+
readonly length: number;
|
|
4
|
+
readonly duration: number;
|
|
5
|
+
readonly sampleRate: number;
|
|
6
|
+
readonly numberOfChannels: number;
|
|
7
|
+
readonly buffer: globalThis.AudioBuffer;
|
|
8
|
+
constructor(buffer: globalThis.AudioBuffer);
|
|
9
|
+
getChannelData(channel: number): number[];
|
|
10
|
+
copyFromChannel(destination: number[], channelNumber: number, startInChannel?: number): void;
|
|
11
|
+
copyToChannel(source: number[], channelNumber: number, startInChannel?: number): void;
|
|
12
|
+
}
|
|
13
|
+
export declare class AudioNode {
|
|
14
|
+
readonly context: AudioContext;
|
|
15
|
+
readonly numberOfInputs: number;
|
|
16
|
+
readonly numberOfOutputs: number;
|
|
17
|
+
readonly channelCount: number;
|
|
18
|
+
readonly channelCountMode: ChannelCountMode;
|
|
19
|
+
readonly channelInterpretation: ChannelInterpretation;
|
|
20
|
+
protected readonly node: globalThis.AudioNode;
|
|
21
|
+
constructor(context: AudioContext, node: globalThis.AudioNode);
|
|
22
|
+
connect(node: AudioNode): void;
|
|
23
|
+
disconnect(node: AudioNode): void;
|
|
24
|
+
}
|
|
25
|
+
export declare class AudioScheduledSourceNode extends AudioNode {
|
|
26
|
+
private hasBeenStarted;
|
|
27
|
+
constructor(context: AudioContext, node: globalThis.AudioScheduledSourceNode);
|
|
28
|
+
start(when?: number): void;
|
|
29
|
+
stop(when?: number): void;
|
|
30
|
+
}
|
|
31
|
+
export declare class AudioBufferSourceNode extends AudioScheduledSourceNode {
|
|
32
|
+
constructor(context: AudioContext, node: globalThis.AudioBufferSourceNode);
|
|
33
|
+
get buffer(): AudioBuffer | null;
|
|
34
|
+
set buffer(buffer: AudioBuffer | null);
|
|
35
|
+
get loop(): boolean;
|
|
36
|
+
set loop(value: boolean);
|
|
37
|
+
}
|
|
38
|
+
export declare class AudioDestinationNode extends AudioNode {
|
|
39
|
+
constructor(context: AudioContext, node: globalThis.AudioDestinationNode);
|
|
40
|
+
}
|
|
41
|
+
export declare class AudioParam {
|
|
42
|
+
readonly defaultValue: number;
|
|
43
|
+
readonly minValue: number;
|
|
44
|
+
readonly maxValue: number;
|
|
45
|
+
private readonly param;
|
|
46
|
+
constructor(param: globalThis.AudioParam);
|
|
47
|
+
get value(): number;
|
|
48
|
+
set value(value: number);
|
|
49
|
+
setValueAtTime(value: number, startTime: number): void;
|
|
50
|
+
linearRampToValueAtTime(value: number, endTime: number): void;
|
|
51
|
+
exponentialRampToValueAtTime(value: number, endTime: number): void;
|
|
52
|
+
}
|
|
53
|
+
export declare class BiquadFilterNode extends AudioNode {
|
|
54
|
+
readonly frequency: AudioParam;
|
|
55
|
+
readonly detune: AudioParam;
|
|
56
|
+
readonly Q: AudioParam;
|
|
57
|
+
readonly gain: AudioParam;
|
|
58
|
+
constructor(context: AudioContext, biquadFilter: globalThis.BiquadFilterNode);
|
|
59
|
+
get type(): BiquadFilterType;
|
|
60
|
+
set type(value: BiquadFilterType);
|
|
61
|
+
getFrequencyResponse(frequencyArray: number[], magResponseOutput: number[], phaseResponseOutput: number[]): void;
|
|
62
|
+
}
|
|
63
|
+
export declare class PeriodicWave {
|
|
64
|
+
readonly periodicWave: globalThis.PeriodicWave;
|
|
65
|
+
constructor(periodicWave: globalThis.PeriodicWave);
|
|
66
|
+
}
|
|
67
|
+
export declare class OscillatorNode extends AudioScheduledSourceNode {
|
|
68
|
+
readonly frequency: AudioParam;
|
|
69
|
+
readonly detune: AudioParam;
|
|
70
|
+
constructor(context: AudioContext, node: globalThis.OscillatorNode);
|
|
71
|
+
get type(): OscillatorType;
|
|
72
|
+
set type(value: OscillatorType);
|
|
73
|
+
setPeriodicWave(wave: PeriodicWave): void;
|
|
74
|
+
}
|
|
75
|
+
export declare class GainNode extends AudioNode {
|
|
76
|
+
readonly gain: AudioParam;
|
|
77
|
+
constructor(context: AudioContext, gain: globalThis.GainNode);
|
|
78
|
+
}
|
|
79
|
+
export declare class StereoPannerNode extends AudioNode {
|
|
80
|
+
readonly pan: AudioParam;
|
|
81
|
+
constructor(context: AudioContext, pan: globalThis.StereoPannerNode);
|
|
82
|
+
}
|
|
83
|
+
export declare class AudioContext {
|
|
84
|
+
protected readonly context: globalThis.AudioContext;
|
|
3
85
|
readonly destination: AudioDestinationNode;
|
|
4
86
|
readonly sampleRate: number;
|
|
5
|
-
private readonly __AudioContext;
|
|
6
87
|
constructor();
|
|
7
88
|
get currentTime(): number;
|
|
8
|
-
get state():
|
|
89
|
+
get state(): ContextState;
|
|
9
90
|
createOscillator(): OscillatorNode;
|
|
10
91
|
createGain(): GainNode;
|
|
11
92
|
createStereoPanner(): StereoPannerNode;
|
|
12
93
|
createBiquadFilter(): BiquadFilterNode;
|
|
13
94
|
createBufferSource(): AudioBufferSourceNode;
|
|
14
95
|
createBuffer(numOfChannels: number, length: number, sampleRate: number): AudioBuffer;
|
|
96
|
+
createPeriodicWave(real: number[], imag: number[], constraints?: PeriodicWaveConstraints): PeriodicWave;
|
|
97
|
+
decodeAudioDataSource(source: AudioSource | number): Promise<AudioBuffer>;
|
|
15
98
|
close(): void;
|
|
16
99
|
}
|
|
17
|
-
export
|
|
100
|
+
export { ContextState, OscillatorType, BiquadFilterType, ChannelCountMode, ChannelInterpretation, } from './core/types';
|
|
18
101
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,YAAY,EACZ,uBAAuB,EACxB,MAAM,cAAc,CAAC;AAEtB,qBAAa,WAAW;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAElC,SAAgB,MAAM,EAAE,UAAU,CAAC,WAAW,CAAC;gBAEnC,MAAM,EAAE,UAAU,CAAC,WAAW;IAQnC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAWzC,eAAe,CACpB,WAAW,EAAE,MAAM,EAAE,EACrB,aAAa,EAAE,MAAM,EACrB,cAAc,GAAE,MAAU,GACzB,IAAI;IAoBA,aAAa,CAClB,MAAM,EAAE,MAAM,EAAE,EAChB,aAAa,EAAE,MAAM,EACrB,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;AAED,OAAO,EACL,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { default as AudioBuffer } from './core/AudioBuffer';
|
|
2
|
+
export { default as AudioBufferSourceNode } from './core/AudioBufferSourceNode';
|
|
3
|
+
export { default as AudioContext } from './core/AudioContext';
|
|
4
|
+
export { default as AudioDestinationNode } from './core/AudioDestinationNode';
|
|
5
|
+
export { default as AudioNode } from './core/AudioNode';
|
|
6
|
+
export { default as AudioParam } from './core/AudioParam';
|
|
7
|
+
export { default as AudioScheduledSourceNode } from './core/AudioScheduledSourceNode';
|
|
8
|
+
export { default as BaseAudioContext } from './core/BaseAudioContext';
|
|
9
|
+
export { default as BiquadFilterNode } from './core/BiquadFilterNode';
|
|
10
|
+
export { default as GainNode } from './core/GainNode';
|
|
11
|
+
export { default as OscillatorNode } from './core/OscillatorNode';
|
|
12
|
+
export { default as StereoPannerNode } from './core/StereoPannerNode';
|
|
13
|
+
export { OscillatorType, BiquadFilterType, ChannelCountMode, ChannelInterpretation, ContextState, } from './core/types';
|
|
14
|
+
//# sourceMappingURL=index.native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.native.d.ts","sourceRoot":"","sources":["../../src/index.native.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAChF,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AACtF,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,YAAY,GACb,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ContextState, BiquadFilterType, OscillatorType, ChannelCountMode, ChannelInterpretation } from './core/types';
|
|
2
|
+
export interface IBaseAudioContext {
|
|
3
|
+
readonly destination: IAudioDestinationNode;
|
|
4
|
+
readonly state: ContextState;
|
|
5
|
+
readonly sampleRate: number;
|
|
6
|
+
readonly currentTime: number;
|
|
7
|
+
createOscillator(): IOscillatorNode;
|
|
8
|
+
createGain(): IGainNode;
|
|
9
|
+
createStereoPanner(): IStereoPannerNode;
|
|
10
|
+
createBiquadFilter: () => IBiquadFilterNode;
|
|
11
|
+
createBufferSource: () => IAudioBufferSourceNode;
|
|
12
|
+
createBuffer: (channels: number, length: number, sampleRate: number) => IAudioBuffer;
|
|
13
|
+
createPeriodicWave: (real: number[], imag: number[], disableNormalization: boolean) => IPeriodicWave;
|
|
14
|
+
decodeAudioDataSource: (source: string) => Promise<IAudioBuffer>;
|
|
15
|
+
}
|
|
16
|
+
export interface IAudioContext extends IBaseAudioContext {
|
|
17
|
+
close(): void;
|
|
18
|
+
}
|
|
19
|
+
export interface IAudioNode {
|
|
20
|
+
readonly context: BaseAudioContext;
|
|
21
|
+
readonly numberOfInputs: number;
|
|
22
|
+
readonly numberOfOutputs: number;
|
|
23
|
+
readonly channelCount: number;
|
|
24
|
+
readonly channelCountMode: ChannelCountMode;
|
|
25
|
+
readonly channelInterpretation: ChannelInterpretation;
|
|
26
|
+
connect: (node: IAudioNode) => void;
|
|
27
|
+
disconnect: (node: IAudioNode) => void;
|
|
28
|
+
}
|
|
29
|
+
export interface IGainNode extends IAudioNode {
|
|
30
|
+
readonly gain: IAudioParam;
|
|
31
|
+
}
|
|
32
|
+
export interface IStereoPannerNode extends IAudioNode {
|
|
33
|
+
readonly pan: IAudioParam;
|
|
34
|
+
}
|
|
35
|
+
export interface IBiquadFilterNode extends IAudioNode {
|
|
36
|
+
readonly frequency: AudioParam;
|
|
37
|
+
readonly detune: AudioParam;
|
|
38
|
+
readonly Q: AudioParam;
|
|
39
|
+
readonly gain: AudioParam;
|
|
40
|
+
type: BiquadFilterType;
|
|
41
|
+
getFrequencyResponse(frequencyArray: number[], magResponseOutput: number[], phaseResponseOutput: number[]): void;
|
|
42
|
+
}
|
|
43
|
+
export interface IAudioDestinationNode extends IAudioNode {
|
|
44
|
+
}
|
|
45
|
+
export interface IAudioScheduledSourceNode extends IAudioNode {
|
|
46
|
+
start: (time: number) => void;
|
|
47
|
+
stop: (time: number) => void;
|
|
48
|
+
}
|
|
49
|
+
export interface IOscillatorNode extends IAudioScheduledSourceNode {
|
|
50
|
+
readonly frequency: IAudioParam;
|
|
51
|
+
readonly detune: IAudioParam;
|
|
52
|
+
type: OscillatorType;
|
|
53
|
+
setPeriodicWave(periodicWave: IPeriodicWave): void;
|
|
54
|
+
}
|
|
55
|
+
export interface IAudioBufferSourceNode extends IAudioScheduledSourceNode {
|
|
56
|
+
buffer: IAudioBuffer | null;
|
|
57
|
+
loop: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface IAudioBuffer {
|
|
60
|
+
readonly length: number;
|
|
61
|
+
readonly duration: number;
|
|
62
|
+
readonly sampleRate: number;
|
|
63
|
+
readonly numberOfChannels: number;
|
|
64
|
+
getChannelData(channel: number): number[];
|
|
65
|
+
copyFromChannel(destination: number[], channelNumber: number, startInChannel: number): void;
|
|
66
|
+
copyToChannel(source: number[], channelNumber: number, startInChannel: number): void;
|
|
67
|
+
}
|
|
68
|
+
export interface IAudioParam {
|
|
69
|
+
value: number;
|
|
70
|
+
defaultValue: number;
|
|
71
|
+
minValue: number;
|
|
72
|
+
maxValue: number;
|
|
73
|
+
setValueAtTime: (value: number, startTime: number) => void;
|
|
74
|
+
linearRampToValueAtTime: (value: number, endTime: number) => void;
|
|
75
|
+
exponentialRampToValueAtTime: (value: number, endTime: number) => void;
|
|
76
|
+
}
|
|
77
|
+
export interface IPeriodicWave {
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,WAAW,EAAE,qBAAqB,CAAC;IAC5C,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B,gBAAgB,IAAI,eAAe,CAAC;IACpC,UAAU,IAAI,SAAS,CAAC;IACxB,kBAAkB,IAAI,iBAAiB,CAAC;IACxC,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;IAC5C,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;IACjD,YAAY,EAAE,CACZ,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,KACf,YAAY,CAAC;IAClB,kBAAkB,EAAE,CAClB,IA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EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3D,uBAAuB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAClE,4BAA4B,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACxE;AAED,MAAM,WAAW,aAAa;CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveAudioSource.d.ts","sourceRoot":"","sources":["../../../src/utils/resolveAudioSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAK5C,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,WAAW,GAAG,MAAM,GAAG,MAAM,GACpC,WAAW,CAMb"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-audio-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-rc1",
|
|
4
4
|
"description": "react-native-audio-api provides system for controlling audio in React Native environment compatible with Web Audio API specification",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -45,7 +45,9 @@
|
|
|
45
45
|
"keywords": [
|
|
46
46
|
"react-native",
|
|
47
47
|
"audio",
|
|
48
|
-
"audio
|
|
48
|
+
"audio api",
|
|
49
|
+
"web audio api",
|
|
50
|
+
"react"
|
|
49
51
|
],
|
|
50
52
|
"repository": {
|
|
51
53
|
"type": "git",
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { IAudioBuffer } from '../interfaces';
|
|
2
|
+
import { IndexSizeError } from '../errors';
|
|
3
|
+
|
|
4
|
+
export default class AudioBuffer {
|
|
5
|
+
readonly length: number;
|
|
6
|
+
readonly duration: number;
|
|
7
|
+
readonly sampleRate: number;
|
|
8
|
+
readonly numberOfChannels: number;
|
|
9
|
+
/** @internal */
|
|
10
|
+
public readonly buffer: IAudioBuffer;
|
|
11
|
+
|
|
12
|
+
constructor(buffer: IAudioBuffer) {
|
|
13
|
+
this.buffer = buffer;
|
|
14
|
+
this.length = buffer.length;
|
|
15
|
+
this.duration = buffer.duration;
|
|
16
|
+
this.sampleRate = buffer.sampleRate;
|
|
17
|
+
this.numberOfChannels = buffer.numberOfChannels;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public getChannelData(channel: number): number[] {
|
|
21
|
+
if (channel < 0 || channel >= this.numberOfChannels) {
|
|
22
|
+
throw new IndexSizeError(
|
|
23
|
+
`The channel number provided (${channel}) is outside the range [0, ${this.numberOfChannels - 1}]`
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
return this.buffer.getChannelData(channel);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public copyFromChannel(
|
|
30
|
+
destination: number[],
|
|
31
|
+
channelNumber: number,
|
|
32
|
+
startInChannel: number = 0
|
|
33
|
+
): void {
|
|
34
|
+
if (channelNumber < 0 || channelNumber >= this.numberOfChannels) {
|
|
35
|
+
throw new IndexSizeError(
|
|
36
|
+
`The channel number provided (${channelNumber}) is outside the range [0, ${this.numberOfChannels - 1}]`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (startInChannel < 0 || startInChannel >= this.length) {
|
|
41
|
+
throw new IndexSizeError(
|
|
42
|
+
`The startInChannel number provided (${startInChannel}) is outside the range [0, ${this.length - 1}]`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this.buffer.copyFromChannel(destination, channelNumber, startInChannel);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public copyToChannel(
|
|
50
|
+
source: number[],
|
|
51
|
+
channelNumber: number,
|
|
52
|
+
startInChannel: number = 0
|
|
53
|
+
): void {
|
|
54
|
+
if (channelNumber < 0 || channelNumber >= this.numberOfChannels) {
|
|
55
|
+
throw new IndexSizeError(
|
|
56
|
+
`The channel number provided (${channelNumber}) is outside the range [0, ${this.numberOfChannels - 1}]`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (startInChannel < 0 || startInChannel >= this.length) {
|
|
61
|
+
throw new IndexSizeError(
|
|
62
|
+
`The startInChannel number provided (${startInChannel}) is outside the range [0, ${this.length - 1}]`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
this.buffer.copyToChannel(source, channelNumber, startInChannel);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { IAudioBufferSourceNode } from '../interfaces';
|
|
2
|
+
import AudioScheduledSourceNode from './AudioScheduledSourceNode';
|
|
3
|
+
import BaseAudioContext from './BaseAudioContext';
|
|
4
|
+
import AudioBuffer from './AudioBuffer';
|
|
5
|
+
|
|
6
|
+
export default class AudioBufferSourceNode extends AudioScheduledSourceNode {
|
|
7
|
+
constructor(context: BaseAudioContext, node: IAudioBufferSourceNode) {
|
|
8
|
+
super(context, node);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public get buffer(): AudioBuffer | null {
|
|
12
|
+
const buffer = (this.node as IAudioBufferSourceNode).buffer;
|
|
13
|
+
if (!buffer) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return new AudioBuffer(buffer);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public set buffer(buffer: AudioBuffer | null) {
|
|
20
|
+
if (!buffer) {
|
|
21
|
+
(this.node as IAudioBufferSourceNode).buffer = null;
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
(this.node as IAudioBufferSourceNode).buffer = buffer.buffer;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public get loop(): boolean {
|
|
29
|
+
return (this.node as IAudioBufferSourceNode).loop;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public set loop(value: boolean) {
|
|
33
|
+
(this.node as IAudioBufferSourceNode).loop = value;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IAudioContext } from '../interfaces';
|
|
2
|
+
import BaseAudioContext from './BaseAudioContext';
|
|
3
|
+
|
|
4
|
+
export default class AudioContext extends BaseAudioContext {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(global.__AudioAPIInstaller.createAudioContext());
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
close(): void {
|
|
10
|
+
(this.context as IAudioContext).close();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IAudioDestinationNode } from '../interfaces';
|
|
2
|
+
import AudioNode from './AudioNode';
|
|
3
|
+
import BaseAudioContext from './BaseAudioContext';
|
|
4
|
+
|
|
5
|
+
export default class AudioDestinationNode extends AudioNode {
|
|
6
|
+
constructor(context: BaseAudioContext, destination: IAudioDestinationNode) {
|
|
7
|
+
super(context, destination);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { IAudioNode } from '../interfaces';
|
|
2
|
+
import { ChannelCountMode, ChannelInterpretation } from './types';
|
|
3
|
+
import BaseAudioContext from './BaseAudioContext';
|
|
4
|
+
import { InvalidAccessError } from '../errors';
|
|
5
|
+
|
|
6
|
+
export default class AudioNode {
|
|
7
|
+
readonly context: BaseAudioContext;
|
|
8
|
+
readonly numberOfInputs: number;
|
|
9
|
+
readonly numberOfOutputs: number;
|
|
10
|
+
readonly channelCount: number;
|
|
11
|
+
readonly channelCountMode: ChannelCountMode;
|
|
12
|
+
readonly channelInterpretation: ChannelInterpretation;
|
|
13
|
+
protected readonly node: IAudioNode;
|
|
14
|
+
|
|
15
|
+
constructor(context: BaseAudioContext, node: IAudioNode) {
|
|
16
|
+
this.context = context;
|
|
17
|
+
this.node = node;
|
|
18
|
+
this.numberOfInputs = this.node.numberOfInputs;
|
|
19
|
+
this.numberOfOutputs = this.node.numberOfOutputs;
|
|
20
|
+
this.channelCount = this.node.channelCount;
|
|
21
|
+
this.channelCountMode = this.node.channelCountMode;
|
|
22
|
+
this.channelInterpretation = this.node.channelInterpretation;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public connect(node: AudioNode): void {
|
|
26
|
+
if (this.context !== node.context) {
|
|
27
|
+
throw new InvalidAccessError(
|
|
28
|
+
'The AudioNodes are from different BaseAudioContexts'
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
this.node.connect(node.node);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public disconnect(node: AudioNode): void {
|
|
36
|
+
this.node.disconnect(node.node);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { IAudioParam } from '../interfaces';
|
|
2
|
+
import { RangeError } from '../errors';
|
|
3
|
+
|
|
4
|
+
export default class AudioParam {
|
|
5
|
+
readonly defaultValue: number;
|
|
6
|
+
readonly minValue: number;
|
|
7
|
+
readonly maxValue: number;
|
|
8
|
+
private readonly audioParam: IAudioParam;
|
|
9
|
+
|
|
10
|
+
constructor(audioParam: IAudioParam) {
|
|
11
|
+
this.audioParam = audioParam;
|
|
12
|
+
this.value = audioParam.value;
|
|
13
|
+
this.defaultValue = audioParam.defaultValue;
|
|
14
|
+
this.minValue = audioParam.minValue;
|
|
15
|
+
this.maxValue = audioParam.maxValue;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public get value(): number {
|
|
19
|
+
return this.audioParam.value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public set value(value: number) {
|
|
23
|
+
this.audioParam.value = value;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public setValueAtTime(value: number, startTime: number): void {
|
|
27
|
+
if (startTime < 0) {
|
|
28
|
+
throw new RangeError(
|
|
29
|
+
`Time must be a finite non-negative number: ${startTime}`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
this.audioParam.setValueAtTime(value, startTime);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public linearRampToValueAtTime(value: number, endTime: number): void {
|
|
37
|
+
if (endTime < 0) {
|
|
38
|
+
throw new RangeError(
|
|
39
|
+
`Time must be a finite non-negative number: ${endTime}`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
this.audioParam.linearRampToValueAtTime(value, endTime);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public exponentialRampToValueAtTime(value: number, endTime: number): void {
|
|
47
|
+
if (endTime < 0) {
|
|
48
|
+
throw new RangeError(
|
|
49
|
+
`Time must be a finite non-negative number: ${endTime}`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
this.audioParam.exponentialRampToValueAtTime(value, endTime);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { IAudioScheduledSourceNode } from '../interfaces';
|
|
2
|
+
import AudioNode from './AudioNode';
|
|
3
|
+
import BaseAudioContext from './BaseAudioContext';
|
|
4
|
+
import { InvalidStateError, RangeError } from '../errors';
|
|
5
|
+
|
|
6
|
+
export default class AudioScheduledSourceNode extends AudioNode {
|
|
7
|
+
private hasBeenStarted: boolean = false;
|
|
8
|
+
|
|
9
|
+
constructor(context: BaseAudioContext, node: IAudioScheduledSourceNode) {
|
|
10
|
+
super(context, node);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public start(when: number = 0): void {
|
|
14
|
+
if (when < 0) {
|
|
15
|
+
throw new RangeError(
|
|
16
|
+
`Time must be a finite non-negative number: ${when}`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (this.hasBeenStarted) {
|
|
21
|
+
throw new InvalidStateError('Cannot call start more than once');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
this.hasBeenStarted = true;
|
|
25
|
+
(this.node as IAudioScheduledSourceNode).start(when);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public stop(when: number = 0): void {
|
|
29
|
+
if (when < 0) {
|
|
30
|
+
throw new RangeError(
|
|
31
|
+
`Time must be a finite non-negative number: ${when}`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!this.hasBeenStarted) {
|
|
36
|
+
throw new InvalidStateError(
|
|
37
|
+
'Cannot call stop without calling start first'
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
(this.node as IAudioScheduledSourceNode).stop(when);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { IBaseAudioContext } from '../interfaces';
|
|
2
|
+
import { ContextState, PeriodicWaveConstraints, AudioSource } from './types';
|
|
3
|
+
import AudioDestinationNode from './AudioDestinationNode';
|
|
4
|
+
import OscillatorNode from './OscillatorNode';
|
|
5
|
+
import GainNode from './GainNode';
|
|
6
|
+
import StereoPannerNode from './StereoPannerNode';
|
|
7
|
+
import BiquadFilterNode from './BiquadFilterNode';
|
|
8
|
+
import AudioBufferSourceNode from './AudioBufferSourceNode';
|
|
9
|
+
import AudioBuffer from './AudioBuffer';
|
|
10
|
+
import PeriodicWave from './PeriodicWave';
|
|
11
|
+
import { InvalidAccessError } from '../errors';
|
|
12
|
+
import { resolveAudioSource } from '../utils/resolveAudioSource';
|
|
13
|
+
|
|
14
|
+
export default class BaseAudioContext {
|
|
15
|
+
readonly destination: AudioDestinationNode;
|
|
16
|
+
readonly sampleRate: number;
|
|
17
|
+
protected readonly context: IBaseAudioContext;
|
|
18
|
+
|
|
19
|
+
constructor(context: IBaseAudioContext) {
|
|
20
|
+
this.context = context;
|
|
21
|
+
this.destination = new AudioDestinationNode(this, context.destination);
|
|
22
|
+
this.sampleRate = context.sampleRate;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public get currentTime(): number {
|
|
26
|
+
return this.context.currentTime;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public get state(): ContextState {
|
|
30
|
+
return this.context.state;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
createOscillator(): OscillatorNode {
|
|
34
|
+
return new OscillatorNode(this, this.context.createOscillator());
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
createGain(): GainNode {
|
|
38
|
+
return new GainNode(this, this.context.createGain());
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
createStereoPanner(): StereoPannerNode {
|
|
42
|
+
return new StereoPannerNode(this, this.context.createStereoPanner());
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
createBiquadFilter(): BiquadFilterNode {
|
|
46
|
+
return new BiquadFilterNode(this, this.context.createBiquadFilter());
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
createBufferSource(): AudioBufferSourceNode {
|
|
50
|
+
return new AudioBufferSourceNode(this, this.context.createBufferSource());
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
createBuffer(
|
|
54
|
+
numOfChannels: number,
|
|
55
|
+
length: number,
|
|
56
|
+
sampleRate: number
|
|
57
|
+
): AudioBuffer {
|
|
58
|
+
if (numOfChannels < 1 || numOfChannels > 3) {
|
|
59
|
+
throw new RangeError(
|
|
60
|
+
`The number of channels provided (${numOfChannels}) is outside the range [1, 2]`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (length <= 0) {
|
|
65
|
+
throw new RangeError(
|
|
66
|
+
`The number of frames provided (${length}) is less than or equal to the minimum bound (0)`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (sampleRate <= 0) {
|
|
71
|
+
throw new RangeError(
|
|
72
|
+
`The sample rate provided (${sampleRate}) is outside the range [3000, 768000]`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return new AudioBuffer(
|
|
77
|
+
this.context.createBuffer(numOfChannels, length, sampleRate)
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
createPeriodicWave(
|
|
82
|
+
real: number[],
|
|
83
|
+
imag: number[],
|
|
84
|
+
constraints?: PeriodicWaveConstraints
|
|
85
|
+
): PeriodicWave {
|
|
86
|
+
if (real.length !== imag.length) {
|
|
87
|
+
throw new InvalidAccessError(
|
|
88
|
+
`The lengths of the real (${real.length}) and imaginary (${imag.length}) arrays must match.`
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const disableNormalization = constraints?.disableNormalization ?? false;
|
|
93
|
+
|
|
94
|
+
return new PeriodicWave(
|
|
95
|
+
this.context.createPeriodicWave(real, imag, disableNormalization)
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async decodeAudioDataSource(
|
|
100
|
+
source: AudioSource | number
|
|
101
|
+
): Promise<AudioBuffer> {
|
|
102
|
+
const buffer = await this.context.decodeAudioDataSource(
|
|
103
|
+
resolveAudioSource(source)
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
return new AudioBuffer(buffer);
|
|
107
|
+
}
|
|
108
|
+
}
|