react-native-audio-api 0.9.1 → 0.9.2
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/RNAudioAPI.podspec +5 -2
- package/android/build.gradle +26 -2
- package/android/src/main/cpp/audioapi/android/AudioAPIModule.cpp +5 -0
- package/android/src/main/cpp/audioapi/android/AudioAPIModule.h +1 -0
- package/android/src/main/cpp/audioapi/android/core/AudioPlayer.cpp +4 -2
- package/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +29 -1
- package/common/cpp/audioapi/AudioAPIModuleInstaller.h +37 -6
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp +12 -5
- package/common/cpp/audioapi/core/BaseAudioContext.cpp +12 -6
- package/common/cpp/audioapi/core/BaseAudioContext.h +14 -3
- package/common/cpp/audioapi/core/effects/WorkletNode.cpp +31 -32
- package/common/cpp/audioapi/core/effects/WorkletNode.h +4 -7
- package/common/cpp/audioapi/core/effects/WorkletProcessingNode.cpp +12 -13
- package/common/cpp/audioapi/core/effects/WorkletProcessingNode.h +2 -5
- package/common/cpp/audioapi/core/sources/WorkletSourceNode.cpp +12 -13
- package/common/cpp/audioapi/core/sources/WorkletSourceNode.h +2 -5
- package/common/cpp/audioapi/core/utils/worklets/SafeIncludes.h +32 -13
- package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.cpp +75 -2
- package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.h +50 -36
- package/ios/audioapi/ios/AudioAPIModule.h +2 -1
- package/ios/audioapi/ios/AudioAPIModule.mm +2 -0
- package/ios/audioapi/ios/core/IOSAudioRecorder.h +2 -1
- package/lib/commonjs/core/AudioContext.js +1 -5
- package/lib/commonjs/core/AudioContext.js.map +1 -1
- package/lib/commonjs/core/BaseAudioContext.js +16 -25
- package/lib/commonjs/core/BaseAudioContext.js.map +1 -1
- package/lib/commonjs/core/OfflineAudioContext.js +1 -5
- package/lib/commonjs/core/OfflineAudioContext.js.map +1 -1
- package/lib/commonjs/utils/index.js +20 -4
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/module/core/AudioContext.js +2 -6
- package/lib/module/core/AudioContext.js.map +1 -1
- package/lib/module/core/BaseAudioContext.js +17 -26
- package/lib/module/core/BaseAudioContext.js.map +1 -1
- package/lib/module/core/OfflineAudioContext.js +2 -6
- package/lib/module/core/OfflineAudioContext.js.map +1 -1
- package/lib/module/utils/index.js +16 -1
- package/lib/module/utils/index.js.map +1 -1
- package/lib/typescript/core/AudioContext.d.ts +0 -1
- package/lib/typescript/core/AudioContext.d.ts.map +1 -1
- package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
- package/lib/typescript/core/OfflineAudioContext.d.ts +0 -1
- package/lib/typescript/core/OfflineAudioContext.d.ts.map +1 -1
- package/lib/typescript/utils/index.d.ts +4 -1
- package/lib/typescript/utils/index.d.ts.map +1 -1
- package/package.json +4 -1
- package/scripts/rnaa_utils.rb +8 -0
- package/scripts/validate-worklets-version.js +28 -0
- package/src/core/AudioContext.ts +3 -7
- package/src/core/BaseAudioContext.ts +44 -60
- package/src/core/OfflineAudioContext.ts +2 -7
- package/src/utils/index.ts +23 -1
|
@@ -5,16 +5,6 @@
|
|
|
5
5
|
#include <string>
|
|
6
6
|
#include <memory>
|
|
7
7
|
|
|
8
|
-
#ifdef __APPLE__
|
|
9
|
-
/// We cannot make any conditional logic inside podspec but it should automatically compile those files
|
|
10
|
-
/// they should be accessible if someone has react-native-worklets in node_modules
|
|
11
|
-
#if __has_include(<worklets/WorkletRuntime/WorkletRuntime.h>)
|
|
12
|
-
#define RN_AUDIO_API_ENABLE_WORKLETS 1
|
|
13
|
-
#else
|
|
14
|
-
#define RN_AUDIO_API_ENABLE_WORKLETS 0
|
|
15
|
-
#endif
|
|
16
|
-
#endif
|
|
17
|
-
|
|
18
8
|
#ifndef RN_AUDIO_API_TEST
|
|
19
9
|
#define RN_AUDIO_API_TEST 0
|
|
20
10
|
#endif
|
|
@@ -27,6 +17,11 @@
|
|
|
27
17
|
#include <worklets/android/WorkletsModule.h>
|
|
28
18
|
#endif
|
|
29
19
|
#else
|
|
20
|
+
|
|
21
|
+
#define RN_AUDIO_API_WORKLETS_DISABLED_ERROR \
|
|
22
|
+
std::runtime_error( \
|
|
23
|
+
"Worklets are disabled. Please install react-native-worklets or check if you have supported version to enable these features.");
|
|
24
|
+
|
|
30
25
|
/// @brief Dummy implementation of worklets for non-worklet builds they should do nothing and mock necessary methods
|
|
31
26
|
/// @note It helps to reduce compile time branching across codebase
|
|
32
27
|
/// @note If you need to base some c++ implementation on if the worklets are enabled use `#if RN_AUDIO_API_ENABLE_WORKLETS`
|
|
@@ -36,17 +31,41 @@ using namespace facebook;
|
|
|
36
31
|
class MessageQueueThread {};
|
|
37
32
|
class WorkletsModuleProxy {};
|
|
38
33
|
class WorkletRuntime {
|
|
39
|
-
|
|
34
|
+
public:
|
|
35
|
+
explicit WorkletRuntime(uint64_t, const std::shared_ptr<MessageQueueThread> &, const std::string &, const bool) {
|
|
36
|
+
throw RN_AUDIO_API_WORKLETS_DISABLED_ERROR
|
|
37
|
+
}
|
|
38
|
+
jsi::Runtime &getJSIRuntime() const {
|
|
39
|
+
throw RN_AUDIO_API_WORKLETS_DISABLED_ERROR
|
|
40
|
+
}
|
|
41
|
+
jsi::Value executeSync(jsi::Runtime &rt, const jsi::Value &worklet) const {
|
|
42
|
+
throw RN_AUDIO_API_WORKLETS_DISABLED_ERROR
|
|
43
|
+
}
|
|
44
|
+
jsi::Value executeSync(std::function<jsi::Value(jsi::Runtime &)> &&job) const {
|
|
45
|
+
throw RN_AUDIO_API_WORKLETS_DISABLED_ERROR
|
|
46
|
+
}
|
|
47
|
+
jsi::Value executeSync(const std::function<jsi::Value(jsi::Runtime &)> &job) const {
|
|
48
|
+
throw RN_AUDIO_API_WORKLETS_DISABLED_ERROR
|
|
49
|
+
}
|
|
40
50
|
};
|
|
41
51
|
class SerializableWorklet {
|
|
42
|
-
|
|
52
|
+
public:
|
|
53
|
+
SerializableWorklet(jsi::Runtime*, const jsi::Object &) {
|
|
54
|
+
throw RN_AUDIO_API_WORKLETS_DISABLED_ERROR
|
|
55
|
+
}
|
|
56
|
+
jsi::Value toJSValue(jsi::Runtime &rt) {
|
|
57
|
+
throw RN_AUDIO_API_WORKLETS_DISABLED_ERROR
|
|
58
|
+
}
|
|
43
59
|
};
|
|
44
60
|
} // namespace worklets
|
|
61
|
+
|
|
62
|
+
#undef RN_AUDIO_API_WORKLETS_DISABLED_ERROR
|
|
63
|
+
|
|
45
64
|
#endif
|
|
46
65
|
|
|
47
66
|
/// @brief Struct to hold references to different runtimes used in the AudioAPI
|
|
48
67
|
/// @note it is used to pass them around and avoid creating multiple instances of the same runtime
|
|
49
68
|
struct RuntimeRegistry {
|
|
50
69
|
std::weak_ptr<worklets::WorkletRuntime> uiRuntime;
|
|
51
|
-
std::
|
|
70
|
+
std::shared_ptr<worklets::WorkletRuntime> audioRuntime;
|
|
52
71
|
};
|
|
@@ -3,7 +3,80 @@
|
|
|
3
3
|
namespace audioapi {
|
|
4
4
|
|
|
5
5
|
WorkletsRunner::WorkletsRunner(
|
|
6
|
-
std::weak_ptr<worklets::WorkletRuntime>
|
|
7
|
-
|
|
6
|
+
std::weak_ptr<worklets::WorkletRuntime> weakRuntime,
|
|
7
|
+
std::shared_ptr<worklets::SerializableWorklet> shareableWorklet,
|
|
8
|
+
bool shouldLockRuntime)
|
|
9
|
+
: weakRuntime_(std::move(weakRuntime)),
|
|
10
|
+
shouldLockRuntime(shouldLockRuntime) {
|
|
11
|
+
auto strongRuntime = weakRuntime_.lock();
|
|
12
|
+
if (strongRuntime == nullptr) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
#if RN_AUDIO_API_ENABLE_WORKLETS
|
|
16
|
+
unsafeRuntimePtr = &strongRuntime->getJSIRuntime();
|
|
17
|
+
strongRuntime->executeSync(
|
|
18
|
+
[this, shareableWorklet](jsi::Runtime &rt) -> jsi::Value {
|
|
19
|
+
/// Placement new to avoid dynamic memory allocation
|
|
20
|
+
new (reinterpret_cast<jsi::Function *>(&unsafeWorklet))
|
|
21
|
+
jsi::Function(shareableWorklet->toJSValue(*unsafeRuntimePtr)
|
|
22
|
+
.asObject(*unsafeRuntimePtr)
|
|
23
|
+
.asFunction(*unsafeRuntimePtr));
|
|
24
|
+
return jsi::Value::undefined();
|
|
25
|
+
});
|
|
26
|
+
workletInitialized = true;
|
|
27
|
+
#else
|
|
28
|
+
unsafeRuntimePtr = nullptr;
|
|
29
|
+
workletInitialized = false;
|
|
30
|
+
#endif
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
WorkletsRunner::WorkletsRunner(WorkletsRunner &&other)
|
|
34
|
+
: weakRuntime_(std::move(other.weakRuntime_)),
|
|
35
|
+
unsafeRuntimePtr(other.unsafeRuntimePtr),
|
|
36
|
+
shouldLockRuntime(other.shouldLockRuntime),
|
|
37
|
+
workletInitialized(other.workletInitialized) {
|
|
38
|
+
if (workletInitialized) {
|
|
39
|
+
std::memcpy(&unsafeWorklet, &other.unsafeWorklet, sizeof(unsafeWorklet));
|
|
40
|
+
other.workletInitialized = false;
|
|
41
|
+
other.unsafeRuntimePtr = nullptr;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
WorkletsRunner::~WorkletsRunner() {
|
|
46
|
+
if (!workletInitialized) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
auto strongRuntime = weakRuntime_.lock();
|
|
50
|
+
if (strongRuntime == nullptr) {
|
|
51
|
+
// We cannot safely destroy the worklet without a valid runtime
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
reinterpret_cast<jsi::Function *>(&unsafeWorklet)->~Function();
|
|
55
|
+
workletInitialized = false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
std::optional<jsi::Value> WorkletsRunner::executeOnRuntimeGuarded(
|
|
59
|
+
const std::function<jsi::Value(jsi::Runtime &)> &&job) const
|
|
60
|
+
noexcept(noexcept(job)) {
|
|
61
|
+
auto strongRuntime = weakRuntime_.lock();
|
|
62
|
+
if (strongRuntime == nullptr) {
|
|
63
|
+
return std::nullopt;
|
|
64
|
+
}
|
|
65
|
+
#if RN_AUDIO_API_ENABLE_WORKLETS
|
|
66
|
+
return strongRuntime->executeSync(std::move(job));
|
|
67
|
+
#else
|
|
68
|
+
return std::nullopt;
|
|
69
|
+
#endif
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
std::optional<jsi::Value> WorkletsRunner::executeOnRuntimeUnsafe(
|
|
73
|
+
const std::function<jsi::Value(jsi::Runtime &)> &&job) const
|
|
74
|
+
noexcept(noexcept(job)) {
|
|
75
|
+
#if RN_AUDIO_API_ENABLE_WORKLETS
|
|
76
|
+
return job(*unsafeRuntimePtr);
|
|
77
|
+
#else
|
|
78
|
+
return std::nullopt;
|
|
79
|
+
#endif
|
|
80
|
+
};
|
|
8
81
|
|
|
9
82
|
}; // namespace audioapi
|
|
@@ -26,48 +26,62 @@ using namespace facebook;
|
|
|
26
26
|
|
|
27
27
|
class WorkletsRunner {
|
|
28
28
|
public:
|
|
29
|
-
|
|
29
|
+
explicit WorkletsRunner(
|
|
30
|
+
std::weak_ptr<worklets::WorkletRuntime> weakRuntime,
|
|
31
|
+
std::shared_ptr<worklets::SerializableWorklet> shareableWorklet,
|
|
32
|
+
bool shouldLockRuntime = true);
|
|
33
|
+
WorkletsRunner(WorkletsRunner&&);
|
|
34
|
+
~WorkletsRunner();
|
|
30
35
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
#if RN_AUDIO_API_ENABLE_WORKLETS
|
|
41
|
-
return strongRuntime->executeSync(std::move(job));
|
|
42
|
-
#else
|
|
43
|
-
return std::nullopt;
|
|
44
|
-
#endif
|
|
45
|
-
}
|
|
36
|
+
/// @brief Call the worklet function with the given arguments.
|
|
37
|
+
/// @tparam ...Args
|
|
38
|
+
/// @param ...args
|
|
39
|
+
/// @return The result of the worklet function call.
|
|
40
|
+
/// @note This method is unsafe and should be used with caution. It assumes that the runtime and worklet are valid and runtime is locked.
|
|
41
|
+
template<typename... Args>
|
|
42
|
+
inline jsi::Value callUnsafe(Args&&... args) {
|
|
43
|
+
return getUnsafeWorklet().call(*unsafeRuntimePtr, std::forward<Args>(args)...);
|
|
44
|
+
}
|
|
46
45
|
|
|
47
|
-
/// @brief Execute a worklet with the given arguments.
|
|
48
|
-
/// @tparam ...Args
|
|
49
|
-
/// @param shareableWorklet
|
|
50
|
-
/// @param ...args
|
|
51
|
-
/// @note Execution is synchronous, this method can be used in `executeOnRuntimeGuardedSync` and `...Async` methods arguments
|
|
52
|
-
/// @return nullopt if the runtime is not available or the result of the worklet execution
|
|
53
|
-
template<typename... Args>
|
|
54
|
-
std::optional<jsi::Value> executeWorklet(const std::shared_ptr<worklets::SerializableWorklet>& shareableWorklet, Args&&... args) {
|
|
55
|
-
auto strongRuntime = weakUiRuntime_.lock();
|
|
56
|
-
if (strongRuntime == nullptr) {
|
|
57
|
-
return std::nullopt;
|
|
58
|
-
}
|
|
59
46
|
|
|
60
|
-
|
|
47
|
+
/// @brief Call the worklet function with the given arguments.
|
|
48
|
+
/// @tparam ...Args
|
|
49
|
+
/// @param ...args
|
|
50
|
+
/// @return The result of the worklet function call.
|
|
51
|
+
/// @note This method is safe and will check if the runtime is available before calling the worklet. If the runtime is not available, it will return nullopt.
|
|
52
|
+
template<typename... Args>
|
|
53
|
+
inline std::optional<jsi::Value> call(Args&&... args) {
|
|
54
|
+
return executeOnRuntimeGuarded([this, args...](jsi::Runtime &rt) -> jsi::Value {
|
|
55
|
+
return callUnsafe(std::forward<Args>(args)...);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
61
58
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
59
|
+
/// @brief Execute a job on the UI runtime safely.
|
|
60
|
+
/// @param job
|
|
61
|
+
/// @return nullopt if the runtime is not available or the result of the job execution
|
|
62
|
+
/// @note Execution is synchronous and will be guarded if shouldLockRuntime is true.
|
|
63
|
+
inline std::optional<jsi::Value> executeOnRuntimeSync(const std::function<jsi::Value(jsi::Runtime&)>&& job) const noexcept(noexcept(job)) {
|
|
64
|
+
if (shouldLockRuntime) return executeOnRuntimeGuarded(std::move(job));
|
|
65
|
+
else return executeOnRuntimeUnsafe(std::move(job));
|
|
66
|
+
}
|
|
68
67
|
|
|
69
68
|
private:
|
|
70
|
-
|
|
69
|
+
std::weak_ptr<worklets::WorkletRuntime> weakRuntime_;
|
|
70
|
+
jsi::Runtime* unsafeRuntimePtr = nullptr;
|
|
71
|
+
|
|
72
|
+
/// @note We want to avoid automatic destruction as
|
|
73
|
+
/// when runtime is destroyed, underlying pointer will be invalid
|
|
74
|
+
char unsafeWorklet[sizeof(jsi::Function)];
|
|
75
|
+
bool workletInitialized = false;
|
|
76
|
+
bool shouldLockRuntime = true;
|
|
77
|
+
|
|
78
|
+
inline jsi::Function &getUnsafeWorklet() {
|
|
79
|
+
return *reinterpret_cast<jsi::Function*>(&unsafeWorklet);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
std::optional<jsi::Value> executeOnRuntimeGuarded(const std::function<jsi::Value(jsi::Runtime&)>&& job) const noexcept(noexcept(job));
|
|
83
|
+
|
|
84
|
+
std::optional<jsi::Value> executeOnRuntimeUnsafe(const std::function<jsi::Value(jsi::Runtime&)>&& job) const noexcept(noexcept(job));
|
|
71
85
|
};
|
|
72
86
|
|
|
73
87
|
} // namespace audioapi
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
2
2
|
#import <React/RCTCallInvokerModule.h>
|
|
3
|
+
#import <React/RCTInvalidating.h>
|
|
3
4
|
#import <rnaudioapi/rnaudioapi.h>
|
|
4
5
|
#else // RCT_NEW_ARCH_ENABLED
|
|
5
6
|
#import <React/RCTBridgeModule.h>
|
|
@@ -14,7 +15,7 @@
|
|
|
14
15
|
|
|
15
16
|
@interface AudioAPIModule : RCTEventEmitter
|
|
16
17
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
17
|
-
<NativeAudioAPIModuleSpec, RCTCallInvokerModule>
|
|
18
|
+
<NativeAudioAPIModuleSpec, RCTCallInvokerModule, RCTInvalidating>
|
|
18
19
|
#else
|
|
19
20
|
<RCTBridgeModule>
|
|
20
21
|
#endif // RCT_NEW_ARCH_ENABLED
|
|
@@ -18,7 +18,8 @@ class IOSAudioRecorder : public AudioRecorder {
|
|
|
18
18
|
IOSAudioRecorder(
|
|
19
19
|
float sampleRate,
|
|
20
20
|
int bufferLength,
|
|
21
|
-
const std::shared_ptr<AudioEventHandlerRegistry>
|
|
21
|
+
const std::shared_ptr<AudioEventHandlerRegistry>
|
|
22
|
+
&audioEventHandlerRegistry);
|
|
22
23
|
|
|
23
24
|
~IOSAudioRecorder() override;
|
|
24
25
|
|
|
@@ -10,19 +10,15 @@ var _errors = require("../errors");
|
|
|
10
10
|
var _utils = require("../utils");
|
|
11
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
12
|
class AudioContext extends _BaseAudioContext.default {
|
|
13
|
-
// We need to keep here a reference to this runtime to better manage its lifecycle
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
|
|
15
|
-
_audioRuntime = null;
|
|
16
13
|
constructor(options) {
|
|
17
14
|
if (options && options.sampleRate && (options.sampleRate < 8000 || options.sampleRate > 96000)) {
|
|
18
15
|
throw new _errors.NotSupportedError(`The provided sampleRate is not supported: ${options.sampleRate}`);
|
|
19
16
|
}
|
|
20
17
|
let audioRuntime = null;
|
|
21
|
-
if (_utils.
|
|
18
|
+
if (_utils.isWorkletsVersionSupported) {
|
|
22
19
|
audioRuntime = _utils.workletsModule.createWorkletRuntime('AudioWorkletRuntime');
|
|
23
20
|
}
|
|
24
21
|
super(global.createAudioContext(options?.sampleRate || _system.default.getDevicePreferredSampleRate(), options?.initSuspended || false, audioRuntime));
|
|
25
|
-
this._audioRuntime = audioRuntime;
|
|
26
22
|
}
|
|
27
23
|
async close() {
|
|
28
24
|
return this.context.close();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_BaseAudioContext","_interopRequireDefault","require","_system","_errors","_utils","e","__esModule","default","AudioContext","BaseAudioContext","
|
|
1
|
+
{"version":3,"names":["_BaseAudioContext","_interopRequireDefault","require","_system","_errors","_utils","e","__esModule","default","AudioContext","BaseAudioContext","constructor","options","sampleRate","NotSupportedError","audioRuntime","isWorkletsVersionSupported","workletsModule","createWorkletRuntime","global","createAudioContext","AudioManager","getDevicePreferredSampleRate","initSuspended","close","context","resume","suspend","exports"],"sourceRoot":"../../../src","sources":["core/AudioContext.ts"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAAsE,SAAAD,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEvD,MAAMG,YAAY,SAASC,yBAAgB,CAAC;EACzDC,WAAWA,CAACC,OAA6B,EAAE;IACzC,IACEA,OAAO,IACPA,OAAO,CAACC,UAAU,KACjBD,OAAO,CAACC,UAAU,GAAG,IAAI,IAAID,OAAO,CAACC,UAAU,GAAG,KAAK,CAAC,EACzD;MACA,MAAM,IAAIC,yBAAiB,CACzB,6CAA6CF,OAAO,CAACC,UAAU,EACjE,CAAC;IACH;IACA,IAAIE,YAAY,GAAG,IAAI;IAEvB,IAAIC,iCAA0B,EAAE;MAC9BD,YAAY,GAAGE,qBAAc,CAACC,oBAAoB,CAAC,qBAAqB,CAAC;IAC3E;IAEA,KAAK,CACHC,MAAM,CAACC,kBAAkB,CACvBR,OAAO,EAAEC,UAAU,IAAIQ,eAAY,CAACC,4BAA4B,CAAC,CAAC,EAClEV,OAAO,EAAEW,aAAa,IAAI,KAAK,EAC/BR,YACF,CACF,CAAC;EACH;EAEA,MAAMS,KAAKA,CAAA,EAAkB;IAC3B,OAAQ,IAAI,CAACC,OAAO,CAAmBD,KAAK,CAAC,CAAC;EAChD;EAEA,MAAME,MAAMA,CAAA,EAAqB;IAC/B,OAAQ,IAAI,CAACD,OAAO,CAAmBC,MAAM,CAAC,CAAC;EACjD;EAEA,MAAMC,OAAOA,CAAA,EAAqB;IAChC,OAAQ,IAAI,CAACF,OAAO,CAAmBE,OAAO,CAAC,CAAC;EAClD;AACF;AAACC,OAAA,CAAApB,OAAA,GAAAC,YAAA","ignoreList":[]}
|
|
@@ -42,37 +42,28 @@ class BaseAudioContext {
|
|
|
42
42
|
if (bufferLength < 1) {
|
|
43
43
|
throw new _errors.NotSupportedError(`The buffer length provided (${bufferLength}) can not be less than 1`);
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
(0, _utils.assertWorkletsEnabled)();
|
|
46
|
+
const shareableWorklet = _utils.workletsModule.makeShareableCloneRecursive((audioBuffers, channelCount) => {
|
|
47
|
+
'worklet';
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
/// User does not have worklets as a dependency so he cannot use the worklet API.
|
|
55
|
-
throw new Error('[RnAudioApi] Worklets are not available, please install react-native-worklets as a dependency. Refer to documentation for more details.');
|
|
49
|
+
const floatAudioData = audioBuffers.map(buffer => new Float32Array(buffer));
|
|
50
|
+
callback(floatAudioData, channelCount);
|
|
51
|
+
});
|
|
52
|
+
return new _WorkletNode.default(this, this.context.createWorkletNode(shareableWorklet, workletRuntime === 'UIRuntime', bufferLength, inputChannelCount));
|
|
56
53
|
}
|
|
57
54
|
createWorkletProcessingNode(callback, workletRuntime = 'AudioRuntime') {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
(0, _utils.assertWorkletsEnabled)();
|
|
56
|
+
const shareableWorklet = _utils.workletsModule.makeShareableCloneRecursive((inputBuffers, outputBuffers, framesToProcess, currentTime) => {
|
|
57
|
+
'worklet';
|
|
61
58
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
/// User does not have worklets as a dependency so he cannot use the worklet API.
|
|
69
|
-
throw new Error('[RnAudioApi] Worklets are not available, please install react-native-worklets as a dependency. Refer to documentation for more details.');
|
|
59
|
+
const inputData = inputBuffers.map(buffer => new Float32Array(buffer, 0, framesToProcess));
|
|
60
|
+
const outputData = outputBuffers.map(buffer => new Float32Array(buffer, 0, framesToProcess));
|
|
61
|
+
callback(inputData, outputData, framesToProcess, currentTime);
|
|
62
|
+
});
|
|
63
|
+
return new _WorkletProcessingNode.default(this, this.context.createWorkletProcessingNode(shareableWorklet, workletRuntime === 'UIRuntime'));
|
|
70
64
|
}
|
|
71
65
|
createWorkletSourceNode(callback, workletRuntime = 'AudioRuntime') {
|
|
72
|
-
|
|
73
|
-
/// User does not have worklets as a dependency so he cannot use the worklet API.
|
|
74
|
-
throw new Error('[RnAudioApi] Worklets are not available, please install react-native-worklets as a dependency. Refer to documentation for more details.');
|
|
75
|
-
}
|
|
66
|
+
(0, _utils.assertWorkletsEnabled)();
|
|
76
67
|
const shareableWorklet = _utils.workletsModule.makeShareableCloneRecursive((audioBuffers, framesToProcess, currentTime, startOffset) => {
|
|
77
68
|
'worklet';
|
|
78
69
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_errors","require","_utils","_WorkletSourceNode","_interopRequireDefault","_WorkletProcessingNode","_AnalyserNode","_AudioBuffer","_AudioBufferQueueSourceNode","_AudioBufferSourceNode","_AudioDestinationNode","_BiquadFilterNode","_GainNode","_OscillatorNode","_PeriodicWave","_RecorderAdapterNode","_StereoPannerNode","_StreamerNode","_WorkletNode","_ConstantSourceNode","e","__esModule","default","BaseAudioContext","constructor","context","destination","AudioDestinationNode","sampleRate","currentTime","state","createWorkletNode","callback","bufferLength","inputChannelCount","workletRuntime","NotSupportedError","
|
|
1
|
+
{"version":3,"names":["_errors","require","_utils","_WorkletSourceNode","_interopRequireDefault","_WorkletProcessingNode","_AnalyserNode","_AudioBuffer","_AudioBufferQueueSourceNode","_AudioBufferSourceNode","_AudioDestinationNode","_BiquadFilterNode","_GainNode","_OscillatorNode","_PeriodicWave","_RecorderAdapterNode","_StereoPannerNode","_StreamerNode","_WorkletNode","_ConstantSourceNode","e","__esModule","default","BaseAudioContext","constructor","context","destination","AudioDestinationNode","sampleRate","currentTime","state","createWorkletNode","callback","bufferLength","inputChannelCount","workletRuntime","NotSupportedError","assertWorkletsEnabled","shareableWorklet","workletsModule","makeShareableCloneRecursive","audioBuffers","channelCount","floatAudioData","map","buffer","Float32Array","WorkletNode","createWorkletProcessingNode","inputBuffers","outputBuffers","framesToProcess","inputData","outputData","WorkletProcessingNode","createWorkletSourceNode","startOffset","WorkletSourceNode","createRecorderAdapter","RecorderAdapterNode","createOscillator","OscillatorNode","createStreamer","StreamerNode","createConstantSource","ConstantSourceNode","createGain","GainNode","createStereoPanner","StereoPannerNode","createBiquadFilter","BiquadFilterNode","createBufferSource","options","pitchCorrection","AudioBufferSourceNode","createBufferQueueSource","AudioBufferQueueSourceNode","createBuffer","numOfChannels","length","AudioBuffer","createPeriodicWave","real","imag","constraints","InvalidAccessError","disableNormalization","PeriodicWave","createAnalyser","AnalyserNode","decodeAudioDataSource","sourcePath","startsWith","replace","decodeAudioData","data","Uint8Array","decodePCMInBase64Data","base64","playbackRate","decodePCMAudioDataInBase64","exports"],"sourceRoot":"../../../src","sources":["core/BaseAudioContext.ts"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAA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A,CAACC,IAAiB,EAAwB;IAC7D,OAAO,IAAIf,oBAAW,CACpB,MAAM,IAAI,CAACxD,OAAO,CAACsE,eAAe,CAAC,IAAIE,UAAU,CAACD,IAAI,CAAC,CACzD,CAAC;EACH;EAEA,MAAME,qBAAqBA,CACzBC,MAAc,EACdC,YAAoB,GAAG,GAAG,EACJ;IACtB,OAAO,IAAInB,oBAAW,CACpB,MAAM,IAAI,CAACxD,OAAO,CAAC4E,0BAA0B,CAACF,MAAM,EAAEC,YAAY,CACpE,CAAC;EACH;AACF;AAACE,OAAA,CAAAhF,OAAA,GAAAC,gBAAA","ignoreList":[]}
|
|
@@ -10,12 +10,9 @@ var _AudioBuffer = _interopRequireDefault(require("./AudioBuffer"));
|
|
|
10
10
|
var _utils = require("../utils");
|
|
11
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
12
|
class OfflineAudioContext extends _BaseAudioContext.default {
|
|
13
|
-
// We need to keep here a reference to this runtime to better manage its lifecycle
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
|
|
15
|
-
|
|
16
13
|
constructor(arg0, arg1, arg2) {
|
|
17
14
|
let audioRuntime = null;
|
|
18
|
-
if (_utils.
|
|
15
|
+
if (_utils.isWorkletsVersionSupported) {
|
|
19
16
|
audioRuntime = _utils.workletsModule.createWorkletRuntime('AudioWorkletRuntime');
|
|
20
17
|
}
|
|
21
18
|
if (typeof arg0 === 'object') {
|
|
@@ -34,7 +31,6 @@ class OfflineAudioContext extends _BaseAudioContext.default {
|
|
|
34
31
|
}
|
|
35
32
|
this.isSuspended = false;
|
|
36
33
|
this.isRendering = false;
|
|
37
|
-
this._audioRuntime = audioRuntime;
|
|
38
34
|
}
|
|
39
35
|
async resume() {
|
|
40
36
|
if (!this.isRendering) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_BaseAudioContext","_interopRequireDefault","require","_errors","_AudioBuffer","_utils","e","__esModule","default","OfflineAudioContext","BaseAudioContext","constructor","arg0","arg1","arg2","audioRuntime","
|
|
1
|
+
{"version":3,"names":["_BaseAudioContext","_interopRequireDefault","require","_errors","_AudioBuffer","_utils","e","__esModule","default","OfflineAudioContext","BaseAudioContext","constructor","arg0","arg1","arg2","audioRuntime","isWorkletsVersionSupported","workletsModule","createWorkletRuntime","numberOfChannels","length","sampleRate","global","createOfflineAudioContext","duration","NotSupportedError","isSuspended","isRendering","resume","InvalidStateError","context","suspend","suspendTime","currentTime","startRendering","audioBuffer","AudioBuffer","exports"],"sourceRoot":"../../../src","sources":["core/OfflineAudioContext.ts"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAAsE,SAAAD,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEvD,MAAMG,mBAAmB,SAASC,yBAAgB,CAAC;EAOhEC,WAAWA,CACTC,IAAyC,EACzCC,IAAa,EACbC,IAAa,EACb;IACA,IAAIC,YAAY,GAAG,IAAI;IACvB,IAAIC,iCAA0B,EAAE;MAC9BD,YAAY,GAAGE,qBAAc,CAACC,oBAAoB,CAAC,qBAAqB,CAAC;IAC3E;IAEA,IAAI,OAAON,IAAI,KAAK,QAAQ,EAAE;MAC5B,MAAM;QAAEO,gBAAgB;QAAEC,MAAM;QAAEC;MAAW,CAAC,GAAGT,IAAI;MACrD,KAAK,CACHU,MAAM,CAACC,yBAAyB,CAC9BJ,gBAAgB,EAChBC,MAAM,EACNC,UAAU,EACVN,YACF,CACF,CAAC;MAED,IAAI,CAACS,QAAQ,GAAGJ,MAAM,GAAGC,UAAU;IACrC,CAAC,MAAM,IACL,OAAOT,IAAI,KAAK,QAAQ,IACxB,OAA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WAAW,EAAE;MACpB,MAAM,IAAIE,yBAAiB,CAAC,0CAA0C,CAAC;IACzE;IAEA,IAAI,CAACF,WAAW,GAAG,IAAI;IAEvB,MAAMQ,WAAW,GAAG,MAClB,IAAI,CAACL,OAAO,CACZI,cAAc,CAAC,CAAC;IAElB,OAAO,IAAIE,oBAAW,CAACD,WAAW,CAAC;EACrC;AACF;AAACE,OAAA,CAAA7B,OAAA,GAAAC,mBAAA","ignoreList":[]}
|
|
@@ -3,17 +3,33 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.assertWorkletsEnabled = assertWorkletsEnabled;
|
|
6
7
|
exports.clamp = clamp;
|
|
7
|
-
exports.workletsModule = exports.
|
|
8
|
+
exports.workletsVersion = exports.workletsModule = exports.supportedWorkletsVersions = exports.isWorkletsVersionSupported = void 0;
|
|
8
9
|
function clamp(value, min, max) {
|
|
9
10
|
return Math.min(Math.max(value, min), max);
|
|
10
11
|
}
|
|
11
|
-
let isWorkletsAvailable =
|
|
12
|
+
let isWorkletsAvailable = false;
|
|
13
|
+
let isWorkletsVersionSupported = exports.isWorkletsVersionSupported = false;
|
|
14
|
+
let workletsVersion = exports.workletsVersion = 'unknown';
|
|
15
|
+
const supportedWorkletsVersions = exports.supportedWorkletsVersions = ['0.6.0', '0.6.1'];
|
|
12
16
|
let workletsModule = exports.workletsModule = void 0;
|
|
17
|
+
function assertWorkletsEnabled() {
|
|
18
|
+
if (!isWorkletsAvailable) {
|
|
19
|
+
throw new Error('[react-native-audio-api]: Worklets are not available. Please install react-native-worklets to use this feature.');
|
|
20
|
+
} else if (!isWorkletsVersionSupported) {
|
|
21
|
+
throw new Error(`[react-native-audio-api]: Worklets version ${workletsVersion} is not supported.
|
|
22
|
+
Please install react-native-worklets of one of the following versions: [${supportedWorkletsVersions.join(', ')}] to use this feature.`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
13
25
|
try {
|
|
14
26
|
exports.workletsModule = workletsModule = require('react-native-worklets');
|
|
15
|
-
|
|
27
|
+
const workletsModuleJson = require('react-native-worklets/package.json');
|
|
28
|
+
exports.isWorkletsVersionSupported = isWorkletsVersionSupported = supportedWorkletsVersions.includes(workletsModuleJson.version);
|
|
29
|
+
isWorkletsAvailable = true;
|
|
30
|
+
exports.workletsVersion = workletsVersion = workletsModuleJson.version;
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
32
|
} catch (error) {
|
|
17
|
-
|
|
33
|
+
isWorkletsAvailable = false;
|
|
18
34
|
}
|
|
19
35
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["clamp","value","min","max","Math","isWorkletsAvailable","exports","workletsModule","require","error"],"sourceRoot":"../../../src","sources":["utils/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"names":["clamp","value","min","max","Math","isWorkletsAvailable","isWorkletsVersionSupported","exports","workletsVersion","supportedWorkletsVersions","workletsModule","assertWorkletsEnabled","Error","join","require","workletsModuleJson","includes","version","error"],"sourceRoot":"../../../src","sources":["utils/index.ts"],"mappings":";;;;;;;;AAWO,SAASA,KAAKA,CAACC,KAAa,EAAEC,GAAW,EAAEC,GAAW,EAAU;EACrE,OAAOC,IAAI,CAACF,GAAG,CAACE,IAAI,CAACD,GAAG,CAACF,KAAK,EAAEC,GAAG,CAAC,EAAEC,GAAG,CAAC;AAC5C;AAEA,IAAIE,mBAAmB,GAAG,KAAK;AACxB,IAAIC,0BAA0B,GAAAC,OAAA,CAAAD,0BAAA,GAAG,KAAK;AACtC,IAAIE,eAAe,GAAAD,OAAA,CAAAC,eAAA,GAAG,SAAS;AAC/B,MAAMC,yBAAyB,GAAAF,OAAA,CAAAE,yBAAA,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC;AACpD,IAAIC,cAAuC,GAAAH,OAAA,CAAAG,cAAA;AAE3C,SAASC,qBAAqBA,CAAA,EAAG;EACtC,IAAI,CAACN,mBAAmB,EAAE;IACxB,MAAM,IAAIO,KAAK,CACb,iHACF,CAAC;EACH,CAAC,MAAM,IAAI,CAACN,0BAA0B,EAAE;IACtC,MAAM,IAAIM,KAAK,CACb,8CAA8CJ,eAAe;AACnE,gFAAgFC,yBAAyB,CAACI,IAAI,CAAC,IAAI,CAAC,wBAChH,CAAC;EACH;AACF;AAEA,IAAI;EACFN,OAAA,CAAAG,cAAA,GAAAA,cAAc,GAAGI,OAAO,CAAC,uBAAuB,CAAC;EACjD,MAAMC,kBAAkB,GAAGD,OAAO,CAAC,oCAAoC,CAAC;EACxEP,OAAA,CAAAD,0BAAA,GAAAA,0BAA0B,GAAGG,yBAAyB,CAACO,QAAQ,CAC7DD,kBAAkB,CAACE,OACrB,CAAC;EACDZ,mBAAmB,GAAG,IAAI;EAC1BE,OAAA,CAAAC,eAAA,GAAAA,eAAe,GAAGO,kBAAkB,CAACE,OAAO;EAC5C;AACF,CAAC,CAAC,OAAOC,KAAK,EAAE;EACdb,mBAAmB,GAAG,KAAK;AAC7B","ignoreList":[]}
|
|
@@ -3,21 +3,17 @@
|
|
|
3
3
|
import BaseAudioContext from "./BaseAudioContext.js";
|
|
4
4
|
import AudioManager from "../system/index.js";
|
|
5
5
|
import { NotSupportedError } from "../errors/index.js";
|
|
6
|
-
import {
|
|
6
|
+
import { isWorkletsVersionSupported, workletsModule } from "../utils/index.js";
|
|
7
7
|
export default class AudioContext extends BaseAudioContext {
|
|
8
|
-
// We need to keep here a reference to this runtime to better manage its lifecycle
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
|
|
10
|
-
_audioRuntime = null;
|
|
11
8
|
constructor(options) {
|
|
12
9
|
if (options && options.sampleRate && (options.sampleRate < 8000 || options.sampleRate > 96000)) {
|
|
13
10
|
throw new NotSupportedError(`The provided sampleRate is not supported: ${options.sampleRate}`);
|
|
14
11
|
}
|
|
15
12
|
let audioRuntime = null;
|
|
16
|
-
if (
|
|
13
|
+
if (isWorkletsVersionSupported) {
|
|
17
14
|
audioRuntime = workletsModule.createWorkletRuntime('AudioWorkletRuntime');
|
|
18
15
|
}
|
|
19
16
|
super(global.createAudioContext(options?.sampleRate || AudioManager.getDevicePreferredSampleRate(), options?.initSuspended || false, audioRuntime));
|
|
20
|
-
this._audioRuntime = audioRuntime;
|
|
21
17
|
}
|
|
22
18
|
async close() {
|
|
23
19
|
return this.context.close();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BaseAudioContext","AudioManager","NotSupportedError","
|
|
1
|
+
{"version":3,"names":["BaseAudioContext","AudioManager","NotSupportedError","isWorkletsVersionSupported","workletsModule","AudioContext","constructor","options","sampleRate","audioRuntime","createWorkletRuntime","global","createAudioContext","getDevicePreferredSampleRate","initSuspended","close","context","resume","suspend"],"sourceRoot":"../../../src","sources":["core/AudioContext.ts"],"mappings":";;AACA,OAAOA,gBAAgB,MAAM,uBAAoB;AACjD,OAAOC,YAAY,MAAM,oBAAW;AAEpC,SAASC,iBAAiB,QAAQ,oBAAW;AAC7C,SAASC,0BAA0B,EAAEC,cAAc,QAAQ,mBAAU;AAErE,eAAe,MAAMC,YAAY,SAASL,gBAAgB,CAAC;EACzDM,WAAWA,CAACC,OAA6B,EAAE;IACzC,IACEA,OAAO,IACPA,OAAO,CAACC,UAAU,KACjBD,OAAO,CAACC,UAAU,GAAG,IAAI,IAAID,OAAO,CAACC,UAAU,GAAG,KAAK,CAAC,EACzD;MACA,MAAM,IAAIN,iBAAiB,CACzB,6CAA6CK,OAAO,CAACC,UAAU,EACjE,CAAC;IACH;IACA,IAAIC,YAAY,GAAG,IAAI;IAEvB,IAAIN,0BAA0B,EAAE;MAC9BM,YAAY,GAAGL,cAAc,CAACM,oBAAoB,CAAC,qBAAqB,CAAC;IAC3E;IAEA,KAAK,CACHC,MAAM,CAACC,kBAAkB,CACvBL,OAAO,EAAEC,UAAU,IAAIP,YAAY,CAACY,4BAA4B,CAAC,CAAC,EAClEN,OAAO,EAAEO,aAAa,IAAI,KAAK,EAC/BL,YACF,CACF,CAAC;EACH;EAEA,MAAMM,KAAKA,CAAA,EAAkB;IAC3B,OAAQ,IAAI,CAACC,OAAO,CAAmBD,KAAK,CAAC,CAAC;EAChD;EAEA,MAAME,MAAMA,CAAA,EAAqB;IAC/B,OAAQ,IAAI,CAACD,OAAO,CAAmBC,MAAM,CAAC,CAAC;EACjD;EAEA,MAAMC,OAAOA,CAAA,EAAqB;IAChC,OAAQ,IAAI,CAACF,OAAO,CAAmBE,OAAO,CAAC,CAAC;EAClD;AACF","ignoreList":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { InvalidAccessError, NotSupportedError } from "../errors/index.js";
|
|
4
|
-
import {
|
|
4
|
+
import { assertWorkletsEnabled, workletsModule } from "../utils/index.js";
|
|
5
5
|
import WorkletSourceNode from "./WorkletSourceNode.js";
|
|
6
6
|
import WorkletProcessingNode from "./WorkletProcessingNode.js";
|
|
7
7
|
import AnalyserNode from "./AnalyserNode.js";
|
|
@@ -37,37 +37,28 @@ export default class BaseAudioContext {
|
|
|
37
37
|
if (bufferLength < 1) {
|
|
38
38
|
throw new NotSupportedError(`The buffer length provided (${bufferLength}) can not be less than 1`);
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
assertWorkletsEnabled();
|
|
41
|
+
const shareableWorklet = workletsModule.makeShareableCloneRecursive((audioBuffers, channelCount) => {
|
|
42
|
+
'worklet';
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
/// User does not have worklets as a dependency so he cannot use the worklet API.
|
|
50
|
-
throw new Error('[RnAudioApi] Worklets are not available, please install react-native-worklets as a dependency. Refer to documentation for more details.');
|
|
44
|
+
const floatAudioData = audioBuffers.map(buffer => new Float32Array(buffer));
|
|
45
|
+
callback(floatAudioData, channelCount);
|
|
46
|
+
});
|
|
47
|
+
return new WorkletNode(this, this.context.createWorkletNode(shareableWorklet, workletRuntime === 'UIRuntime', bufferLength, inputChannelCount));
|
|
51
48
|
}
|
|
52
49
|
createWorkletProcessingNode(callback, workletRuntime = 'AudioRuntime') {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
assertWorkletsEnabled();
|
|
51
|
+
const shareableWorklet = workletsModule.makeShareableCloneRecursive((inputBuffers, outputBuffers, framesToProcess, currentTime) => {
|
|
52
|
+
'worklet';
|
|
56
53
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
/// User does not have worklets as a dependency so he cannot use the worklet API.
|
|
64
|
-
throw new Error('[RnAudioApi] Worklets are not available, please install react-native-worklets as a dependency. Refer to documentation for more details.');
|
|
54
|
+
const inputData = inputBuffers.map(buffer => new Float32Array(buffer, 0, framesToProcess));
|
|
55
|
+
const outputData = outputBuffers.map(buffer => new Float32Array(buffer, 0, framesToProcess));
|
|
56
|
+
callback(inputData, outputData, framesToProcess, currentTime);
|
|
57
|
+
});
|
|
58
|
+
return new WorkletProcessingNode(this, this.context.createWorkletProcessingNode(shareableWorklet, workletRuntime === 'UIRuntime'));
|
|
65
59
|
}
|
|
66
60
|
createWorkletSourceNode(callback, workletRuntime = 'AudioRuntime') {
|
|
67
|
-
|
|
68
|
-
/// User does not have worklets as a dependency so he cannot use the worklet API.
|
|
69
|
-
throw new Error('[RnAudioApi] Worklets are not available, please install react-native-worklets as a dependency. Refer to documentation for more details.');
|
|
70
|
-
}
|
|
61
|
+
assertWorkletsEnabled();
|
|
71
62
|
const shareableWorklet = workletsModule.makeShareableCloneRecursive((audioBuffers, framesToProcess, currentTime, startOffset) => {
|
|
72
63
|
'worklet';
|
|
73
64
|
|