-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from software-mansion-labs/feat/android/gain-node
Feat/android/gain node
- Loading branch information
Showing
36 changed files
with
450 additions
and
114 deletions.
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 was deleted.
Oops, something went wrong.
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.