react-native-audio-api 0.6.0-rc.4 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/cpp/audioapi/android/AudioAPIModule.cpp +35 -2
- package/android/src/main/cpp/audioapi/android/AudioAPIModule.h +4 -0
- package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp +31 -17
- package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.h +1 -3
- package/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +56 -2
- package/android/src/main/java/com/swmansion/audioapi/AudioAPIPackage.kt +0 -12
- package/android/src/main/java/com/swmansion/audioapi/system/AudioFocusListener.kt +35 -12
- package/android/src/main/java/com/swmansion/audioapi/system/LockScreenManager.kt +30 -29
- package/android/src/main/java/com/swmansion/audioapi/system/MediaNotificationManager.kt +20 -22
- package/android/src/main/java/com/swmansion/audioapi/system/MediaReceiver.kt +19 -9
- package/android/src/main/java/com/swmansion/audioapi/system/MediaSessionCallback.kt +30 -11
- package/android/src/main/java/com/swmansion/audioapi/system/MediaSessionManager.kt +53 -26
- package/android/src/main/java/com/swmansion/audioapi/system/VolumeChangeListener.kt +10 -5
- package/android/src/oldarch/NativeAudioAPIModuleSpec.java +39 -0
- package/common/cpp/audioapi/AudioAPIModuleInstaller.h +20 -14
- package/common/cpp/audioapi/HostObjects/AudioBufferSourceNodeHostObject.h +2 -3
- package/common/cpp/audioapi/HostObjects/AudioNodeHostObject.h +24 -11
- package/common/cpp/audioapi/HostObjects/AudioParamHostObject.h +1 -0
- package/common/cpp/audioapi/HostObjects/AudioRecorderHostObject.h +10 -89
- package/common/cpp/audioapi/HostObjects/AudioScheduledSourceNodeHostObject.h +3 -24
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h +2 -2
- package/common/cpp/audioapi/HostObjects/OscillatorNodeHostObject.h +2 -3
- package/common/cpp/audioapi/core/AudioContext.cpp +4 -1
- package/common/cpp/audioapi/core/AudioContext.h +1 -1
- package/common/cpp/audioapi/core/AudioNode.cpp +31 -2
- package/common/cpp/audioapi/core/AudioNode.h +7 -1
- package/common/cpp/audioapi/core/AudioParam.cpp +84 -2
- package/common/cpp/audioapi/core/AudioParam.h +14 -1
- package/common/cpp/audioapi/core/BaseAudioContext.cpp +7 -1
- package/common/cpp/audioapi/core/BaseAudioContext.h +7 -1
- package/common/cpp/audioapi/core/OfflineAudioContext.cpp +3 -2
- package/common/cpp/audioapi/core/OfflineAudioContext.h +1 -1
- package/common/cpp/audioapi/core/analysis/AnalyserNode.cpp +19 -56
- package/common/cpp/audioapi/core/analysis/AnalyserNode.h +3 -2
- package/common/cpp/audioapi/core/effects/BiquadFilterNode.cpp +28 -26
- package/common/cpp/audioapi/core/effects/GainNode.cpp +9 -9
- package/common/cpp/audioapi/core/effects/StereoPannerNode.cpp +5 -2
- package/common/cpp/audioapi/core/inputs/AudioRecorder.cpp +56 -0
- package/common/cpp/audioapi/core/inputs/AudioRecorder.h +13 -13
- package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp +14 -10
- package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.h +1 -1
- package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp +7 -6
- package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.h +5 -3
- package/common/cpp/audioapi/core/sources/OscillatorNode.cpp +15 -10
- package/common/cpp/audioapi/core/utils/AudioNodeManager.cpp +35 -1
- package/common/cpp/audioapi/core/utils/AudioNodeManager.h +15 -1
- package/common/cpp/audioapi/events/AudioEventHandlerRegistry.cpp +108 -0
- package/common/cpp/audioapi/events/AudioEventHandlerRegistry.h +62 -0
- package/common/cpp/audioapi/events/AudioEventHandlerRegistryHostObject.h +48 -0
- package/common/cpp/audioapi/jsi/JsiPromise.cpp +3 -4
- package/common/cpp/audioapi/utils/AudioArray.h +1 -1
- package/common/cpp/audioapi/utils/CircularAudioArray.cpp +94 -0
- package/common/cpp/audioapi/utils/CircularAudioArray.h +26 -0
- package/ios/audioapi/ios/AudioAPIModule.h +13 -0
- package/ios/audioapi/ios/AudioAPIModule.mm +115 -6
- package/ios/audioapi/ios/core/IOSAudioRecorder.h +3 -10
- package/ios/audioapi/ios/core/IOSAudioRecorder.mm +15 -52
- package/ios/audioapi/ios/core/NativeAudioPlayer.m +2 -0
- package/ios/audioapi/ios/core/NativeAudioRecorder.m +7 -3
- package/ios/audioapi/ios/events/IOSAudioEventHandlerRegistry.h +7 -0
- package/ios/audioapi/ios/events/IOSAudioEventHandlerRegistry.mm +12 -0
- package/ios/audioapi/ios/system/AudioEngine.h +5 -0
- package/ios/audioapi/ios/system/AudioEngine.mm +7 -15
- package/ios/audioapi/ios/system/AudioSessionManager.h +3 -1
- package/ios/audioapi/ios/system/AudioSessionManager.mm +36 -17
- package/ios/audioapi/ios/system/LockScreenManager.h +3 -3
- package/ios/audioapi/ios/system/LockScreenManager.mm +36 -48
- package/ios/audioapi/ios/system/NotificationManager.h +3 -3
- package/ios/audioapi/ios/system/NotificationManager.mm +21 -29
- package/lib/commonjs/api.js +4 -4
- package/lib/commonjs/api.js.map +1 -1
- package/lib/commonjs/core/AudioBufferSourceNode.js +2 -2
- package/lib/commonjs/core/AudioBufferSourceNode.js.map +1 -1
- package/lib/commonjs/core/AudioNode.js +8 -2
- package/lib/commonjs/core/AudioNode.js.map +1 -1
- package/lib/commonjs/core/AudioParam.js +2 -1
- package/lib/commonjs/core/AudioParam.js.map +1 -1
- package/lib/commonjs/core/AudioRecorder.js +11 -28
- package/lib/commonjs/core/AudioRecorder.js.map +1 -1
- package/lib/commonjs/core/AudioScheduledSourceNode.js +4 -1
- package/lib/commonjs/core/AudioScheduledSourceNode.js.map +1 -1
- package/lib/commonjs/core/BiquadFilterNode.js +4 -4
- package/lib/commonjs/core/BiquadFilterNode.js.map +1 -1
- package/lib/commonjs/core/GainNode.js +1 -1
- package/lib/commonjs/core/GainNode.js.map +1 -1
- package/lib/commonjs/core/OscillatorNode.js +2 -2
- package/lib/commonjs/core/OscillatorNode.js.map +1 -1
- package/lib/commonjs/core/StereoPannerNode.js +1 -1
- package/lib/commonjs/core/StereoPannerNode.js.map +1 -1
- package/lib/commonjs/events/AudioEventEmitter.js +22 -0
- package/lib/commonjs/events/AudioEventEmitter.js.map +1 -0
- package/lib/commonjs/events/AudioEventSubscription.js +20 -0
- package/lib/commonjs/events/AudioEventSubscription.js.map +1 -0
- package/lib/commonjs/events/index.js +21 -0
- package/lib/commonjs/events/index.js.map +1 -0
- package/lib/commonjs/events/types.js +6 -0
- package/lib/commonjs/events/types.js.map +1 -0
- package/lib/commonjs/hooks/useSytemVolume.js +1 -1
- package/lib/commonjs/hooks/useSytemVolume.js.map +1 -1
- package/lib/commonjs/specs/NativeAudioAPIModule.js +3 -3
- package/lib/commonjs/specs/NativeAudioAPIModule.js.map +1 -1
- package/lib/commonjs/specs/index.js +2 -16
- package/lib/commonjs/specs/index.js.map +1 -1
- package/lib/commonjs/system/AudioManager.js +26 -26
- package/lib/commonjs/system/AudioManager.js.map +1 -1
- package/lib/module/api.js +2 -2
- package/lib/module/api.js.map +1 -1
- package/lib/module/core/AudioBufferSourceNode.js +2 -2
- package/lib/module/core/AudioBufferSourceNode.js.map +1 -1
- package/lib/module/core/AudioNode.js +7 -2
- package/lib/module/core/AudioNode.js.map +1 -1
- package/lib/module/core/AudioParam.js +2 -1
- package/lib/module/core/AudioParam.js.map +1 -1
- package/lib/module/core/AudioRecorder.js +11 -28
- package/lib/module/core/AudioRecorder.js.map +1 -1
- package/lib/module/core/AudioScheduledSourceNode.js +4 -1
- package/lib/module/core/AudioScheduledSourceNode.js.map +1 -1
- package/lib/module/core/BiquadFilterNode.js +4 -4
- package/lib/module/core/BiquadFilterNode.js.map +1 -1
- package/lib/module/core/GainNode.js +1 -1
- package/lib/module/core/GainNode.js.map +1 -1
- package/lib/module/core/OscillatorNode.js +2 -2
- package/lib/module/core/OscillatorNode.js.map +1 -1
- package/lib/module/core/StereoPannerNode.js +1 -1
- package/lib/module/core/StereoPannerNode.js.map +1 -1
- package/lib/module/events/AudioEventEmitter.js +16 -0
- package/lib/module/events/AudioEventEmitter.js.map +1 -0
- package/lib/module/events/AudioEventSubscription.js +15 -0
- package/lib/module/events/AudioEventSubscription.js.map +1 -0
- package/lib/module/events/index.js +6 -0
- package/lib/module/events/index.js.map +1 -0
- package/lib/module/events/types.js +4 -0
- package/lib/module/events/types.js.map +1 -0
- package/lib/module/hooks/useSytemVolume.js +1 -1
- package/lib/module/hooks/useSytemVolume.js.map +1 -1
- package/lib/module/specs/NativeAudioAPIModule.js +3 -2
- package/lib/module/specs/NativeAudioAPIModule.js.map +1 -1
- package/lib/module/specs/index.js +2 -3
- package/lib/module/specs/index.js.map +1 -1
- package/lib/module/system/AudioManager.js +27 -27
- package/lib/module/system/AudioManager.js.map +1 -1
- package/lib/typescript/api.d.ts +2 -1
- package/lib/typescript/api.d.ts.map +1 -1
- package/lib/typescript/core/AudioNode.d.ts +2 -1
- package/lib/typescript/core/AudioNode.d.ts.map +1 -1
- package/lib/typescript/core/AudioParam.d.ts +4 -2
- package/lib/typescript/core/AudioParam.d.ts.map +1 -1
- package/lib/typescript/core/AudioRecorder.d.ts +4 -14
- package/lib/typescript/core/AudioRecorder.d.ts.map +1 -1
- package/lib/typescript/core/AudioScheduledSourceNode.d.ts +3 -1
- package/lib/typescript/core/AudioScheduledSourceNode.d.ts.map +1 -1
- package/lib/typescript/events/AudioEventEmitter.d.ts +10 -0
- package/lib/typescript/events/AudioEventEmitter.d.ts.map +1 -0
- package/lib/typescript/events/AudioEventSubscription.d.ts +11 -0
- package/lib/typescript/events/AudioEventSubscription.d.ts.map +1 -0
- package/lib/typescript/events/index.d.ts +4 -0
- package/lib/typescript/events/index.d.ts.map +1 -0
- package/lib/typescript/events/types.d.ts +50 -0
- package/lib/typescript/events/types.d.ts.map +1 -0
- package/lib/typescript/hooks/useSytemVolume.d.ts.map +1 -1
- package/lib/typescript/interfaces.d.ts +10 -10
- package/lib/typescript/interfaces.d.ts.map +1 -1
- package/lib/typescript/specs/NativeAudioAPIModule.d.ts +15 -3
- package/lib/typescript/specs/NativeAudioAPIModule.d.ts.map +1 -1
- package/lib/typescript/specs/index.d.ts +2 -3
- package/lib/typescript/specs/index.d.ts.map +1 -1
- package/lib/typescript/system/AudioManager.d.ts +8 -4
- package/lib/typescript/system/AudioManager.d.ts.map +1 -1
- package/lib/typescript/system/types.d.ts +1 -34
- package/lib/typescript/system/types.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +0 -1
- package/lib/typescript/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/api.ts +6 -3
- package/src/core/AudioBufferSourceNode.ts +2 -2
- package/src/core/AudioNode.ts +8 -3
- package/src/core/AudioParam.ts +5 -2
- package/src/core/AudioRecorder.ts +22 -62
- package/src/core/AudioScheduledSourceNode.ts +13 -2
- package/src/core/BiquadFilterNode.ts +4 -4
- package/src/core/GainNode.ts +1 -1
- package/src/core/OscillatorNode.ts +2 -2
- package/src/core/StereoPannerNode.ts +1 -1
- package/src/events/AudioEventEmitter.ts +29 -0
- package/src/events/AudioEventSubscription.ts +26 -0
- package/src/events/index.ts +4 -0
- package/src/events/types.ts +64 -0
- package/src/hooks/useSytemVolume.ts +2 -1
- package/src/interfaces.ts +19 -20
- package/src/specs/NativeAudioAPIModule.ts +23 -2
- package/src/specs/index.ts +2 -4
- package/src/system/AudioManager.ts +39 -38
- package/src/system/types.ts +1 -41
- package/src/types.ts +0 -8
- package/android/src/main/java/com/swmansion/audioapi/AudioManagerModule.kt +0 -64
- package/android/src/main/java/com/swmansion/audioapi/system/MediaSessionEventEmitter.kt +0 -88
- package/android/src/oldarch/NativeAudioManagerModuleSpec.java +0 -99
- package/ios/audioapi/ios/AudioManagerModule.h +0 -18
- package/ios/audioapi/ios/AudioManagerModule.mm +0 -93
- package/lib/commonjs/specs/NativeAudioManagerModule.js +0 -36
- package/lib/commonjs/specs/NativeAudioManagerModule.js.map +0 -1
- package/lib/module/specs/NativeAudioManagerModule.js +0 -33
- package/lib/module/specs/NativeAudioManagerModule.js.map +0 -1
- package/lib/typescript/specs/NativeAudioManagerModule.d.ts +0 -15
- package/lib/typescript/specs/NativeAudioManagerModule.d.ts.map +0 -1
- package/src/specs/NativeAudioManagerModule.ts +0 -45
|
@@ -12,6 +12,7 @@ namespace audioapi {
|
|
|
12
12
|
|
|
13
13
|
class AudioNode;
|
|
14
14
|
class AudioScheduledSourceNode;
|
|
15
|
+
class AudioParam;
|
|
15
16
|
|
|
16
17
|
class AudioNodeManager {
|
|
17
18
|
public:
|
|
@@ -23,13 +24,19 @@ class AudioNodeManager {
|
|
|
23
24
|
|
|
24
25
|
void preProcessGraph();
|
|
25
26
|
|
|
26
|
-
void
|
|
27
|
+
void addPendingNodeConnection(
|
|
27
28
|
const std::shared_ptr<AudioNode> &from,
|
|
28
29
|
const std::shared_ptr<AudioNode> &to,
|
|
29
30
|
ConnectionType type);
|
|
30
31
|
|
|
32
|
+
void addPendingParamConnection(
|
|
33
|
+
const std::shared_ptr<AudioNode> &from,
|
|
34
|
+
const std::shared_ptr<AudioParam> &to,
|
|
35
|
+
ConnectionType type);
|
|
36
|
+
|
|
31
37
|
void addProcessingNode(const std::shared_ptr<AudioNode> &node);
|
|
32
38
|
void addSourceNode(const std::shared_ptr<AudioScheduledSourceNode> &node);
|
|
39
|
+
void addAudioParam(const std::shared_ptr<AudioParam> ¶m);
|
|
33
40
|
|
|
34
41
|
void cleanup();
|
|
35
42
|
|
|
@@ -40,6 +47,7 @@ class AudioNodeManager {
|
|
|
40
47
|
// all nodes created in the context
|
|
41
48
|
std::unordered_set<std::shared_ptr<AudioScheduledSourceNode>> sourceNodes_;
|
|
42
49
|
std::unordered_set<std::shared_ptr<AudioNode>> processingNodes_;
|
|
50
|
+
std::unordered_set<std::shared_ptr<AudioParam>> audioParams_;
|
|
43
51
|
|
|
44
52
|
// connections to be settled
|
|
45
53
|
std::vector<std::tuple<
|
|
@@ -48,6 +56,12 @@ class AudioNodeManager {
|
|
|
48
56
|
ConnectionType>>
|
|
49
57
|
audioNodesToConnect_;
|
|
50
58
|
|
|
59
|
+
std::vector<std::tuple<
|
|
60
|
+
std::shared_ptr<AudioNode>,
|
|
61
|
+
std::shared_ptr<AudioParam>,
|
|
62
|
+
ConnectionType>>
|
|
63
|
+
audioParamToConnect_;
|
|
64
|
+
|
|
51
65
|
void settlePendingConnections();
|
|
52
66
|
void cleanupNode(const std::shared_ptr<AudioNode> &node);
|
|
53
67
|
void prepareNodesForDestruction();
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
#include <audioapi/events/AudioEventHandlerRegistry.h>
|
|
2
|
+
|
|
3
|
+
namespace audioapi {
|
|
4
|
+
|
|
5
|
+
AudioEventHandlerRegistry::AudioEventHandlerRegistry(
|
|
6
|
+
jsi::Runtime *runtime,
|
|
7
|
+
const std::shared_ptr<react::CallInvoker> &callInvoker) {
|
|
8
|
+
runtime_ = runtime;
|
|
9
|
+
callInvoker_ = callInvoker;
|
|
10
|
+
|
|
11
|
+
for (const auto &eventName : SYSTEM_EVENT_NAMES) {
|
|
12
|
+
eventHandlers_[std::string(eventName)] = {};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
for (const auto &eventName : AUDIO_API_EVENT_NAMES) {
|
|
16
|
+
eventHandlers_[std::string(eventName)] = {};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
AudioEventHandlerRegistry::~AudioEventHandlerRegistry() {
|
|
21
|
+
eventHandlers_.clear();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
uint64_t AudioEventHandlerRegistry::registerHandler(
|
|
25
|
+
const std::string &eventName,
|
|
26
|
+
const std::shared_ptr<jsi::Function> &handler) {
|
|
27
|
+
static uint64_t LISTENER_ID = 0;
|
|
28
|
+
|
|
29
|
+
eventHandlers_[eventName][LISTENER_ID] = handler;
|
|
30
|
+
|
|
31
|
+
return LISTENER_ID++;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
void AudioEventHandlerRegistry::unregisterHandler(
|
|
35
|
+
const std::string &eventName,
|
|
36
|
+
uint64_t listenerId) {
|
|
37
|
+
auto it = eventHandlers_.find(eventName);
|
|
38
|
+
if (it != eventHandlers_.end()) {
|
|
39
|
+
it->second.erase(listenerId);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
void AudioEventHandlerRegistry::invokeHandlerWithEventBody(
|
|
44
|
+
const std::string &eventName,
|
|
45
|
+
const std::unordered_map<std::string, EventValue> &body) {
|
|
46
|
+
auto it = eventHandlers_.find(eventName);
|
|
47
|
+
if (it != eventHandlers_.end()) {
|
|
48
|
+
for (const auto &pair : it->second) {
|
|
49
|
+
auto handler = pair.second;
|
|
50
|
+
if (handler) {
|
|
51
|
+
callInvoker_->invokeAsync([this, handler, body]() {
|
|
52
|
+
auto eventObject = createEventObject(body);
|
|
53
|
+
handler->call(*runtime_, eventObject);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
void AudioEventHandlerRegistry::invokeHandlerWithEventBody(
|
|
61
|
+
const std::string &eventName,
|
|
62
|
+
uint64_t listenerId,
|
|
63
|
+
const std::unordered_map<std::string, EventValue> &body) {
|
|
64
|
+
auto it = eventHandlers_.find(eventName);
|
|
65
|
+
if (it != eventHandlers_.end()) {
|
|
66
|
+
auto handlersMap = it->second;
|
|
67
|
+
auto handlerIt = handlersMap.find(listenerId);
|
|
68
|
+
if (handlerIt != handlersMap.end()) {
|
|
69
|
+
auto handler = handlerIt->second;
|
|
70
|
+
if (handler) {
|
|
71
|
+
callInvoker_->invokeAsync([this, handler, body]() {
|
|
72
|
+
auto eventObject = createEventObject(body);
|
|
73
|
+
handler->call(*runtime_, eventObject);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
jsi::Object AudioEventHandlerRegistry::createEventObject(
|
|
81
|
+
const std::unordered_map<std::string, EventValue> &body) {
|
|
82
|
+
auto eventObject = jsi::Object(*runtime_);
|
|
83
|
+
|
|
84
|
+
for (const auto &pair : body) {
|
|
85
|
+
const auto name = pair.first.data();
|
|
86
|
+
const auto &value = pair.second;
|
|
87
|
+
|
|
88
|
+
if (holds_alternative<int>(value)) {
|
|
89
|
+
eventObject.setProperty(*runtime_, name, get<int>(value));
|
|
90
|
+
} else if (holds_alternative<double>(value)) {
|
|
91
|
+
eventObject.setProperty(*runtime_, name, get<double>(value));
|
|
92
|
+
} else if (holds_alternative<float>(value)) {
|
|
93
|
+
eventObject.setProperty(*runtime_, name, get<float>(value));
|
|
94
|
+
} else if (holds_alternative<bool>(value)) {
|
|
95
|
+
eventObject.setProperty(*runtime_, name, get<bool>(value));
|
|
96
|
+
} else if (holds_alternative<std::string>(value)) {
|
|
97
|
+
eventObject.setProperty(*runtime_, name, get<std::string>(value));
|
|
98
|
+
} else if (holds_alternative<std::shared_ptr<jsi::HostObject>>(value)) {
|
|
99
|
+
auto hostObject = jsi::Object::createFromHostObject(
|
|
100
|
+
*runtime_, get<std::shared_ptr<jsi::HostObject>>(value));
|
|
101
|
+
eventObject.setProperty(*runtime_, name, hostObject);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return eventObject;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
} // namespace audioapi
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
#include <ReactCommon/CallInvoker.h>
|
|
5
|
+
#include <memory>
|
|
6
|
+
#include <unordered_map>
|
|
7
|
+
#include <array>
|
|
8
|
+
#include <string>
|
|
9
|
+
#include <variant>
|
|
10
|
+
|
|
11
|
+
namespace audioapi {
|
|
12
|
+
using namespace facebook;
|
|
13
|
+
|
|
14
|
+
using EventValue = std::variant<int, float, double, std::string, bool, std::shared_ptr<jsi::HostObject>>;
|
|
15
|
+
|
|
16
|
+
class AudioEventHandlerRegistry {
|
|
17
|
+
public:
|
|
18
|
+
explicit AudioEventHandlerRegistry(
|
|
19
|
+
jsi::Runtime *runtime,
|
|
20
|
+
const std::shared_ptr<react::CallInvoker> &callInvoker);
|
|
21
|
+
~AudioEventHandlerRegistry();
|
|
22
|
+
|
|
23
|
+
uint64_t registerHandler(const std::string &eventName, const std::shared_ptr<jsi::Function> &handler);
|
|
24
|
+
void unregisterHandler(const std::string &eventName, uint64_t listenerId);
|
|
25
|
+
|
|
26
|
+
void invokeHandlerWithEventBody(const std::string &eventName, const std::unordered_map<std::string, EventValue> &body);
|
|
27
|
+
void invokeHandlerWithEventBody(const std::string &eventName, uint64_t listenerId, const std::unordered_map<std::string, EventValue> &body);
|
|
28
|
+
|
|
29
|
+
private:
|
|
30
|
+
std::shared_ptr<react::CallInvoker> callInvoker_;
|
|
31
|
+
jsi::Runtime *runtime_;
|
|
32
|
+
std::unordered_map<std::string, std::unordered_map<uint64_t, std::shared_ptr<jsi::Function>>> eventHandlers_;
|
|
33
|
+
|
|
34
|
+
static constexpr std::array<std::string_view, 15> SYSTEM_EVENT_NAMES = {
|
|
35
|
+
"remotePlay",
|
|
36
|
+
"remotePause",
|
|
37
|
+
"remoteStop",
|
|
38
|
+
"remoteTogglePlayPause",
|
|
39
|
+
"remoteChangePlaybackRate",
|
|
40
|
+
"remoteNextTrack",
|
|
41
|
+
"remotePreviousTrack",
|
|
42
|
+
"remoteSkipForward",
|
|
43
|
+
"remoteSkipBackward",
|
|
44
|
+
"remoteSeekForward",
|
|
45
|
+
"remoteSeekBackward",
|
|
46
|
+
"remoteChangePlaybackPosition",
|
|
47
|
+
"routeChange",
|
|
48
|
+
"interruption",
|
|
49
|
+
"volumeChange",
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
static constexpr std::array<std::string_view, 4> AUDIO_API_EVENT_NAMES = {
|
|
53
|
+
"ended",
|
|
54
|
+
"audioReady",
|
|
55
|
+
"audioError",
|
|
56
|
+
"systemStateChanged"
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
jsi::Object createEventObject(const std::unordered_map<std::string, EventValue> &body);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
} // namespace audioapi
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <audioapi/jsi/JsiHostObject.h>
|
|
4
|
+
#include <audioapi/events/AudioEventHandlerRegistry.h>
|
|
5
|
+
|
|
6
|
+
#include <jsi/jsi.h>
|
|
7
|
+
#include <ReactCommon/CallInvoker.h>
|
|
8
|
+
#include <memory>
|
|
9
|
+
#include <unordered_map>
|
|
10
|
+
#include <vector>
|
|
11
|
+
#include <string>
|
|
12
|
+
|
|
13
|
+
namespace audioapi {
|
|
14
|
+
using namespace facebook;
|
|
15
|
+
|
|
16
|
+
class AudioEventHandlerRegistryHostObject : public JsiHostObject {
|
|
17
|
+
public:
|
|
18
|
+
explicit AudioEventHandlerRegistryHostObject(const std::shared_ptr<AudioEventHandlerRegistry>& eventHandlerRegistry) {
|
|
19
|
+
eventHandlerRegistry_ = eventHandlerRegistry;
|
|
20
|
+
|
|
21
|
+
addFunctions(
|
|
22
|
+
JSI_EXPORT_FUNCTION(AudioEventHandlerRegistryHostObject, addAudioEventListener),
|
|
23
|
+
JSI_EXPORT_FUNCTION(AudioEventHandlerRegistryHostObject, removeAudioEventListener));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
JSI_HOST_FUNCTION(addAudioEventListener) {
|
|
27
|
+
auto eventName = args[0].getString(runtime).utf8(runtime);
|
|
28
|
+
auto callback = std::make_shared<jsi::Function>(args[1].getObject(runtime).getFunction(runtime));
|
|
29
|
+
|
|
30
|
+
auto listenerId = eventHandlerRegistry_->registerHandler(eventName, callback);
|
|
31
|
+
|
|
32
|
+
return jsi::String::createFromUtf8(runtime, std::to_string(listenerId));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
JSI_HOST_FUNCTION(removeAudioEventListener) {
|
|
36
|
+
auto eventName = args[0].getString(runtime).utf8(runtime);
|
|
37
|
+
uint64_t listenerId = std::stoull(args[1].getString(runtime).utf8(runtime));
|
|
38
|
+
|
|
39
|
+
eventHandlerRegistry_->unregisterHandler(eventName, listenerId);
|
|
40
|
+
|
|
41
|
+
return jsi::Value::undefined();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private:
|
|
45
|
+
std::shared_ptr<AudioEventHandlerRegistry> eventHandlerRegistry_;
|
|
46
|
+
};
|
|
47
|
+
} // namespace audioapi
|
|
48
|
+
|
|
@@ -44,10 +44,9 @@ jsi::Value PromiseVendor::createPromise(
|
|
|
44
44
|
|
|
45
45
|
auto rejectWrapper = [reject, &runtime, callInvoker](
|
|
46
46
|
const std::string &errorMessage) -> void {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
reject->call(runtime, errorShared->value());
|
|
47
|
+
callInvoker->invokeAsync([reject, &runtime, errorMessage]() -> void {
|
|
48
|
+
auto error = jsi::JSError(runtime, errorMessage);
|
|
49
|
+
reject->call(runtime, error.value());
|
|
51
50
|
});
|
|
52
51
|
};
|
|
53
52
|
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#include <audioapi/utils/CircularAudioArray.h>
|
|
2
|
+
|
|
3
|
+
namespace audioapi {
|
|
4
|
+
|
|
5
|
+
CircularAudioArray::CircularAudioArray(size_t size) : AudioArray(size) {}
|
|
6
|
+
|
|
7
|
+
void CircularAudioArray::push_back(
|
|
8
|
+
const float *data,
|
|
9
|
+
size_t size,
|
|
10
|
+
bool skipAvailableSpaceCheck) {
|
|
11
|
+
if (size > size_) {
|
|
12
|
+
throw std::overflow_error("size exceeds CircularAudioArray size_");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (size > getAvailableSpace() && !skipAvailableSpaceCheck) {
|
|
16
|
+
throw std::overflow_error("not enough space in CircularAudioArray");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (vWriteIndex_ + size > size_) {
|
|
20
|
+
auto partSize = size_ - vWriteIndex_;
|
|
21
|
+
memcpy(data_ + vWriteIndex_, data, partSize * sizeof(float));
|
|
22
|
+
memcpy(data_, data + partSize, (size - partSize) * sizeof(float));
|
|
23
|
+
} else {
|
|
24
|
+
memcpy(data_ + vWriteIndex_, data, size * sizeof(float));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
vWriteIndex_ = vWriteIndex_ + size > size_ ? vWriteIndex_ + size - size_
|
|
28
|
+
: vWriteIndex_ + size;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
void CircularAudioArray::pop_front(
|
|
32
|
+
float *data,
|
|
33
|
+
size_t size,
|
|
34
|
+
bool skipAvailableDataCheck) {
|
|
35
|
+
if (size > size_) {
|
|
36
|
+
throw std::overflow_error("size exceeds CircularAudioArray size_");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (size > getNumberOfAvailableFrames() && !skipAvailableDataCheck) {
|
|
40
|
+
throw std::overflow_error("not enough data in CircularAudioArray");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (vReadIndex_ + size > size_) {
|
|
44
|
+
auto partSize = size_ - vReadIndex_;
|
|
45
|
+
memcpy(data, data_ + vReadIndex_, partSize * sizeof(float));
|
|
46
|
+
memcpy(data + partSize, data_, (size - partSize) * sizeof(float));
|
|
47
|
+
} else {
|
|
48
|
+
memcpy(data, data_ + vReadIndex_, size * sizeof(float));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
vReadIndex_ = vReadIndex_ + size > size_ ? vReadIndex_ + size - size_
|
|
52
|
+
: vReadIndex_ + size;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
void CircularAudioArray::pop_back(
|
|
56
|
+
float *data,
|
|
57
|
+
size_t size,
|
|
58
|
+
size_t offset,
|
|
59
|
+
bool skipAvailableDataCheck) {
|
|
60
|
+
if (size > size_) {
|
|
61
|
+
throw std::overflow_error("size exceeds CircularAudioArray size_");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (size + offset > getNumberOfAvailableFrames() && !skipAvailableDataCheck) {
|
|
65
|
+
throw std::overflow_error("not enough data in CircularAudioArray");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (vWriteIndex_ <= offset) {
|
|
69
|
+
memcpy(
|
|
70
|
+
data,
|
|
71
|
+
data_ + size_ - (offset - vWriteIndex_) - size,
|
|
72
|
+
size * sizeof(float));
|
|
73
|
+
} else if (vWriteIndex_ <= size + offset) {
|
|
74
|
+
auto partSize = size + offset - vWriteIndex_;
|
|
75
|
+
memcpy(data, data_ + size_ - partSize, partSize * sizeof(float));
|
|
76
|
+
memcpy(data + partSize, data_, (size - partSize) * sizeof(float));
|
|
77
|
+
} else {
|
|
78
|
+
memcpy(data, data_ + vWriteIndex_ - size - offset, size * sizeof(float));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
vReadIndex_ = vWriteIndex_ - offset < 0 ? size + vWriteIndex_ - offset
|
|
82
|
+
: vWriteIndex_ - offset;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
size_t CircularAudioArray::getNumberOfAvailableFrames() const {
|
|
86
|
+
return vWriteIndex_ >= vReadIndex_ ? vWriteIndex_ - vReadIndex_
|
|
87
|
+
: size_ - vReadIndex_ + vWriteIndex_;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
size_t CircularAudioArray::getAvailableSpace() const {
|
|
91
|
+
return size_ - getNumberOfAvailableFrames();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
} // namespace audioapi
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <audioapi/utils/AudioArray.h>
|
|
4
|
+
|
|
5
|
+
namespace audioapi {
|
|
6
|
+
|
|
7
|
+
class CircularAudioArray : public AudioArray {
|
|
8
|
+
public:
|
|
9
|
+
explicit CircularAudioArray(size_t size);
|
|
10
|
+
CircularAudioArray(const CircularAudioArray &other) = default;
|
|
11
|
+
~CircularAudioArray() = default;
|
|
12
|
+
|
|
13
|
+
void push_back(const float *data, size_t size, bool skipAvailableSpaceCheck = false);
|
|
14
|
+
void pop_front(float *data, size_t size, bool skipAvailableDataCheck = false);
|
|
15
|
+
void pop_back(float *data, size_t size, size_t offset = 0, bool skipAvailableDataCheck = false);
|
|
16
|
+
|
|
17
|
+
[[nodiscard]] size_t getNumberOfAvailableFrames() const;
|
|
18
|
+
|
|
19
|
+
private:
|
|
20
|
+
size_t vWriteIndex_ = 0;
|
|
21
|
+
size_t vReadIndex_ = 0;
|
|
22
|
+
|
|
23
|
+
[[nodiscard]] size_t getAvailableSpace() const;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
} // namespace audioapi
|
|
@@ -7,10 +7,23 @@
|
|
|
7
7
|
|
|
8
8
|
#import <React/RCTEventEmitter.h>
|
|
9
9
|
|
|
10
|
+
@class AudioEngine;
|
|
11
|
+
@class NotificationManager;
|
|
12
|
+
@class AudioSessionManager;
|
|
13
|
+
@class LockScreenManager;
|
|
14
|
+
|
|
10
15
|
@interface AudioAPIModule : RCTEventEmitter
|
|
11
16
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
12
17
|
<NativeAudioAPIModuleSpec, RCTCallInvokerModule>
|
|
13
18
|
#else
|
|
14
19
|
<RCTBridgeModule>
|
|
15
20
|
#endif // RCT_NEW_ARCH_ENABLED
|
|
21
|
+
|
|
22
|
+
@property (nonatomic, strong) AudioEngine *audioEngine;
|
|
23
|
+
@property (nonatomic, strong) NotificationManager *notificationManager;
|
|
24
|
+
@property (nonatomic, strong) AudioSessionManager *audioSessionManager;
|
|
25
|
+
@property (nonatomic, strong) LockScreenManager *lockScreenManager;
|
|
26
|
+
|
|
27
|
+
- (void)invokeHandlerWithEventName:(NSString *)eventName eventBody:(NSDictionary *)eventBody;
|
|
28
|
+
|
|
16
29
|
@end
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
#import "AudioAPIModule.h"
|
|
2
|
-
|
|
3
1
|
#import <React/RCTBridge+Private.h>
|
|
4
|
-
|
|
2
|
+
#import <audioapi/ios/AudioAPIModule.h>
|
|
5
3
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
6
4
|
#import <React/RCTCallInvoker.h>
|
|
7
5
|
#endif // RCT_NEW_ARCH_ENABLED
|
|
8
6
|
|
|
9
|
-
#
|
|
7
|
+
#import <audioapi/AudioAPIModuleInstaller.h>
|
|
8
|
+
#import <audioapi/ios/system/AudioEngine.h>
|
|
9
|
+
#import <audioapi/ios/system/AudioSessionManager.h>
|
|
10
|
+
#import <audioapi/ios/system/LockScreenManager.h>
|
|
11
|
+
#import <audioapi/ios/system/NotificationManager.h>
|
|
12
|
+
|
|
13
|
+
#import <audioapi/events/AudioEventHandlerRegistry.h>
|
|
10
14
|
|
|
11
15
|
using namespace audioapi;
|
|
12
16
|
using namespace facebook::react;
|
|
@@ -24,7 +28,9 @@ using namespace facebook::react;
|
|
|
24
28
|
@end
|
|
25
29
|
#endif // RCT_NEW_ARCH_ENABLED
|
|
26
30
|
|
|
27
|
-
@implementation AudioAPIModule
|
|
31
|
+
@implementation AudioAPIModule {
|
|
32
|
+
std::shared_ptr<AudioEventHandlerRegistry> _eventHandler;
|
|
33
|
+
}
|
|
28
34
|
|
|
29
35
|
#if defined(RCT_NEW_ARCH_ENABLED)
|
|
30
36
|
@synthesize callInvoker = _callInvoker;
|
|
@@ -32,8 +38,25 @@ using namespace facebook::react;
|
|
|
32
38
|
|
|
33
39
|
RCT_EXPORT_MODULE(AudioAPIModule);
|
|
34
40
|
|
|
41
|
+
- (void)invalidate
|
|
42
|
+
{
|
|
43
|
+
[self.audioEngine cleanup];
|
|
44
|
+
[self.notificationManager cleanup];
|
|
45
|
+
[self.audioSessionManager cleanup];
|
|
46
|
+
[self.lockScreenManager cleanup];
|
|
47
|
+
|
|
48
|
+
_eventHandler = nullptr;
|
|
49
|
+
|
|
50
|
+
[super invalidate];
|
|
51
|
+
}
|
|
52
|
+
|
|
35
53
|
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install)
|
|
36
54
|
{
|
|
55
|
+
self.audioSessionManager = [[AudioSessionManager alloc] init];
|
|
56
|
+
self.audioEngine = [[AudioEngine alloc] initWithAudioSessionManager:self.audioSessionManager];
|
|
57
|
+
self.lockScreenManager = [[LockScreenManager alloc] initWithAudioAPIModule:self];
|
|
58
|
+
self.notificationManager = [[NotificationManager alloc] initWithAudioAPIModule:self];
|
|
59
|
+
|
|
37
60
|
auto jsiRuntime = reinterpret_cast<facebook::jsi::Runtime *>(self.bridge.runtime);
|
|
38
61
|
|
|
39
62
|
#if defined(RCT_NEW_ARCH_ENABLED)
|
|
@@ -44,12 +67,68 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install)
|
|
|
44
67
|
|
|
45
68
|
assert(jsiRuntime != nullptr);
|
|
46
69
|
|
|
47
|
-
|
|
70
|
+
_eventHandler = std::make_shared<AudioEventHandlerRegistry>(jsiRuntime, jsCallInvoker);
|
|
71
|
+
|
|
72
|
+
self.audioSessionManager = [[AudioSessionManager alloc] init];
|
|
73
|
+
self.audioEngine = [[AudioEngine alloc] initWithAudioSessionManager:self.audioSessionManager];
|
|
74
|
+
self.lockScreenManager = [[LockScreenManager alloc] initWithAudioAPIModule:self];
|
|
75
|
+
self.notificationManager = [[NotificationManager alloc] initWithAudioAPIModule:self];
|
|
76
|
+
|
|
77
|
+
audioapi::AudioAPIModuleInstaller::injectJSIBindings(jsiRuntime, jsCallInvoker, _eventHandler);
|
|
48
78
|
|
|
49
79
|
NSLog(@"Successfully installed JSI bindings for react-native-audio-api!");
|
|
50
80
|
return @true;
|
|
51
81
|
}
|
|
52
82
|
|
|
83
|
+
RCT_EXPORT_METHOD(setLockScreenInfo : (NSDictionary *)info)
|
|
84
|
+
{
|
|
85
|
+
[self.lockScreenManager setLockScreenInfo:info];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
RCT_EXPORT_METHOD(resetLockScreenInfo)
|
|
89
|
+
{
|
|
90
|
+
[self.lockScreenManager resetLockScreenInfo];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
RCT_EXPORT_METHOD(enableRemoteCommand : (NSString *)name enabled : (BOOL)enabled)
|
|
94
|
+
{
|
|
95
|
+
[self.lockScreenManager enableRemoteCommand:name enabled:enabled];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
RCT_EXPORT_METHOD(setAudioSessionOptions : (NSString *)category mode : (NSString *)mode options : (NSArray *)options)
|
|
99
|
+
{
|
|
100
|
+
[self.audioSessionManager setAudioSessionOptions:category mode:mode options:options];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getDevicePreferredSampleRate)
|
|
104
|
+
{
|
|
105
|
+
return [self.audioSessionManager getDevicePreferredSampleRate];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
RCT_EXPORT_METHOD(observeAudioInterruptions : (BOOL)enabled)
|
|
109
|
+
{
|
|
110
|
+
[self.notificationManager observeAudioInterruptions:enabled];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
RCT_EXPORT_METHOD(observeVolumeChanges : (BOOL)enabled)
|
|
114
|
+
{
|
|
115
|
+
[self.notificationManager observeVolumeChanges:(BOOL)enabled];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
RCT_EXPORT_METHOD(requestRecordingPermissions : (nonnull RCTPromiseResolveBlock)
|
|
119
|
+
resolve reject : (nonnull RCTPromiseRejectBlock)reject)
|
|
120
|
+
{
|
|
121
|
+
NSString *res = [self.audioSessionManager requestRecordingPermissions];
|
|
122
|
+
resolve(res);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
RCT_EXPORT_METHOD(checkRecordingPermissions : (nonnull RCTPromiseResolveBlock)
|
|
126
|
+
resolve reject : (nonnull RCTPromiseRejectBlock)reject)
|
|
127
|
+
{
|
|
128
|
+
NSString *res = [self.audioSessionManager checkRecordingPermissions];
|
|
129
|
+
resolve(res);
|
|
130
|
+
}
|
|
131
|
+
|
|
53
132
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
54
133
|
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
55
134
|
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
@@ -58,4 +137,34 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install)
|
|
|
58
137
|
}
|
|
59
138
|
#endif // RCT_NEW_ARCH_ENABLED
|
|
60
139
|
|
|
140
|
+
- (void)invokeHandlerWithEventName:(NSString *)eventName eventBody:(NSDictionary *)eventBody
|
|
141
|
+
{
|
|
142
|
+
auto name = [eventName UTF8String];
|
|
143
|
+
|
|
144
|
+
std::unordered_map<std::string, EventValue> body = {};
|
|
145
|
+
|
|
146
|
+
for (NSString *key in eventBody) {
|
|
147
|
+
id value = eventBody[key];
|
|
148
|
+
std::string stdKey = [key UTF8String];
|
|
149
|
+
|
|
150
|
+
if ([value isKindOfClass:[NSString class]]) {
|
|
151
|
+
std::string stdValue = [value UTF8String];
|
|
152
|
+
body[stdKey] = EventValue(stdValue);
|
|
153
|
+
} else if ([value isKindOfClass:[NSNumber class]]) {
|
|
154
|
+
const char *type = [value objCType];
|
|
155
|
+
if (strcmp(type, @encode(int)) == 0) {
|
|
156
|
+
body[stdKey] = EventValue([value intValue]);
|
|
157
|
+
} else if (strcmp(type, @encode(double)) == 0) {
|
|
158
|
+
body[stdKey] = EventValue([value doubleValue]);
|
|
159
|
+
} else if (strcmp(type, @encode(float)) == 0) {
|
|
160
|
+
body[stdKey] = EventValue([value floatValue]);
|
|
161
|
+
} else if (strcmp(type, @encode(BOOL)) == 0) {
|
|
162
|
+
body[stdKey] = EventValue([value boolValue]);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
_eventHandler->invokeHandlerWithEventBody(name, body);
|
|
168
|
+
}
|
|
169
|
+
|
|
61
170
|
@end
|
|
@@ -7,21 +7,19 @@ typedef struct objc_object NativeAudioRecorder;
|
|
|
7
7
|
#endif // __OBJC__
|
|
8
8
|
|
|
9
9
|
#include <audioapi/core/inputs/AudioRecorder.h>
|
|
10
|
-
#include <functional>
|
|
11
10
|
|
|
12
11
|
namespace audioapi {
|
|
13
12
|
|
|
14
13
|
class AudioBus;
|
|
14
|
+
class CircularAudioArray;
|
|
15
15
|
|
|
16
16
|
class IOSAudioRecorder : public AudioRecorder {
|
|
17
17
|
public:
|
|
18
18
|
IOSAudioRecorder(
|
|
19
19
|
float sampleRate,
|
|
20
20
|
int bufferLength,
|
|
21
|
-
const std::
|
|
22
|
-
|
|
23
|
-
const std::function<void(std::shared_ptr<AudioBus>, int, double)>
|
|
24
|
-
&onAudioReady);
|
|
21
|
+
const std::shared_ptr<AudioEventHandlerRegistry>
|
|
22
|
+
&audioEventHandlerRegistry);
|
|
25
23
|
|
|
26
24
|
~IOSAudioRecorder() override;
|
|
27
25
|
|
|
@@ -30,11 +28,6 @@ class IOSAudioRecorder : public AudioRecorder {
|
|
|
30
28
|
|
|
31
29
|
private:
|
|
32
30
|
NativeAudioRecorder *audioRecorder_;
|
|
33
|
-
std::atomic<bool> isRunning_;
|
|
34
|
-
|
|
35
|
-
std::shared_ptr<AudioBus> circularBuffer_;
|
|
36
|
-
int writeIdx_ = 0;
|
|
37
|
-
int readIdx_ = 0;
|
|
38
31
|
};
|
|
39
32
|
|
|
40
33
|
} // namespace audioapi
|