react-native-audio-api 0.4.13 → 0.5.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/android/src/main/cpp/audioapi/android/core/AudioDecoder.cpp +87 -5
- package/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +7 -6
- package/android/src/main/java/com/swmansion/audioapi/AudioAPIPackage.kt +25 -24
- package/common/cpp/audioapi/HostObjects/AnalyserNodeHostObject.h +17 -41
- package/common/cpp/audioapi/HostObjects/AudioBufferHostObject.h +25 -34
- package/common/cpp/audioapi/HostObjects/AudioBufferSourceNodeHostObject.h +2 -17
- package/common/cpp/audioapi/HostObjects/AudioContextHostObject.h +14 -4
- package/common/cpp/audioapi/HostObjects/AudioParamHostObject.h +5 -8
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h +38 -9
- package/common/cpp/audioapi/HostObjects/BiquadFilterNodeHostObject.h +8 -19
- package/common/cpp/audioapi/core/AudioContext.cpp +14 -4
- package/common/cpp/audioapi/core/AudioContext.h +2 -2
- package/common/cpp/audioapi/core/BaseAudioContext.cpp +16 -2
- package/common/cpp/audioapi/core/BaseAudioContext.h +2 -1
- package/common/cpp/audioapi/core/effects/BiquadFilterNode.cpp +5 -6
- package/common/cpp/audioapi/core/effects/BiquadFilterNode.h +4 -3
- package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp +5 -11
- package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.h +3 -31
- package/common/cpp/audioapi/core/utils/AudioDecoder.h +2 -1
- package/common/cpp/audioapi/jsi/AudioArrayBuffer.cpp +13 -0
- package/common/cpp/audioapi/jsi/AudioArrayBuffer.h +23 -0
- package/ios/audioapi/ios/core/AudioDecoder.mm +45 -1
- package/lib/module/api.js +1 -1
- package/lib/module/api.js.map +1 -1
- package/lib/module/api.web.js +1 -2
- package/lib/module/api.web.js.map +1 -1
- package/lib/module/core/AnalyserNode.js.map +1 -1
- package/lib/module/core/AudioBuffer.js.map +1 -1
- package/lib/module/core/AudioBufferSourceNode.js +0 -6
- package/lib/module/core/AudioBufferSourceNode.js.map +1 -1
- package/lib/module/core/AudioParam.js.map +1 -1
- package/lib/module/core/BaseAudioContext.js +6 -2
- package/lib/module/core/BaseAudioContext.js.map +1 -1
- package/lib/module/core/BiquadFilterNode.js.map +1 -1
- package/lib/module/utils/index.js +6 -0
- package/lib/module/utils/index.js.map +1 -0
- package/lib/module/web-core/AnalyserNode.js +4 -20
- package/lib/module/web-core/AnalyserNode.js.map +1 -1
- package/lib/module/web-core/AudioBuffer.js +2 -6
- package/lib/module/web-core/AudioBuffer.js.map +1 -1
- package/lib/module/web-core/AudioBufferSourceNode.js +161 -21
- package/lib/module/web-core/AudioBufferSourceNode.js.map +1 -1
- package/lib/module/web-core/AudioContext.js +10 -8
- package/lib/module/web-core/AudioContext.js.map +1 -1
- package/lib/module/web-core/AudioParam.js +1 -1
- package/lib/module/web-core/AudioParam.js.map +1 -1
- package/lib/module/web-core/BiquadFilterNode.js +1 -9
- package/lib/module/web-core/BiquadFilterNode.js.map +1 -1
- package/lib/module/web-core/custom/signalsmithStretch/SignalsmithStretch.mjs +2 -2
- package/lib/module/web-core/custom/signalsmithStretch/SignalsmithStretch.mjs.map +1 -1
- package/lib/typescript/api.d.ts +1 -1
- package/lib/typescript/api.d.ts.map +1 -1
- package/lib/typescript/api.web.d.ts +1 -2
- package/lib/typescript/api.web.d.ts.map +1 -1
- package/lib/typescript/core/AnalyserNode.d.ts +4 -4
- package/lib/typescript/core/AnalyserNode.d.ts.map +1 -1
- package/lib/typescript/core/AudioBuffer.d.ts +3 -3
- package/lib/typescript/core/AudioBuffer.d.ts.map +1 -1
- package/lib/typescript/core/AudioBufferSourceNode.d.ts +0 -3
- package/lib/typescript/core/AudioBufferSourceNode.d.ts.map +1 -1
- package/lib/typescript/core/AudioParam.d.ts +1 -1
- package/lib/typescript/core/AudioParam.d.ts.map +1 -1
- package/lib/typescript/core/BaseAudioContext.d.ts +4 -3
- package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
- package/lib/typescript/core/BiquadFilterNode.d.ts +1 -1
- package/lib/typescript/core/BiquadFilterNode.d.ts.map +1 -1
- package/lib/typescript/interfaces.d.ts +13 -13
- package/lib/typescript/interfaces.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +3 -1
- package/lib/typescript/types.d.ts.map +1 -1
- package/lib/typescript/utils/index.d.ts +2 -0
- package/lib/typescript/utils/index.d.ts.map +1 -0
- package/lib/typescript/web-core/AnalyserNode.d.ts +4 -4
- package/lib/typescript/web-core/AnalyserNode.d.ts.map +1 -1
- package/lib/typescript/web-core/AudioBuffer.d.ts +2 -2
- package/lib/typescript/web-core/AudioBuffer.d.ts.map +1 -1
- package/lib/typescript/web-core/AudioBufferSourceNode.d.ts +58 -6
- package/lib/typescript/web-core/AudioBufferSourceNode.d.ts.map +1 -1
- package/lib/typescript/web-core/AudioContext.d.ts +4 -5
- package/lib/typescript/web-core/AudioContext.d.ts.map +1 -1
- package/lib/typescript/web-core/AudioParam.d.ts +1 -1
- package/lib/typescript/web-core/AudioParam.d.ts.map +1 -1
- package/lib/typescript/web-core/BaseAudioContext.d.ts +3 -2
- package/lib/typescript/web-core/BaseAudioContext.d.ts.map +1 -1
- package/lib/typescript/web-core/BiquadFilterNode.d.ts +1 -1
- package/lib/typescript/web-core/BiquadFilterNode.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/api.ts +0 -1
- package/src/api.web.ts +0 -2
- package/src/core/AnalyserNode.ts +4 -4
- package/src/core/AudioBuffer.ts +3 -3
- package/src/core/AudioBufferSourceNode.ts +0 -9
- package/src/core/AudioParam.ts +1 -1
- package/src/core/BaseAudioContext.ts +22 -5
- package/src/core/BiquadFilterNode.ts +3 -3
- package/src/interfaces.ts +15 -16
- package/src/types.ts +3 -1
- package/src/utils/index.ts +3 -0
- package/src/web-core/AnalyserNode.tsx +8 -30
- package/src/web-core/AudioBuffer.tsx +4 -14
- package/src/web-core/AudioBufferSourceNode.tsx +357 -31
- package/src/web-core/AudioContext.tsx +23 -13
- package/src/web-core/AudioParam.tsx +2 -6
- package/src/web-core/BaseAudioContext.tsx +4 -3
- package/src/web-core/BiquadFilterNode.tsx +6 -16
- package/src/web-core/custom/signalsmithStretch/SignalsmithStretch.mjs +4 -3
- package/common/cpp/audioapi/core/types/TimeStretchType.h +0 -7
- package/lib/module/web-core/StretcherNode.js +0 -81
- package/lib/module/web-core/StretcherNode.js.map +0 -1
- package/lib/module/web-core/custom/signalsmithStretch/SignalsmithStretch.js +0 -823
- package/lib/module/web-core/custom/signalsmithStretch/SignalsmithStretch.js.map +0 -1
- package/lib/typescript/web-core/StretcherNode.d.ts +0 -48
- package/lib/typescript/web-core/StretcherNode.d.ts.map +0 -1
- package/src/web-core/StretcherNode.tsx +0 -145
- package/src/web-core/custom/signalsmithStretch/SignalsmithStretch.js +0 -946
package/src/core/AudioBuffer.ts
CHANGED
|
@@ -17,7 +17,7 @@ export default class AudioBuffer {
|
|
|
17
17
|
this.numberOfChannels = buffer.numberOfChannels;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
public getChannelData(channel: number):
|
|
20
|
+
public getChannelData(channel: number): Float32Array {
|
|
21
21
|
if (channel < 0 || channel >= this.numberOfChannels) {
|
|
22
22
|
throw new IndexSizeError(
|
|
23
23
|
`The channel number provided (${channel}) is outside the range [0, ${this.numberOfChannels - 1}]`
|
|
@@ -27,7 +27,7 @@ export default class AudioBuffer {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
public copyFromChannel(
|
|
30
|
-
destination:
|
|
30
|
+
destination: Float32Array,
|
|
31
31
|
channelNumber: number,
|
|
32
32
|
startInChannel: number = 0
|
|
33
33
|
): void {
|
|
@@ -47,7 +47,7 @@ export default class AudioBuffer {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
public copyToChannel(
|
|
50
|
-
source:
|
|
50
|
+
source: Float32Array,
|
|
51
51
|
channelNumber: number,
|
|
52
52
|
startInChannel: number = 0
|
|
53
53
|
): void {
|
|
@@ -4,7 +4,6 @@ import BaseAudioContext from './BaseAudioContext';
|
|
|
4
4
|
import AudioBuffer from './AudioBuffer';
|
|
5
5
|
import AudioParam from './AudioParam';
|
|
6
6
|
import { InvalidStateError, RangeError } from '../errors';
|
|
7
|
-
import { TimeStretchType } from '../types';
|
|
8
7
|
|
|
9
8
|
export default class AudioBufferSourceNode extends AudioScheduledSourceNode {
|
|
10
9
|
readonly playbackRate: AudioParam;
|
|
@@ -58,14 +57,6 @@ export default class AudioBufferSourceNode extends AudioScheduledSourceNode {
|
|
|
58
57
|
(this.node as IAudioBufferSourceNode).loopEnd = value;
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
public get timeStretch(): TimeStretchType {
|
|
62
|
-
return (this.node as IAudioBufferSourceNode).timeStretch;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public set timeStretch(value: TimeStretchType) {
|
|
66
|
-
(this.node as IAudioBufferSourceNode).timeStretch = value;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
60
|
public start(when: number = 0, offset: number = 0, duration?: number): void {
|
|
70
61
|
if (when < 0) {
|
|
71
62
|
throw new RangeError(
|
package/src/core/AudioParam.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { IBaseAudioContext } from '../interfaces';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ContextState,
|
|
4
|
+
PeriodicWaveConstraints,
|
|
5
|
+
AudioBufferSourceNodeOptions,
|
|
6
|
+
} from '../types';
|
|
3
7
|
import AudioDestinationNode from './AudioDestinationNode';
|
|
4
8
|
import OscillatorNode from './OscillatorNode';
|
|
5
9
|
import GainNode from './GainNode';
|
|
@@ -46,8 +50,15 @@ export default class BaseAudioContext {
|
|
|
46
50
|
return new BiquadFilterNode(this, this.context.createBiquadFilter());
|
|
47
51
|
}
|
|
48
52
|
|
|
49
|
-
createBufferSource(
|
|
50
|
-
|
|
53
|
+
createBufferSource(
|
|
54
|
+
options?: AudioBufferSourceNodeOptions
|
|
55
|
+
): AudioBufferSourceNode {
|
|
56
|
+
const pitchCorrection = options?.pitchCorrection ?? false;
|
|
57
|
+
|
|
58
|
+
return new AudioBufferSourceNode(
|
|
59
|
+
this,
|
|
60
|
+
this.context.createBufferSource(pitchCorrection)
|
|
61
|
+
);
|
|
51
62
|
}
|
|
52
63
|
|
|
53
64
|
createBuffer(
|
|
@@ -79,8 +90,8 @@ export default class BaseAudioContext {
|
|
|
79
90
|
}
|
|
80
91
|
|
|
81
92
|
createPeriodicWave(
|
|
82
|
-
real:
|
|
83
|
-
imag:
|
|
93
|
+
real: Float32Array,
|
|
94
|
+
imag: Float32Array,
|
|
84
95
|
constraints?: PeriodicWaveConstraints
|
|
85
96
|
): PeriodicWave {
|
|
86
97
|
if (real.length !== imag.length) {
|
|
@@ -110,4 +121,10 @@ export default class BaseAudioContext {
|
|
|
110
121
|
await this.context.decodeAudioDataSource(sourcePath)
|
|
111
122
|
);
|
|
112
123
|
}
|
|
124
|
+
|
|
125
|
+
async decodeAudioData(arrayBuffer: ArrayBuffer): Promise<AudioBuffer> {
|
|
126
|
+
return new AudioBuffer(
|
|
127
|
+
await this.context.decodeAudioData(new Uint8Array(arrayBuffer))
|
|
128
|
+
);
|
|
129
|
+
}
|
|
113
130
|
}
|
|
@@ -28,9 +28,9 @@ export default class BiquadFilterNode extends AudioNode {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
public getFrequencyResponse(
|
|
31
|
-
frequencyArray:
|
|
32
|
-
magResponseOutput:
|
|
33
|
-
phaseResponseOutput:
|
|
31
|
+
frequencyArray: Float32Array,
|
|
32
|
+
magResponseOutput: Float32Array,
|
|
33
|
+
phaseResponseOutput: Float32Array
|
|
34
34
|
) {
|
|
35
35
|
if (
|
|
36
36
|
frequencyArray.length !== magResponseOutput.length ||
|
package/src/interfaces.ts
CHANGED
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
ChannelCountMode,
|
|
6
6
|
ChannelInterpretation,
|
|
7
7
|
WindowType,
|
|
8
|
-
TimeStretchType,
|
|
9
8
|
} from './types';
|
|
10
9
|
|
|
11
10
|
export interface AudioAPIInstaller {
|
|
@@ -22,19 +21,20 @@ export interface IBaseAudioContext {
|
|
|
22
21
|
createGain(): IGainNode;
|
|
23
22
|
createStereoPanner(): IStereoPannerNode;
|
|
24
23
|
createBiquadFilter: () => IBiquadFilterNode;
|
|
25
|
-
createBufferSource: () => IAudioBufferSourceNode;
|
|
24
|
+
createBufferSource: (pitchCorrection: boolean) => IAudioBufferSourceNode;
|
|
26
25
|
createBuffer: (
|
|
27
26
|
channels: number,
|
|
28
27
|
length: number,
|
|
29
28
|
sampleRate: number
|
|
30
29
|
) => IAudioBuffer;
|
|
31
30
|
createPeriodicWave: (
|
|
32
|
-
real:
|
|
33
|
-
imag:
|
|
31
|
+
real: Float32Array,
|
|
32
|
+
imag: Float32Array,
|
|
34
33
|
disableNormalization: boolean
|
|
35
34
|
) => IPeriodicWave;
|
|
36
35
|
createAnalyser: () => IAnalyserNode;
|
|
37
36
|
decodeAudioDataSource: (sourcePath: string) => Promise<IAudioBuffer>;
|
|
37
|
+
decodeAudioData: (arrayBuffer: ArrayBuffer) => Promise<IAudioBuffer>;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export interface IAudioContext extends IBaseAudioContext {
|
|
@@ -71,9 +71,9 @@ export interface IBiquadFilterNode extends IAudioNode {
|
|
|
71
71
|
type: BiquadFilterType;
|
|
72
72
|
|
|
73
73
|
getFrequencyResponse(
|
|
74
|
-
frequencyArray:
|
|
75
|
-
magResponseOutput:
|
|
76
|
-
phaseResponseOutput:
|
|
74
|
+
frequencyArray: Float32Array,
|
|
75
|
+
magResponseOutput: Float32Array,
|
|
76
|
+
phaseResponseOutput: Float32Array
|
|
77
77
|
): void;
|
|
78
78
|
}
|
|
79
79
|
|
|
@@ -100,7 +100,6 @@ export interface IAudioBufferSourceNode extends IAudioScheduledSourceNode {
|
|
|
100
100
|
loopEnd: number;
|
|
101
101
|
detune: IAudioParam;
|
|
102
102
|
playbackRate: IAudioParam;
|
|
103
|
-
timeStretch: TimeStretchType;
|
|
104
103
|
|
|
105
104
|
start: (when?: number, offset?: number, duration?: number) => void;
|
|
106
105
|
}
|
|
@@ -111,14 +110,14 @@ export interface IAudioBuffer {
|
|
|
111
110
|
readonly sampleRate: number;
|
|
112
111
|
readonly numberOfChannels: number;
|
|
113
112
|
|
|
114
|
-
getChannelData(channel: number):
|
|
113
|
+
getChannelData(channel: number): Float32Array;
|
|
115
114
|
copyFromChannel(
|
|
116
|
-
destination:
|
|
115
|
+
destination: Float32Array,
|
|
117
116
|
channelNumber: number,
|
|
118
117
|
startInChannel: number
|
|
119
118
|
): void;
|
|
120
119
|
copyToChannel(
|
|
121
|
-
source:
|
|
120
|
+
source: Float32Array,
|
|
122
121
|
channelNumber: number,
|
|
123
122
|
startInChannel: number
|
|
124
123
|
): void;
|
|
@@ -139,7 +138,7 @@ export interface IAudioParam {
|
|
|
139
138
|
timeConstant: number
|
|
140
139
|
) => void;
|
|
141
140
|
setValueCurveAtTime: (
|
|
142
|
-
values:
|
|
141
|
+
values: Float32Array,
|
|
143
142
|
startTime: number,
|
|
144
143
|
duration: number
|
|
145
144
|
) => void;
|
|
@@ -157,8 +156,8 @@ export interface IAnalyserNode extends IAudioNode {
|
|
|
157
156
|
smoothingTimeConstant: number;
|
|
158
157
|
window: WindowType;
|
|
159
158
|
|
|
160
|
-
getFloatFrequencyData: (array:
|
|
161
|
-
getByteFrequencyData: (array:
|
|
162
|
-
getFloatTimeDomainData: (array:
|
|
163
|
-
getByteTimeDomainData: (array:
|
|
159
|
+
getFloatFrequencyData: (array: Float32Array) => void;
|
|
160
|
+
getByteFrequencyData: (array: Uint8Array) => void;
|
|
161
|
+
getFloatTimeDomainData: (array: Float32Array) => void;
|
|
162
|
+
getByteTimeDomainData: (array: Uint8Array) => void;
|
|
164
163
|
}
|
package/src/types.ts
CHANGED
|
@@ -29,41 +29,19 @@ export default class AnalyserNode extends AudioNode {
|
|
|
29
29
|
);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
public getByteFrequencyData(array:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
(this.node as globalThis.AnalyserNode).getByteFrequencyData(data);
|
|
36
|
-
|
|
37
|
-
for (let i = 0; i < array.length; i++) {
|
|
38
|
-
array[i] = data[i];
|
|
39
|
-
}
|
|
32
|
+
public getByteFrequencyData(array: Uint8Array): void {
|
|
33
|
+
(this.node as globalThis.AnalyserNode).getByteFrequencyData(array);
|
|
40
34
|
}
|
|
41
35
|
|
|
42
|
-
public getByteTimeDomainData(array:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
(this.node as globalThis.AnalyserNode).getByteTimeDomainData(data);
|
|
46
|
-
|
|
47
|
-
for (let i = 0; i < array.length; i++) {
|
|
48
|
-
array[i] = data[i];
|
|
49
|
-
}
|
|
36
|
+
public getByteTimeDomainData(array: Uint8Array): void {
|
|
37
|
+
(this.node as globalThis.AnalyserNode).getByteTimeDomainData(array);
|
|
50
38
|
}
|
|
51
39
|
|
|
52
|
-
public getFloatFrequencyData(array:
|
|
53
|
-
|
|
54
|
-
(this.node as globalThis.AnalyserNode).getFloatFrequencyData(data);
|
|
55
|
-
|
|
56
|
-
for (let i = 0; i < array.length; i++) {
|
|
57
|
-
array[i] = data[i];
|
|
58
|
-
}
|
|
40
|
+
public getFloatFrequencyData(array: Float32Array): void {
|
|
41
|
+
(this.node as globalThis.AnalyserNode).getFloatFrequencyData(array);
|
|
59
42
|
}
|
|
60
43
|
|
|
61
|
-
public getFloatTimeDomainData(array:
|
|
62
|
-
|
|
63
|
-
(this.node as globalThis.AnalyserNode).getFloatTimeDomainData(data);
|
|
64
|
-
|
|
65
|
-
for (let i = 0; i < array.length; i++) {
|
|
66
|
-
array[i] = data[i];
|
|
67
|
-
}
|
|
44
|
+
public getFloatTimeDomainData(array: Float32Array): void {
|
|
45
|
+
(this.node as globalThis.AnalyserNode).getFloatTimeDomainData(array);
|
|
68
46
|
}
|
|
69
47
|
}
|
|
@@ -28,7 +28,7 @@ export default class AudioBuffer {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
public copyFromChannel(
|
|
31
|
-
destination:
|
|
31
|
+
destination: Float32Array,
|
|
32
32
|
channelNumber: number,
|
|
33
33
|
startInChannel: number = 0
|
|
34
34
|
): void {
|
|
@@ -44,17 +44,11 @@ export default class AudioBuffer {
|
|
|
44
44
|
);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
this.buffer.copyFromChannel(array, channelNumber, startInChannel);
|
|
50
|
-
|
|
51
|
-
for (let i = 0; i < destination.length; i++) {
|
|
52
|
-
destination[i] = array[i];
|
|
53
|
-
}
|
|
47
|
+
this.buffer.copyFromChannel(destination, channelNumber, startInChannel);
|
|
54
48
|
}
|
|
55
49
|
|
|
56
50
|
public copyToChannel(
|
|
57
|
-
source:
|
|
51
|
+
source: Float32Array,
|
|
58
52
|
channelNumber: number,
|
|
59
53
|
startInChannel: number = 0
|
|
60
54
|
): void {
|
|
@@ -70,10 +64,6 @@ export default class AudioBuffer {
|
|
|
70
64
|
);
|
|
71
65
|
}
|
|
72
66
|
|
|
73
|
-
this.buffer.copyToChannel(
|
|
74
|
-
new Float32Array(source),
|
|
75
|
-
channelNumber,
|
|
76
|
-
startInChannel
|
|
77
|
-
);
|
|
67
|
+
this.buffer.copyToChannel(source, channelNumber, startInChannel);
|
|
78
68
|
}
|
|
79
69
|
}
|