Skip to content
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/periodic wave #205

Merged
merged 36 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
26e11ee
feat: added periodic wave cpp files
Nov 7, 2024
d75ddee
feat: added props
Nov 7, 2024
436a5eb
refactor: enums refactoring
Nov 7, 2024
1b58071
feat: declared different constructor of PeriodicWave
Nov 7, 2024
c7e1914
Merge branch 'main' into feat/periodic-wave
Nov 7, 2024
e5d5ea5
ci: yarn format
Nov 7, 2024
daa2387
feat: added generating coeffs for basic wave forms function
Nov 8, 2024
8165ba4
feat: added fft implementation for ios
Nov 13, 2024
7767c6c
feat: added creating band limited tables
Nov 13, 2024
68608c5
feat: defined preprocessor macro for using Accelerate on ios
Nov 13, 2024
76dcdc8
feat: implemented getWaveDataTableForFundamentalFrequency function an…
Nov 13, 2024
a434d60
feat: implemented interpolation and gettingSample
Nov 14, 2024
bfaedc6
feat: added getRateScale
Nov 14, 2024
9a1e39f
feat: introduced PeriodicWave into OscillatorNode
Nov 14, 2024
f77f54a
feat: added caching for periodicWave
Nov 14, 2024
456713e
feat: added createPeriodicWave BaseAudioContext method
Nov 14, 2024
01d898a
feat: implemented setPeriodicWave method
Nov 14, 2024
d104c5a
feat: implemented PeriodicWave wrapper and HostObject
Nov 14, 2024
7389e47
feat: updated interfaces
Nov 14, 2024
fdd5035
docs: updated API coverage
Nov 14, 2024
9dce295
ci: spell-checker checks only .md files
Nov 14, 2024
a63d710
ci: added rnaa to allowed words
Nov 14, 2024
4b3c1cc
refactor: yarn lint fixes
Nov 14, 2024
f1fa823
refactor: enhanced modulo operation, fixed small nitpicks and added c…
Nov 15, 2024
dbd512c
fix: fixed interfaces and errors connected with PeriodicWave
Nov 15, 2024
c14d4c8
feat: added disableNormalization PeriodicWave constraint
Nov 15, 2024
869dd64
fix: removed commented code
Nov 15, 2024
4b41abf
refactor: changed bufferIndex param name to phase
Nov 15, 2024
11543f5
feat: added kfr lib but it does not work
Nov 22, 2024
6395782
fix: fixed buildi kfr
Nov 22, 2024
60a0a44
fix: finally works on Android
Nov 22, 2024
3d7baef
ci: yarn format
Nov 23, 2024
9b1a58d
feat: added kfr as submodule
Nov 23, 2024
8a2b291
ci: yarn lint
Nov 25, 2024
5d472af
refactor: moved kfr to external/kfr
Nov 25, 2024
bd6e50c
fix: fixed kfr submodule
Nov 25, 2024
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
1 change: 1 addition & 0 deletions .github/actions/spelling/allow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ shopify
skia
swm
swmansion
rnaa

tada
vec
Expand Down
3 changes: 0 additions & 3 deletions .github/actions/spelling/only.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
\.ts$
\.tsx$

\.md$
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ android/keystores/debug.keystore
# Turborepo
.turbo/

# generated by bob
lib/
packages/react-native-audio-api/lib

# Android
.kotlin
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "packages/react-native-audio-api/external/kfr"]
path = packages/react-native-audio-api/external/kfr
url = https://github.com/kfrlib/kfr.git
8 changes: 4 additions & 4 deletions apps/common-app/src/examples/Oscillator/Oscillator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
GainNode,
OscillatorNode,
StereoPannerNode,
type WaveType,
type OscillatorType,
} from 'react-native-audio-api';

import { Container, Slider, Spacer, Button } from '../../components';
Expand All @@ -26,7 +26,7 @@ const Oscillator: FC = () => {
const [frequency, setFrequency] = useState(INITIAL_FREQUENCY);
const [detune, setDetune] = useState(INITIAL_DETUNE);
const [pan, setPan] = useState(INITIAL_PAN);
const [oscillatorType, setOscillatorType] = useState<WaveType>('sine');
const [oscillatorType, setOscillatorType] = useState<OscillatorType>('sine');

const audioContextRef = useRef<AudioContext | null>(null);
const oscillatorRef = useRef<OscillatorNode | null>(null);
Expand Down Expand Up @@ -97,7 +97,7 @@ const Oscillator: FC = () => {
setIsPlaying((prev) => !prev);
};

const handleOscillatorTypeChange = (type: WaveType) => {
const handleOscillatorTypeChange = (type: OscillatorType) => {
setOscillatorType(type);
if (oscillatorRef.current) {
oscillatorRef.current.type = type;
Expand Down Expand Up @@ -159,7 +159,7 @@ const Oscillator: FC = () => {
/>
<Spacer.Vertical size={40} />
<View style={styles.oscillatorTypeContainer}>
{OSCILLATOR_TYPES.map((type: WaveType) => (
{OSCILLATOR_TYPES.map((type: OscillatorType) => (
<Pressable
key={type}
style={({ pressed }) => [
Expand Down
14 changes: 7 additions & 7 deletions apps/fabric-example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ PODS:
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- react-native-skia (1.5.1):
- react-native-skia (1.5.3):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1619,7 +1619,7 @@ PODS:
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- RNGestureHandler (2.20.2):
- RNGestureHandler (2.21.1):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -2030,7 +2030,7 @@ SPEC CHECKSUMS:
React-Mapbuffer: b0b4ace5b62b269f3838df26ba2d8b4f39f90783
React-microtasksnativemodule: 0b7db04c18f6bb01ef5b1f9007c3229abecc35dd
react-native-safe-area-context: 2500e4fe998caad50ad3bc51ec23ef951308569e
react-native-skia: 7346a82f02bd8c318611ea22b78ae9ebfba97bb4
react-native-skia: b5216ffad62ec47294094cb25630332bb8f96493
React-nativeconfig: 72c10ff34863148ef90df9c9c8eacba99d2faaaa
React-NativeModulesApple: 5ec49182fa000b2215ee1bed03e2867f8323ccf5
React-perflogger: 073c7a8a436b3fe724f1df34e9d1f3db1d25fe74
Expand Down Expand Up @@ -2058,13 +2058,13 @@ SPEC CHECKSUMS:
React-utils: d9624101245ebaab39c9f1bd786132da0b4f27ff
ReactCodegen: dbfef1fef26f42c900bb1884fa149d49d501d64d
ReactCommon: 429ca28cd813c31359c73ffac6dc24f93347d522
RNAudioAPI: c2c7e844f9245985fca7b1ae9c872d23e7528837
RNGestureHandler: fc5ce5bf284640d3af6431c3a5c3bc121e98d045
RNAudioAPI: a4068f739b4e80e636ac6110d70858ea89ac4835
RNGestureHandler: a3822e519fd1e9885b92d8c9bd82a7a0be305fe3
RNReanimated: 77242c6d67416988a2fd9f5cf574bb3e60016362
RNScreens: e389d6a6a66a4f0d3662924ecae803073ccce8ec
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Yoga: 1d66db49f38fd9e576a1d7c3b081e46ab4c28b9e
Yoga: f8ec45ce98bba1bc93dd28f2ee37215180e6d2b6

PODFILE CHECKSUM: 75ad38075e71875257a2590065853ea6a608b897

COCOAPODS: 1.16.2
COCOAPODS: 1.15.2
33 changes: 10 additions & 23 deletions docs/web-audio-coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Some of the noticeable implementation details that are still in progress or not
- Support of different number of channels (current approach in most of the audio-graph nodes assumes working with two channel audio)
- Multi-input for each node and input mixing (Although specification suggests that most of the nodes can cave only one input or output, common use-cases proves otherwise). Only node that mixes multiple inputs is `DestinationNode`.

## ✅ Completed (**7** out of 33)
## ✅ Completed (**9** out of 33)

<details>
<summary><b>AudioBuffer</b></summary>
Expand All @@ -27,11 +27,17 @@ Some of the noticeable implementation details that are still in progress or not
<details>
<summary><b>GainNode</b></summary>
</details>
<details>
<summary><b>OscillatorNode</b></summary>
</details>
<details>
<summary><b>PeriodicWave</b></summary>
</details>
<details>
<summary><b>StereoPannerNode</b></summary>
</details>

## 🚧 In Progress (**5** out of 33)
## 🚧 In Progress (**4** out of 33)

<details>
<summary><b>AudioContext</b></summary>
Expand Down Expand Up @@ -123,7 +129,7 @@ Some of the noticeable implementation details that are still in progress or not
| 🔘 createIIRFilter | ❌ |
| 🔘 createOscillator | ✅ |
| 🔘 createPanner | ❌ |
| 🔘 createPeriodicWave | |
| 🔘 createPeriodicWave | |
| 🔘 createStereoPanner | ✅ |
| 🔘 createWaveShaper | ❌ |
| 🔘 decodeAudioData | ❌ |
Expand All @@ -132,23 +138,7 @@ Some of the noticeable implementation details that are still in progress or not

</details>

<details>
<summary><b>OscillatorNode</b></summary>

<div style="padding: 16px; padding-left: 42px;">

| Property 🔹/ Method 🔘 | state |
| ---------------------- | ----- |
| 🔹 frequency | ✅ |
| 🔹 detune | ✅ |
| 🔹 type | ✅ |
| 🔘 setPeriodicWave | ❌ |

</div>

</details>

## ❌ Not yet available (**21** out of 33)
## ❌ Not yet available (**20** out of 33)

<details>
<summary><b>AudioParamMap</b></summary>
Expand All @@ -174,9 +164,6 @@ Some of the noticeable implementation details that are still in progress or not
<details>
<summary><b>WaveShaperNode</b></summary>
</details>
<details>
<summary><b>PeriodicWave</b></summary>
</details>
<details>
<summary><b>IIRFilterNode</b></summary>
</details>
Expand Down
5 changes: 5 additions & 0 deletions packages/react-native-audio-api/RNAudioAPI.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ Pod::Spec.new do |s|

s.source_files = "ios/**/*.{h,m,mm}", "common/cpp/**/*.{hpp,cpp,c,h}"

s.ios.frameworks = 'Accelerate'
s.xcconfig = {
'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) HAVE_ACCELERATE=1'
}

# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
if respond_to?(:install_modules_dependencies, true)
Expand Down
23 changes: 9 additions & 14 deletions packages/react-native-audio-api/android/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.9.0)
cmake_minimum_required(VERSION 3.12.0)
project(react-native-audio-api)

set(CMAKE_VERBOSE_MAKEFILE ON)
Expand Down Expand Up @@ -32,8 +32,11 @@ file(GLOB_RECURSE SOURCE_FILES
"../common/cpp/HostObjects/*.h"
"../common/cpp/utils/*.cpp"
"../common/cpp/utils/*.h"
"../common/cpp/types/*.h"
)

add_subdirectory(../external/kfr ${CMAKE_CURRENT_BINARY_DIR}/kfr-build)

add_library(react-native-audio-api SHARED ${SOURCE_FILES})

file(GLOB DIRS CONFIGURE_DEPENDS "src/main/cpp/**" "../common/cpp/**")
Expand All @@ -49,25 +52,18 @@ target_include_directories(

find_package(ReactAndroid REQUIRED CONFIG)
find_package(fbjni REQUIRED CONFIG)
find_package (oboe REQUIRED CONFIG)

# set(LINK_LIBRARIES
# ReactAndroid::reactnative
# ReactAndroid::jsi
# fbjni::fbjni
# android
# log
# oboe::oboe
# )

# target_link_libraries(react-native-audio-api ${LINK_LIBRARIES})
find_package(oboe REQUIRED CONFIG)

set(LINK_LIBRARIES
ReactAndroid::jsi
fbjni::fbjni
android
log
oboe::oboe
kfr
kfr_dsp
kfr_dft
kfr_io
)

if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
Expand All @@ -83,4 +79,3 @@ else()
endif()

target_link_libraries(react-native-audio-api ${LINK_LIBRARIES} ${RN_VERSION_LINK_LIBRARIES})

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ std::vector<jsi::PropNameID> BaseAudioContextHostObject::getPropertyNames(
propertyNames.push_back(
jsi::PropNameID::forUtf8(runtime, "createBufferSource"));
propertyNames.push_back(jsi::PropNameID::forUtf8(runtime, "createBuffer"));
propertyNames.push_back(
jsi::PropNameID::forUtf8(runtime, "createPeriodicWave"));
return propertyNames;
}

Expand Down Expand Up @@ -161,6 +163,43 @@ jsi::Value BaseAudioContextHostObject::get(
});
}

if (propName == "createPeriodicWave") {
return jsi::Function::createFromHostFunction(
runtime,
propNameId,
3,
[this](
jsi::Runtime &runtime,
const jsi::Value &thisValue,
const jsi::Value *arguments,
size_t count) -> jsi::Value {
auto real = arguments[0].getObject(runtime).getArray(runtime);
auto imag = arguments[1].getObject(runtime).getArray(runtime);
auto disableNormalization = arguments[2].getBool();
auto length =
static_cast<int>(real.getProperty(runtime, "length").asNumber());

auto *realData = new float[length];
auto *imagData = new float[length];

for (size_t i = 0; i < real.length(runtime); i++) {
realData[i] = static_cast<float>(
real.getValueAtIndex(runtime, i).getNumber());
}
for (size_t i = 0; i < imag.length(runtime); i++) {
realData[i] = static_cast<float>(
imag.getValueAtIndex(runtime, i).getNumber());
}

auto periodicWave = wrapper_->createPeriodicWave(
realData, imagData, disableNormalization, length);
auto periodicWaveHostObject =
PeriodicWaveHostObject::createFromWrapper(periodicWave);
return jsi::Object::createFromHostObject(
runtime, periodicWaveHostObject);
});
}

throw std::runtime_error("Not yet implemented!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "BiquadFilterNodeHostObject.h"
#include "GainNodeHostObject.h"
#include "OscillatorNodeHostObject.h"
#include "PeriodicWaveHostObject.h"
#include "StereoPannerNodeHostObject.h"

namespace audioapi {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ std::vector<jsi::PropNameID> OscillatorNodeHostObject::getPropertyNames(
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, "frequency"));
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, "detune"));
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, "type"));
propertyNames.push_back(
jsi::PropNameID::forAscii(runtime, "setPeriodicWave"));
return propertyNames;
}

Expand All @@ -46,6 +48,25 @@ jsi::Value OscillatorNodeHostObject::get(
return jsi::String::createFromUtf8(runtime, waveType);
}

if (propName == "setPeriodicWave") {
return jsi::Function::createFromHostFunction(
runtime,
propNameId,
1,
[this](
jsi::Runtime &rt,
const jsi::Value &thisVal,
const jsi::Value *args,
size_t count) -> jsi::Value {
auto wrapper = getOscillatorNodeWrapperFromAudioNodeWrapper();
auto periodicWaveHostObject =
args[0].getObject(rt).asHostObject<PeriodicWaveHostObject>(rt);

wrapper->setPeriodicWave(periodicWaveHostObject->wrapper_);
return jsi::Value::undefined();
});
}

return AudioScheduledSourceNodeHostObject::get(runtime, propNameId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "AudioParamHostObject.h"
#include "AudioScheduledSourceNodeHostObject.h"
#include "OscillatorNodeWrapper.h"
#include "PeriodicWaveHostObject.h"

namespace audioapi {
using namespace facebook;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "PeriodicWaveHostObject.h"

namespace audioapi {
using namespace facebook;

PeriodicWaveHostObject::PeriodicWaveHostObject(
const std::shared_ptr<PeriodicWaveWrapper> &wrapper)
: wrapper_(wrapper) {}

std::vector<jsi::PropNameID> PeriodicWaveHostObject::getPropertyNames(
jsi::Runtime &runtime) {
std::vector<jsi::PropNameID> propertyNames;
return propertyNames;
}

jsi::Value PeriodicWaveHostObject::get(
jsi::Runtime &runtime,
const jsi::PropNameID &propNameId) {
auto propName = propNameId.utf8(runtime);

throw std::runtime_error("Not yet implemented!");
}

void PeriodicWaveHostObject::set(
jsi::Runtime &runtime,
const jsi::PropNameID &propNameId,
const jsi::Value &value) {
auto propName = propNameId.utf8(runtime);

throw std::runtime_error("Not yet implemented!");
}

} // namespace audioapi
Loading
Loading