react-native-audio-api 0.4.10 → 0.4.12-beta.1

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 (116) hide show
  1. package/android/build.gradle +2 -0
  2. package/android/src/main/cpp/{core/AudioAPIInstaller.cpp → AudioAPIModule.cpp} +12 -11
  3. package/android/src/main/cpp/{core/AudioAPIInstaller.h → AudioAPIModule.h} +9 -11
  4. package/android/src/main/cpp/OnLoad.cpp +2 -2
  5. package/android/src/main/cpp/core/AudioDecoder.cpp +5 -5
  6. package/android/src/main/cpp/core/AudioPlayer.cpp +12 -0
  7. package/android/src/main/cpp/core/AudioPlayer.h +2 -0
  8. package/android/src/main/java/com/swmansion/audioapi/{module/AudioAPIInstaller.kt → AudioAPIModule.kt} +22 -10
  9. package/android/src/main/java/com/swmansion/audioapi/AudioAPIPackage.kt +31 -6
  10. package/android/src/oldarch/NativeAudioAPIModuleSpec.java +37 -0
  11. package/common/cpp/HostObjects/AudioBufferSourceNodeHostObject.h +1 -2
  12. package/common/cpp/HostObjects/AudioContextHostObject.h +34 -1
  13. package/common/cpp/HostObjects/BaseAudioContextHostObject.h +8 -0
  14. package/common/cpp/HostObjects/GainNodeHostObject.h +2 -2
  15. package/common/cpp/HostObjects/StretcherNodeHostObject.h +35 -0
  16. package/common/cpp/core/AnalyserNode.cpp +2 -2
  17. package/common/cpp/core/AnalyserNode.h +1 -1
  18. package/common/cpp/core/AudioBuffer.cpp +4 -2
  19. package/common/cpp/core/AudioBuffer.h +1 -1
  20. package/common/cpp/core/AudioBufferSourceNode.cpp +3 -3
  21. package/common/cpp/core/AudioBufferSourceNode.h +3 -3
  22. package/common/cpp/core/AudioBus.cpp +8 -0
  23. package/common/cpp/core/AudioBus.h +3 -0
  24. package/common/cpp/core/AudioContext.cpp +10 -0
  25. package/common/cpp/core/AudioContext.h +2 -0
  26. package/common/cpp/core/AudioDecoder.h +2 -1
  27. package/common/cpp/core/AudioDestinationNode.cpp +1 -1
  28. package/common/cpp/core/AudioDestinationNode.h +1 -1
  29. package/common/cpp/core/AudioNode.cpp +10 -6
  30. package/common/cpp/core/AudioNode.h +5 -3
  31. package/common/cpp/core/AudioScheduledSourceNode.cpp +1 -1
  32. package/common/cpp/core/AudioScheduledSourceNode.h +1 -1
  33. package/common/cpp/core/BaseAudioContext.cpp +7 -0
  34. package/common/cpp/core/BaseAudioContext.h +2 -0
  35. package/common/cpp/core/BiquadFilterNode.cpp +1 -1
  36. package/common/cpp/core/BiquadFilterNode.h +1 -1
  37. package/common/cpp/core/GainNode.cpp +3 -1
  38. package/common/cpp/core/GainNode.h +1 -1
  39. package/common/cpp/core/OscillatorNode.cpp +3 -1
  40. package/common/cpp/core/OscillatorNode.h +1 -1
  41. package/common/cpp/core/StereoPannerNode.cpp +1 -1
  42. package/common/cpp/core/StereoPannerNode.h +1 -1
  43. package/common/cpp/core/StretcherNode.cpp +96 -0
  44. package/common/cpp/core/StretcherNode.h +63 -0
  45. package/common/cpp/installer/AudioAPIModuleInstaller.h +49 -0
  46. package/common/cpp/libs/dsp/LICENSE.txt +21 -0
  47. package/common/cpp/libs/dsp/README.md +40 -0
  48. package/common/cpp/libs/dsp/common.h +47 -0
  49. package/common/cpp/libs/dsp/curves.h +371 -0
  50. package/common/cpp/libs/dsp/delay.h +717 -0
  51. package/common/cpp/libs/dsp/envelopes.h +523 -0
  52. package/common/cpp/libs/dsp/fft.h +523 -0
  53. package/common/cpp/libs/dsp/filters.h +436 -0
  54. package/common/cpp/libs/dsp/mix.h +218 -0
  55. package/common/cpp/libs/dsp/perf.h +84 -0
  56. package/common/cpp/libs/dsp/rates.h +184 -0
  57. package/common/cpp/libs/dsp/spectral.h +496 -0
  58. package/common/cpp/libs/dsp/windows.h +219 -0
  59. package/common/cpp/libs/signalsmith-stretch.h +637 -0
  60. package/common/cpp/types/TimeStretchType.h +6 -0
  61. package/ios/AudioAPIModule.h +1 -1
  62. package/ios/AudioAPIModule.mm +10 -3
  63. package/ios/core/AudioDecoder.mm +2 -3
  64. package/ios/core/AudioPlayer.h +14 -0
  65. package/ios/core/AudioPlayer.m +86 -25
  66. package/ios/core/IOSAudioPlayer.h +2 -0
  67. package/ios/core/IOSAudioPlayer.mm +10 -0
  68. package/lib/module/core/AudioContext.js +7 -1
  69. package/lib/module/core/AudioContext.js.map +1 -1
  70. package/lib/module/core/BaseAudioContext.js +4 -0
  71. package/lib/module/core/BaseAudioContext.js.map +1 -1
  72. package/lib/module/core/StretcherNode.js +12 -0
  73. package/lib/module/core/StretcherNode.js.map +1 -0
  74. package/lib/module/index.js +12 -3
  75. package/lib/module/index.js.map +1 -1
  76. package/lib/module/index.web.js +1 -1
  77. package/lib/module/index.web.js.map +1 -1
  78. package/lib/module/specs/NativeAudioAPIModule.js +5 -0
  79. package/lib/module/specs/NativeAudioAPIModule.js.map +1 -0
  80. package/lib/module/web-core/AudioContext.js +6 -0
  81. package/lib/module/web-core/AudioContext.js.map +1 -1
  82. package/lib/typescript/core/AudioContext.d.ts +2 -0
  83. package/lib/typescript/core/AudioContext.d.ts.map +1 -1
  84. package/lib/typescript/core/BaseAudioContext.d.ts +2 -0
  85. package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
  86. package/lib/typescript/core/StretcherNode.d.ts +10 -0
  87. package/lib/typescript/core/StretcherNode.d.ts.map +1 -0
  88. package/lib/typescript/index.d.ts +5 -0
  89. package/lib/typescript/index.d.ts.map +1 -1
  90. package/lib/typescript/index.web.d.ts +1 -1
  91. package/lib/typescript/index.web.d.ts.map +1 -1
  92. package/lib/typescript/interfaces.d.ts +11 -1
  93. package/lib/typescript/interfaces.d.ts.map +1 -1
  94. package/lib/typescript/specs/NativeAudioAPIModule.d.ts +7 -0
  95. package/lib/typescript/specs/NativeAudioAPIModule.d.ts.map +1 -0
  96. package/lib/typescript/web-core/AudioContext.d.ts +3 -1
  97. package/lib/typescript/web-core/AudioContext.d.ts.map +1 -1
  98. package/package.json +9 -7
  99. package/src/core/AudioContext.ts +9 -1
  100. package/src/core/BaseAudioContext.ts +5 -0
  101. package/src/core/StretcherNode.ts +15 -0
  102. package/src/index.ts +17 -3
  103. package/src/index.web.ts +1 -0
  104. package/src/interfaces.ts +13 -1
  105. package/src/specs/NativeAudioAPIModule.ts +7 -0
  106. package/src/web-core/AudioContext.tsx +9 -1
  107. package/android/src/main/java/com/swmansion/audioapi/nativemodules/AudioAPIModule.kt +0 -26
  108. package/common/cpp/HostObjects/AudioAPIInstallerHostObject.h +0 -56
  109. package/lib/module/specs/global.d.js +0 -4
  110. package/lib/module/specs/global.d.js.map +0 -1
  111. package/lib/module/specs/install.js +0 -18
  112. package/lib/module/specs/install.js.map +0 -1
  113. package/lib/typescript/specs/install.d.ts +0 -7
  114. package/lib/typescript/specs/install.d.ts.map +0 -1
  115. package/src/specs/global.d.ts +0 -12
  116. package/src/specs/install.ts +0 -32
@@ -11,10 +11,18 @@ export default class AudioContext extends BaseAudioContext {
11
11
  );
12
12
  }
13
13
 
14
- super(global.__AudioAPIInstaller.createAudioContext(options?.sampleRate));
14
+ super(global.createAudioContext(options?.sampleRate));
15
15
  }
16
16
 
17
17
  async close(): Promise<undefined> {
18
18
  await (this.context as IAudioContext).close();
19
19
  }
20
+
21
+ async resume(): Promise<undefined> {
22
+ await (this.context as IAudioContext).resume();
23
+ }
24
+
25
+ async suspend(): Promise<undefined> {
26
+ await (this.context as IAudioContext).suspend();
27
+ }
20
28
  }
@@ -9,6 +9,7 @@ import AudioBufferSourceNode from './AudioBufferSourceNode';
9
9
  import AudioBuffer from './AudioBuffer';
10
10
  import PeriodicWave from './PeriodicWave';
11
11
  import AnalyserNode from './AnalyserNode';
12
+ import StretcherNode from './StretcherNode';
12
13
  import { InvalidAccessError, NotSupportedError } from '../errors';
13
14
 
14
15
  export default class BaseAudioContext {
@@ -100,6 +101,10 @@ export default class BaseAudioContext {
100
101
  return new AnalyserNode(this, this.context.createAnalyser());
101
102
  }
102
103
 
104
+ createStretcher(): StretcherNode {
105
+ return new StretcherNode(this, this.context.createStretcher());
106
+ }
107
+
103
108
  async decodeAudioDataSource(sourcePath: string): Promise<AudioBuffer> {
104
109
  // Remove the file:// prefix if it exists
105
110
  if (sourcePath.startsWith('file://')) {
@@ -0,0 +1,15 @@
1
+ import { IStretcherNode } from '../interfaces';
2
+ import AudioNode from './AudioNode';
3
+ import AudioParam from './AudioParam';
4
+ import BaseAudioContext from './BaseAudioContext';
5
+
6
+ export default class StretcherNode extends AudioNode {
7
+ readonly rate: AudioParam;
8
+ readonly semitones: AudioParam;
9
+
10
+ constructor(context: BaseAudioContext, stretcher: IStretcherNode) {
11
+ super(context, stretcher);
12
+ this.rate = new AudioParam(stretcher.rate);
13
+ this.semitones = new AudioParam(stretcher.semitones);
14
+ }
15
+ }
package/src/index.ts CHANGED
@@ -1,7 +1,20 @@
1
- import { installModule } from './specs/install';
1
+ import NativeAudioAPIModule from './specs/NativeAudioAPIModule';
2
+ import type { IAudioContext } from './interfaces';
2
3
 
3
- if (global.__AudioAPIInstaller == null) {
4
- installModule();
4
+ /* eslint-disable no-var */
5
+ declare global {
6
+ var createAudioContext: (sampleRate?: number) => IAudioContext;
7
+ }
8
+ /* eslint-disable no-var */
9
+
10
+ if (global.createAudioContext == null) {
11
+ if (!NativeAudioAPIModule) {
12
+ throw new Error(
13
+ `Failed to install react-native-audio-api: The native module could not be found.`
14
+ );
15
+ }
16
+
17
+ NativeAudioAPIModule.install();
5
18
  }
6
19
 
7
20
  export { default as AudioBuffer } from './core/AudioBuffer';
@@ -17,6 +30,7 @@ export { default as BiquadFilterNode } from './core/BiquadFilterNode';
17
30
  export { default as GainNode } from './core/GainNode';
18
31
  export { default as OscillatorNode } from './core/OscillatorNode';
19
32
  export { default as StereoPannerNode } from './core/StereoPannerNode';
33
+ export { default as StretcherNode } from './core/StretcherNode';
20
34
 
21
35
  export {
22
36
  OscillatorType,
package/src/index.web.ts CHANGED
@@ -27,4 +27,5 @@ export {
27
27
  InvalidAccessError,
28
28
  InvalidStateError,
29
29
  RangeError,
30
+ NotSupportedError,
30
31
  } from './errors';
package/src/interfaces.ts CHANGED
@@ -7,6 +7,10 @@ import {
7
7
  WindowType,
8
8
  } from './types';
9
9
 
10
+ export interface AudioAPIInstaller {
11
+ createAudioContext: (sampleRate?: number) => IAudioContext;
12
+ }
13
+
10
14
  export interface IBaseAudioContext {
11
15
  readonly destination: IAudioDestinationNode;
12
16
  readonly state: ContextState;
@@ -29,11 +33,14 @@ export interface IBaseAudioContext {
29
33
  disableNormalization: boolean
30
34
  ) => IPeriodicWave;
31
35
  createAnalyser: () => IAnalyserNode;
36
+ createStretcher: () => IStretcherNode;
32
37
  decodeAudioDataSource: (sourcePath: string) => Promise<IAudioBuffer>;
33
38
  }
34
39
 
35
40
  export interface IAudioContext extends IBaseAudioContext {
36
- close(): Promise<undefined>;
41
+ close(): Promise<void>;
42
+ resume(): Promise<void>;
43
+ suspend(): Promise<void>;
37
44
  }
38
45
 
39
46
  export interface IAudioNode {
@@ -153,3 +160,8 @@ export interface IAnalyserNode extends IAudioNode {
153
160
  getFloatTimeDomainData: (array: number[]) => void;
154
161
  getByteTimeDomainData: (array: number[]) => void;
155
162
  }
163
+
164
+ export interface IStretcherNode extends IAudioNode {
165
+ readonly rate: IAudioParam;
166
+ readonly semitones: IAudioParam;
167
+ }
@@ -0,0 +1,7 @@
1
+ import { TurboModuleRegistry, TurboModule } from 'react-native';
2
+
3
+ interface Spec extends TurboModule {
4
+ install(): boolean;
5
+ }
6
+
7
+ export default TurboModuleRegistry.get<Spec>('AudioAPIModule');
@@ -118,7 +118,15 @@ export default class AudioContext implements BaseAudioContext {
118
118
  return new AudioBuffer(await this.context.decodeAudioData(arrayBuffer));
119
119
  }
120
120
 
121
- async close(): Promise<undefined> {
121
+ async close(): Promise<void> {
122
122
  await this.context.close();
123
123
  }
124
+
125
+ async resume(): Promise<void> {
126
+ await this.context.resume();
127
+ }
128
+
129
+ async suspend(): Promise<void> {
130
+ await this.context.suspend();
131
+ }
124
132
  }
@@ -1,26 +0,0 @@
1
- package com.swmansion.audioapi.nativemodules
2
-
3
- import com.facebook.react.bridge.ReactApplicationContext
4
- import com.facebook.react.bridge.ReactContextBaseJavaModule
5
- import com.facebook.react.bridge.ReactMethod
6
- import com.facebook.react.module.annotations.ReactModule
7
- import com.swmansion.audioapi.module.AudioAPIInstaller
8
-
9
- @ReactModule(name = AudioAPIModule.NAME)
10
- class AudioAPIModule(
11
- private val reactContext: ReactApplicationContext,
12
- ) : ReactContextBaseJavaModule(reactContext) {
13
- companion object {
14
- const val NAME: String = "AudioAPIModule"
15
- }
16
-
17
- override fun getName(): String = NAME
18
-
19
- @ReactMethod(isBlockingSynchronousMethod = true)
20
- fun install(): Boolean {
21
- val audioAPIInstaller = AudioAPIInstaller(reactContext)
22
- audioAPIInstaller.install()
23
-
24
- return true
25
- }
26
- }
@@ -1,56 +0,0 @@
1
- #pragma once
2
-
3
- #include <ReactCommon/CallInvoker.h>
4
- #include <jsi/jsi.h>
5
- #include <memory>
6
- #include <utility>
7
- #include <vector>
8
-
9
- #include <JsiHostObject.h>
10
- #include <JsiPromise.h>
11
- #include "AudioContextHostObject.h"
12
-
13
- namespace audioapi {
14
- using namespace facebook;
15
-
16
- class AudioAPIInstallerHostObject
17
- : public JsiHostObject,
18
- public std::enable_shared_from_this<AudioAPIInstallerHostObject> {
19
- public:
20
- explicit AudioAPIInstallerHostObject(
21
- jsi::Runtime *runtime,
22
- const std::shared_ptr<react::CallInvoker> &jsInvoker)
23
- : rnRuntime_(runtime) {
24
- promiseVendor_ = std::make_shared<PromiseVendor>(runtime, jsInvoker);
25
-
26
- addFunctions(
27
- JSI_EXPORT_FUNCTION(AudioAPIInstallerHostObject, createAudioContext));
28
- }
29
-
30
- void install() {
31
- auto object =
32
- jsi::Object::createFromHostObject(*rnRuntime_, shared_from_this());
33
- rnRuntime_->global().setProperty(
34
- *rnRuntime_, "__AudioAPIInstaller", std::move(object));
35
- }
36
-
37
- JSI_HOST_FUNCTION(createAudioContext) {
38
- std::shared_ptr<AudioContext> audioContext;
39
- if (args[0].isUndefined()) {
40
- audioContext = std::make_shared<AudioContext>();
41
- } else {
42
- auto sampleRate = static_cast<float>(args[0].getNumber());
43
- audioContext = std::make_shared<AudioContext>(sampleRate);
44
- }
45
-
46
- auto audioContextHostObject =
47
- std::make_shared<AudioContextHostObject>(audioContext, promiseVendor_);
48
-
49
- return jsi::Object::createFromHostObject(runtime, audioContextHostObject);
50
- }
51
-
52
- private:
53
- std::shared_ptr<PromiseVendor> promiseVendor_;
54
- jsi::Runtime *rnRuntime_;
55
- };
56
- } // namespace audioapi
@@ -1,4 +0,0 @@
1
- "use strict";
2
-
3
- export {};
4
- //# sourceMappingURL=global.d.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../src","sources":["specs/global.d.ts"],"mappings":"","ignoreList":[]}
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- import { TurboModuleRegistry } from 'react-native';
4
- export function installModule() {
5
- const AudioAPIModule = TurboModuleRegistry.get('AudioAPIModule');
6
- if (AudioAPIModule == null) {
7
- throw new Error(`Failed to install react-native-audio-api: The native module could not be found.`);
8
- }
9
- const result = AudioAPIModule.install();
10
- if (result !== true) {
11
- throw new Error(`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}`);
12
- }
13
- if (global.__AudioAPIInstaller == null) {
14
- throw new Error('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?');
15
- }
16
- return AudioAPIModule;
17
- }
18
- //# sourceMappingURL=install.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["TurboModuleRegistry","installModule","AudioAPIModule","get","Error","result","install","global","__AudioAPIInstaller"],"sourceRoot":"../../../src","sources":["specs/install.ts"],"mappings":";;AAAA,SAASA,mBAAmB,QAAqB,cAAc;AAM/D,OAAO,SAASC,aAAaA,CAAA,EAAG;EAC9B,MAAMC,cAAc,GAClBF,mBAAmB,CAACG,GAAG,CAAqB,gBAAgB,CAAC;EAE/D,IAAID,cAAc,IAAI,IAAI,EAAE;IAC1B,MAAM,IAAIE,KAAK,CACb,iFACF,CAAC;EACH;EAEA,MAAMC,MAAM,GAAGH,cAAc,CAACI,OAAO,CAAC,CAAC;EAEvC,IAAID,MAAM,KAAK,IAAI,EAAE;IACnB,MAAM,IAAID,KAAK,CACb,+JAA+JC,MAAM,EACvK,CAAC;EACH;EAEA,IAAIE,MAAM,CAACC,mBAAmB,IAAI,IAAI,EAAE;IACtC,MAAM,IAAIJ,KAAK,CACb,sJACF,CAAC;EACH;EAEA,OAAOF,cAAc;AACvB","ignoreList":[]}
@@ -1,7 +0,0 @@
1
- import { TurboModule } from 'react-native';
2
- interface AudioAPIModuleSpec extends TurboModule {
3
- install(): boolean;
4
- }
5
- export declare function installModule(): AudioAPIModuleSpec;
6
- export {};
7
- //# sourceMappingURL=install.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../src/specs/install.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhE,UAAU,kBAAmB,SAAQ,WAAW;IAC9C,OAAO,IAAI,OAAO,CAAC;CACpB;AAED,wBAAgB,aAAa,uBAyB5B"}
@@ -1,12 +0,0 @@
1
- /* eslint-disable no-var */
2
- import type { IAudioContext } from '../interfaces';
3
-
4
- type AudioAPIInstaller = {
5
- createAudioContext: (sampleRate?: number) => IAudioContext;
6
- };
7
-
8
- declare global {
9
- function nativeCallSyncHook(): unknown;
10
- var __AudioAPIInstaller: AudioAPIInstaller;
11
- }
12
- /* eslint-disable no-var */
@@ -1,32 +0,0 @@
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.get<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
- const result = AudioAPIModule.install();
18
-
19
- if (result !== true) {
20
- throw new Error(
21
- `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}`
22
- );
23
- }
24
-
25
- if (global.__AudioAPIInstaller == null) {
26
- throw new Error(
27
- '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?'
28
- );
29
- }
30
-
31
- return AudioAPIModule;
32
- }