Skip to content

Commit f33289f

Browse files
maciejmakowski2003mdydekgabimonchaMaciej Makowskimichalsek
authored
merge main to docsprod (#483)
* docs: add docs for oscillator node * docs: added wave shapes img * docs: removed empty periodic wave screen * docs: stereo panner node * update installation docs to include metro config (#447) * fix: linted file * Feat/onended/added state to payload (#453) * feat: added state to payload of onended event * ci: yarn format * fix: added appropriate type to arg of onended method --------- Co-authored-by: Maciej Makowski <maciej.makowski2608@gmail.com> * fix: number of channelCount * fix: added possibility of disconnection between node and param in ts * docs: add mention about connecting node to param * feat: naive approach to streaming in beloved cpp (#461) * feat: naive approach streaming in beloved cpp * refactor: minor improvements * fix: minor fix * fix: bring back Audiofile example * fix: renamed new node * fix: revert project.pbxproj changes and formatting --------- Co-authored-by: Maciej Makowski <maciej.makowski2608@gmail.com> * docs: added search bar into the documentation * Feat/streaming/additional features (#462) * feat: added bufferId arg to enqueueBuffer and attached it to onended payload * feat: added onPositionChanged event * ci: yarn format * fix: minor fix --------- Co-authored-by: Maciej Makowski <maciej.makowski2608@gmail.com> * Refactor/system settings and audio engine (#466) * feat: added bufferId arg to enqueueBuffer and attached it to onended payload * feat: added onPositionChanged event * ci: yarn format * fix: minor fix * fix: fixed system settings * fix: fixed engine connections * feat: implemented setAudioSessionActivity * ci: yarn format * fix: small fix --------- Co-authored-by: Maciej Makowski <maciej.makowski2608@gmail.com> * fix: changed type of reason to string union * fix: removed double unknown type * fix: fixed NativeAudioAPIModuleSpec on oldArch (#470) Co-authored-by: Maciej Makowski <maciej.makowski2608@gmail.com> * fix: fixed building without withAudioAPI plugin (#471) Co-authored-by: Maciej Makowski <maciej.makowski2608@gmail.com> * Docs/audio manager (#458) * docs: add audio manager documentation * feat: rewrote types section * docs: better info on returning types * docs: added missing explanation and aligned with new impl * fix: small typos * fix: typos * feat: extended examples * fix: minor fixes (#474) Co-authored-by: Maciej Makowski <maciej.makowski2608@gmail.com> * fix: possibility of connecting node to param on web * chore: readme update to 0.6.0 * chore: readme update to 0.6.0 v2 * chore: add 0.6.0 link * fix: typo * Revert "Chore/update readme 0.6.0" * chore: small refactor in readme * fix: config plugin defaults and types * fix: config plugin defaults and types * fix: cleanup types * fix: fixed system playback speed (#479) Co-authored-by: Maciej Makowski <maciej.makowski2608@gmail.com> * Refactor/system audio settings and engines (#480) * refactor: android system functions improvement * ci: yarn format * feat: added option to init audioContext suspended * refactor: refactored audio player behaviors * ci: yarn format * refactor: small refactor of AudioContextOptions * fix: small nitpick * refactor: pausing engine only if all players are paused * ci: yarn format * fix: removed synchronized decorator from AudioAPIModule --------- Co-authored-by: Maciej Makowski <maciej.makowski2608@gmail.com> * fix returning status in requestRecordingPermissions (#473) * fix: ios fix * fix: android fix * fix: 2nd iteration of andoroid implementation * docs: added info note about plugin (#472) * docs: added info note plugin * fix: naming * docs: removed info about connecting to only node from web audio api coverage * fix: small fix --------- Co-authored-by: Maciej Makowski <maciej.makowski2608@gmail.com> Co-authored-by: michal <dydmichal@gmail.com> --------- Co-authored-by: michal <dydmichal@gmail.com> Co-authored-by: gabimoncha <gabimoncha@gmail.com> Co-authored-by: MichaΕ‚ Dydek <54865962+mdydek@users.noreply.github.com> Co-authored-by: Maciej Makowski <maciej.makowski2608@gmail.com> Co-authored-by: MichaΕ‚ SΔ™k <michal.sek@swmansion.com>
1 parent c8a9c58 commit f33289f

File tree

82 files changed

+1779
-328
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1779
-328
lines changed

β€Ž.github/workflows/publish-docs.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,11 @@ jobs:
4545
- name: Setup Pages
4646
uses: actions/configure-pages@v5
4747

48+
- name: Recrawl search index
49+
run: |
50+
curl -X POST https://crawler.algolia.com/api/1/crawlers/${{ secrets.CRAWLER_ID }}/reindex \
51+
-H "Content-Type: application/json" \
52+
-u ${{ secrets.CRAWLER_USER_ID }}:${{ secrets.CRAWLER_API_KEY }}
53+
4854
- name: Deploy to Github Pages
4955
uses: actions/deploy-pages@v4

β€ŽREADME.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,12 @@ check out the [Getting Started](https://docs.swmansion.com/react-native-audio-ap
3434
Ability to modify playback speed without affecting pitch of the sound
3535
<br />
3636

37-
- <sub>![Coming in 0.6.0](https://img.shields.io/badge/Coming_in-0.6.0-blue)</sub> **System configuration** πŸ› οΈ <br />
38-
Full control of system audio settings, remote controls, lock screen integration and most importantly configurable background modes
39-
<br />
40-
41-
- **Microphone support** πŸŽ™οΈ <br />
42-
Grab audio data from device microphone or connected device, connect it to the audio graph or stream through the internet
43-
<br />
44-
45-
- **Connect audio param** 🀞 <br />
46-
Ability to connect Audio nodes to audio params, which will allow for powerful and efficient modulation of audio parameters, creating effects like tremolo, vibrato or complex envelope followers.
47-
<br />
37+
- <sub>[![Released in 0.6.0](https://img.shields.io/badge/Released_in-0.6.0-green)](https://github.com/software-mansion/react-native-audio-api/releases/tag/0.6.0)</sub> <br/> **System configuration** πŸ› οΈ <br />
38+
Full control of system audio settings, remote controls, lock screen integration and most importantly configurable background modes <br />
39+
<br /> **Microphone support** πŸŽ™οΈ <br />
40+
Grab audio data from device microphone or connected device, connect it to the audio graph or stream through the internet <br />
41+
<br /> **Connect audio param** 🀞 <br />
42+
Ability to connect Audio nodes to audio params, which will allow for powerful and efficient modulation of audio parameters, creating effects like tremolo, vibrato or complex envelope followers. <br />
4843

4944
- **JS Audio Worklets** 🐎 <br />
5045
Ability to run JS functions connected to the audio graph running on audio thread allowing for full customization of what happens to the audio signal.

β€Žapps/common-app/src/examples/AudioFile/AudioFile.tsx

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ import { Container, Button, Spacer, Slider } from '../../components';
1212
const URL =
1313
'https://software-mansion.github.io/react-native-audio-api/audio/voice/example-voice-01.mp3';
1414

15-
const LOOP_START = 0;
16-
const LOOP_END = 10;
17-
1815
const INITIAL_RATE = 1;
1916
const INITIAL_DETUNE = 0;
2017

@@ -49,7 +46,7 @@ const AudioFile: FC = () => {
4946
}
5047
};
5148

52-
const handlePress = () => {
49+
const handlePress = async () => {
5350
if (!audioContextRef.current) {
5451
return;
5552
}
@@ -59,11 +56,17 @@ const AudioFile: FC = () => {
5956
AudioManager.setLockScreenInfo({
6057
state: 'state_paused',
6158
});
59+
60+
setTimeout(async () => {
61+
await audioContextRef.current?.suspend();
62+
}, 5);
6263
} else {
6364
if (!audioBuffer) {
6465
fetchAudioBuffer();
6566
}
6667

68+
await audioContextRef.current.resume();
69+
6770
AudioManager.setLockScreenInfo({
6871
state: 'state_playing',
6972
});
@@ -74,12 +77,9 @@ const AudioFile: FC = () => {
7477
pitchCorrection: true,
7578
});
7679
bufferSourceRef.current.buffer = audioBuffer;
77-
bufferSourceRef.current.loop = true;
7880
bufferSourceRef.current.onended = (event) => {
7981
setOffset((_prev) => event.value || 0);
8082
};
81-
bufferSourceRef.current.loopStart = LOOP_START;
82-
bufferSourceRef.current.loopEnd = LOOP_END;
8383
bufferSourceRef.current.playbackRate.value = playbackRate;
8484
bufferSourceRef.current.detune.value = detune;
8585
bufferSourceRef.current.connect(audioContextRef.current.destination);
@@ -113,7 +113,7 @@ const AudioFile: FC = () => {
113113

114114
useEffect(() => {
115115
if (!audioContextRef.current) {
116-
audioContextRef.current = new AudioContext();
116+
audioContextRef.current = new AudioContext({ initSuspended: true });
117117
}
118118

119119
AudioManager.setLockScreenInfo({
@@ -123,37 +123,40 @@ const AudioFile: FC = () => {
123123
duration: 10,
124124
});
125125

126-
const remotePlaySubscription = AudioManager.enableSystemEvent(
126+
AudioManager.enableRemoteCommand('remotePlay', true);
127+
AudioManager.enableRemoteCommand('remotePause', true);
128+
AudioManager.enableRemoteCommand('remoteChangePlaybackPosition', true);
129+
AudioManager.observeAudioInterruptions(true);
130+
131+
const remotePlaySubscription = AudioManager.addSystemEventListener(
127132
'remotePlay',
128133
(event) => {
129134
console.log('remotePlay event:', event);
130135
}
131136
);
132137

133-
const remotePauseSubscription = AudioManager.enableSystemEvent(
138+
const remotePauseSubscription = AudioManager.addSystemEventListener(
134139
'remotePause',
135140
(event) => {
136141
console.log('remotePause event:', event);
137142
}
138143
);
139144

140145
const remoteChangePlaybackPositionSubscription =
141-
AudioManager.enableSystemEvent(
146+
AudioManager.addSystemEventListener(
142147
'remoteChangePlaybackPosition',
143148
(event) => {
144149
console.log('remoteChangePlaybackPosition event:', event);
145150
}
146151
);
147152

148-
const interruptionSubscription = AudioManager.enableSystemEvent(
153+
const interruptionSubscription = AudioManager.addSystemEventListener(
149154
'interruption',
150155
(event) => {
151156
console.log('Interruption event:', event);
152157
}
153158
);
154159

155-
AudioManager.observeAudioInterruptions(true);
156-
157160
fetchAudioBuffer();
158161

159162
return () => {
@@ -162,6 +165,7 @@ const AudioFile: FC = () => {
162165
remoteChangePlaybackPositionSubscription?.remove();
163166
interruptionSubscription?.remove();
164167
audioContextRef.current?.close();
168+
AudioManager.resetLockScreenInfo();
165169
};
166170
}, [fetchAudioBuffer]);
167171

β€Žpackages/audiodocs/docs/core/audio-node.mdx

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,52 @@ Based on them we can obtain output's number of channels and mixing strategy.
3535
| `channelCountMode` | [`ChannelCountMode`](/types/channel-count-mode) | Enumerated value that specifies the method by which channels are mixed between the node's inputs and outputs. | <ReadOnly /> |
3636
| `channelInterpretation` | [`ChannelInterpretation`](/types/channel-interpretation) | Enumerated value that specifies how input channels are mapped to output channels when number of them is different. | <ReadOnly /> |
3737

38+
## Examples
39+
40+
### Connecting node to node
41+
42+
```tsx
43+
import { OscillatorNode, GainNode, AudioContext } from 'react-native-audio-api';
44+
45+
function App() {
46+
const audioContext = new AudioContext();
47+
const oscillatorNode = audioContext.createOscillator();
48+
const gainNode = audioContext.createGain();
49+
50+
gainNode.gain.value = 0.5; //lower volume to 0.5
51+
oscillatorNode.connect(gainNode);
52+
gainNode.connect(audioContext.destination);
53+
oscillatorNode.start(audioContext.currentTime);
54+
}
55+
```
56+
57+
### Connecting node to audio param (LFO-controlled parameter)
58+
59+
```tsx
60+
import { OscillatorNode, GainNode, AudioContext } from 'react-native-audio-api';
61+
62+
function App() {
63+
const audioContext = new AudioContext();
64+
const oscillatorNode = audioContext.createOscillator();
65+
const lfo = audioContext.createOscillator();
66+
const gainNode = audioContext.createGain();
67+
68+
gainNode.gain.value = 0.5; //lower volume to 0.5
69+
lfo.frequency.value = 2; //low frequency oscillator with 2Hz
70+
71+
// by default oscillator wave values ranges from -1 to 1
72+
// connecting lfo to gain param will cause the gain param to oscillate at 2Hz and its value will range from 0.5 - 1 to 0.5 + 1
73+
// you can modulate amplitude by connecting lfo to another gain that would be responsible for this value
74+
lfo.connect(gainNode.gain)
75+
76+
oscillatorNode.connect(gainNode);
77+
gainNode.connect(audioContext.destination);
78+
oscillatorNode.start(audioContext.currentTime);
79+
lfo.start(audioContext.currentTime);
80+
}
81+
```
82+
83+
3884
## Methods
3985

4086
### `connect`
@@ -43,7 +89,7 @@ The above method lets you connect one of the node's outputs to a destination.
4389

4490
| Parameters | Type | Description |
4591
| :---: | :---: | :---- |
46-
| `destination` | [`AudioNode`](/core/audio-node) | `AudioNode` to which to connect. |
92+
| `destination` | [`AudioNode`](/core/audio-node) or [`AudioParam`](/core/audio-param) | `AudioNode` or `AudioParam` to which to connect. |
4793

4894
#### Errors:
4995

@@ -59,7 +105,7 @@ The above method lets you disconnect one or more nodes from the node.
59105

60106
| Parameters | Type | Description |
61107
| :---: | :---: | :---- |
62-
| `destination` <Optional /> | [`AudioNode`](/core/audio-node) | `AudioNode` to which to connect. |
108+
| `destination` <Optional /> | [`AudioNode`](/core/audio-node) or [`AudioParam`](/core/audio-param) | `AudioNode` or `AudioParam` from which to disconnect. |
63109

64110
If no arguments provided node disconnects from all outgoing connections.
65111

β€Žpackages/audiodocs/docs/core/base-audio-context.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ The above method lets you create [`GainNode`](/effects/gain-node).
9696

9797
### `createOscillator`
9898

99-
The above method lets you create `OscillatorNode`.
99+
The above method lets you create [`OscillatorNode`](/sources/oscillator-node).
100100

101101
#### Returns `OscillatorNode`.
102102

@@ -122,7 +122,7 @@ The above method lets you create `PeriodicWave`.
122122

123123
The above method lets you create `StereoPannerNode`.
124124

125-
#### Returns `StereoPannerNode`.
125+
#### Returns [`StereoPannerNode`](/effects/stereo-panner-node).
126126

127127
### `decodeAudioData`
128128

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
sidebar_position: 2
3+
---
4+
5+
import AudioNodePropsTable from "@site/src/components/AudioNodePropsTable"
6+
import { ReadOnly } from '@site/src/components/Badges';
7+
8+
# StereoPannerNode
9+
10+
The `StereoPannerNode` interface represents the change in ratio between two outputing channels (f. e. left and right speaker).
11+
12+
#### [`AudioNode`](/core/audio-node#read-only-properties) properties
13+
14+
<AudioNodePropsTable numberOfInputs={1} numberOfOutputs={1} channelCount={2} channelCountMode={"explicit"} channelInterpretation={"speakers"} />
15+
16+
## Constructor
17+
18+
[`BaseAudioContext.createStereoPanner()`](/core/base-audio-context#createstereopanner)
19+
20+
## Properties
21+
22+
| Name | Type | Default value | Description |
23+
| :----: | :----: | :-------- | :------ |
24+
| `pan` | [`AudioParam`](/core/audio-param) <ReadOnly /> | 0 | [`a-rate`](/core/audio-param#a-rate-vs-k-rate) `AudioParam` representing value of pan to apply. |
25+
26+
## Remarks
27+
28+
#### `pan`
29+
- Nominal range is -1 (only left channel) to 1 (only right channel).

β€Žpackages/audiodocs/docs/fundamentals/getting-started.mdx

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The goal of _Fundamentals_ is to guide you through the setup process of the Audi
1313

1414
It takes only a few steps to add Audio API to your project:
1515

16-
### Install the package
16+
### Step 1: Install the package
1717

1818
Install the `react-native-audio-api` package from npm:
1919

@@ -35,6 +35,80 @@ Install the `react-native-audio-api` package from npm:
3535
</TabItem>
3636
</Tabs>
3737

38+
### Step 2: Add Audio API expo plugin (optional)
39+
40+
Add `react-native-audio-api` expo plugin to your `app.json` or `app.config.js`.
41+
42+
<details>
43+
<summary>app.json</summary>
44+
```javascript
45+
{
46+
"plugins": [
47+
[
48+
"react-native-audio-api",
49+
{
50+
"iosBackgroundMode": true,
51+
"androidPermissions" : [
52+
"android.permission.MODIFY_AUDIO_SETTINGS",
53+
"android.permission.FOREGROUND_SERVICE",
54+
"android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"
55+
],
56+
"androidForegroundService": true,
57+
"androidFSTypes": [
58+
"mediaPlayback"
59+
]
60+
}
61+
]
62+
]
63+
}
64+
```
65+
</details>
66+
67+
<details>
68+
<summary>app.config.js</summary>
69+
```javascript
70+
export default {
71+
...
72+
"plugins": [
73+
[
74+
"react-native-audio-api",
75+
{
76+
"iosBackgroundMode": true,
77+
"androidPermissions" : [
78+
"android.permission.MODIFY_AUDIO_SETTINGS",
79+
"android.permission.FOREGROUND_SERVICE",
80+
"android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"
81+
],
82+
"androidForegroundService": true,
83+
"androidFSTypes": [
84+
"mediaPlayback"
85+
]
86+
}
87+
]
88+
]
89+
};
90+
```
91+
</details>
92+
93+
Read more about plugin [here](/other/audio-api-plugin)!
94+
95+
### Step 3: Wrap metro config with Audio API wrapper (recommended)
96+
97+
Wrap your existing Metro configuration in the `metro.config.js` file with the `wrapWithAudioAPIMetroConfig` function:
98+
99+
```javascript
100+
// metro.config.js
101+
const {
102+
wrapWithAudioAPIMetroConfig,
103+
} = require('react-native-audio-api/metro-config');
104+
105+
const config = {
106+
// Your existing Metro configuration options
107+
};
108+
109+
module.exports = wrapWithAudioAPIMetroConfig(config);
110+
```
111+
38112
### Usage with expo
39113

40114
`react-native-audio-api` contains native custom code and isn't part of the Expo Go application. In order to be available in expo managed builds, you have to use Expo development build. Simplest way on starting local expo dev builds, is to use:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
id: audio-api-plugin
3+
sidebar_label: Audio API Expo plugin
4+
sidebar_position: 3
5+
---
6+
7+
# 🚧 Audio API Expo plugin 🚧

β€Žpackages/audiodocs/docs/other/web-audio-api-coverage.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ sidebar_position: 2
1414
| AudioBuffer | βœ… |
1515
| AudioBufferSourceNode | βœ… |
1616
| AudioDestinationNode | βœ… |
17-
| AudioNode | βœ… | `connect` to `AudioNode` is only possible |
17+
| AudioNode | βœ… |
1818
| AudioParam | βœ… |
1919
| AudioScheduledSourceNode | βœ… |
2020
| BiquadFilterNode | βœ… |

β€Žpackages/audiodocs/docs/sources/audio-buffer-source-node.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { Optional, Overridden } from '@site/src/components/Badges';
1010
The `AudioBufferSourceNode` is an [`AudioScheduledSourceNode`](/sources/audio-scheduled-source-node) which represents audio source with in-memory audio data, stored in `AudioBuffer`.
1111
You can use it for audio playback, including standard pause and resume functionalities.
1212

13-
An `AudioBufferSourceNode` can be started only once, so if you want to play the same sound again you have to created new one.
14-
However this node is very inexpensive to create, and what is crucial you can reuse same [`AudioBuffer`](/sources/audio-buffer).
13+
An `AudioBufferSourceNode` can be started only once, so if you want to play the same sound again you have to create a new one.
14+
However, this node is very inexpensive to create, and what is crucial you can reuse same [`AudioBuffer`](/sources/audio-buffer).
1515

1616
#### [`AudioNode`](/core/audio-node#read-only-properties) properties
1717

0 commit comments

Comments
Β (0)