Skip to content

Fix/piano example #153

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

Merged
merged 6 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions apps/common-app/src/examples/Piano/Piano.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ const Piano: FC = () => {
});

notesRef.current = newNotes as Record<KeyName, PianoNote>;

return () => {
audioContextRef.current?.close();
};
}, []);

return (
Expand Down
3 changes: 0 additions & 3 deletions apps/common-app/src/examples/Piano/PianoNote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ class PianoNote {

this.oscillator.stop(tNow + 0.1);

this.gain.disconnect(this.audioContext.destination);
this.oscillator.disconnect(this.gain);

this.oscillator = null;
this.gain = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class HiHat implements SoundEngine {
gain.gain.exponentialRampToValueAtTime(this.volume * 0.33, time + 0.03);
gain.gain.exponentialRampToValueAtTime(this.volume * 0.0001, time + 0.3);
gain.gain.setValueAtTime(0, time + 0.3 + 0.001);
//number of inputs of filter is 1 on android- check it

oscillator.connect(bandpassFilter);
bandpassFilter.connect(highpassFilter);
highpassFilter.connect(gain);
Expand Down
12 changes: 12 additions & 0 deletions packages/react-native-audio-api/android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ project(react-native-audio-api)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 17)

# Detect the operating system
if(APPLE)
set(HAVE_ACCELERATE TRUE)
endif()

# Detect the processor and SIMD support
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
set(HAVE_ARM_NEON_INTRINSICS TRUE)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64")
set(HAVE_X86_SSE2 TRUE)
endif()

include("${REACT_NATIVE_DIR}/ReactAndroid/cmake-utils/folly-flags.cmake")
add_compile_options(${folly_FLAGS})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ AudioBuffer::AudioBuffer(int numberOfChannels, int length, int sampleRate)
throw std::invalid_argument("Invalid number of channels");
}

channels_ = new float*[numberOfChannels];
channels_ = new float *[numberOfChannels];

for (int i = 0; i < numberOfChannels; i++) {
channels_[i] = new float[length];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

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

namespace audioapi {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ bool AudioBufferSourceNode::getLoop() const {
}

std::shared_ptr<AudioBuffer> AudioBufferSourceNode::getBuffer() const {
if (!buffer_.has_value()) {
throw std::runtime_error("Buffer is not set");
}
if (!buffer_.has_value()) {
throw std::runtime_error("Buffer is not set");
}

return buffer_.value();
return buffer_.value();
}

void AudioBufferSourceNode::setLoop(bool loop) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ bool AudioDestinationNode::processAudio(float *audioData, int32_t numFrames) {

for (auto &node : inputNodes_) {
if (node->processAudio(mixingBuffer.get(), numFrames)) {
for (int i = 0; i < numSamples; i++) {
audioData[i] += mixingBuffer[i];
}
VectorMath::add(audioData, mixingBuffer.get(), audioData, numSamples);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <vector>

#include "AudioNode.h"
#include "VectorMath.h"

namespace audioapi {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,9 @@ bool StereoPannerNode::processAudio(float *audioData, int32_t numFrames) {
}

void StereoPannerNode::normalize(float *audioData, int32_t numFrames) {
auto maxValue = 1.0f;

for (int i = 0; i < numFrames * channelCount_; i++) {
maxValue = std::max(maxValue, std::abs(audioData[i]));
}

for (int i = 0; i < numFrames * channelCount_; i++) {
audioData[i] /= maxValue;
}
auto maxValue = std::max(
1.0f, VectorMath::maximumMagnitude(audioData, numFrames * channelCount_));
VectorMath::multiplyByScalar(
audioData, 1.0f / maxValue, audioData, numFrames * channelCount_);
}
} // namespace audioapi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "AudioNode.h"
#include "AudioParam.h"
#include "VectorMath.h"

namespace audioapi {

Expand Down
Loading
Loading