Skip to content

Commit

Permalink
feat: added HostObject for AnalyserNode
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciej Makowski committed Dec 18, 2024
1 parent e88d713 commit 2f857fb
Showing 1 changed file with 107 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#pragma once

#include <memory>
#include <string>
#include <vector>

#include "AnalyserNodeHostObject.h"
#include "AudioNodeHostObject.h"

namespace audioapi {
using namespace facebook;

class AnalyserNodeHostObject : public AudioNodeHostObject {
public:
explicit AnalyserNodeHostObject(const std::shared_ptr<AnalyserNode> &node)
: AudioNodeHostObject(node) {
addGetters(
JSI_EXPORT_PROPERTY_GETTER(AnalyserNodeHostObject, fftSize),
JSI_EXPORT_PROPERTY_GETTER(AnalyserNodeHostObject, frequencyBinCount),
JSI_EXPORT_PROPERTY_GETTER(AnalyserNodeHostObject, minDecibels),
JSI_EXPORT_PROPERTY_GETTER(AnalyserNodeHostObject, maxDecibels),
JSI_EXPORT_PROPERTY_GETTER(
AnalyserNodeHostObject, smoothingTimeConstant));
);

addFunctions(
JSI_EXPORT_FUNCTION(
AnalyserNodeHostObject, getFloatFrequencyData),
JSI_EXPORT_FUNCTION(
AnalyserNodeHostObject, getByteFrequencyData),
JSI_EXPORT_FUNCTION(
AnalyserNodeHostObject, getFloatTimeDomainData),
JSI_EXPORT_FUNCTION(
AnalyserNodeHostObject, getByteTimeDomainData));
);

addSetters(
JSI_EXPORT_PROPERTY_SETTER(AnalyserNodeHostObject, fftSize),
JSI_EXPORT_PROPERTY_SETTER(AnalyserNodeHostObject, minDecibels),
JSI_EXPORT_PROPERTY_SETTER(AnalyserNodeHostObject, maxDecibels),
JSI_EXPORT_PROPERTY_SETTER(
AnalyserNodeHostObject, smoothingTimeConstant));
);
}

JSI_PROPERTY_GETTER(fftSize) {
auto analyserNode = std::static_pointer_cast<AnalyserNode>(node_);
return {analyserNode->getFftSize()};
}

JSI_PROPERTY_GETTER(frequencyBinCount) {
auto analyserNode = std::static_pointer_cast<AnalyserNode>(node_);
return {analyserNode->getFrequencyBinCount()};
}

JSI_PROPERTY_GETTER(minDecibels) {
auto analyserNode = std::static_pointer_cast<AnalyserNode>(node_);
return {analyserNode->getMinDecibels()};
}

JSI_PROPERTY_GETTER(maxDecibels) {
auto analyserNode = std::static_pointer_cast<AnalyserNode>(node_);
return {analyserNode->getMaxDecibels()};
}

JSI_PROPERTY_GETTER(smoothingTimeConstant) {
auto analyserNode = std::static_pointer_cast<AnalyserNode>(node_);
return {analyserNode->getSmoothingTimeConstant()};
}

JSI_HOST_FUNCTION(getFloatFrequencyData) {
return jsi::Value::undefined();
}

JSI_HOST_FUNCTION(getByteFrequencyData) {
return jsi::Value::undefined();
}

JSI_HOST_FUNCTION(getFloatTimeDomainData) {
return jsi::Value::undefined();
}

JSI_HOST_FUNCTION(getByteTimeDomainData) {
return jsi::Value::undefined();
}

JSI_PROPERTY_SETTER(fftSize) {
auto analyserNode = std::static_pointer_cast<AnalyserNode>(node_);
analyserNode->setFftSize(args[0].getNumber());
}

JSI_PROPERTY_SETTER(minDecibels) {
auto analyserNode = std::static_pointer_cast<AnalyserNode>(node_);
analyserNode->setMinDecibels(args[0].getNumber());
}

JSI_PROPERTY_SETTER(maxDecibels) {
auto analyserNode = std::static_pointer_cast<AnalyserNode>(node_);
analyserNode->setMaxDecibels(args[0].getNumber());
}

JSI_PROPERTY_SETTER(smoothingTimeConstant) {
auto analyserNode = std::static_pointer_cast<AnalyserNode>(node_);
analyserNode->setSmoothingTimeConstant(args[0].getNumber());
}
};
} // namespace audioapi

0 comments on commit 2f857fb

Please sign in to comment.