react-native-audio-api 0.0.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/README.md +60 -1
- package/RNAudioAPI.podspec +46 -0
- package/android/CMakeLists.txt +74 -0
- package/android/build.gradle +194 -0
- package/android/gradle.properties +5 -0
- 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/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/cpp/AudioAPIInstaller/AudioAPIInstaller.cpp +22 -0
- package/android/src/main/cpp/AudioAPIInstaller/AudioAPIInstaller.h +48 -0
- package/android/src/main/cpp/AudioPlayer/AudioPlayer.cpp +66 -0
- package/android/src/main/cpp/AudioPlayer/AudioPlayer.h +33 -0
- package/android/src/main/cpp/OnLoad.cpp +9 -0
- package/android/src/main/java/com/swmansion/audioapi/AudioAPIPackage.kt +14 -0
- package/android/src/main/java/com/swmansion/audioapi/module/AudioAPIInstaller.kt +21 -0
- package/android/src/main/java/com/swmansion/audioapi/nativemodules/AudioAPIModule.kt +25 -0
- package/common/cpp/AudioAPIInstaller/AudioAPIInstallerHostObject.cpp +52 -0
- package/common/cpp/AudioAPIInstaller/AudioAPIInstallerHostObject.h +45 -0
- package/common/cpp/AudioAPIInstaller/AudioAPIInstallerWrapper.h +38 -0
- package/common/cpp/AudioAPIInstaller/android/AudioAPIInstallerWrapper.cpp +16 -0
- package/common/cpp/AudioAPIInstaller/ios/AudioAPIInstallerWrapper.cpp +12 -0
- package/common/cpp/HostObjects/AudioBufferHostObject.cpp +143 -0
- package/common/cpp/HostObjects/AudioBufferHostObject.h +33 -0
- package/common/cpp/HostObjects/AudioBufferSourceNodeHostObject.cpp +79 -0
- package/common/cpp/HostObjects/AudioBufferSourceNodeHostObject.h +37 -0
- package/common/cpp/HostObjects/AudioContextHostObject.cpp +54 -0
- package/common/cpp/HostObjects/AudioContextHostObject.h +36 -0
- package/common/cpp/HostObjects/AudioDestinationNodeHostObject.cpp +33 -0
- package/common/cpp/HostObjects/AudioDestinationNodeHostObject.h +31 -0
- package/common/cpp/HostObjects/AudioNodeHostObject.cpp +102 -0
- package/common/cpp/HostObjects/AudioNodeHostObject.h +29 -0
- package/common/cpp/HostObjects/AudioParamHostObject.cpp +115 -0
- package/common/cpp/HostObjects/AudioParamHostObject.h +34 -0
- package/common/cpp/HostObjects/AudioScheduledSourceNodeHostObject.cpp +73 -0
- package/common/cpp/HostObjects/AudioScheduledSourceNodeHostObject.h +31 -0
- package/common/cpp/HostObjects/BaseAudioContextHostObject.cpp +214 -0
- package/common/cpp/HostObjects/BaseAudioContextHostObject.h +39 -0
- package/common/cpp/HostObjects/BiquadFilterNodeHostObject.cpp +125 -0
- package/common/cpp/HostObjects/BiquadFilterNodeHostObject.h +42 -0
- package/common/cpp/HostObjects/Constants.h +22 -0
- package/common/cpp/HostObjects/GainNodeHostObject.cpp +41 -0
- package/common/cpp/HostObjects/GainNodeHostObject.h +32 -0
- package/common/cpp/HostObjects/OscillatorNodeHostObject.cpp +88 -0
- package/common/cpp/HostObjects/OscillatorNodeHostObject.h +41 -0
- package/common/cpp/HostObjects/PeriodicWaveHostObject.cpp +33 -0
- package/common/cpp/HostObjects/PeriodicWaveHostObject.h +33 -0
- package/common/cpp/HostObjects/StereoPannerNodeHostObject.cpp +41 -0
- package/common/cpp/HostObjects/StereoPannerNodeHostObject.h +36 -0
- package/common/cpp/core/AudioArray.cpp +103 -0
- package/common/cpp/core/AudioArray.h +42 -0
- package/common/cpp/core/AudioBuffer.cpp +55 -0
- package/common/cpp/core/AudioBuffer.h +40 -0
- package/common/cpp/core/AudioBufferSourceNode.cpp +135 -0
- package/common/cpp/core/AudioBufferSourceNode.h +30 -0
- package/common/cpp/core/AudioBus.cpp +357 -0
- package/common/cpp/core/AudioBus.h +63 -0
- package/common/cpp/core/AudioContext.cpp +24 -0
- package/common/cpp/core/AudioContext.h +16 -0
- package/common/cpp/core/AudioDestinationNode.cpp +45 -0
- package/common/cpp/core/AudioDestinationNode.h +32 -0
- package/common/cpp/core/AudioNode.cpp +222 -0
- package/common/cpp/core/AudioNode.h +74 -0
- package/common/cpp/core/AudioNodeManager.cpp +72 -0
- package/common/cpp/core/AudioNodeManager.h +35 -0
- package/common/cpp/core/AudioParam.cpp +133 -0
- package/common/cpp/core/AudioParam.h +50 -0
- package/common/cpp/core/AudioScheduledSourceNode.cpp +53 -0
- package/common/cpp/core/AudioScheduledSourceNode.h +34 -0
- package/common/cpp/core/BaseAudioContext.cpp +157 -0
- package/common/cpp/core/BaseAudioContext.h +80 -0
- package/common/cpp/core/BiquadFilterNode.cpp +385 -0
- package/common/cpp/core/BiquadFilterNode.h +124 -0
- package/common/cpp/core/GainNode.cpp +30 -0
- package/common/cpp/core/GainNode.h +25 -0
- package/common/cpp/core/OscillatorNode.cpp +75 -0
- package/common/cpp/core/OscillatorNode.h +72 -0
- package/common/cpp/core/ParamChange.cpp +46 -0
- package/common/cpp/core/ParamChange.h +34 -0
- package/common/cpp/core/PeriodicWave.cpp +362 -0
- package/common/cpp/core/PeriodicWave.h +119 -0
- package/common/cpp/core/StereoPannerNode.cpp +56 -0
- package/common/cpp/core/StereoPannerNode.h +26 -0
- 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 +63 -0
- package/common/cpp/utils/Locker.h +47 -0
- package/common/cpp/utils/VectorMath.cpp +678 -0
- package/common/cpp/utils/VectorMath.h +71 -0
- package/common/cpp/utils/android/FFTFrame.cpp +22 -0
- package/common/cpp/utils/ios/FFTFrame.cpp +24 -0
- package/common/cpp/wrappers/AudioBufferSourceNodeWrapper.cpp +45 -0
- package/common/cpp/wrappers/AudioBufferSourceNodeWrapper.h +26 -0
- package/common/cpp/wrappers/AudioBufferWrapper.cpp +46 -0
- package/common/cpp/wrappers/AudioBufferWrapper.h +30 -0
- package/common/cpp/wrappers/AudioContextWrapper.cpp +17 -0
- package/common/cpp/wrappers/AudioContextWrapper.h +19 -0
- package/common/cpp/wrappers/AudioDestinationNodeWrapper.h +16 -0
- package/common/cpp/wrappers/AudioNodeWrapper.cpp +37 -0
- package/common/cpp/wrappers/AudioNodeWrapper.h +25 -0
- package/common/cpp/wrappers/AudioParamWrapper.cpp +42 -0
- package/common/cpp/wrappers/AudioParamWrapper.h +25 -0
- package/common/cpp/wrappers/AudioScheduledSourceNodeWrapper.cpp +23 -0
- package/common/cpp/wrappers/AudioScheduledSourceNodeWrapper.h +23 -0
- package/common/cpp/wrappers/BaseAudioContextWrapper.cpp +76 -0
- package/common/cpp/wrappers/BaseAudioContextWrapper.h +49 -0
- package/common/cpp/wrappers/BiquadFilterNodeWrapper.cpp +60 -0
- package/common/cpp/wrappers/BiquadFilterNodeWrapper.h +37 -0
- package/common/cpp/wrappers/GainNodeWrapper.cpp +14 -0
- package/common/cpp/wrappers/GainNodeWrapper.h +20 -0
- package/common/cpp/wrappers/OscillatorNodeWrapper.cpp +44 -0
- package/common/cpp/wrappers/OscillatorNodeWrapper.h +31 -0
- package/common/cpp/wrappers/PeriodicWaveWrapper.h +17 -0
- package/common/cpp/wrappers/StereoPannerNodeWrapper.cpp +16 -0
- package/common/cpp/wrappers/StereoPannerNodeWrapper.h +21 -0
- package/ios/AudioAPIModule.h +24 -0
- package/ios/AudioAPIModule.mm +44 -0
- package/ios/AudioPlayer/AudioPlayer.h +28 -0
- package/ios/AudioPlayer/AudioPlayer.m +119 -0
- package/ios/AudioPlayer/IOSAudioPlayer.h +33 -0
- package/ios/AudioPlayer/IOSAudioPlayer.mm +57 -0
- 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 +57 -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 +2 -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 +18 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/interfaces.js +2 -0
- package/lib/module/interfaces.js.map +1 -0
- package/lib/module/modules/global.d.js +2 -0
- package/lib/module/modules/global.d.js.map +1 -0
- package/lib/module/utils/install.js +22 -0
- package/lib/module/utils/install.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 +26 -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 +9 -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 +14 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/interfaces.d.ts +78 -0
- package/lib/typescript/interfaces.d.ts.map +1 -0
- package/lib/typescript/utils/install.d.ts +7 -0
- package/lib/typescript/utils/install.d.ts.map +1 -0
- package/package.json +104 -5
- 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 +97 -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 +26 -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.ts +25 -0
- package/src/interfaces.ts +120 -0
- package/src/modules/global.d.ts +10 -0
- package/src/utils/install.ts +39 -0
- package/index.ts +0 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { IBaseAudioContext } from '../interfaces';
|
|
2
|
+
import { ContextState, PeriodicWaveConstraints } 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
|
+
|
|
13
|
+
export default class BaseAudioContext {
|
|
14
|
+
readonly destination: AudioDestinationNode;
|
|
15
|
+
readonly sampleRate: number;
|
|
16
|
+
protected readonly context: IBaseAudioContext;
|
|
17
|
+
|
|
18
|
+
constructor(context: IBaseAudioContext) {
|
|
19
|
+
this.context = context;
|
|
20
|
+
this.destination = new AudioDestinationNode(this, context.destination);
|
|
21
|
+
this.sampleRate = context.sampleRate;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public get currentTime(): number {
|
|
25
|
+
return this.context.currentTime;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public get state(): ContextState {
|
|
29
|
+
return this.context.state;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
createOscillator(): OscillatorNode {
|
|
33
|
+
return new OscillatorNode(this, this.context.createOscillator());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
createGain(): GainNode {
|
|
37
|
+
return new GainNode(this, this.context.createGain());
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
createStereoPanner(): StereoPannerNode {
|
|
41
|
+
return new StereoPannerNode(this, this.context.createStereoPanner());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
createBiquadFilter(): BiquadFilterNode {
|
|
45
|
+
return new BiquadFilterNode(this, this.context.createBiquadFilter());
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
createBufferSource(): AudioBufferSourceNode {
|
|
49
|
+
return new AudioBufferSourceNode(this, this.context.createBufferSource());
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
createBuffer(
|
|
53
|
+
numOfChannels: number,
|
|
54
|
+
length: number,
|
|
55
|
+
sampleRate: number
|
|
56
|
+
): AudioBuffer {
|
|
57
|
+
if (numOfChannels < 1 || numOfChannels > 3) {
|
|
58
|
+
throw new RangeError(
|
|
59
|
+
`The number of channels provided (${numOfChannels}) is outside the range [1, 2]`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (length <= 0) {
|
|
64
|
+
throw new RangeError(
|
|
65
|
+
`The number of frames provided (${length}) is less than or equal to the minimum bound (0)`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (sampleRate <= 0) {
|
|
70
|
+
throw new RangeError(
|
|
71
|
+
`The sample rate provided (${sampleRate}) is outside the range [3000, 768000]`
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return new AudioBuffer(
|
|
76
|
+
this.context.createBuffer(numOfChannels, length, sampleRate)
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
createPeriodicWave(
|
|
81
|
+
real: number[],
|
|
82
|
+
imag: number[],
|
|
83
|
+
constraints?: PeriodicWaveConstraints
|
|
84
|
+
): PeriodicWave {
|
|
85
|
+
if (real.length !== imag.length) {
|
|
86
|
+
throw new InvalidAccessError(
|
|
87
|
+
`The lengths of the real (${real.length}) and imaginary (${imag.length}) arrays must match.`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const disableNormalization = constraints?.disableNormalization ?? false;
|
|
92
|
+
|
|
93
|
+
return new PeriodicWave(
|
|
94
|
+
this.context.createPeriodicWave(real, imag, disableNormalization)
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { InvalidAccessError } from '../errors';
|
|
2
|
+
import { IBiquadFilterNode } from '../interfaces';
|
|
3
|
+
import AudioNode from './AudioNode';
|
|
4
|
+
import AudioParam from './AudioParam';
|
|
5
|
+
import BaseAudioContext from './BaseAudioContext';
|
|
6
|
+
import { BiquadFilterType } from './types';
|
|
7
|
+
|
|
8
|
+
export default class BiquadFilterNode extends AudioNode {
|
|
9
|
+
readonly frequency: AudioParam;
|
|
10
|
+
readonly detune: AudioParam;
|
|
11
|
+
readonly Q: AudioParam;
|
|
12
|
+
readonly gain: AudioParam;
|
|
13
|
+
|
|
14
|
+
constructor(context: BaseAudioContext, biquadFilter: IBiquadFilterNode) {
|
|
15
|
+
super(context, biquadFilter);
|
|
16
|
+
this.frequency = new AudioParam(biquadFilter.frequency);
|
|
17
|
+
this.detune = new AudioParam(biquadFilter.detune);
|
|
18
|
+
this.Q = new AudioParam(biquadFilter.Q);
|
|
19
|
+
this.gain = new AudioParam(biquadFilter.gain);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public get type(): BiquadFilterType {
|
|
23
|
+
return (this.node as IBiquadFilterNode).type;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public set type(value: BiquadFilterType) {
|
|
27
|
+
(this.node as IBiquadFilterNode).type = value;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public getFrequencyResponse(
|
|
31
|
+
frequencyArray: number[],
|
|
32
|
+
magResponseOutput: number[],
|
|
33
|
+
phaseResponseOutput: number[]
|
|
34
|
+
) {
|
|
35
|
+
if (
|
|
36
|
+
frequencyArray.length !== magResponseOutput.length ||
|
|
37
|
+
frequencyArray.length !== phaseResponseOutput.length
|
|
38
|
+
) {
|
|
39
|
+
throw new InvalidAccessError(
|
|
40
|
+
`The lengths of the arrays are not the same frequencyArray: ${frequencyArray.length}, magResponseOutput: ${magResponseOutput.length}, phaseResponseOutput: ${phaseResponseOutput.length}`
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
(this.node as IBiquadFilterNode).getFrequencyResponse(
|
|
44
|
+
frequencyArray,
|
|
45
|
+
magResponseOutput,
|
|
46
|
+
phaseResponseOutput
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IGainNode } from '../interfaces';
|
|
2
|
+
import AudioNode from './AudioNode';
|
|
3
|
+
import AudioParam from './AudioParam';
|
|
4
|
+
import BaseAudioContext from './BaseAudioContext';
|
|
5
|
+
|
|
6
|
+
export default class GainNode extends AudioNode {
|
|
7
|
+
readonly gain: AudioParam;
|
|
8
|
+
|
|
9
|
+
constructor(context: BaseAudioContext, gain: IGainNode) {
|
|
10
|
+
super(context, gain);
|
|
11
|
+
this.gain = new AudioParam(gain.gain);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { IOscillatorNode } from '../interfaces';
|
|
2
|
+
import { OscillatorType } from './types';
|
|
3
|
+
import AudioScheduledSourceNode from './AudioScheduledSourceNode';
|
|
4
|
+
import AudioParam from './AudioParam';
|
|
5
|
+
import BaseAudioContext from './BaseAudioContext';
|
|
6
|
+
import PeriodicWave from './PeriodicWave';
|
|
7
|
+
import { InvalidStateError } from '../errors';
|
|
8
|
+
|
|
9
|
+
export default class OscillatorNode extends AudioScheduledSourceNode {
|
|
10
|
+
readonly frequency: AudioParam;
|
|
11
|
+
readonly detune: AudioParam;
|
|
12
|
+
|
|
13
|
+
constructor(context: BaseAudioContext, node: IOscillatorNode) {
|
|
14
|
+
super(context, node);
|
|
15
|
+
this.frequency = new AudioParam(node.frequency);
|
|
16
|
+
this.detune = new AudioParam(node.detune);
|
|
17
|
+
this.type = node.type;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public get type(): OscillatorType {
|
|
21
|
+
return (this.node as IOscillatorNode).type;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public set type(value: OscillatorType) {
|
|
25
|
+
if (value === 'custom') {
|
|
26
|
+
throw new InvalidStateError(
|
|
27
|
+
"'type' cannot be set directly to 'custom'. Use setPeriodicWave() to create a custom Oscillator type."
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
(this.node as IOscillatorNode).type = value;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public setPeriodicWave(wave: PeriodicWave): void {
|
|
35
|
+
(this.node as IOscillatorNode).setPeriodicWave(wave.periodicWave);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IStereoPannerNode } from '../interfaces';
|
|
2
|
+
import AudioNode from './AudioNode';
|
|
3
|
+
import AudioParam from './AudioParam';
|
|
4
|
+
import BaseAudioContext from './BaseAudioContext';
|
|
5
|
+
|
|
6
|
+
export default class StereoPannerNode extends AudioNode {
|
|
7
|
+
readonly pan: AudioParam;
|
|
8
|
+
|
|
9
|
+
constructor(context: BaseAudioContext, pan: IStereoPannerNode) {
|
|
10
|
+
super(context, pan);
|
|
11
|
+
this.pan = new AudioParam(pan.pan);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type ChannelCountMode = 'max' | 'clamped-max' | 'explicit';
|
|
2
|
+
|
|
3
|
+
export type ChannelInterpretation = 'speakers' | 'discrete';
|
|
4
|
+
|
|
5
|
+
export type BiquadFilterType =
|
|
6
|
+
| 'lowpass'
|
|
7
|
+
| 'highpass'
|
|
8
|
+
| 'bandpass'
|
|
9
|
+
| 'lowshelf'
|
|
10
|
+
| 'highshelf'
|
|
11
|
+
| 'peaking'
|
|
12
|
+
| 'notch'
|
|
13
|
+
| 'allpass';
|
|
14
|
+
|
|
15
|
+
export type ContextState = 'running' | 'closed';
|
|
16
|
+
|
|
17
|
+
export type OscillatorType =
|
|
18
|
+
| 'sine'
|
|
19
|
+
| 'square'
|
|
20
|
+
| 'sawtooth'
|
|
21
|
+
| 'triangle'
|
|
22
|
+
| 'custom';
|
|
23
|
+
|
|
24
|
+
export interface PeriodicWaveConstraints {
|
|
25
|
+
disableNormalization: boolean;
|
|
26
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { installModule } from './utils/install';
|
|
2
|
+
|
|
3
|
+
if (global.__AudioAPIInstaller == null) {
|
|
4
|
+
installModule();
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export { default as AudioBuffer } from './core/AudioBuffer';
|
|
8
|
+
export { default as AudioBufferSourceNode } from './core/AudioBufferSourceNode';
|
|
9
|
+
export { default as AudioContext } from './core/AudioContext';
|
|
10
|
+
export { default as AudioDestinationNode } from './core/AudioDestinationNode';
|
|
11
|
+
export { default as AudioNode } from './core/AudioNode';
|
|
12
|
+
export { default as AudioParam } from './core/AudioParam';
|
|
13
|
+
export { default as AudioScheduledSourceNode } from './core/AudioScheduledSourceNode';
|
|
14
|
+
export { default as BaseAudioContext } from './core/BaseAudioContext';
|
|
15
|
+
export { default as BiquadFilterNode } from './core/BiquadFilterNode';
|
|
16
|
+
export { default as GainNode } from './core/GainNode';
|
|
17
|
+
export { default as OscillatorNode } from './core/OscillatorNode';
|
|
18
|
+
export { default as StereoPannerNode } from './core/StereoPannerNode';
|
|
19
|
+
export {
|
|
20
|
+
OscillatorType,
|
|
21
|
+
BiquadFilterType,
|
|
22
|
+
ChannelCountMode,
|
|
23
|
+
ChannelInterpretation,
|
|
24
|
+
ContextState,
|
|
25
|
+
} from './core/types';
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ContextState,
|
|
3
|
+
BiquadFilterType,
|
|
4
|
+
OscillatorType,
|
|
5
|
+
ChannelCountMode,
|
|
6
|
+
ChannelInterpretation,
|
|
7
|
+
} from './core/types';
|
|
8
|
+
|
|
9
|
+
export interface IBaseAudioContext {
|
|
10
|
+
readonly destination: IAudioDestinationNode;
|
|
11
|
+
readonly state: ContextState;
|
|
12
|
+
readonly sampleRate: number;
|
|
13
|
+
readonly currentTime: number;
|
|
14
|
+
|
|
15
|
+
createOscillator(): IOscillatorNode;
|
|
16
|
+
createGain(): IGainNode;
|
|
17
|
+
createStereoPanner(): IStereoPannerNode;
|
|
18
|
+
createBiquadFilter: () => IBiquadFilterNode;
|
|
19
|
+
createBufferSource: () => IAudioBufferSourceNode;
|
|
20
|
+
createBuffer: (
|
|
21
|
+
channels: number,
|
|
22
|
+
length: number,
|
|
23
|
+
sampleRate: number
|
|
24
|
+
) => IAudioBuffer;
|
|
25
|
+
createPeriodicWave: (
|
|
26
|
+
real: number[],
|
|
27
|
+
imag: number[],
|
|
28
|
+
disableNormalization: boolean
|
|
29
|
+
) => IPeriodicWave;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface IAudioContext extends IBaseAudioContext {
|
|
33
|
+
close(): void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface IAudioNode {
|
|
37
|
+
readonly context: BaseAudioContext;
|
|
38
|
+
readonly numberOfInputs: number;
|
|
39
|
+
readonly numberOfOutputs: number;
|
|
40
|
+
readonly channelCount: number;
|
|
41
|
+
readonly channelCountMode: ChannelCountMode;
|
|
42
|
+
readonly channelInterpretation: ChannelInterpretation;
|
|
43
|
+
|
|
44
|
+
connect: (node: IAudioNode) => void;
|
|
45
|
+
disconnect: (node: IAudioNode) => void;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface IGainNode extends IAudioNode {
|
|
49
|
+
readonly gain: IAudioParam;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface IStereoPannerNode extends IAudioNode {
|
|
53
|
+
readonly pan: IAudioParam;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface IBiquadFilterNode extends IAudioNode {
|
|
57
|
+
readonly frequency: AudioParam;
|
|
58
|
+
readonly detune: AudioParam;
|
|
59
|
+
readonly Q: AudioParam;
|
|
60
|
+
readonly gain: AudioParam;
|
|
61
|
+
type: BiquadFilterType;
|
|
62
|
+
|
|
63
|
+
getFrequencyResponse(
|
|
64
|
+
frequencyArray: number[],
|
|
65
|
+
magResponseOutput: number[],
|
|
66
|
+
phaseResponseOutput: number[]
|
|
67
|
+
): void;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface IAudioDestinationNode extends IAudioNode {}
|
|
71
|
+
|
|
72
|
+
export interface IAudioScheduledSourceNode extends IAudioNode {
|
|
73
|
+
start: (time: number) => void;
|
|
74
|
+
stop: (time: number) => void;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface IOscillatorNode extends IAudioScheduledSourceNode {
|
|
78
|
+
readonly frequency: IAudioParam;
|
|
79
|
+
readonly detune: IAudioParam;
|
|
80
|
+
type: OscillatorType;
|
|
81
|
+
|
|
82
|
+
setPeriodicWave(periodicWave: IPeriodicWave): void;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface IAudioBufferSourceNode extends IAudioScheduledSourceNode {
|
|
86
|
+
buffer: IAudioBuffer | null;
|
|
87
|
+
loop: boolean;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface IAudioBuffer {
|
|
91
|
+
readonly length: number;
|
|
92
|
+
readonly duration: number;
|
|
93
|
+
readonly sampleRate: number;
|
|
94
|
+
readonly numberOfChannels: number;
|
|
95
|
+
|
|
96
|
+
getChannelData(channel: number): number[];
|
|
97
|
+
copyFromChannel(
|
|
98
|
+
destination: number[],
|
|
99
|
+
channelNumber: number,
|
|
100
|
+
startInChannel: number
|
|
101
|
+
): void;
|
|
102
|
+
copyToChannel(
|
|
103
|
+
source: number[],
|
|
104
|
+
channelNumber: number,
|
|
105
|
+
startInChannel: number
|
|
106
|
+
): void;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface IAudioParam {
|
|
110
|
+
value: number;
|
|
111
|
+
defaultValue: number;
|
|
112
|
+
minValue: number;
|
|
113
|
+
maxValue: number;
|
|
114
|
+
|
|
115
|
+
setValueAtTime: (value: number, startTime: number) => void;
|
|
116
|
+
linearRampToValueAtTime: (value: number, endTime: number) => void;
|
|
117
|
+
exponentialRampToValueAtTime: (value: number, endTime: number) => void;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface IPeriodicWave {}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { TurboModuleRegistry, TurboModule } from 'react-native';
|
|
2
|
+
|
|
3
|
+
interface AudioAPIModuleSpec extends TurboModule {
|
|
4
|
+
install(): boolean;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function installModule() {
|
|
8
|
+
const AudioAPIModule =
|
|
9
|
+
TurboModuleRegistry.getEnforcing<AudioAPIModuleSpec>('AudioAPIModule');
|
|
10
|
+
|
|
11
|
+
if (AudioAPIModule == null) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
`Failed to install react-native-audio-api: The native module could not be found.`
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
runInstall(AudioAPIModule);
|
|
18
|
+
verifyInstallation();
|
|
19
|
+
|
|
20
|
+
return AudioAPIModule;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function runInstall(Module: any) {
|
|
24
|
+
const result = Module.install();
|
|
25
|
+
|
|
26
|
+
if (result !== true) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
`Failed to install react-native-audio-api: The native Audio API Module could not be installed! Looks like something went wrong when installing JSI bindings: ${result}`
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function verifyInstallation() {
|
|
34
|
+
if (global.__AudioAPIInstaller == null) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
'Failed to install react-native-audio-api, the native initializer private does not exist. Are you trying to use Audio API from different JS Runtimes?'
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
}
|
package/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default {};
|