Only 1 layer of custom nodes?
In my experiments when I create custom nodes that themselves contain custom nodes I don't hear any output. Is that a limitation? I don't think it's a big problem this way just to know.
Sorry hijacking this thread for another followup question. Are nodes only updated when their key changes?
I'm creating a new audio graph where the buffers of the bufferSource's are changed but I only hear the new sound if i change the key.
Hi @voodoohop, custom nodes can be composed of other custom nodes. There is ony 1 test case for that though https://github.com/benji6/virtual-audio-graph/blob/master/test/customNodes/expectedBehaviour.ts#L26 so it's possible you hit an edge case.
I just tested this example which seemed fine:
const osc = createNode(
({ gain: gainValue, startTime, stopTime, ...rest }) => {
const duration = stopTime - startTime;
return {
0: gain("output", {
gain: [
["setValueAtTime", 0, startTime],
[
"linearRampToValueAtTime",
gainValue,
startTime + duration * 0.15,
],
["setValueAtTime", gainValue, stopTime - duration * 0.25],
["linearRampToValueAtTime", 0, stopTime],
],
}),
1: oscillator(0, { startTime, stopTime, ...rest }),
};
},
);
const pingPongDelay = createNode(({ decay, delayTime }) => ({
0: stereoPanner("output", { pan: -1 }),
1: stereoPanner("output", { pan: 1 }),
2: delay([1, 5], { delayTime, maxDelayTime: delayTime }),
3: gain(2, { gain: decay }),
4: delay([0, 3], { delayTime, maxDelayTime: delayTime }),
5: gain(4, { gain: decay }, "input"), // connections will be made here
}));
const synth = createNode(({ startTime, stopTime }) => ({
0: pingPongDelay("output", { decay: 0.8, delayTime: 0.5 }),
1: osc(0, {
frequency: 110,
gain: 0.2,
startTime,
stopTime,
type: "square",
}),
}));
const { currentTime } = virtualAudioGraph;
virtualAudioGraph.update({
0: synth("output", { startTime: currentTime, stopTime: currentTime + 1 }),
});
And in answer to your second question, nodes should be updated whenever any properties change (not just the key). There may be some limitations to this (e.g. if the underlying audio API does not allow this). Or of course there may be a bug - do share an example if you are having trouble.
Cool. Good to know the expected behaviour. I'll try to make some tests