How to link AudioWorkletNode with V2 busses?

Hi everyone,

I am trying to process two audio nodes and pass on the result (sidechain ducking). There do not seem to be public properties I can access. AI suggests something like that:

    const ctx = audio.ctx as AudioContext;
    await ctx.audioWorklet.addModule('./assets/+proto/ducking.js');
    const babyAudio = audio.audioEngine;
    const duckingNode = new AudioWorkletNode(ctx, 'ducking-processor', {
        numberOfInputs: 2,
        numberOfOutputs: 1
    });
    const duckingNodeBabylon = await babyAudio.createSoundSourceAsync("duckingNode", duckingNode);

    this.sounds.buses.ambient._outNode.disconnect();
    this.sounds.buses.music._outNode.disconnect();

    this.sounds.buses.ambient._outNode.connect(duckingNode, 0, 0); 
    this.sounds.buses.music._outNode.connect(duckingNode, 0, 1);        

    duckingNodeBabylon.outBus = babyAudio.defaultMainBus;

This, however, makes both busses dead quiet :frowning: So before I move on, please let me just ask: is it possible at all to use busses like so? Or maybe I use the private props incorrectly?

FYI: await ctx.audioWorklet.addModule('./assets/+proto/ducking.js'); This cannot run in the playground. But the question is rather general so I hope it is alright :pleading_face:

Best wishes
Joe

Hi @Joe_Kerr

In other projects where I’ve implemented ducking (using libraries such as Howler.js and custom Web Audio graphs), I usually don’t route both signals through the same processing node.

Instead, I use one signal purely as a control source:

const analyser = ctx.createAnalyser();

ambientBus.connect(analyser);

I then measure its RMS/peak level and use that value to drive the gain of the music bus through a GainNode.

Conceptually:

Ambient Bus ---> AnalyserNode ---> level detection

Music Bus -----> GainNode -------> Output
                    ^
                    |
             gain controlled
           by ambient level

This has worked well for me in other Web Audio setups because the sidechain signal is only used for level detection, while the music signal stays on its own path and is attenuated according to the detected level.

I don’t know whether Babylon Audio V2 exposes enough of the bus graph to implement it cleanly, but it might be worth exploring if there’s a supported way to attach an AnalyserNode or custom node to a bus output rather than routing both buses through a single AudioWorkletNode.