Best node for balanced channels?

Discussion in 'Programming' started by General_Cool, Nov 2, 2025 at 3:03 AM.

  1. General_Cool

    General_Cool
    Expand Collapse

    Joined:
    Jul 29, 2014
    Messages:
    17
    I'm trying to make a sound (specifically, a horn/siren) play from a node in the vehicle (any vehicle, not one specifically) where the audio is balanced in both L/R stereo channels regardless of camera view. I'm currently using "v.data.refNodes[0].ref" to do this, however the audio is 99% biased towards the right channel in the default hood view while the left channel audio cuts in and out sporadically and quietly. Panning the camera solves this issue, and the audio sounds normal in 360 view, meaning it is most certainly the node being chosen causing the issue. I originally tried using this, which is the same Lua used in reverseWarn.lua, along with "soundNode:":["rf1l"] in my jbeam file for each specific sound:

    if jbeamData.soundNode_nodes and type(jbeamData.soundNode_nodes) == "table" and type(jbeamData.soundNode_nodes[1]) == "number" then
    node = jbeamData.soundNode_nodes[1]
    else
    node = 0
    end

    I tried multiple different nodes in that soundNode slot in the jbeam file and the game did not seem to care about any of them. Will this method work if I do it correctly? Perhaps I was just doing it wrong in the first place.

    Whats a good solution to this? Looking through the jbeam files for the vanilla cars I see all use a different node for siren sounds (bb2 on the Bastion, s1 on the fullsize, etc.), but I need a common node for use on all vehicles. Could I just duplicate the sound on two common nodes on either side of the car or would that cause overlapping issues? I'd prefer a specific node (for example, one that specifies the middle front node of the vehicle in general) to keep the Lua simple. Is there a common node list somewhere?

    Update: I found a shoddy workaround where I just created two separate instances of the sound played at the exact same time on "v.data.refNodes[0].ref" and "v.data.refNodes[0].left" using ipairs. It satisfies my problem for now, albeit in a rudimentary manner, until somebody gets back to me on this thread. At least I've found it creates a nice echo effect for the siren and horn and mimics how the sound would sound in real life on police cars utilizing dual speakers.
     
    #1 General_Cool, Nov 2, 2025 at 3:03 AM
    Last edited: Nov 2, 2025 at 6:09 AM
  2. Agent_Y

    Agent_Y
    Expand Collapse
    Jbeam/QA support
    BeamNG Team

    Joined:
    Jul 10, 2020
    Messages:
    10,553
    I don't think there is a universal center node name on all cars. Other than maybe the hood camera node, you can try using that. You should rather programatically find the most central node somehow, instead of relying on node names.
     
  3. General_Cool

    General_Cool
    Expand Collapse

    Joined:
    Jul 29, 2014
    Messages:
    17
    Unfortunately, it seems that the most central node changes based upon the car (vanilla or modded) and using just "v.data.refNodes[0].ref" works on some cars but not on others. Per the documentation, the refnode should be as close to 0,0,0 as possible, but it does not need to be there, and I think that is where the problem lies. Some vehicles do not have it at 0,0,0, and that is creating the issue where it is stereo on some vehicles and mono on others. I may be complicating it and it may just come down to how the hood camera is situated on some cars, not being perfectly centered, and that is actually the issue. Using both "v.data.refNodes[0].ref" and "v.data.refNodes[0].left", while shoddy, does in fact create surround sound (at least on the vehicles I tested with, which were the fullsize, roamer, bastion, and Maxy's CVPI mod). I suppose I could make the left node play a left channel audio track and the ref node play a right channel audio track, but this is still a workaround for something that doesn't seem that complicated, and then I'd be worried with audio glitching on mod vehicles where the refnode is actually slightly left of center or the camera is misaligned (depending on what the actual issue is).

    What is the name of the hood camera node? I think that is a good test option for now. Finding the most central node on each vehicle would take a ridiculous amount of time since this is meant to be a common mod for all vehicles.
     
  4. Agent_Y

    Agent_Y
    Expand Collapse
    Jbeam/QA support
    BeamNG Team

    Joined:
    Jul 10, 2020
    Messages:
    10,553
    Hood camera node is just called hood, it should be in center for all vanilla vehicles. And I still don't get why you need a specific node name. It shouldn't be that hard to figure out an algorithm that searches through all nodes, checks their positions, and picks only the ones where x position is 0, then chooses one to be the node you want based on some other criteria.
     
  5. General_Cool

    General_Cool
    Expand Collapse

    Joined:
    Jul 29, 2014
    Messages:
    17
    Ah, I see what you meant in your original reply now. I wanted to use a specific generic node name (for example, ref, left, back, etc.) because every vehicle, vanilla or modded, has that, meaning there would be no compatibility issues. You say it's not that hard...I just started learning Lua about a week ago. I'll see if ChatGPT has any ideas on how I could get this done. Have you created an algo like that in Lua before?

    UPDATE: You were right...it was pretty easy :p. Playing it from the negative most Z axis and closest to 0 X axis makes it sound perfect on all the vehicles I've just tested. Thank you for pointing me in the right direction.
     
    #5 General_Cool, Nov 2, 2025 at 7:03 PM
    Last edited: Nov 2, 2025 at 7:20 PM
  6. Agent_Y

    Agent_Y
    Expand Collapse
    Jbeam/QA support
    BeamNG Team

    Joined:
    Jul 10, 2020
    Messages:
    10,553
    Well, to get a node with a specific name, you have to iterate over each existing node already. You can check how vanilla scripts do this. And you can do the same thing but instead of checking the name, you check if the X coordinate is 0. That would be good for a start
     
  7. General_Cool

    General_Cool
    Expand Collapse

    Joined:
    Jul 29, 2014
    Messages:
    17
    I ended up scripting it in a way that it takes the lowest Y and highest Y and chooses the one closer to the front of the vehicle but not all the way forward. This makes it so that the siren does not cut to mono from certain camera angles (unless you're really looking for them) while still making it sound like its coming from the front center of the vehicle.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice