react-native-audio-api 0.11.0-nightly-66e4495-20251201 → 0.11.0-nightly-befc3c6-20251202
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/java/com/swmansion/audioapi/system/AudioFocusListener.kt +2 -0
- package/android/src/main/java/com/swmansion/audioapi/system/LockScreenManager.kt +1 -0
- package/lib/commonjs/AudioAPIModule/AudioAPIModule.js +90 -0
- package/lib/commonjs/AudioAPIModule/AudioAPIModule.js.map +1 -0
- package/lib/commonjs/AudioAPIModule/globals.d.js +6 -0
- package/lib/commonjs/AudioAPIModule/globals.d.js.map +1 -0
- package/lib/commonjs/AudioAPIModule/index.js +14 -0
- package/lib/commonjs/AudioAPIModule/index.js.map +1 -0
- package/lib/commonjs/api.js +14 -24
- package/lib/commonjs/api.js.map +1 -1
- package/lib/commonjs/core/AudioContext.js +4 -7
- package/lib/commonjs/core/AudioContext.js.map +1 -1
- package/lib/commonjs/core/BaseAudioContext.js +9 -8
- package/lib/commonjs/core/BaseAudioContext.js.map +1 -1
- package/lib/commonjs/core/OfflineAudioContext.js +3 -6
- package/lib/commonjs/core/OfflineAudioContext.js.map +1 -1
- package/lib/commonjs/system/AudioManager.js +1 -7
- package/lib/commonjs/system/AudioManager.js.map +1 -1
- package/lib/commonjs/utils/index.js +9 -22
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/module/AudioAPIModule/AudioAPIModule.js +87 -0
- package/lib/module/AudioAPIModule/AudioAPIModule.js.map +1 -0
- package/lib/module/AudioAPIModule/globals.d.js +4 -0
- package/lib/module/AudioAPIModule/globals.d.js.map +1 -0
- package/lib/module/AudioAPIModule/index.js +4 -0
- package/lib/module/AudioAPIModule/index.js.map +1 -0
- package/lib/module/api.js +17 -28
- package/lib/module/api.js.map +1 -1
- package/lib/module/core/AudioContext.js +4 -7
- package/lib/module/core/AudioContext.js.map +1 -1
- package/lib/module/core/BaseAudioContext.js +10 -9
- package/lib/module/core/BaseAudioContext.js.map +1 -1
- package/lib/module/core/OfflineAudioContext.js +3 -6
- package/lib/module/core/OfflineAudioContext.js.map +1 -1
- package/lib/module/system/AudioManager.js +1 -7
- package/lib/module/system/AudioManager.js.map +1 -1
- package/lib/module/utils/index.js +8 -21
- package/lib/module/utils/index.js.map +1 -1
- package/lib/typescript/AudioAPIModule/AudioAPIModule.d.ts +36 -0
- package/lib/typescript/AudioAPIModule/AudioAPIModule.d.ts.map +1 -0
- package/lib/typescript/AudioAPIModule/index.d.ts +2 -0
- package/lib/typescript/AudioAPIModule/index.d.ts.map +1 -0
- package/lib/typescript/api.d.ts +17 -26
- package/lib/typescript/api.d.ts.map +1 -1
- package/lib/typescript/core/AudioContext.d.ts +1 -1
- package/lib/typescript/core/AudioContext.d.ts.map +1 -1
- package/lib/typescript/core/BaseAudioContext.d.ts +5 -5
- package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
- package/lib/typescript/core/OfflineAudioContext.d.ts +1 -1
- package/lib/typescript/core/OfflineAudioContext.d.ts.map +1 -1
- package/lib/typescript/system/AudioManager.d.ts +2 -2
- package/lib/typescript/system/AudioManager.d.ts.map +1 -1
- package/lib/typescript/utils/index.d.ts +1 -11
- package/lib/typescript/utils/index.d.ts.map +1 -1
- package/package.json +4 -1
- package/scripts/validate-worklets-version.js +4 -5
- package/src/AudioAPIModule/AudioAPIModule.ts +122 -0
- package/src/AudioAPIModule/globals.d.ts +34 -0
- package/src/AudioAPIModule/index.ts +1 -0
- package/src/api.ts +20 -71
- package/src/core/AudioContext.ts +4 -7
- package/src/core/BaseAudioContext.ts +59 -48
- package/src/core/OfflineAudioContext.ts +4 -7
- package/src/system/AudioManager.ts +9 -19
- package/src/utils/index.ts +9 -35
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AudioManager.d.ts","sourceRoot":"","sources":["../../../src/system/AudioManager.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"AudioManager.d.ts","sourceRoot":"","sources":["../../../src/system/AudioManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,eAAe,EAChB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACf,MAAM,SAAS,CAAC;AAEjB,cAAM,YAAY;IAChB,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAoB;;IAKtD,4BAA4B,IAAI,MAAM;IAItC,uBAAuB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAI3D,sBAAsB,CAAC,OAAO,EAAE,cAAc;IAS9C,wBAAwB;IAIxB,iBAAiB,CAAC,IAAI,EAAE,cAAc;IAItC,mBAAmB;IAInB,yBAAyB,CAAC,OAAO,EAAE,OAAO;IAI1C;;;;;;;;;;;;OAYG;IACH,sBAAsB,CAAC,OAAO,EAAE,OAAO;IAIvC,oBAAoB,CAAC,OAAO,EAAE,OAAO;IAIrC,mBAAmB,CAAC,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,OAAO;IAIlE,sBAAsB,CAAC,IAAI,SAAS,eAAe,EACjD,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,mBAAmB,CAAC,IAAI,CAAC,GAClC,sBAAsB;IAInB,2BAA2B,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAIxD,yBAAyB,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAItD,cAAc,IAAI,OAAO,CAAC,gBAAgB,CAAC;CAGlD;;AAED,wBAAkC"}
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import type { ShareableWorkletCallback } from '../interfaces';
|
|
2
|
-
interface SimplifiedWorkletModule {
|
|
3
|
-
makeShareableCloneRecursive: (workletCallback: ShareableWorkletCallback) => ShareableWorkletCallback;
|
|
4
|
-
createWorkletRuntime: (options?: any) => any;
|
|
5
|
-
}
|
|
6
|
-
export declare function clamp(value: number, min: number, max: number): number;
|
|
7
|
-
export declare let isWorkletsVersionSupported: boolean;
|
|
8
|
-
export declare let workletsVersion: string;
|
|
9
|
-
export declare const supportedWorkletsVersions: string[];
|
|
10
|
-
export declare let workletsModule: SimplifiedWorkletModule;
|
|
11
1
|
export declare function assertWorkletsEnabled(): void;
|
|
12
|
-
export
|
|
2
|
+
export declare function clamp(value: number, min: number, max: number): number;
|
|
13
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAEA,wBAAgB,qBAAqB,SAapC;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAErE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-audio-api",
|
|
3
|
-
"version": "0.11.0-nightly-
|
|
3
|
+
"version": "0.11.0-nightly-befc3c6-20251202",
|
|
4
4
|
"description": "react-native-audio-api provides system for controlling audio in React Native environment compatible with Web Audio API specification",
|
|
5
5
|
"bin": {
|
|
6
6
|
"setup-rn-audio-api-web": "./scripts/setup-rn-audio-api-web.js"
|
|
@@ -164,5 +164,8 @@
|
|
|
164
164
|
"type": "module-legacy",
|
|
165
165
|
"languages": "cpp",
|
|
166
166
|
"version": "0.37.1"
|
|
167
|
+
},
|
|
168
|
+
"dependencies": {
|
|
169
|
+
"semver": "^7.7.3"
|
|
167
170
|
}
|
|
168
171
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
|
|
2
3
|
const semverPrerelease = require('semver/functions/prerelease');
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
'0.6.1',
|
|
6
|
-
];
|
|
4
|
+
|
|
5
|
+
const validWorkletsVersions = ['0.6.0', '0.6.1'];
|
|
7
6
|
|
|
8
7
|
function validateVersion() {
|
|
9
8
|
let workletsVersion;
|
|
@@ -22,7 +21,7 @@ function validateVersion() {
|
|
|
22
21
|
|
|
23
22
|
if (!validateVersion()) {
|
|
24
23
|
console.warn(
|
|
25
|
-
'[RNAudioApi] Incompatible version of react-native-audio-worklets detected. Please install a compatible version if you want to use worklet nodes in react-native-audio-api.'
|
|
24
|
+
'[RNAudioApi] Incompatible version of react-native-audio-worklets detected. Please install a compatible version if you want to use worklet nodes in react-native-audio-api.'
|
|
26
25
|
);
|
|
27
26
|
process.exit(1);
|
|
28
27
|
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { ShareableWorkletCallback } from '../interfaces';
|
|
2
|
+
import { NativeAudioAPIModule } from '../specs';
|
|
3
|
+
|
|
4
|
+
// Hint: Copied from react-native-worklets
|
|
5
|
+
// Doesn't really matter what is inside, just need a unique type
|
|
6
|
+
interface WorkletRuntime {
|
|
7
|
+
__hostObjectWorkletRuntime: never;
|
|
8
|
+
readonly name: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface IWorkletsModule {
|
|
12
|
+
makeShareableCloneRecursive: (
|
|
13
|
+
workletCallback: ShareableWorkletCallback
|
|
14
|
+
) => ShareableWorkletCallback;
|
|
15
|
+
|
|
16
|
+
createWorkletRuntime: (runtimeName: string) => WorkletRuntime;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
class AudioAPIModule {
|
|
20
|
+
#workletsModule_: IWorkletsModule | null = null;
|
|
21
|
+
#canUseWorklets_ = false;
|
|
22
|
+
#workletsVersion = 'unknown';
|
|
23
|
+
#workletsAvailable_ = false;
|
|
24
|
+
|
|
25
|
+
public supportedWorkletsVersion = ['0.6.0', '0.6.1'];
|
|
26
|
+
|
|
27
|
+
constructor() {
|
|
28
|
+
// Important! Verify and import worklets first
|
|
29
|
+
// otherwise the native module installation might crash
|
|
30
|
+
// if react-native-worklets is not imported before audio-api
|
|
31
|
+
this.#verifyWorklets();
|
|
32
|
+
|
|
33
|
+
if (this.#verifyInstallation()) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!NativeAudioAPIModule) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
`Failed to install react-native-audio-api: The native module could not be found.`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
NativeAudioAPIModule.install();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
#verifyWorklets(): boolean {
|
|
47
|
+
try {
|
|
48
|
+
const workletsPackage = require('react-native-worklets');
|
|
49
|
+
const workletsPackageJson = require('react-native-worklets/package.json');
|
|
50
|
+
this.#workletsVersion = workletsPackageJson.version;
|
|
51
|
+
this.#workletsAvailable_ = true;
|
|
52
|
+
|
|
53
|
+
this.#canUseWorklets_ = this.supportedWorkletsVersion.includes(
|
|
54
|
+
workletsPackageJson.version
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
if (this.#canUseWorklets_) {
|
|
58
|
+
this.#workletsModule_ = workletsPackage;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return this.#canUseWorklets_;
|
|
62
|
+
} catch {
|
|
63
|
+
this.#canUseWorklets_ = false;
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
#verifyInstallation(): boolean {
|
|
69
|
+
return (
|
|
70
|
+
global.createAudioContext != null &&
|
|
71
|
+
global.createOfflineAudioContext != null &&
|
|
72
|
+
global.createAudioRecorder != null &&
|
|
73
|
+
global.createAudioDecoder != null &&
|
|
74
|
+
global.createAudioStretcher != null &&
|
|
75
|
+
global.AudioEventEmitter != null
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
get workletsModule(): IWorkletsModule | null {
|
|
80
|
+
return this.#workletsModule_;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Indicates whether react-native-worklets are installed in matching version,
|
|
85
|
+
* for usage with react-native-audio-api.
|
|
86
|
+
*/
|
|
87
|
+
get canUseWorklets(): boolean {
|
|
88
|
+
return this.#canUseWorklets_;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Returns the installed worklets version or 'unknown'. */
|
|
92
|
+
get workletsVersion(): string {
|
|
93
|
+
return this.#workletsVersion;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Indicates whether react-native-worklets are installed, regardless of
|
|
98
|
+
* version support. Useful for asserting compatibility.
|
|
99
|
+
*/
|
|
100
|
+
get areWorkletsAvailable(): boolean {
|
|
101
|
+
return this.#workletsAvailable_;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Indicates whether the installed react-native-worklets version is supported.
|
|
106
|
+
* Useful for asserting compatibility.
|
|
107
|
+
*/
|
|
108
|
+
get isWorkletsVersionSupported(): boolean {
|
|
109
|
+
// Note: if areWorkletsAvailable is true, canUseWorklets is equivalent to version check
|
|
110
|
+
return this.#canUseWorklets_;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public createAudioRuntime(): WorkletRuntime | null {
|
|
114
|
+
if (!this.#canUseWorklets_) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return this.#workletsModule_!.createWorkletRuntime('AudioWorkletRuntime');
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export default new AudioAPIModule();
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
IAudioContext,
|
|
3
|
+
IAudioDecoder,
|
|
4
|
+
IAudioEventEmitter,
|
|
5
|
+
IAudioRecorder,
|
|
6
|
+
IAudioStretcher,
|
|
7
|
+
IOfflineAudioContext,
|
|
8
|
+
} from '../interfaces';
|
|
9
|
+
import type { AudioRecorderOptions } from '../types';
|
|
10
|
+
|
|
11
|
+
/* eslint-disable no-var */
|
|
12
|
+
declare global {
|
|
13
|
+
var createAudioContext: (
|
|
14
|
+
sampleRate: number,
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
audioWorkletRuntime: any
|
|
17
|
+
) => IAudioContext;
|
|
18
|
+
var createOfflineAudioContext: (
|
|
19
|
+
numberOfChannels: number,
|
|
20
|
+
length: number,
|
|
21
|
+
sampleRate: number,
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
+
audioWorkletRuntime: any
|
|
24
|
+
) => IOfflineAudioContext;
|
|
25
|
+
|
|
26
|
+
var createAudioRecorder: (options: AudioRecorderOptions) => IAudioRecorder;
|
|
27
|
+
|
|
28
|
+
var createAudioDecoder: () => IAudioDecoder;
|
|
29
|
+
|
|
30
|
+
var createAudioStretcher: () => IAudioStretcher;
|
|
31
|
+
|
|
32
|
+
var AudioEventEmitter: IAudioEventEmitter;
|
|
33
|
+
}
|
|
34
|
+
/* eslint-disable no-var */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './AudioAPIModule';
|
package/src/api.ts
CHANGED
|
@@ -1,109 +1,58 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { AudioRecorderOptions } from './types';
|
|
3
|
-
import type {
|
|
4
|
-
IAudioContext,
|
|
5
|
-
IAudioDecoder,
|
|
6
|
-
IAudioRecorder,
|
|
7
|
-
IAudioStretcher,
|
|
8
|
-
IOfflineAudioContext,
|
|
9
|
-
IAudioEventEmitter,
|
|
10
|
-
} from './interfaces';
|
|
1
|
+
import './AudioAPIModule';
|
|
11
2
|
|
|
12
|
-
|
|
13
|
-
declare global {
|
|
14
|
-
var createAudioContext: (
|
|
15
|
-
sampleRate: number,
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
-
audioWorkletRuntime: any
|
|
18
|
-
) => IAudioContext;
|
|
19
|
-
var createOfflineAudioContext: (
|
|
20
|
-
numberOfChannels: number,
|
|
21
|
-
length: number,
|
|
22
|
-
sampleRate: number,
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
-
audioWorkletRuntime: any
|
|
25
|
-
) => IOfflineAudioContext;
|
|
26
|
-
|
|
27
|
-
var createAudioRecorder: (options: AudioRecorderOptions) => IAudioRecorder;
|
|
28
|
-
|
|
29
|
-
var createAudioDecoder: () => IAudioDecoder;
|
|
30
|
-
|
|
31
|
-
var createAudioStretcher: () => IAudioStretcher;
|
|
32
|
-
|
|
33
|
-
var AudioEventEmitter: IAudioEventEmitter;
|
|
34
|
-
}
|
|
35
|
-
/* eslint-disable no-var */
|
|
36
|
-
|
|
37
|
-
if (
|
|
38
|
-
global.createAudioContext == null ||
|
|
39
|
-
global.createOfflineAudioContext == null ||
|
|
40
|
-
global.createAudioRecorder == null ||
|
|
41
|
-
global.createAudioDecoder == null ||
|
|
42
|
-
global.createAudioStretcher == null ||
|
|
43
|
-
global.AudioEventEmitter == null
|
|
44
|
-
) {
|
|
45
|
-
if (!NativeAudioAPIModule) {
|
|
46
|
-
throw new Error(
|
|
47
|
-
`Failed to install react-native-audio-api: The native module could not be found.`
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
NativeAudioAPIModule.install();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export { default as WorkletNode } from './core/WorkletNode';
|
|
55
|
-
export { default as WorkletSourceNode } from './core/WorkletSourceNode';
|
|
56
|
-
export { default as WorkletProcessingNode } from './core/WorkletProcessingNode';
|
|
57
|
-
export { default as RecorderAdapterNode } from './core/RecorderAdapterNode';
|
|
3
|
+
export { default as AnalyserNode } from './core/AnalyserNode';
|
|
58
4
|
export { default as AudioBuffer } from './core/AudioBuffer';
|
|
59
|
-
export { default as AudioBufferSourceNode } from './core/AudioBufferSourceNode';
|
|
60
5
|
export { default as AudioBufferQueueSourceNode } from './core/AudioBufferQueueSourceNode';
|
|
6
|
+
export { default as AudioBufferSourceNode } from './core/AudioBufferSourceNode';
|
|
61
7
|
export { default as AudioContext } from './core/AudioContext';
|
|
62
|
-
export {
|
|
8
|
+
export { decodeAudioData, decodePCMInBase64 } from './core/AudioDecoder';
|
|
63
9
|
export { default as AudioDestinationNode } from './core/AudioDestinationNode';
|
|
64
10
|
export { default as AudioNode } from './core/AudioNode';
|
|
65
|
-
export { default as AnalyserNode } from './core/AnalyserNode';
|
|
66
11
|
export { default as AudioParam } from './core/AudioParam';
|
|
12
|
+
export { default as AudioRecorder } from './core/AudioRecorder';
|
|
67
13
|
export { default as AudioScheduledSourceNode } from './core/AudioScheduledSourceNode';
|
|
14
|
+
export { default as changePlaybackSpeed } from './core/AudioStretcher';
|
|
68
15
|
export { default as BaseAudioContext } from './core/BaseAudioContext';
|
|
69
16
|
export { default as BiquadFilterNode } from './core/BiquadFilterNode';
|
|
17
|
+
export { default as ConstantSourceNode } from './core/ConstantSourceNode';
|
|
18
|
+
export { default as ConvolverNode } from './core/ConvolverNode';
|
|
70
19
|
export { default as GainNode } from './core/GainNode';
|
|
20
|
+
export { default as OfflineAudioContext } from './core/OfflineAudioContext';
|
|
71
21
|
export { default as OscillatorNode } from './core/OscillatorNode';
|
|
22
|
+
export { default as RecorderAdapterNode } from './core/RecorderAdapterNode';
|
|
72
23
|
export { default as StereoPannerNode } from './core/StereoPannerNode';
|
|
73
|
-
export { default as AudioRecorder } from './core/AudioRecorder';
|
|
74
24
|
export { default as StreamerNode } from './core/StreamerNode';
|
|
75
|
-
export { default as
|
|
76
|
-
export { default as
|
|
77
|
-
export { default as
|
|
25
|
+
export { default as WorkletNode } from './core/WorkletNode';
|
|
26
|
+
export { default as WorkletProcessingNode } from './core/WorkletProcessingNode';
|
|
27
|
+
export { default as WorkletSourceNode } from './core/WorkletSourceNode';
|
|
78
28
|
export { default as useSystemVolume } from './hooks/useSystemVolume';
|
|
79
|
-
export {
|
|
80
|
-
export { default as changePlaybackSpeed } from './core/AudioStretcher';
|
|
29
|
+
export { default as AudioManager } from './system';
|
|
81
30
|
|
|
82
31
|
export {
|
|
83
|
-
|
|
32
|
+
AudioWorkletRuntime,
|
|
84
33
|
BiquadFilterType,
|
|
85
34
|
ChannelCountMode,
|
|
86
35
|
ChannelInterpretation,
|
|
87
36
|
ContextState,
|
|
88
|
-
|
|
37
|
+
OscillatorType,
|
|
89
38
|
PeriodicWaveConstraints,
|
|
90
|
-
|
|
39
|
+
WindowType,
|
|
91
40
|
} from './types';
|
|
92
41
|
|
|
93
42
|
export {
|
|
94
43
|
IOSCategory,
|
|
95
44
|
IOSMode,
|
|
96
45
|
IOSOption,
|
|
97
|
-
SessionOptions,
|
|
98
|
-
MediaState,
|
|
99
46
|
LockScreenInfo,
|
|
47
|
+
MediaState,
|
|
100
48
|
PermissionStatus,
|
|
49
|
+
SessionOptions,
|
|
101
50
|
} from './system/types';
|
|
102
51
|
|
|
103
52
|
export {
|
|
104
53
|
IndexSizeError,
|
|
105
54
|
InvalidAccessError,
|
|
106
55
|
InvalidStateError,
|
|
107
|
-
RangeError,
|
|
108
56
|
NotSupportedError,
|
|
57
|
+
RangeError,
|
|
109
58
|
} from './errors';
|
package/src/core/AudioContext.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import AudioAPIModule from '../AudioAPIModule';
|
|
2
|
+
import { NotSupportedError } from '../errors';
|
|
1
3
|
import { IAudioContext } from '../interfaces';
|
|
2
|
-
import BaseAudioContext from './BaseAudioContext';
|
|
3
4
|
import AudioManager from '../system';
|
|
4
5
|
import { AudioContextOptions } from '../types';
|
|
5
|
-
import
|
|
6
|
-
import { isWorkletsVersionSupported, workletsModule } from '../utils';
|
|
6
|
+
import BaseAudioContext from './BaseAudioContext';
|
|
7
7
|
|
|
8
8
|
export default class AudioContext extends BaseAudioContext {
|
|
9
9
|
constructor(options?: AudioContextOptions) {
|
|
@@ -16,11 +16,8 @@ export default class AudioContext extends BaseAudioContext {
|
|
|
16
16
|
`The provided sampleRate is not supported: ${options.sampleRate}`
|
|
17
17
|
);
|
|
18
18
|
}
|
|
19
|
-
let audioRuntime = null;
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
audioRuntime = workletsModule.createWorkletRuntime('AudioWorkletRuntime');
|
|
23
|
-
}
|
|
20
|
+
const audioRuntime = AudioAPIModule.createAudioRuntime();
|
|
24
21
|
|
|
25
22
|
super(
|
|
26
23
|
global.createAudioContext(
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import AudioAPIModule from '../AudioAPIModule';
|
|
1
2
|
import {
|
|
2
3
|
InvalidAccessError,
|
|
3
4
|
InvalidStateError,
|
|
@@ -6,32 +7,32 @@ import {
|
|
|
6
7
|
import { IBaseAudioContext } from '../interfaces';
|
|
7
8
|
import {
|
|
8
9
|
AudioBufferBaseSourceNodeOptions,
|
|
9
|
-
ContextState,
|
|
10
|
-
PeriodicWaveConstraints,
|
|
11
10
|
AudioWorkletRuntime,
|
|
11
|
+
ContextState,
|
|
12
12
|
ConvolverNodeOptions,
|
|
13
13
|
IIRFilterNodeOptions,
|
|
14
|
+
PeriodicWaveConstraints,
|
|
14
15
|
} from '../types';
|
|
15
|
-
import { assertWorkletsEnabled
|
|
16
|
-
import WorkletSourceNode from './WorkletSourceNode';
|
|
17
|
-
import WorkletProcessingNode from './WorkletProcessingNode';
|
|
16
|
+
import { assertWorkletsEnabled } from '../utils';
|
|
18
17
|
import AnalyserNode from './AnalyserNode';
|
|
19
18
|
import AudioBuffer from './AudioBuffer';
|
|
20
19
|
import AudioBufferQueueSourceNode from './AudioBufferQueueSourceNode';
|
|
21
|
-
import ConvolverNode from './ConvolverNode';
|
|
22
20
|
import AudioBufferSourceNode from './AudioBufferSourceNode';
|
|
21
|
+
import { decodeAudioData, decodePCMInBase64 } from './AudioDecoder';
|
|
23
22
|
import AudioDestinationNode from './AudioDestinationNode';
|
|
24
23
|
import BiquadFilterNode from './BiquadFilterNode';
|
|
25
24
|
import ConstantSourceNode from './ConstantSourceNode';
|
|
25
|
+
import ConvolverNode from './ConvolverNode';
|
|
26
26
|
import GainNode from './GainNode';
|
|
27
|
+
import IIRFilterNode from './IIRFilterNode';
|
|
27
28
|
import OscillatorNode from './OscillatorNode';
|
|
28
29
|
import PeriodicWave from './PeriodicWave';
|
|
29
30
|
import RecorderAdapterNode from './RecorderAdapterNode';
|
|
30
31
|
import StereoPannerNode from './StereoPannerNode';
|
|
31
32
|
import StreamerNode from './StreamerNode';
|
|
32
33
|
import WorkletNode from './WorkletNode';
|
|
33
|
-
import
|
|
34
|
-
import
|
|
34
|
+
import WorkletProcessingNode from './WorkletProcessingNode';
|
|
35
|
+
import WorkletSourceNode from './WorkletSourceNode';
|
|
35
36
|
|
|
36
37
|
export default class BaseAudioContext {
|
|
37
38
|
readonly destination: AudioDestinationNode;
|
|
@@ -87,21 +88,26 @@ export default class BaseAudioContext {
|
|
|
87
88
|
`The number of input channels provided (${inputChannelCount}) can not be less than 1 or greater than 32`
|
|
88
89
|
);
|
|
89
90
|
}
|
|
91
|
+
|
|
90
92
|
if (bufferLength < 1) {
|
|
91
93
|
throw new NotSupportedError(
|
|
92
94
|
`The buffer length provided (${bufferLength}) can not be less than 1`
|
|
93
95
|
);
|
|
94
96
|
}
|
|
97
|
+
|
|
95
98
|
assertWorkletsEnabled();
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
|
|
100
|
+
const shareableWorklet =
|
|
101
|
+
AudioAPIModule.workletsModule!.makeShareableCloneRecursive(
|
|
102
|
+
(audioBuffers: Array<ArrayBuffer>, channelCount: number) => {
|
|
103
|
+
'worklet';
|
|
104
|
+
const floatAudioData: Array<Float32Array> = audioBuffers.map(
|
|
105
|
+
(buffer) => new Float32Array(buffer)
|
|
106
|
+
);
|
|
107
|
+
callback(floatAudioData, channelCount);
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
|
|
105
111
|
return new WorkletNode(
|
|
106
112
|
this,
|
|
107
113
|
this.context.createWorkletNode(
|
|
@@ -123,23 +129,26 @@ export default class BaseAudioContext {
|
|
|
123
129
|
workletRuntime: AudioWorkletRuntime = 'AudioRuntime'
|
|
124
130
|
): WorkletProcessingNode {
|
|
125
131
|
assertWorkletsEnabled();
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
132
|
+
|
|
133
|
+
const shareableWorklet =
|
|
134
|
+
AudioAPIModule.workletsModule!.makeShareableCloneRecursive(
|
|
135
|
+
(
|
|
136
|
+
inputBuffers: Array<ArrayBuffer>,
|
|
137
|
+
outputBuffers: Array<ArrayBuffer>,
|
|
138
|
+
framesToProcess: number,
|
|
139
|
+
currentTime: number
|
|
140
|
+
) => {
|
|
141
|
+
'worklet';
|
|
142
|
+
const inputData: Array<Float32Array> = inputBuffers.map(
|
|
143
|
+
(buffer) => new Float32Array(buffer, 0, framesToProcess)
|
|
144
|
+
);
|
|
145
|
+
const outputData: Array<Float32Array> = outputBuffers.map(
|
|
146
|
+
(buffer) => new Float32Array(buffer, 0, framesToProcess)
|
|
147
|
+
);
|
|
148
|
+
callback(inputData, outputData, framesToProcess, currentTime);
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
|
|
143
152
|
return new WorkletProcessingNode(
|
|
144
153
|
this,
|
|
145
154
|
this.context.createWorkletProcessingNode(
|
|
@@ -159,20 +168,22 @@ export default class BaseAudioContext {
|
|
|
159
168
|
workletRuntime: AudioWorkletRuntime = 'AudioRuntime'
|
|
160
169
|
): WorkletSourceNode {
|
|
161
170
|
assertWorkletsEnabled();
|
|
162
|
-
const shareableWorklet =
|
|
163
|
-
(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
171
|
+
const shareableWorklet =
|
|
172
|
+
AudioAPIModule.workletsModule!.makeShareableCloneRecursive(
|
|
173
|
+
(
|
|
174
|
+
audioBuffers: Array<ArrayBuffer>,
|
|
175
|
+
framesToProcess: number,
|
|
176
|
+
currentTime: number,
|
|
177
|
+
startOffset: number
|
|
178
|
+
) => {
|
|
179
|
+
'worklet';
|
|
180
|
+
const floatAudioData: Array<Float32Array> = audioBuffers.map(
|
|
181
|
+
(buffer) => new Float32Array(buffer)
|
|
182
|
+
);
|
|
183
|
+
callback(floatAudioData, framesToProcess, currentTime, startOffset);
|
|
184
|
+
}
|
|
185
|
+
);
|
|
186
|
+
|
|
176
187
|
return new WorkletSourceNode(
|
|
177
188
|
this,
|
|
178
189
|
this.context.createWorkletSourceNode(
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import AudioAPIModule from '../AudioAPIModule';
|
|
2
|
+
import { InvalidStateError, NotSupportedError } from '../errors';
|
|
1
3
|
import { IOfflineAudioContext } from '../interfaces';
|
|
2
|
-
import BaseAudioContext from './BaseAudioContext';
|
|
3
4
|
import { OfflineAudioContextOptions } from '../types';
|
|
4
|
-
import { InvalidStateError, NotSupportedError } from '../errors';
|
|
5
5
|
import AudioBuffer from './AudioBuffer';
|
|
6
|
-
import
|
|
6
|
+
import BaseAudioContext from './BaseAudioContext';
|
|
7
7
|
|
|
8
8
|
export default class OfflineAudioContext extends BaseAudioContext {
|
|
9
9
|
private isSuspended: boolean;
|
|
@@ -17,10 +17,7 @@ export default class OfflineAudioContext extends BaseAudioContext {
|
|
|
17
17
|
arg1?: number,
|
|
18
18
|
arg2?: number
|
|
19
19
|
) {
|
|
20
|
-
|
|
21
|
-
if (isWorkletsVersionSupported) {
|
|
22
|
-
audioRuntime = workletsModule.createWorkletRuntime('AudioWorkletRuntime');
|
|
23
|
-
}
|
|
20
|
+
const audioRuntime = AudioAPIModule.createAudioRuntime();
|
|
24
21
|
|
|
25
22
|
if (typeof arg0 === 'object') {
|
|
26
23
|
const { numberOfChannels, length, sampleRate } = arg0;
|
|
@@ -1,26 +1,16 @@
|
|
|
1
|
+
import { AudioEventEmitter, AudioEventSubscription } from '../events';
|
|
1
2
|
import {
|
|
2
|
-
SessionOptions,
|
|
3
|
-
LockScreenInfo,
|
|
4
|
-
PermissionStatus,
|
|
5
|
-
AudioDevicesInfo,
|
|
6
|
-
} from './types';
|
|
7
|
-
import {
|
|
8
|
-
SystemEventName,
|
|
9
|
-
SystemEventCallback,
|
|
10
3
|
RemoteCommandEventName,
|
|
4
|
+
SystemEventCallback,
|
|
5
|
+
SystemEventName,
|
|
11
6
|
} from '../events/types';
|
|
12
7
|
import { NativeAudioAPIModule } from '../specs';
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
NativeAudioAPIModule.install();
|
|
23
|
-
}
|
|
8
|
+
import {
|
|
9
|
+
AudioDevicesInfo,
|
|
10
|
+
LockScreenInfo,
|
|
11
|
+
PermissionStatus,
|
|
12
|
+
SessionOptions,
|
|
13
|
+
} from './types';
|
|
24
14
|
|
|
25
15
|
class AudioManager {
|
|
26
16
|
private readonly audioEventEmitter: AudioEventEmitter;
|
package/src/utils/index.ts
CHANGED
|
@@ -1,46 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
interface SimplifiedWorkletModule {
|
|
4
|
-
makeShareableCloneRecursive: (
|
|
5
|
-
workletCallback: ShareableWorkletCallback
|
|
6
|
-
) => ShareableWorkletCallback;
|
|
7
|
-
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
-
createWorkletRuntime: (options?: any) => any;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function clamp(value: number, min: number, max: number): number {
|
|
13
|
-
return Math.min(Math.max(value, min), max);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
let isWorkletsAvailable = false;
|
|
17
|
-
export let isWorkletsVersionSupported = false;
|
|
18
|
-
export let workletsVersion = 'unknown';
|
|
19
|
-
export const supportedWorkletsVersions = ['0.6.0', '0.6.1'];
|
|
20
|
-
export let workletsModule: SimplifiedWorkletModule;
|
|
1
|
+
import AudioAPIModule from '../AudioAPIModule';
|
|
21
2
|
|
|
22
3
|
export function assertWorkletsEnabled() {
|
|
23
|
-
if (!
|
|
4
|
+
if (!AudioAPIModule.areWorkletsAvailable) {
|
|
24
5
|
throw new Error(
|
|
25
6
|
'[react-native-audio-api]: Worklets are not available. Please install react-native-worklets to use this feature.'
|
|
26
7
|
);
|
|
27
|
-
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (!AudioAPIModule.isWorkletsVersionSupported) {
|
|
28
11
|
throw new Error(
|
|
29
|
-
`[react-native-audio-api]: Worklets version ${workletsVersion} is not supported.
|
|
30
|
-
Please install react-native-worklets of one of the following versions: [${
|
|
12
|
+
`[react-native-audio-api]: Worklets version ${AudioAPIModule.workletsVersion} is not supported.
|
|
13
|
+
Please install react-native-worklets of one of the following versions: [${AudioAPIModule.supportedWorkletsVersion.join(', ')}] to use this feature.`
|
|
31
14
|
);
|
|
32
15
|
}
|
|
33
16
|
}
|
|
34
17
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const workletsModuleJson = require('react-native-worklets/package.json');
|
|
38
|
-
isWorkletsVersionSupported = supportedWorkletsVersions.includes(
|
|
39
|
-
workletsModuleJson.version
|
|
40
|
-
);
|
|
41
|
-
isWorkletsAvailable = true;
|
|
42
|
-
workletsVersion = workletsModuleJson.version;
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
44
|
-
} catch (error) {
|
|
45
|
-
isWorkletsAvailable = false;
|
|
18
|
+
export function clamp(value: number, min: number, max: number): number {
|
|
19
|
+
return Math.min(Math.max(value, min), max);
|
|
46
20
|
}
|