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

Only 1 layer of custom nodes? #443

Open
voodoohop opened this issue Nov 27, 2023 · 3 comments
Open

Only 1 layer of custom nodes? #443

voodoohop opened this issue Nov 27, 2023 · 3 comments

Comments

@voodoohop
Copy link

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.

@voodoohop
Copy link
Author

voodoohop commented Nov 27, 2023

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.

@benji6
Copy link
Owner

benji6 commented Nov 27, 2023

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.

@voodoohop
Copy link
Author

Cool. Good to know the expected behaviour. I'll try to make some tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants