-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/android/gain node #39
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
74f09dc
feat: implemented gain node
7403fad
refactor: imports refactoring
9323b5f
feat: implemented silders for changing volume, frequency and detune
1e61c13
refactor: added get methods to AudioNodeHostObject, refactored derive…
276d5f0
refactor: code review changes
1266a6c
Merge branch 'main' into feat/android/gain-node
maciejmakowski2003 92568e0
fix: linting fix
9749b8d
fix: fix merge unwanted changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1 @@ | ||
#include "AudioDestinationNode.h" | ||
|
||
namespace audiocontext { | ||
|
||
using namespace facebook::jni; | ||
|
||
} // namespace audiocontext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "GainNode.h" | ||
|
||
namespace audiocontext{ | ||
|
||
using namespace facebook::jni; | ||
|
||
double GainNode::getGain(){ | ||
static const auto method = javaClassLocal()->getMethod<jdouble()>("getGain"); | ||
return method(javaObject_.get()); | ||
} | ||
|
||
void GainNode::setGain(double gain){ | ||
static const auto method = javaClassLocal()->getMethod<void(jdouble)>("setGain"); | ||
method(javaObject_.get(), gain); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include <fbjni/fbjni.h> | ||
#include <react/jni/CxxModuleWrapper.h> | ||
#include <react/jni/JMessageQueueThread.h> | ||
#include <memory> | ||
#include "AudioNode.h" | ||
|
||
namespace audiocontext { | ||
|
||
using namespace facebook; | ||
using namespace facebook::jni; | ||
|
||
class GainNode : public jni::HybridClass<GainNode, AudioNode> { | ||
public: | ||
static auto constexpr kJavaDescriptor = "Lcom/audiocontext/nodes/GainNode;"; | ||
|
||
double getGain(); | ||
|
||
void setGain(double gain); | ||
}; | ||
|
||
} // namespace audiocontext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
android/src/main/java/com/audiocontext/context/BaseAudioContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
package com.audiocontext.context | ||
|
||
import com.audiocontext.nodes.AudioDestinationNode | ||
import com.audiocontext.nodes.GainNode | ||
import com.audiocontext.nodes.oscillator.OscillatorNode | ||
|
||
interface BaseAudioContext { | ||
val sampleRate: Int | ||
val destination: AudioDestinationNode | ||
|
||
abstract fun createOscillator(): OscillatorNode | ||
abstract fun createGain(): GainNode | ||
} |
2 changes: 0 additions & 2 deletions
2
android/src/main/java/com/audiocontext/nodes/AudioDestinationNode.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.audiocontext.nodes | ||
|
||
import android.media.AudioTrack | ||
import com.audiocontext.context.BaseAudioContext | ||
import com.facebook.jni.HybridData | ||
|
||
class GainNode(context: BaseAudioContext): AudioNode(context) { | ||
override val numberOfInputs: Int = 1 | ||
override val numberOfOutputs: Int = 1 | ||
private var gain: Double = 1.0 | ||
get() = field | ||
set(value) { | ||
field = value | ||
} | ||
|
||
private val mHybridData: HybridData? = initHybrid(); | ||
|
||
override fun process(buffer: ShortArray, audioTrack: AudioTrack) { | ||
audioTrack.setVolume(gain.toFloat()) | ||
super.process(buffer, audioTrack) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "AudioNodeHostObject.h" | ||
|
||
namespace audiocontext { | ||
using namespace facebook; | ||
|
||
std::vector<jsi::PropNameID> AudioNodeHostObject::getPropertyNames(jsi::Runtime& runtime) { | ||
std::vector<jsi::PropNameID> propertyNames; | ||
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, "connect")); | ||
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, "disconnect")); | ||
return propertyNames; | ||
} | ||
|
||
jsi::Value AudioNodeHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& propNameId) { | ||
auto propName = propNameId.utf8(runtime); | ||
|
||
if (propName == "connect") | ||
{ | ||
return jsi::Function::createFromHostFunction(runtime, propNameId, 1, [this](jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) -> jsi::Value | ||
{ | ||
auto node = args[0].getObject(rt).getHostObject<AudioNodeHostObject>(rt); | ||
wrapper_->connect(std::shared_ptr<AudioNodeHostObject>(node)->wrapper_); | ||
return jsi::Value::undefined(); | ||
}); | ||
} | ||
|
||
if (propName == "disconnect") | ||
{ | ||
return jsi::Function::createFromHostFunction(runtime, propNameId, 1, [this](jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) -> jsi::Value | ||
{ | ||
auto node = args[0].getObject(rt).getHostObject<AudioNodeHostObject>(rt); | ||
wrapper_->disconnect(std::shared_ptr<AudioNodeHostObject>(node)->wrapper_); | ||
return jsi::Value::undefined(); | ||
}); | ||
} | ||
|
||
throw std::runtime_error("Not yet implemented!"); | ||
} | ||
|
||
void AudioNodeHostObject::set(jsi::Runtime& runtime, const jsi::PropNameID& propNameId, const jsi::Value& value) { | ||
auto propName = propNameId.utf8(runtime); | ||
|
||
throw std::runtime_error("Not yet implemented!"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this file then? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right