react-native-audio-api 0.5.5 → 0.5.7

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.
Files changed (44) hide show
  1. package/common/cpp/audioapi/AudioAPIModuleInstaller.h +28 -0
  2. package/common/cpp/audioapi/HostObjects/OfflineAudioContextHostObject.h +70 -0
  3. package/common/cpp/audioapi/core/OfflineAudioContext.cpp +117 -0
  4. package/common/cpp/audioapi/core/OfflineAudioContext.h +40 -0
  5. package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp +3 -3
  6. package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp +28 -2
  7. package/common/cpp/audioapi/core/utils/AudioNodeDestructor.cpp +53 -0
  8. package/common/cpp/audioapi/core/utils/AudioNodeDestructor.h +33 -0
  9. package/common/cpp/audioapi/core/utils/AudioNodeManager.cpp +13 -10
  10. package/common/cpp/audioapi/core/utils/AudioNodeManager.h +3 -0
  11. package/common/cpp/audioapi/libs/signalsmith-stretch/fft-accelerate.h +326 -0
  12. package/common/cpp/audioapi/libs/signalsmith-stretch/fft.h +1257 -413
  13. package/common/cpp/audioapi/libs/signalsmith-stretch/signalsmith-stretch.h +398 -232
  14. package/common/cpp/audioapi/libs/signalsmith-stretch/stft.h +625 -0
  15. package/lib/module/api.js +2 -1
  16. package/lib/module/api.js.map +1 -1
  17. package/lib/module/api.web.js +1 -0
  18. package/lib/module/api.web.js.map +1 -1
  19. package/lib/module/core/OfflineAudioContext.js +57 -0
  20. package/lib/module/core/OfflineAudioContext.js.map +1 -0
  21. package/lib/module/web-core/OfflineAudioContext.js +90 -0
  22. package/lib/module/web-core/OfflineAudioContext.js.map +1 -0
  23. package/lib/typescript/api.d.ts +3 -1
  24. package/lib/typescript/api.d.ts.map +1 -1
  25. package/lib/typescript/api.web.d.ts +1 -0
  26. package/lib/typescript/api.web.d.ts.map +1 -1
  27. package/lib/typescript/core/OfflineAudioContext.d.ts +14 -0
  28. package/lib/typescript/core/OfflineAudioContext.d.ts.map +1 -0
  29. package/lib/typescript/interfaces.d.ts +6 -0
  30. package/lib/typescript/interfaces.d.ts.map +1 -1
  31. package/lib/typescript/types.d.ts +5 -0
  32. package/lib/typescript/types.d.ts.map +1 -1
  33. package/lib/typescript/web-core/OfflineAudioContext.d.ts +34 -0
  34. package/lib/typescript/web-core/OfflineAudioContext.d.ts.map +1 -0
  35. package/package.json +1 -1
  36. package/src/api.ts +11 -2
  37. package/src/api.web.ts +1 -0
  38. package/src/core/OfflineAudioContext.ts +94 -0
  39. package/src/interfaces.ts +11 -0
  40. package/src/types.ts +6 -0
  41. package/src/web-core/OfflineAudioContext.tsx +163 -0
  42. package/common/cpp/audioapi/libs/signalsmith-stretch/delay.h +0 -715
  43. package/common/cpp/audioapi/libs/signalsmith-stretch/perf.h +0 -82
  44. package/common/cpp/audioapi/libs/signalsmith-stretch/spectral.h +0 -493
@@ -0,0 +1,163 @@
1
+ import {
2
+ ContextState,
3
+ PeriodicWaveConstraints,
4
+ OfflineAudioContextOptions,
5
+ AudioBufferSourceNodeOptions,
6
+ } from '../types';
7
+ import { InvalidAccessError, NotSupportedError } from '../errors';
8
+ import BaseAudioContext from './BaseAudioContext';
9
+ import AnalyserNode from './AnalyserNode';
10
+ import AudioDestinationNode from './AudioDestinationNode';
11
+ import AudioBuffer from './AudioBuffer';
12
+ import AudioBufferSourceNode from './AudioBufferSourceNode';
13
+ import BiquadFilterNode from './BiquadFilterNode';
14
+ import GainNode from './GainNode';
15
+ import OscillatorNode from './OscillatorNode';
16
+ import PeriodicWave from './PeriodicWave';
17
+ import StereoPannerNode from './StereoPannerNode';
18
+
19
+ import { globalWasmPromise, globalTag } from './custom/LoadCustomWasm';
20
+
21
+ export default class OfflineAudioContext implements BaseAudioContext {
22
+ readonly context: globalThis.OfflineAudioContext;
23
+
24
+ readonly destination: AudioDestinationNode;
25
+ readonly sampleRate: number;
26
+
27
+ constructor(options: OfflineAudioContextOptions);
28
+ constructor(numberOfChannels: number, length: number, sampleRate: number);
29
+ constructor(
30
+ arg0: OfflineAudioContextOptions | number,
31
+ arg1?: number,
32
+ arg2?: number
33
+ ) {
34
+ if (typeof arg0 === 'object') {
35
+ this.context = new window.OfflineAudioContext(arg0);
36
+ } else if (
37
+ typeof arg0 === 'number' &&
38
+ typeof arg1 === 'number' &&
39
+ typeof arg2 === 'number'
40
+ ) {
41
+ this.context = new window.OfflineAudioContext(arg0, arg1, arg2);
42
+ } else {
43
+ throw new NotSupportedError('Invalid constructor arguments');
44
+ }
45
+
46
+ this.sampleRate = this.context.sampleRate;
47
+ this.destination = new AudioDestinationNode(this, this.context.destination);
48
+ }
49
+
50
+ public get currentTime(): number {
51
+ return this.context.currentTime;
52
+ }
53
+
54
+ public get state(): ContextState {
55
+ return this.context.state as ContextState;
56
+ }
57
+
58
+ createOscillator(): OscillatorNode {
59
+ return new OscillatorNode(this, this.context.createOscillator());
60
+ }
61
+
62
+ createGain(): GainNode {
63
+ return new GainNode(this, this.context.createGain());
64
+ }
65
+
66
+ createStereoPanner(): StereoPannerNode {
67
+ return new StereoPannerNode(this, this.context.createStereoPanner());
68
+ }
69
+
70
+ createBiquadFilter(): BiquadFilterNode {
71
+ return new BiquadFilterNode(this, this.context.createBiquadFilter());
72
+ }
73
+
74
+ async createBufferSource(
75
+ options?: AudioBufferSourceNodeOptions
76
+ ): Promise<AudioBufferSourceNode> {
77
+ if (!options || !options.pitchCorrection) {
78
+ return new AudioBufferSourceNode(
79
+ this,
80
+ this.context.createBufferSource(),
81
+ false
82
+ );
83
+ }
84
+
85
+ await globalWasmPromise;
86
+
87
+ const wasmStretch = await window[globalTag](this.context);
88
+
89
+ return new AudioBufferSourceNode(this, wasmStretch, true);
90
+ }
91
+
92
+ createBuffer(
93
+ numOfChannels: number,
94
+ length: number,
95
+ sampleRate: number
96
+ ): AudioBuffer {
97
+ if (numOfChannels < 1 || numOfChannels >= 32) {
98
+ throw new NotSupportedError(
99
+ `The number of channels provided (${numOfChannels}) is outside the range [1, 32]`
100
+ );
101
+ }
102
+
103
+ if (length <= 0) {
104
+ throw new NotSupportedError(
105
+ `The number of frames provided (${length}) is less than or equal to the minimum bound (0)`
106
+ );
107
+ }
108
+
109
+ if (sampleRate < 8000 || sampleRate > 96000) {
110
+ throw new NotSupportedError(
111
+ `The sample rate provided (${sampleRate}) is outside the range [8000, 96000]`
112
+ );
113
+ }
114
+
115
+ return new AudioBuffer(
116
+ this.context.createBuffer(numOfChannels, length, sampleRate)
117
+ );
118
+ }
119
+
120
+ createPeriodicWave(
121
+ real: Float32Array,
122
+ imag: Float32Array,
123
+ constraints?: PeriodicWaveConstraints
124
+ ): PeriodicWave {
125
+ if (real.length !== imag.length) {
126
+ throw new InvalidAccessError(
127
+ `The lengths of the real (${real.length}) and imaginary (${imag.length}) arrays must match.`
128
+ );
129
+ }
130
+
131
+ return new PeriodicWave(
132
+ this.context.createPeriodicWave(real, imag, constraints)
133
+ );
134
+ }
135
+
136
+ createAnalyser(): AnalyserNode {
137
+ return new AnalyserNode(this, this.context.createAnalyser());
138
+ }
139
+
140
+ async decodeAudioDataSource(source: string): Promise<AudioBuffer> {
141
+ const arrayBuffer = await fetch(source).then((response) =>
142
+ response.arrayBuffer()
143
+ );
144
+
145
+ return this.decodeAudioData(arrayBuffer);
146
+ }
147
+
148
+ async decodeAudioData(arrayBuffer: ArrayBuffer): Promise<AudioBuffer> {
149
+ return new AudioBuffer(await this.context.decodeAudioData(arrayBuffer));
150
+ }
151
+
152
+ async startRendering(): Promise<AudioBuffer> {
153
+ return new AudioBuffer(await this.context.startRendering());
154
+ }
155
+
156
+ async resume(): Promise<void> {
157
+ await this.context.resume();
158
+ }
159
+
160
+ async suspend(suspendTime: number): Promise<void> {
161
+ await this.context.suspend(suspendTime);
162
+ }
163
+ }