-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: removed duplicated code * fix: removed deltaTime property * feat: impemented AudioBuffer in kotlin * feat: addec channel properties * fix: fixed bug * feat: added enums * feat: implemented channel properties in different nodes * feat: replaced buffer list with AudioBuffer class * feat: implemented mixing buffers * refactor: refractored mixing * feat: added AudioBufferSourceNode * refactor: start, stop methods refactoring * fix: fixed hihat ios bug * refactor: changed getBuffer method name to fillBuffer * fix: fixed AudioTrack reusing * feat: implemented getters for channel properties of AudioNode * feat: updated api coverage map * feat: implemented AudioBufferSourceNode commonclasses * feat: implemneted JNi AudioBuffer class and added targets to CMakeList.txt * feat: implemented AudioBufferSourceNode classes * refactor: changed static_cast to dynamic_cast * Revert "refactor: changed static_cast to dynamic_cast" This reverts commit 8d7500a. * fix: fixed array serialization and typo in descriptor * feat: added createBuffer and createBufferSource methods and proper types * fix: fixed bugs and added setChannelData method * fix: trying to fix sigsegv during creating AudioBufferSource * refactor: refactored includes * feat: implemented Clap sound * fix: fixed AudioBufferSourceNode buffer filling * fix: fixed OscillatorNode buffer filling, buffer filling in Clap and types * fix: merge changes --------- Co-authored-by: Maciej Makowski <[email protected]>
- Loading branch information
1 parent
715cf83
commit fec8936
Showing
64 changed files
with
1,320 additions
and
154 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "AudioBuffer.h" | ||
|
||
namespace audiocontext { | ||
|
||
AudioBuffer::AudioBuffer(jni::alias_ref<AudioBuffer::jhybridobject>& jThis): javaPart_(make_global(jThis)) {} | ||
|
||
int AudioBuffer::getSampleRate() { | ||
static const auto method = javaClassStatic()->getMethod<jint()>("getSampleRate"); | ||
return method(javaPart_); | ||
} | ||
|
||
int AudioBuffer::getLength() { | ||
static const auto method = javaClassStatic()->getMethod<jint()>("getLength"); | ||
return method(javaPart_); | ||
} | ||
|
||
double AudioBuffer::getDuration() { | ||
static const auto method = javaClassStatic()->getMethod<jdouble()>("getDuration"); | ||
return method(javaPart_); | ||
} | ||
|
||
int AudioBuffer::getNumberOfChannels() { | ||
static const auto method = javaClassStatic()->getMethod<jint()>("getNumberOfChannels"); | ||
return method(javaPart_); | ||
} | ||
|
||
short **AudioBuffer::getChannelData(int channel) { | ||
static const auto method = javaClassStatic()->getMethod<JArrayShort (jint)>("getChannelData"); | ||
auto jArray = method(javaPart_, channel); | ||
auto length = jArray->size(); | ||
|
||
auto channelData = new short*[length]; | ||
auto pin = jArray->pin(); | ||
for (int i = 0; i < length; i++) { | ||
channelData[i] = &pin[i]; | ||
} | ||
|
||
return channelData; | ||
} | ||
|
||
void AudioBuffer::setChannelData(int channel, short** data) { | ||
static const auto method = javaClassStatic()->getMethod<void(jint, jshortArray)>("setChannelData"); | ||
std::vector<jshort> buffer(getLength()); | ||
for (int i = 0; i < getLength(); i++) { | ||
buffer[i] = *data[i]; | ||
} | ||
auto jArray = JArrayShort::newArray(getLength()); | ||
jArray->setRegion(0, getLength(), buffer.data()); | ||
|
||
method(javaPart_, channel, jArray.get()); | ||
} | ||
|
||
void AudioBuffer::prepareForDeconstruction() { | ||
javaPart_.reset(); | ||
} | ||
|
||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#pragma once | ||
|
||
#include <fbjni/fbjni.h> | ||
#include <react/jni/CxxModuleWrapper.h> | ||
#include <react/jni/JMessageQueueThread.h> | ||
#include <memory> | ||
|
||
namespace audiocontext { | ||
|
||
using namespace facebook; | ||
using namespace facebook::jni; | ||
|
||
class AudioBuffer : public jni::HybridClass<AudioBuffer> { | ||
public: | ||
static auto constexpr kJavaDescriptor = "Lcom/audiocontext/utils/AudioBuffer;"; | ||
|
||
static jni::local_ref<AudioBuffer::jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis) | ||
{ | ||
return makeCxxInstance(jThis); | ||
} | ||
|
||
static void registerNatives() { | ||
registerHybrid({ | ||
makeNativeMethod("initHybrid", AudioBuffer::initHybrid), | ||
}); | ||
} | ||
|
||
int getSampleRate(); | ||
int getLength(); | ||
double getDuration(); | ||
int getNumberOfChannels(); | ||
short** getChannelData(int channel); | ||
void setChannelData(int channel, short** data); | ||
void prepareForDeconstruction(); | ||
|
||
public: | ||
friend HybridBase; | ||
|
||
global_ref<AudioBuffer::javaobject> javaPart_; | ||
|
||
explicit AudioBuffer(jni::alias_ref<AudioBuffer::jhybridobject>& jThis); | ||
}; | ||
|
||
} // namespace audiocontext |
38 changes: 38 additions & 0 deletions
38
android/src/main/cpp/AudioBufferSourceNode/AudioBufferSourceNode.cpp
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,38 @@ | ||
#include "AudioBufferSourceNode.h" | ||
|
||
namespace audiocontext { | ||
|
||
using namespace facebook::jni; | ||
|
||
void AudioBufferSourceNode::start(double time) { | ||
static const auto method = javaClassLocal()->getMethod<void(jdouble)>("start"); | ||
method(javaPart_.get(), time); | ||
} | ||
|
||
void AudioBufferSourceNode::stop(double time) { | ||
static const auto method = javaClassLocal()->getMethod<void(jdouble)>("stop"); | ||
method(javaPart_.get(), time); | ||
} | ||
|
||
bool AudioBufferSourceNode::getLoop() { | ||
static const auto method = javaClassLocal()->getMethod<jboolean()>("getLoop"); | ||
return method(javaPart_.get()); | ||
} | ||
|
||
void AudioBufferSourceNode::setLoop(bool loop) { | ||
static const auto method = javaClassLocal()->getMethod<void(jboolean)>("setLoop"); | ||
method(javaPart_.get(), loop); | ||
} | ||
|
||
AudioBuffer *AudioBufferSourceNode::getBuffer() { | ||
static const auto method = javaClassLocal()->getMethod<AudioBuffer()>("getBuffer"); | ||
auto buffer = method(javaPart_.get()); | ||
|
||
return buffer->cthis(); | ||
} | ||
|
||
void AudioBufferSourceNode::setBuffer(const AudioBuffer* buffer) { | ||
static const auto method = javaClassLocal()->getMethod<void(AudioBuffer::javaobject)>("setBuffer"); | ||
method(javaPart_.get(), buffer->javaPart_.get()); | ||
} | ||
} // namespace audiocontext |
22 changes: 22 additions & 0 deletions
22
android/src/main/cpp/AudioBufferSourceNode/AudioBufferSourceNode.h
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 @@ | ||
#pragma once | ||
|
||
#include "AudioNode.h" | ||
#include "AudioBuffer.h" | ||
|
||
namespace audiocontext { | ||
|
||
using namespace facebook; | ||
using namespace facebook::jni; | ||
|
||
class AudioBufferSourceNode : public jni::HybridClass<AudioBufferSourceNode, AudioNode> { | ||
public: | ||
static auto constexpr kJavaDescriptor = "Lcom/audiocontext/nodes/AudioBufferSourceNode;"; | ||
|
||
void start(double time); | ||
void stop(double time); | ||
bool getLoop(); | ||
void setLoop(bool loop); | ||
AudioBuffer* getBuffer(); | ||
void setBuffer(const AudioBuffer* buffer); | ||
}; | ||
}// 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
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
Oops, something went wrong.