-
-
Notifications
You must be signed in to change notification settings - Fork 33
Feat: Indexed connect + channel merger/splitter #742
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
Draft
miloszwielgus
wants to merge
42
commits into
main
Choose a base branch
from
indexed-connect
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
aff8dac
feat: prepare headers for indexed connect
miloszwielgus fb20be1
feat: implement NodeConnections
miloszwielgus 445194d
feat: adjusted cpp layer to indexed connect
miloszwielgus 9221b15
feat: implement channel merger and splitter cpp layer
miloszwielgus 612464b
feat: implement jsi layer for merger/splitter and indexed connect
miloszwielgus 0e05c4e
fix: lint
miloszwielgus e09fcd8
feat: implement ts layer
miloszwielgus e5bc9e2
feat: implement example for testing
miloszwielgus f617171
fix: adjust AudioParam to indexed connect
miloszwielgus 0fa83a5
fix: revert to originall SterePanner impl with small adjustment
miloszwielgus 3b7aab0
fix: delete pointless resizes, lint
miloszwielgus 8ce140f
feat: errors thrown closer to spec
miloszwielgus ecdd102
fix: lint
miloszwielgus c7b7f97
feat: web support for merger/splitter
miloszwielgus e72cf31
Merge remote-tracking branch 'main' into indexed-connect
miloszwielgus 5ad73dd
fix: correctly initialize input processing buses
miloszwielgus 21c98ca
fix: make processAudio void, comments, lint
miloszwielgus 0035e95
fix: de-ref the example
miloszwielgus cc6e877
fix: delete unsued methods
miloszwielgus 0e9a73b
feat: docs for indexed connect
miloszwielgus 6c13ae9
fix: use RENDER_QUANTUM_SIZE to create needed buses, instead of curre…
miloszwielgus 35a18dc
fix: nits
miloszwielgus de2f27e
fix: fixed internal summing / mixing
miloszwielgus e5b55f5
feat: add ocillator to the example
miloszwielgus 5da3bc7
feat: docs for splitter/merger
miloszwielgus cab643e
refactor: make processInputAtIndex more readable
miloszwielgus 8bb4b0e
feat: implement InvalidAccessError propagation on disconnect
miloszwielgus cae36e7
fix: nits, styling
miloszwielgus badbff5
Merge remote-tracking branch 'upstream/main' into indexed-connect
miloszwielgus 1614fd0
Merge remote-tracking branch 'main' into indexed-connect
miloszwielgus 5065d4c
feat: update web-audio-api coverage
miloszwielgus 49a392b
fix: reallocate output bus if channel count does not match
miloszwielgus 0cd0b3e
feat: merger/mergerless example
miloszwielgus 1444374
fix: got rid of unnecesary getters in host objects
miloszwielgus 4bbc411
fix: converage in alphabetical order
miloszwielgus a93ddfd
fix: unsigned -> unsigned int
miloszwielgus c288e4d
refactor: move connection types to a separate file
miloszwielgus cc10d04
fix: nitpicks
miloszwielgus ca71ad2
fix: comments in NodeConnections.h, lint
miloszwielgus aa2c248
fix: implicit bool casts, unsafe method delete
miloszwielgus 86b3e71
chore: merge remote-tracking branch main into indexed-connect
miloszwielgus fc7d761
fix: temp fix to see if convolver works
miloszwielgus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
288 changes: 288 additions & 0 deletions
288
apps/common-app/src/examples/MergerSplitter/MergerSplitter.tsx
This file contains hidden or 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,288 @@ | ||
| import React, { useRef, useState, useEffect, FC, useMemo } from 'react'; | ||
| import { Alert, ActivityIndicator } from 'react-native'; | ||
| import { | ||
| AudioContext, | ||
| AudioBufferSourceNode, | ||
| AudioBuffer, | ||
| OscillatorNode, | ||
| } from 'react-native-audio-api'; | ||
|
|
||
| import { Container, Slider, Spacer, Button } from '../../components'; | ||
|
|
||
| // test url pointing to my public repo, to be changed / deleted | ||
| const AUDIO_URL = | ||
| 'https://github.com/miloszwielgus/test-files/raw/refs/heads/main/output.m4a'; | ||
|
|
||
| const INITIAL_GAIN = 0.5; | ||
| const labelWidth = 100; | ||
|
|
||
| const SplitterMerger: FC = () => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. inconsistent file name with component name |
||
| const [isPlayingFile, setIsPlayingFile] = useState(false); | ||
| const [isPlayingOsc, setIsPlayingOsc] = useState(false); | ||
| const [isLoading, setIsLoading] = useState(false); | ||
|
|
||
| const [gain1, setGain1] = useState(INITIAL_GAIN); | ||
| const [gain2, setGain2] = useState(INITIAL_GAIN); | ||
| const [gain3, setGain3] = useState(INITIAL_GAIN); | ||
| const [gain4, setGain4] = useState(INITIAL_GAIN); | ||
| const [gain5, setGain5] = useState(INITIAL_GAIN); | ||
| const [gain6, setGain6] = useState(INITIAL_GAIN); | ||
| /* | ||
| Uncomment all the merger lines and comment the gain connect to destintation lines to test the merger node. | ||
| The changes you will notice are that the channels are panned out correctly (channel 1st is left etc) | ||
| and that channel 4 is silent (effect of 6->2 downmixing) | ||
| */ | ||
| const { | ||
| context, | ||
| splitter, | ||
| // merger, | ||
| gainNode1, | ||
| gainNode2, | ||
| gainNode3, | ||
| gainNode4, | ||
| gainNode5, | ||
| gainNode6, | ||
| } = useMemo(() => { | ||
| const ctx = new AudioContext(); | ||
|
|
||
| const splitNode = ctx.createChannelSplitter(6); | ||
| // const mergeNode = ctx.createChannelMerger(6); | ||
|
|
||
| const g1 = ctx.createGain(); | ||
| g1.gain.value = INITIAL_GAIN; | ||
| const g2 = ctx.createGain(); | ||
| g2.gain.value = INITIAL_GAIN; | ||
| const g3 = ctx.createGain(); | ||
| g3.gain.value = INITIAL_GAIN; | ||
| const g4 = ctx.createGain(); | ||
| g4.gain.value = INITIAL_GAIN; | ||
| const g5 = ctx.createGain(); | ||
| g5.gain.value = INITIAL_GAIN; | ||
| const g6 = ctx.createGain(); | ||
| g6.gain.value = INITIAL_GAIN; | ||
|
|
||
| splitNode.connect(g1, 0, 0); | ||
| // g1.connect(mergeNode, 0, 0); | ||
| g1.connect(ctx.destination); | ||
| splitNode.connect(g2, 1, 0); | ||
| // g2.connect(mergeNode, 0, 1); | ||
| g2.connect(ctx.destination); | ||
| splitNode.connect(g3, 2, 0); | ||
| // g3.connect(mergeNode, 0, 2); | ||
| g3.connect(ctx.destination); | ||
| splitNode.connect(g4, 3, 0); | ||
| // g4.connect(mergeNode, 0, 3); | ||
| g4.connect(ctx.destination); | ||
| splitNode.connect(g5, 4, 0); | ||
| // g5.connect(mergeNode, 0, 4); | ||
| g5.connect(ctx.destination); | ||
| splitNode.connect(g6, 5, 0); | ||
| g6.connect(ctx.destination); | ||
| // g6.connect(mergeNode, 0, 5); | ||
|
|
||
| // mergeNode.connect(ctx.destination); | ||
|
|
||
| return { | ||
| context: ctx, | ||
| splitter: splitNode, | ||
| // merger: mergeNode, | ||
| gainNode1: g1, | ||
| gainNode2: g2, | ||
| gainNode3: g3, | ||
| gainNode4: g4, | ||
| gainNode5: g5, | ||
| gainNode6: g6, | ||
| }; | ||
| }, []); | ||
|
|
||
| const [audioBuffer, setAudioBuffer] = useState<AudioBuffer | null>(null); | ||
|
|
||
| const sourceNodeRef = useRef<AudioBufferSourceNode | null>(null); | ||
| const oscNodeRef = useRef<OscillatorNode | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| const fetchAndDecodeAudio = async () => { | ||
| setIsLoading(true); | ||
| try { | ||
| const response = await fetch(AUDIO_URL); | ||
| const arrayBuffer = await response.arrayBuffer(); | ||
| const buffer = await context.decodeAudioData(arrayBuffer); | ||
| setAudioBuffer(buffer); | ||
| } catch (error) { | ||
| console.error('Failed to fetch or decode audio:', error); | ||
| Alert.alert( | ||
| 'Error', | ||
| 'Could not load the audio file. Check network and URL.' | ||
| ); | ||
| } finally { | ||
| setIsLoading(false); | ||
| } | ||
| }; | ||
|
|
||
| fetchAndDecodeAudio(); | ||
|
|
||
| return () => { | ||
| if (sourceNodeRef.current) { | ||
| sourceNodeRef.current.stop(0); | ||
| sourceNodeRef.current.disconnect(); | ||
| sourceNodeRef.current = null; | ||
| } | ||
| if (oscNodeRef.current) { | ||
| oscNodeRef.current.stop(0); | ||
| oscNodeRef.current.disconnect(); | ||
| oscNodeRef.current = null; | ||
| } | ||
| context.close(); | ||
| }; | ||
| }, [context]); | ||
|
|
||
| const handlePlayPauseFile = () => { | ||
| if (isPlayingFile) { | ||
| if (sourceNodeRef.current) { | ||
| sourceNodeRef.current.stop(0); | ||
| sourceNodeRef.current.disconnect(); | ||
| sourceNodeRef.current = null; | ||
| } | ||
| setIsPlayingFile(false); | ||
| } else { | ||
| if (!audioBuffer) return; | ||
|
|
||
| const sourceNode = context.createBufferSource(); | ||
| sourceNode.buffer = audioBuffer; | ||
| sourceNode.loop = true; | ||
|
|
||
| sourceNode.connect(splitter); | ||
|
|
||
| sourceNode.start(0); | ||
| sourceNodeRef.current = sourceNode; | ||
| setIsPlayingFile(true); | ||
| } | ||
| }; | ||
|
|
||
| const handlePlayPauseOsc = () => { | ||
| if (isPlayingOsc) { | ||
| if (oscNodeRef.current) { | ||
| oscNodeRef.current.stop(0); | ||
| oscNodeRef.current.disconnect(); | ||
| oscNodeRef.current = null; | ||
| } | ||
| setIsPlayingOsc(false); | ||
| } else { | ||
| const osc = context.createOscillator(); | ||
| osc.type = 'sine'; | ||
| osc.frequency.value = 440; // A4 | ||
|
|
||
| osc.connect(splitter); | ||
|
|
||
| osc.start(0); | ||
| oscNodeRef.current = osc; | ||
| setIsPlayingOsc(true); | ||
| } | ||
| }; | ||
|
|
||
| const handleGain1Change = (value: number) => { | ||
| setGain1(value); | ||
| gainNode1.gain.value = value; | ||
| }; | ||
| const handleGain2Change = (value: number) => { | ||
| setGain2(value); | ||
| gainNode2.gain.value = value; | ||
| }; | ||
| const handleGain3Change = (value: number) => { | ||
| setGain3(value); | ||
| gainNode3.gain.value = value; | ||
| }; | ||
| const handleGain4Change = (value: number) => { | ||
| setGain4(value); | ||
| gainNode4.gain.value = value; | ||
| }; | ||
| const handleGain5Change = (value: number) => { | ||
| setGain5(value); | ||
| gainNode5.gain.value = value; | ||
| }; | ||
| const handleGain6Change = (value: number) => { | ||
| setGain6(value); | ||
| gainNode6.gain.value = value; | ||
| }; | ||
|
|
||
| return ( | ||
| <Container centered> | ||
| {isLoading && <ActivityIndicator size="large" color="#FFFFFF" />} | ||
| <Button | ||
| onPress={handlePlayPauseFile} | ||
| title={isPlayingFile ? 'Stop File' : 'Play File'} | ||
| disabled={isLoading || !audioBuffer} | ||
| /> | ||
| <Spacer.Vertical size={15} /> | ||
| <Button | ||
| onPress={handlePlayPauseOsc} | ||
| title={isPlayingOsc ? 'Stop Oscillator' : 'Play Oscillator'} | ||
| disabled={isLoading} | ||
| /> | ||
| <Spacer.Vertical size={30} /> | ||
|
|
||
| <Slider | ||
| label="Gain Path 1" | ||
| value={gain1} | ||
| onValueChange={handleGain1Change} | ||
| min={0.0} | ||
| max={1.5} | ||
| step={0.01} | ||
| minLabelWidth={labelWidth} | ||
| /> | ||
| <Spacer.Vertical size={15} /> | ||
| <Slider | ||
| label="Gain Path 2" | ||
| value={gain2} | ||
| onValueChange={handleGain2Change} | ||
| min={0.0} | ||
| max={1.5} | ||
| step={0.01} | ||
| minLabelWidth={labelWidth} | ||
| /> | ||
| <Spacer.Vertical size={15} /> | ||
| <Slider | ||
| label="Gain Path 3" | ||
| value={gain3} | ||
| onValueChange={handleGain3Change} | ||
| min={0.0} | ||
| max={1.5} | ||
| step={0.01} | ||
| minLabelWidth={labelWidth} | ||
| /> | ||
| <Spacer.Vertical size={15} /> | ||
| <Slider | ||
| label="Gain Path 4" | ||
| value={gain4} | ||
| onValueChange={handleGain4Change} | ||
| min={0.0} | ||
| max={1.5} | ||
| step={0.01} | ||
| minLabelWidth={labelWidth} | ||
| /> | ||
| <Spacer.Vertical size={15} /> | ||
| <Slider | ||
| label="Gain Path 5" | ||
| value={gain5} | ||
| onValueChange={handleGain5Change} | ||
| min={0.0} | ||
| max={1.5} | ||
| step={0.01} | ||
| minLabelWidth={labelWidth} | ||
| /> | ||
| <Spacer.Vertical size={15} /> | ||
| <Slider | ||
| label="Gain Path 6" | ||
| value={gain6} | ||
| onValueChange={handleGain6Change} | ||
| min={0.0} | ||
| max={1.5} | ||
| step={0.01} | ||
| minLabelWidth={labelWidth} | ||
| /> | ||
| <Spacer.Vertical size={30} /> | ||
| </Container> | ||
| ); | ||
| }; | ||
|
|
||
| export default SplitterMerger; | ||
This file contains hidden or 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 @@ | ||
| export { default } from './MergerSplitter'; |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
possibly could be added to
audiodocs/static/audiowith informative description -> what is it, number of channels, SR