Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/fabric-example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3081,7 +3081,7 @@ SPEC CHECKSUMS:
ReactAppDependencyProvider: c91900fa724baee992f01c05eeb4c9e01a807f78
ReactCodegen: 8125d6ee06ea06f48f156cbddec5c2ca576d62e6
ReactCommon: 116d6ee71679243698620d8cd9a9042541e44aa6
RNAudioAPI: 33e9940fd9e8b3694107f461a45fe23eb40c652b
RNAudioAPI: 0d2c90bedff404ca1b8b31dfe8e734937244a9c0
RNGestureHandler: 3a73f098d74712952870e948b3d9cf7b6cae9961
RNReanimated: a035264789d1f64cb5adba7085d6aac6e9ec70a7
RNScreens: 6ced6ae8a526512a6eef6e28c2286e1fc2d378c3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ MyProcessorNode::MyProcessorNode(BaseAudioContext *context)
isInitialized_ = true;
}

void MyProcessorNode::processNode(const std::shared_ptr<AudioBus> &bus,
std::shared_ptr<AudioBus> MyProcessorNode::processNode(const std::shared_ptr<AudioBus> &bus,
int framesToProcess) {
// put your processing logic here
}
} // namespace audioapi
} // namespace audioapi
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class MyProcessorNode : public AudioNode {
explicit MyProcessorNode(BaseAudioContext *context);

protected:
void processNode(const std::shared_ptr<AudioBus> &bus,
std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus> &bus,
int framesToProcess) override;

};
} // namespace audioapi
} // namespace audioapi
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ std::shared_ptr<AudioBus> AudioNode::processAudio(

assert(processingBus != nullptr);
// Finally, process the node itself.
processNode(processingBus, framesToProcess);
auto resultBus = processNode(processingBus, framesToProcess);

return processingBus;
return resultBus;
}

bool AudioNode::isAlreadyProcessed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class AudioNode : public std::enable_shared_from_this<AudioNode> {
static std::string toString(ChannelCountMode mode);
static std::string toString(ChannelInterpretation interpretation);

virtual void processNode(const std::shared_ptr<AudioBus>&, int) = 0;
virtual std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>&, int) = 0;

bool isAlreadyProcessed();
std::shared_ptr<AudioBus> processInputs(const std::shared_ptr<AudioBus>& outputBus, int framesToProcess, bool checkIsAlreadyProcessed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void AnalyserNode::getByteTimeDomainData(uint8_t *data, int length) {
}
}

void AnalyserNode::processNode(
std::shared_ptr<AudioBus> AnalyserNode::processNode(
const std::shared_ptr<AudioBus> &processingBus,
int framesToProcess) {
// Analyser should behave like a sniffer node, it should not modify the
Expand All @@ -156,6 +156,8 @@ void AnalyserNode::processNode(
downMixBus_->getChannel(0)->getData(), framesToProcess, true);

shouldDoFFTAnalysis_ = true;

return processingBus;
}

void AnalyserNode::doFFTAnalysis() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class AnalyserNode : public AudioNode {
void getByteTimeDomainData(uint8_t *data, int length);

protected:
void processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;

private:
int fftSize_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AudioDestinationNode : public AudioNode {
protected:
// DestinationNode is triggered by AudioContext using renderAudio
// processNode function is not necessary and is never called.
void processNode(const std::shared_ptr<AudioBus>& processingBus, int) final {};
std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int) final { return processingBus; };

private:
std::size_t currentSampleFrame_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ void BiquadFilterNode::applyFilter() {
}
}

void BiquadFilterNode::processNode(
std::shared_ptr<AudioBus> BiquadFilterNode::processNode(
const std::shared_ptr<AudioBus> &processingBus,
int framesToProcess) {
int numChannels = processingBus->getNumberOfChannels();
Expand Down Expand Up @@ -393,6 +393,8 @@ void BiquadFilterNode::processNode(
x2_ = x2;
y1_ = y1;
y2_ = y2;

return processingBus;
}

} // namespace audioapi
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BiquadFilterNode : public AudioNode {
int length);

protected:
void processNode(
std::shared_ptr<AudioBus> processNode(
const std::shared_ptr<AudioBus> &processingBus,
int framesToProcess) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ std::shared_ptr<AudioParam> GainNode::getGainParam() const {
return gainParam_;
}

void GainNode::processNode(
std::shared_ptr<AudioBus> GainNode::processNode(
const std::shared_ptr<AudioBus> &processingBus,
int framesToProcess) {
double time = context_->getCurrentTime();
Expand All @@ -28,6 +28,8 @@ void GainNode::processNode(
processingBus->getChannel(i)->getData(),
framesToProcess);
}

return processingBus;
}

} // namespace audioapi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GainNode : public AudioNode {
[[nodiscard]] std::shared_ptr<AudioParam> getGainParam() const;

protected:
void processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;

private:
std::shared_ptr<AudioParam> gainParam_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@ std::shared_ptr<AudioParam> StereoPannerNode::getPanParam() const {
return panParam_;
}

void StereoPannerNode::processNode(
std::shared_ptr<AudioBus> StereoPannerNode::processNode(
const std::shared_ptr<AudioBus> &processingBus,
int framesToProcess) {
double time = context_->getCurrentTime();
double deltaTime = 1.0 / context_->getSampleRate();

AudioArray *left = processingBus->getChannelByType(AudioBus::ChannelLeft);
AudioArray *right = processingBus->getChannelByType(AudioBus::ChannelRight);
auto *inputLeft = processingBus->getChannelByType(AudioBus::ChannelLeft);
auto panParamValues = panParam_->processARateParam(framesToProcess, time)
->getChannel(0)
->getData();

auto *outputLeft = audioBus_->getChannelByType(AudioBus::ChannelLeft);
auto *outputRight = audioBus_->getChannelByType(AudioBus::ChannelRight);

// Input is mono
if (processingBus->getNumberOfChannels() == 1) {
for (int i = 0; i < framesToProcess; i++) {
Expand All @@ -40,34 +42,37 @@ void StereoPannerNode::processNode(
auto gainL = static_cast<float>(cos(x * PI / 2));
auto gainR = static_cast<float>(sin(x * PI / 2));

float input = (*left)[i];
float input = (*inputLeft)[i];

(*left)[i] = input * gainL;
(*right)[i] = input * gainR;
(*outputLeft)[i] = input * gainL;
(*outputRight)[i] = input * gainR;
time += deltaTime;
}
} else { // Input is stereo
auto *inputRight = processingBus->getChannelByType(AudioBus::ChannelRight);
for (int i = 0; i < framesToProcess; i++) {
auto pan = std::clamp(panParamValues[i], -1.0f, 1.0f);
auto x = (pan <= 0 ? pan + 1 : pan);

auto gainL = static_cast<float>(cos(x * PI / 2));
auto gainR = static_cast<float>(sin(x * PI / 2));

float inputL = (*left)[i];
float inputR = (*right)[i];
float inputL = (*inputLeft)[i];
float inputR = (*inputRight)[i];

if (pan <= 0) {
(*left)[i] = inputL + inputR * gainL;
(*right)[i] = inputR * gainR;
(*outputLeft)[i] = inputL + inputR * gainL;
(*outputRight)[i] = inputR * gainR;
} else {
(*left)[i] = inputL * gainL;
(*right)[i] = inputR + inputL * gainR;
(*outputLeft)[i] = inputL * gainL;
(*outputRight)[i] = inputR + inputL * gainR;
}

time += deltaTime;
}
}

return audioBus_;
}

} // namespace audioapi
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class StereoPannerNode : public AudioNode {
[[nodiscard]] std::shared_ptr<AudioParam> getPanParam() const;

protected:
void processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;

private:
std::shared_ptr<AudioParam> panParam_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ WorkletNode::~WorkletNode() {
}
}

void WorkletNode::processNode(
std::shared_ptr<AudioBus> WorkletNode::processNode(
const std::shared_ptr<AudioBus> &processingBus,
int framesToProcess) {
size_t processed = 0;
Expand Down Expand Up @@ -82,6 +82,8 @@ void WorkletNode::processNode(
});
}
}

return processingBus;
}

} // namespace audioapi
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class WorkletNode : public AudioNode {
) : AudioNode(context) {}

protected:
void processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override {}
std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override { return processingBus; }
};
#else

Expand All @@ -45,7 +45,7 @@ class WorkletNode : public AudioNode {
~WorkletNode() override;

protected:
void processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;


private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ WorkletProcessingNode::WorkletProcessingNode(
}
}

void WorkletProcessingNode::processNode(
std::shared_ptr<AudioBus> WorkletProcessingNode::processNode(
const std::shared_ptr<AudioBus> &processingBus,
int framesToProcess) {
size_t channelCount = std::min(
Expand Down Expand Up @@ -84,6 +84,8 @@ void WorkletProcessingNode::processNode(
std::memset(channelData, 0, framesToProcess * sizeof(float));
}
}

return processingBus;
}

} // namespace audioapi
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class WorkletProcessingNode : public AudioNode {
) : AudioNode(context) {}

protected:
void processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override {}
std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override { return processingBus; }
};
#else

Expand All @@ -38,7 +38,7 @@ class WorkletProcessingNode : public AudioNode {
);

protected:
void processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;

private:
WorkletsRunner workletRunner_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ void AudioBufferQueueSourceNode::disable() {
buffers_ = {};
}

void AudioBufferQueueSourceNode::processNode(
std::shared_ptr<AudioBus> AudioBufferQueueSourceNode::processNode(
const std::shared_ptr<AudioBus> &processingBus,
int framesToProcess) {
if (auto locker = Locker::tryLock(getBufferLock())) {
// no audio data to fill, zero the output and return.
if (buffers_.empty()) {
processingBus->zero();
return;
return processingBus;
}

if (!pitchCorrection_) {
Expand All @@ -107,6 +107,8 @@ void AudioBufferQueueSourceNode::processNode(
} else {
processingBus->zero();
}

return processingBus;
}

double AudioBufferQueueSourceNode::getCurrentPosition() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AudioBufferQueueSourceNode : public AudioBufferBaseSourceNode {
void disable() override;

protected:
void processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
double getCurrentPosition() const override;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ void AudioBufferSourceNode::setOnLoopEndedCallbackId(uint64_t callbackId) {
onLoopEndedCallbackId_ = callbackId;
}

void AudioBufferSourceNode::processNode(
std::shared_ptr<AudioBus> AudioBufferSourceNode::processNode(
const std::shared_ptr<AudioBus> &processingBus,
int framesToProcess) {
if (auto locker = Locker::tryLock(getBufferLock())) {
// No audio data to fill, zero the output and return.
if (!alignedBus_) {
processingBus->zero();
return;
return processingBus;
}

if (!pitchCorrection_) {
Expand All @@ -160,6 +160,8 @@ void AudioBufferSourceNode::processNode(
} else {
processingBus->zero();
}

return processingBus;
}

double AudioBufferSourceNode::getCurrentPosition() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AudioBufferSourceNode : public AudioBufferBaseSourceNode {
void setOnLoopEndedCallbackId(uint64_t callbackId);

protected:
void processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
double getCurrentPosition() const override;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ std::shared_ptr<AudioParam> ConstantSourceNode::getOffsetParam() const {
return offsetParam_;
}

void ConstantSourceNode::processNode(
std::shared_ptr<AudioBus> ConstantSourceNode::processNode(
const std::shared_ptr<AudioBus> &processingBus,
int framesToProcess) {
size_t startOffset = 0;
Expand All @@ -26,7 +26,7 @@ void ConstantSourceNode::processNode(

if (!isPlaying() && !isStopScheduled()) {
processingBus->zero();
return;
return processingBus;
}

auto offsetBus = offsetParam_->processARateParam(
Expand All @@ -47,5 +47,7 @@ void ConstantSourceNode::processNode(
if (isStopScheduled()) {
handleStopScheduled();
}

return processingBus;
}
} // namespace audioapi
Loading