react-native-audio-api 0.7.0-nightly-4fc09d1-20250727 → 0.7.0-nightly-a914864-20250729
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/README.md +3 -4
- package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp +3 -1
- package/common/cpp/audioapi/HostObjects/AudioNodeHostObject.cpp +9 -0
- package/common/cpp/audioapi/HostObjects/AudioNodeHostObject.h +2 -0
- package/common/cpp/audioapi/HostObjects/AudioRecorderHostObject.h +17 -1
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp +9 -0
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h +18 -16
- package/common/cpp/audioapi/HostObjects/RecorderAdapterNodeHostObject.h +26 -0
- package/common/cpp/audioapi/core/BaseAudioContext.cpp +9 -10
- package/common/cpp/audioapi/core/BaseAudioContext.h +3 -2
- package/common/cpp/audioapi/core/inputs/AudioRecorder.cpp +28 -2
- package/common/cpp/audioapi/core/inputs/AudioRecorder.h +24 -0
- package/common/cpp/audioapi/core/sources/RecorderAdapterNode.cpp +48 -0
- package/common/cpp/audioapi/core/sources/RecorderAdapterNode.h +43 -0
- package/common/cpp/audioapi/jsi/AudioArrayBuffer.h +1 -1
- package/common/cpp/audioapi/utils/CircularOverflowableAudioArray.cpp +61 -0
- package/common/cpp/audioapi/utils/CircularOverflowableAudioArray.h +42 -0
- package/ios/audioapi/ios/core/IOSAudioRecorder.mm +2 -1
- package/ios/audioapi/ios/core/NativeAudioRecorder.m +7 -0
- package/lib/commonjs/api.js +7 -7
- package/lib/commonjs/api.js.map +1 -1
- package/lib/commonjs/core/AudioRecorder.js +10 -0
- package/lib/commonjs/core/AudioRecorder.js.map +1 -1
- package/lib/commonjs/core/BaseAudioContext.js +4 -4
- package/lib/commonjs/core/BaseAudioContext.js.map +1 -1
- package/lib/commonjs/core/RecorderAdapterNode.js +19 -0
- package/lib/commonjs/core/RecorderAdapterNode.js.map +1 -0
- package/lib/module/api.js +1 -1
- package/lib/module/api.js.map +1 -1
- package/lib/module/core/AudioRecorder.js +10 -0
- package/lib/module/core/AudioRecorder.js.map +1 -1
- package/lib/module/core/BaseAudioContext.js +4 -4
- package/lib/module/core/BaseAudioContext.js.map +1 -1
- package/lib/module/core/RecorderAdapterNode.js +13 -0
- package/lib/module/core/RecorderAdapterNode.js.map +1 -0
- package/lib/typescript/api.d.ts +1 -1
- package/lib/typescript/api.d.ts.map +1 -1
- package/lib/typescript/core/AudioRecorder.d.ts +3 -0
- package/lib/typescript/core/AudioRecorder.d.ts.map +1 -1
- package/lib/typescript/core/BaseAudioContext.d.ts +3 -3
- package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
- package/lib/typescript/core/RecorderAdapterNode.d.ts +9 -0
- package/lib/typescript/core/RecorderAdapterNode.d.ts.map +1 -0
- package/lib/typescript/interfaces.d.ts +6 -6
- package/lib/typescript/interfaces.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/api.ts +1 -1
- package/src/core/AudioRecorder.ts +16 -0
- package/src/core/BaseAudioContext.ts +6 -9
- package/src/core/RecorderAdapterNode.ts +12 -0
- package/src/interfaces.ts +5 -7
- package/common/cpp/audioapi/HostObjects/CustomProcessorNodeHostObject.h +0 -54
- package/common/cpp/audioapi/core/effects/CustomProcessorNode.cpp +0 -173
- package/common/cpp/audioapi/core/effects/CustomProcessorNode.h +0 -186
- package/lib/commonjs/core/CustomProcessorNode.js +0 -23
- package/lib/commonjs/core/CustomProcessorNode.js.map +0 -1
- package/lib/module/core/CustomProcessorNode.js +0 -17
- package/lib/module/core/CustomProcessorNode.js.map +0 -1
- package/lib/typescript/core/CustomProcessorNode.d.ts +0 -12
- package/lib/typescript/core/CustomProcessorNode.d.ts.map +0 -1
- package/src/core/CustomProcessorNode.ts +0 -28
package/src/interfaces.ts
CHANGED
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
BiquadFilterType,
|
|
6
6
|
ChannelCountMode,
|
|
7
7
|
ChannelInterpretation,
|
|
8
|
-
ProcessorMode,
|
|
9
8
|
} from './types';
|
|
10
9
|
import { AudioEventName, AudioEventCallback } from './events/types';
|
|
11
10
|
|
|
@@ -15,8 +14,8 @@ export interface IBaseAudioContext {
|
|
|
15
14
|
readonly sampleRate: number;
|
|
16
15
|
readonly currentTime: number;
|
|
17
16
|
|
|
17
|
+
createRecorderAdapter(): IRecorderAdapterNode;
|
|
18
18
|
createOscillator(): IOscillatorNode;
|
|
19
|
-
createCustomProcessor(identifier: string): ICustomProcessorNode;
|
|
20
19
|
createGain(): IGainNode;
|
|
21
20
|
createStereoPanner(): IStereoPannerNode;
|
|
22
21
|
createBiquadFilter: () => IBiquadFilterNode;
|
|
@@ -65,11 +64,6 @@ export interface IAudioNode {
|
|
|
65
64
|
disconnect: (destination?: IAudioNode | IAudioParam) => void;
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
export interface ICustomProcessorNode extends IAudioNode {
|
|
69
|
-
readonly customProcessor: IAudioParam;
|
|
70
|
-
processorMode: ProcessorMode;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
67
|
export interface IGainNode extends IAudioNode {
|
|
74
68
|
readonly gain: IAudioParam;
|
|
75
69
|
}
|
|
@@ -195,9 +189,13 @@ export interface IAnalyserNode extends IAudioNode {
|
|
|
195
189
|
getByteTimeDomainData: (array: Uint8Array) => void;
|
|
196
190
|
}
|
|
197
191
|
|
|
192
|
+
export interface IRecorderAdapterNode extends IAudioNode {}
|
|
193
|
+
|
|
198
194
|
export interface IAudioRecorder {
|
|
199
195
|
start: () => void;
|
|
200
196
|
stop: () => void;
|
|
197
|
+
connect: (node: IRecorderAdapterNode) => void;
|
|
198
|
+
disconnect: () => void;
|
|
201
199
|
|
|
202
200
|
// passing subscriptionId(uint_64 in cpp, string in js) to the cpp
|
|
203
201
|
onAudioReady: string;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <audioapi/HostObjects/AudioNodeHostObject.h>
|
|
4
|
-
#include <audioapi/HostObjects/AudioParamHostObject.h>
|
|
5
|
-
#include <audioapi/core/effects/CustomProcessorNode.h>
|
|
6
|
-
|
|
7
|
-
#include <memory>
|
|
8
|
-
#include <string>
|
|
9
|
-
#include <vector>
|
|
10
|
-
|
|
11
|
-
namespace audioapi {
|
|
12
|
-
using namespace facebook;
|
|
13
|
-
|
|
14
|
-
class CustomProcessorNodeHostObject : public AudioNodeHostObject {
|
|
15
|
-
public:
|
|
16
|
-
explicit CustomProcessorNodeHostObject(const std::shared_ptr<CustomProcessorNode> &node)
|
|
17
|
-
: AudioNodeHostObject(node) {
|
|
18
|
-
addGetters(
|
|
19
|
-
JSI_EXPORT_PROPERTY_GETTER(CustomProcessorNodeHostObject, customProcessor),
|
|
20
|
-
JSI_EXPORT_PROPERTY_GETTER(CustomProcessorNodeHostObject, processorMode));
|
|
21
|
-
|
|
22
|
-
addSetters(
|
|
23
|
-
JSI_EXPORT_PROPERTY_SETTER(CustomProcessorNodeHostObject, processorMode));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
JSI_PROPERTY_GETTER(customProcessor) {
|
|
27
|
-
auto customProcessorNode = std::static_pointer_cast<CustomProcessorNode>(node_);
|
|
28
|
-
auto customProcessorParam =
|
|
29
|
-
std::make_shared<AudioParamHostObject>(customProcessorNode->getCustomProcessorParam());
|
|
30
|
-
return jsi::Object::createFromHostObject(runtime, customProcessorParam);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
JSI_PROPERTY_GETTER(processorMode) {
|
|
34
|
-
auto customProcessorNode = std::static_pointer_cast<CustomProcessorNode>(node_);
|
|
35
|
-
auto mode = customProcessorNode->getProcessorMode();
|
|
36
|
-
std::string modeStr = (mode == CustomProcessorNode::ProcessorMode::ProcessThrough)
|
|
37
|
-
? "processThrough"
|
|
38
|
-
: "processInPlace";
|
|
39
|
-
return jsi::String::createFromUtf8(runtime, modeStr);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
JSI_PROPERTY_SETTER(processorMode) {
|
|
43
|
-
auto customProcessorNode = std::static_pointer_cast<CustomProcessorNode>(node_);
|
|
44
|
-
std::string modeStr = value.getString(runtime).utf8(runtime);
|
|
45
|
-
|
|
46
|
-
if (modeStr == "processThrough") {
|
|
47
|
-
customProcessorNode->setProcessorMode(CustomProcessorNode::ProcessorMode::ProcessThrough);
|
|
48
|
-
} else {
|
|
49
|
-
customProcessorNode->setProcessorMode(CustomProcessorNode::ProcessorMode::ProcessInPlace);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
} // namespace audioapi
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
#include <audioapi/core/BaseAudioContext.h>
|
|
2
|
-
#include <audioapi/core/effects/CustomProcessorNode.h>
|
|
3
|
-
#include <audioapi/utils/AudioArray.h>
|
|
4
|
-
#include <audioapi/utils/AudioBus.h>
|
|
5
|
-
|
|
6
|
-
#include <algorithm>
|
|
7
|
-
#include <cstring>
|
|
8
|
-
#include <iostream>
|
|
9
|
-
|
|
10
|
-
namespace audioapi {
|
|
11
|
-
|
|
12
|
-
// Static registries and active node tracking
|
|
13
|
-
std::map<std::string, std::function<std::shared_ptr<CustomAudioProcessor>()>>
|
|
14
|
-
CustomProcessorNode::s_processorFactoriesByIdentifier;
|
|
15
|
-
std::unordered_map<std::string, CustomProcessorNode::GenericControlHandler>
|
|
16
|
-
CustomProcessorNode::s_controlHandlersByIdentifier;
|
|
17
|
-
std::unordered_map<std::string, std::vector<CustomProcessorNode *>>
|
|
18
|
-
CustomProcessorNode::s_activeNodes;
|
|
19
|
-
|
|
20
|
-
// Constructor: initializes processor, tracking, and preallocated buffers
|
|
21
|
-
CustomProcessorNode::CustomProcessorNode(
|
|
22
|
-
BaseAudioContext *context,
|
|
23
|
-
const std::string &identifier)
|
|
24
|
-
: AudioNode(context), processorMode_(ProcessorMode::ProcessInPlace) {
|
|
25
|
-
customProcessorParam_ = std::make_shared<AudioParam>(
|
|
26
|
-
1.0f, MOST_NEGATIVE_SINGLE_FLOAT, MOST_POSITIVE_SINGLE_FLOAT, context);
|
|
27
|
-
isInitialized_ = true;
|
|
28
|
-
|
|
29
|
-
auto it = s_processorFactoriesByIdentifier.find(identifier);
|
|
30
|
-
processor_ =
|
|
31
|
-
(it != s_processorFactoriesByIdentifier.end()) ? it->second() : nullptr;
|
|
32
|
-
|
|
33
|
-
s_activeNodes[identifier].push_back(this);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Destructor: cleans up tracking for this instance
|
|
37
|
-
CustomProcessorNode::~CustomProcessorNode() {
|
|
38
|
-
for (auto &pair : s_activeNodes) {
|
|
39
|
-
auto &vec = pair.second;
|
|
40
|
-
vec.erase(std::remove(vec.begin(), vec.end(), this), vec.end());
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Gets the modifiable parameter
|
|
45
|
-
std::shared_ptr<AudioParam> CustomProcessorNode::getCustomProcessorParam()
|
|
46
|
-
const {
|
|
47
|
-
return customProcessorParam_;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Returns the current processing mode
|
|
51
|
-
CustomProcessorNode::ProcessorMode CustomProcessorNode::getProcessorMode()
|
|
52
|
-
const {
|
|
53
|
-
return processorMode_;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Updates the processing mode
|
|
57
|
-
void CustomProcessorNode::setProcessorMode(ProcessorMode mode) {
|
|
58
|
-
processorMode_ = mode;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Registers a factory for dynamic processor instantiation
|
|
62
|
-
void CustomProcessorNode::registerProcessorFactory(
|
|
63
|
-
const std::string &identifier,
|
|
64
|
-
std::function<std::shared_ptr<CustomAudioProcessor>()> factory) {
|
|
65
|
-
s_processorFactoriesByIdentifier[identifier] = std::move(factory);
|
|
66
|
-
notifyProcessorChanged(identifier);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Removes a processor factory from registry
|
|
70
|
-
void CustomProcessorNode::unregisterProcessorFactory(
|
|
71
|
-
const std::string &identifier) {
|
|
72
|
-
s_processorFactoriesByIdentifier.erase(identifier);
|
|
73
|
-
notifyProcessorChanged(identifier);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Updates processor instances for all nodes using given identifier
|
|
77
|
-
void CustomProcessorNode::notifyProcessorChanged(
|
|
78
|
-
const std::string &identifier) {
|
|
79
|
-
auto it = s_activeNodes.find(identifier);
|
|
80
|
-
if (it != s_activeNodes.end()) {
|
|
81
|
-
for (CustomProcessorNode *node : it->second) {
|
|
82
|
-
auto f = s_processorFactoriesByIdentifier.find(identifier);
|
|
83
|
-
node->processor_ =
|
|
84
|
-
(f != s_processorFactoriesByIdentifier.end()) ? f->second() : nullptr;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Registers control handler for runtime automation
|
|
90
|
-
void CustomProcessorNode::registerControlHandler(
|
|
91
|
-
const std::string &identifier,
|
|
92
|
-
GenericControlHandler handler) {
|
|
93
|
-
s_controlHandlersByIdentifier[identifier] = std::move(handler);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Removes a control handler
|
|
97
|
-
void CustomProcessorNode::unregisterControlHandler(
|
|
98
|
-
const std::string &identifier) {
|
|
99
|
-
s_controlHandlersByIdentifier.erase(identifier);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Core processing method routed by selected mode
|
|
103
|
-
void CustomProcessorNode::processNode(
|
|
104
|
-
const std::shared_ptr<AudioBus> &processingBus,
|
|
105
|
-
int framesToProcess) {
|
|
106
|
-
if (!processor_)
|
|
107
|
-
return;
|
|
108
|
-
|
|
109
|
-
int numChannels = processingBus->getNumberOfChannels();
|
|
110
|
-
if (preallocatedOutputBuffers_.size() != static_cast<size_t>(numChannels)) {
|
|
111
|
-
preallocatedOutputBuffers_.resize(numChannels);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
for (int ch = 0; ch < numChannels; ++ch) {
|
|
115
|
-
if (preallocatedOutputBuffers_[ch].size() !=
|
|
116
|
-
static_cast<size_t>(framesToProcess)) {
|
|
117
|
-
preallocatedOutputBuffers_[ch].resize(framesToProcess);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
switch (processorMode_) {
|
|
122
|
-
case ProcessorMode::ProcessThrough:
|
|
123
|
-
processThrough(processingBus, framesToProcess);
|
|
124
|
-
break;
|
|
125
|
-
case ProcessorMode::ProcessInPlace:
|
|
126
|
-
default:
|
|
127
|
-
processInPlace(processingBus, framesToProcess);
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Executes in-place processing on the shared audio buffer
|
|
133
|
-
void CustomProcessorNode::processInPlace(
|
|
134
|
-
const std::shared_ptr<AudioBus> &bus,
|
|
135
|
-
int frames) {
|
|
136
|
-
if (!processor_)
|
|
137
|
-
return;
|
|
138
|
-
|
|
139
|
-
int numChannels = bus->getNumberOfChannels();
|
|
140
|
-
std::vector<float *> channelData(numChannels);
|
|
141
|
-
for (int ch = 0; ch < numChannels; ++ch) {
|
|
142
|
-
channelData[ch] = bus->getChannel(ch)->getData();
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
processor_->processInPlace(channelData.data(), numChannels, frames);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Executes processing using separate input and output buffers with
|
|
149
|
-
// preallocation
|
|
150
|
-
void CustomProcessorNode::processThrough(
|
|
151
|
-
const std::shared_ptr<AudioBus> &bus,
|
|
152
|
-
int frames) {
|
|
153
|
-
if (!processor_)
|
|
154
|
-
return;
|
|
155
|
-
|
|
156
|
-
int numChannels = bus->getNumberOfChannels();
|
|
157
|
-
std::vector<float *> input(numChannels);
|
|
158
|
-
std::vector<float *> output(numChannels);
|
|
159
|
-
|
|
160
|
-
for (int ch = 0; ch < numChannels; ++ch) {
|
|
161
|
-
input[ch] = bus->getChannel(ch)->getData();
|
|
162
|
-
output[ch] = preallocatedOutputBuffers_[ch].data();
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
processor_->processThrough(input.data(), output.data(), numChannels, frames);
|
|
166
|
-
|
|
167
|
-
for (int ch = 0; ch < numChannels; ++ch) {
|
|
168
|
-
std::memcpy(
|
|
169
|
-
bus->getChannel(ch)->getData(), output[ch], sizeof(float) * frames);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
} // namespace audioapi
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <audioapi/core/AudioNode.h>
|
|
4
|
-
#include <audioapi/core/AudioParam.h>
|
|
5
|
-
#include <memory>
|
|
6
|
-
#include <string>
|
|
7
|
-
#include <cstring>
|
|
8
|
-
#include <functional>
|
|
9
|
-
#include <map>
|
|
10
|
-
#include <unordered_map>
|
|
11
|
-
#include <vector>
|
|
12
|
-
#include <any>
|
|
13
|
-
#include <utility>
|
|
14
|
-
|
|
15
|
-
namespace audioapi {
|
|
16
|
-
|
|
17
|
-
class AudioBus;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @brief Interface for defining custom audio processors that can be attached to nodes.
|
|
21
|
-
*/
|
|
22
|
-
class CustomAudioProcessor {
|
|
23
|
-
public:
|
|
24
|
-
virtual ~CustomAudioProcessor() = default;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @brief Processes audio data in-place.
|
|
28
|
-
* @param channelData Array of float pointers for each channel.
|
|
29
|
-
* @param numChannels Number of audio channels.
|
|
30
|
-
* @param numFrames Number of frames per channel.
|
|
31
|
-
*/
|
|
32
|
-
virtual void processInPlace(float** channelData, int numChannels, int numFrames) {
|
|
33
|
-
// Default: do nothing
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @brief Processes audio data from input to output buffers.
|
|
38
|
-
* Default behavior copies input to output and then calls in-place processing.
|
|
39
|
-
* @param input Input audio buffers.
|
|
40
|
-
* @param output Output audio buffers.
|
|
41
|
-
* @param numChannels Number of channels.
|
|
42
|
-
* @param numFrames Number of frames per channel.
|
|
43
|
-
*/
|
|
44
|
-
virtual void processThrough(float** input, float** output, int numChannels, int numFrames) {
|
|
45
|
-
for (int ch = 0; ch < numChannels; ++ch) {
|
|
46
|
-
std::memcpy(output[ch], input[ch], sizeof(float) * numFrames);
|
|
47
|
-
}
|
|
48
|
-
processInPlace(output, numChannels, numFrames);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* @brief Audio node that wraps a user-defined processor for custom audio processing.
|
|
54
|
-
*/
|
|
55
|
-
class CustomProcessorNode : public AudioNode {
|
|
56
|
-
public:
|
|
57
|
-
/**
|
|
58
|
-
* @brief Enumerates supported audio processing modes.
|
|
59
|
-
*/
|
|
60
|
-
enum class ProcessorMode {
|
|
61
|
-
ProcessInPlace,
|
|
62
|
-
ProcessThrough
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @brief Constructs a new CustomProcessorNode attached to a given context with a processor identifier.
|
|
67
|
-
* @param context Audio context this node belongs to.
|
|
68
|
-
* @param identifier The identifier of the processor to instantiate and bind.
|
|
69
|
-
*/
|
|
70
|
-
CustomProcessorNode(BaseAudioContext* context, const std::string& identifier);
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @brief Destroys the node and removes it from active tracking.
|
|
74
|
-
*/
|
|
75
|
-
~CustomProcessorNode();
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* @brief Gets the custom AudioParam associated with this node.
|
|
79
|
-
* @return Shared pointer to an AudioParam.
|
|
80
|
-
*/
|
|
81
|
-
std::shared_ptr<AudioParam> getCustomProcessorParam() const;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @brief Gets the processor mode.
|
|
85
|
-
* @return The current processing mode as an enum.
|
|
86
|
-
*/
|
|
87
|
-
ProcessorMode getProcessorMode() const;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* @brief Sets the processor mode.
|
|
91
|
-
* @param processorMode Processing mode to apply.
|
|
92
|
-
*/
|
|
93
|
-
void setProcessorMode(ProcessorMode processorMode);
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* @brief Registers a factory for creating processors for a given identifier.
|
|
97
|
-
* @param identifier Unique string key.
|
|
98
|
-
* @param factory Function that returns a shared CustomAudioProcessor.
|
|
99
|
-
*/
|
|
100
|
-
static void registerProcessorFactory(
|
|
101
|
-
const std::string& identifier,
|
|
102
|
-
std::function<std::shared_ptr<CustomAudioProcessor>()> factory);
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* @brief Unregisters a processor factory.
|
|
106
|
-
* @param identifier Key to remove.
|
|
107
|
-
*/
|
|
108
|
-
static void unregisterProcessorFactory(const std::string& identifier);
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* @brief Alias for control callbacks accepting arbitrary parameters.
|
|
112
|
-
*/
|
|
113
|
-
using GenericControlHandler = std::function<void(const std::vector<std::any>&)>;
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* @brief Registers a control handler for automation (e.g., gain or filter changes).
|
|
117
|
-
* @param identifier Control name key.
|
|
118
|
-
* @param handler Function to handle dynamic updates.
|
|
119
|
-
*/
|
|
120
|
-
static void registerControlHandler(const std::string& identifier, GenericControlHandler handler);
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* @brief Unregisters a control handler by identifier.
|
|
124
|
-
* @param identifier The key to remove.
|
|
125
|
-
*/
|
|
126
|
-
static void unregisterControlHandler(const std::string& identifier);
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* @brief Invokes a control handler using variadic arguments.
|
|
130
|
-
* @tparam Args Parameter types.
|
|
131
|
-
* @param identifier Key associated with the control handler.
|
|
132
|
-
* @param args Arguments passed to the handler.
|
|
133
|
-
*/
|
|
134
|
-
template <typename... Args>
|
|
135
|
-
static void applyControlToNode(const std::string& identifier, Args&&... args) {
|
|
136
|
-
auto it = s_controlHandlersByIdentifier.find(identifier);
|
|
137
|
-
if (it != s_controlHandlersByIdentifier.end()) {
|
|
138
|
-
std::vector<std::any> paramList = { std::forward<Args>(args)... };
|
|
139
|
-
it->second(paramList);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
protected:
|
|
144
|
-
/**
|
|
145
|
-
* @brief Core audio processing callback invoked each render cycle.
|
|
146
|
-
* @param processingBus The audio bus containing buffers.
|
|
147
|
-
* @param framesToProcess Number of frames to process.
|
|
148
|
-
*/
|
|
149
|
-
void processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
|
|
150
|
-
|
|
151
|
-
private:
|
|
152
|
-
/**
|
|
153
|
-
* @brief In-place audio processing.
|
|
154
|
-
* @param bus The shared audio bus buffer.
|
|
155
|
-
* @param frames Number of frames to process.
|
|
156
|
-
*/
|
|
157
|
-
void processInPlace(const std::shared_ptr<AudioBus>& bus, int frames);
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* @brief Processes audio using separate input and output buffers.
|
|
161
|
-
* @param bus Audio bus used for both input and output access.
|
|
162
|
-
* @param frames Number of frames to process.
|
|
163
|
-
*/
|
|
164
|
-
void processThrough(const std::shared_ptr<AudioBus>& bus, int frames);
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* @brief Ensures that preallocated output buffers match the required frame and channel dimensions.
|
|
168
|
-
* This avoids real-time heap allocations.
|
|
169
|
-
*/
|
|
170
|
-
void ensurePreallocatedBuffers(int numChannels, int numFrames);
|
|
171
|
-
|
|
172
|
-
std::shared_ptr<AudioParam> customProcessorParam_; ///< Optional real-time modifiable parameter.
|
|
173
|
-
ProcessorMode processorMode_ = ProcessorMode::ProcessInPlace; ///< Determines processing style.
|
|
174
|
-
std::shared_ptr<CustomAudioProcessor> processor_; ///< Processor instance.
|
|
175
|
-
|
|
176
|
-
std::vector<std::vector<float>> preallocatedOutputBuffers_; ///< Storage for preallocated channel data.
|
|
177
|
-
std::vector<float*> preallocatedOutputPointers_; ///< Pointers to preallocatedOutputBuffers_ for processor API.
|
|
178
|
-
|
|
179
|
-
static void notifyProcessorChanged(const std::string& identifier); ///< Notify and update all nodes with given identifier.
|
|
180
|
-
|
|
181
|
-
static std::map<std::string, std::function<std::shared_ptr<CustomAudioProcessor>()>> s_processorFactoriesByIdentifier; ///< Global registry of processor factories.
|
|
182
|
-
static std::unordered_map<std::string, GenericControlHandler> s_controlHandlersByIdentifier; ///< Global registry of control handlers.
|
|
183
|
-
static std::unordered_map<std::string, std::vector<CustomProcessorNode*>> s_activeNodes; ///< Tracks active node instances by identifier.
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
} // namespace audioapi
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _AudioNode = _interopRequireDefault(require("./AudioNode"));
|
|
8
|
-
var _AudioParam = _interopRequireDefault(require("./AudioParam"));
|
|
9
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
-
class CustomProcessorNode extends _AudioNode.default {
|
|
11
|
-
constructor(context, customProcessor) {
|
|
12
|
-
super(context, customProcessor);
|
|
13
|
-
this.customProcessor = new _AudioParam.default(customProcessor.customProcessor, context);
|
|
14
|
-
}
|
|
15
|
-
get processorMode() {
|
|
16
|
-
return this.node.processorMode;
|
|
17
|
-
}
|
|
18
|
-
set processorMode(value) {
|
|
19
|
-
this.node.processorMode = value;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.default = CustomProcessorNode;
|
|
23
|
-
//# sourceMappingURL=CustomProcessorNode.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_AudioNode","_interopRequireDefault","require","_AudioParam","e","__esModule","default","CustomProcessorNode","AudioNode","constructor","context","customProcessor","AudioParam","processorMode","node","value","exports"],"sourceRoot":"../../../src","sources":["core/CustomProcessorNode.ts"],"mappings":";;;;;;AAEA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAF,sBAAA,CAAAC,OAAA;AAAsC,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAGvB,MAAMG,mBAAmB,SAASC,kBAAS,CAAC;EAGzDC,WAAWA,CACTC,OAAyB,EACzBC,eAAqC,EACrC;IACA,KAAK,CAACD,OAAO,EAAEC,eAAe,CAAC;IAC/B,IAAI,CAACA,eAAe,GAAG,IAAIC,mBAAU,CACnCD,eAAe,CAACA,eAAe,EAC/BD,OACF,CAAC;EACH;EAEA,IAAWG,aAAaA,CAAA,EAAkB;IACxC,OAAQ,IAAI,CAACC,IAAI,CAA0BD,aAAa;EAC1D;EAEA,IAAWA,aAAaA,CAACE,KAAoB,EAAE;IAC5C,IAAI,CAACD,IAAI,CAA0BD,aAAa,GAAGE,KAAK;EAC3D;AACF;AAACC,OAAA,CAAAV,OAAA,GAAAC,mBAAA","ignoreList":[]}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import AudioNode from "./AudioNode.js";
|
|
4
|
-
import AudioParam from "./AudioParam.js";
|
|
5
|
-
export default class CustomProcessorNode extends AudioNode {
|
|
6
|
-
constructor(context, customProcessor) {
|
|
7
|
-
super(context, customProcessor);
|
|
8
|
-
this.customProcessor = new AudioParam(customProcessor.customProcessor, context);
|
|
9
|
-
}
|
|
10
|
-
get processorMode() {
|
|
11
|
-
return this.node.processorMode;
|
|
12
|
-
}
|
|
13
|
-
set processorMode(value) {
|
|
14
|
-
this.node.processorMode = value;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=CustomProcessorNode.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["AudioNode","AudioParam","CustomProcessorNode","constructor","context","customProcessor","processorMode","node","value"],"sourceRoot":"../../../src","sources":["core/CustomProcessorNode.ts"],"mappings":";;AAEA,OAAOA,SAAS,MAAM,gBAAa;AACnC,OAAOC,UAAU,MAAM,iBAAc;AAGrC,eAAe,MAAMC,mBAAmB,SAASF,SAAS,CAAC;EAGzDG,WAAWA,CACTC,OAAyB,EACzBC,eAAqC,EACrC;IACA,KAAK,CAACD,OAAO,EAAEC,eAAe,CAAC;IAC/B,IAAI,CAACA,eAAe,GAAG,IAAIJ,UAAU,CACnCI,eAAe,CAACA,eAAe,EAC/BD,OACF,CAAC;EACH;EAEA,IAAWE,aAAaA,CAAA,EAAkB;IACxC,OAAQ,IAAI,CAACC,IAAI,CAA0BD,aAAa;EAC1D;EAEA,IAAWA,aAAaA,CAACE,KAAoB,EAAE;IAC5C,IAAI,CAACD,IAAI,CAA0BD,aAAa,GAAGE,KAAK;EAC3D;AACF","ignoreList":[]}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ICustomProcessorNode } from '../interfaces';
|
|
2
|
-
import { ProcessorMode } from '../types';
|
|
3
|
-
import AudioNode from './AudioNode';
|
|
4
|
-
import AudioParam from './AudioParam';
|
|
5
|
-
import BaseAudioContext from './BaseAudioContext';
|
|
6
|
-
export default class CustomProcessorNode extends AudioNode {
|
|
7
|
-
readonly customProcessor: AudioParam;
|
|
8
|
-
constructor(context: BaseAudioContext, customProcessor: ICustomProcessorNode);
|
|
9
|
-
get processorMode(): ProcessorMode;
|
|
10
|
-
set processorMode(value: ProcessorMode);
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=CustomProcessorNode.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CustomProcessorNode.d.ts","sourceRoot":"","sources":["../../../src/core/CustomProcessorNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,UAAU,MAAM,cAAc,CAAC;AACtC,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAElD,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,SAAS;IACxD,QAAQ,CAAC,eAAe,EAAE,UAAU,CAAC;gBAGnC,OAAO,EAAE,gBAAgB,EACzB,eAAe,EAAE,oBAAoB;IASvC,IAAW,aAAa,IAAI,aAAa,CAExC;IAED,IAAW,aAAa,CAAC,KAAK,EAAE,aAAa,EAE5C;CACF"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { ICustomProcessorNode } from '../interfaces';
|
|
2
|
-
import { ProcessorMode } from '../types';
|
|
3
|
-
import AudioNode from './AudioNode';
|
|
4
|
-
import AudioParam from './AudioParam';
|
|
5
|
-
import BaseAudioContext from './BaseAudioContext';
|
|
6
|
-
|
|
7
|
-
export default class CustomProcessorNode extends AudioNode {
|
|
8
|
-
readonly customProcessor: AudioParam;
|
|
9
|
-
|
|
10
|
-
constructor(
|
|
11
|
-
context: BaseAudioContext,
|
|
12
|
-
customProcessor: ICustomProcessorNode
|
|
13
|
-
) {
|
|
14
|
-
super(context, customProcessor);
|
|
15
|
-
this.customProcessor = new AudioParam(
|
|
16
|
-
customProcessor.customProcessor,
|
|
17
|
-
context
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public get processorMode(): ProcessorMode {
|
|
22
|
-
return (this.node as ICustomProcessorNode).processorMode;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public set processorMode(value: ProcessorMode) {
|
|
26
|
-
(this.node as ICustomProcessorNode).processorMode = value;
|
|
27
|
-
}
|
|
28
|
-
}
|