Can you have custom airbrake sounds?

Discussion in 'Programming' started by MrRadYT, Oct 18, 2024.

  1. MrRadYT

    MrRadYT
    Expand Collapse

    Joined:
    Jan 18, 2023
    Messages:
    221
    Hi, I'm working on a bus mod for BeamNG, and would like to change the airbrake sounds to my own. It says on this beamng documentation that airbrakes can have their own custom sound event, but I tried it with my custom sound, and it didn't work. I checked out the lua from the game's folder and it does allow this to be changed, so why isn't it working for me? And yes, the files are compatible with the game, because my custom air suspension sound and buzzer sound all work, so it's not an issue with the file format. Also, the sounds are .wav, but I converted it to .ogg to see if that was the issue, but it wasn't

    This is my code. It should be working. I tried putting sound event where the controller is too and it didn't work either. upload_2024-10-18_17-43-16.png

    Any help would be appreciated. Thanks!
     
    #1 MrRadYT, Oct 18, 2024
    Last edited: Oct 18, 2024
  2. MrRadYT

    MrRadYT
    Expand Collapse

    Joined:
    Jan 18, 2023
    Messages:
    221
    Bump! Can anyone help?
     
  3. DaddelZeit

    DaddelZeit
    Expand Collapse

    Joined:
    Jul 17, 2019
    Messages:
    3,462
    This is actually completely normal behaviour. A sound event is an FMOD Designer sound event, which gives more control over the sounds and allows linking: e.g. a starting audio and then a loop.
    These FMOD sounds are managed by the C++ engine from the .bank files and can, as far as I know due to Torque3D's initial design, be played directly. Other sounds from files require their own object which the Lua code usually creates via obj:createSFXSource and obj:createSFXSource2, respectively.
    Unlike what the function name might have you assume, this actually creates an SFXProfile and not an SFXSource. No idea why.

    Anyways, this step is typically already included in most code files that play audio files, however the airbrakes.lua file does not do this and instead uses the event directly.
    That might work fine for the devs, but not for modders: as soon as this soundEvent value is no longer a valid event or SFXProfile, or an object with that name does not exist at all, the playSFX API fails.



    So, what we need is a profile. This can be created by a managing Lua script, but for our case this is too complicated and gives just a bit more Lua overhead to the game that we just do not need.
    Instead, you can let a *.materials.json file create the SFXProfile datablock. To actually use that profile, enter the name of the object as the soundEvent.

    Code:
    {
      "customAirBrakeSound": {
        "name": "customAirBrakeSound",
        "class": "SFXProfile",
        "persistentId": "b0b0b411-7180-4da3-af0b-7550dec2f5b3",
        "description": "AudioDefault3D",
        "filename": "/art/air_brake1.wav"
      }
    }
    These JSON files can spawn any object you want, not just materials: you can create new particles or solid meshes via these.



    Now, this alone only lets you play a single sound. Events often play a random sound from a list when triggered.
    You can re-create this with an SFXPlaylist object by using the name of this object as the soundEvent:
    Code:
    {
      "customAirBrakeSound1": {
        "name": "customAirBrakeSound1",
        "class": "SFXProfile",
        "persistentId": "b0b0b411-7180-4da3-af0b-7550dec2f5b1",
        "description": "AudioDefault3D",
        "filename": "/art/air_brake1.wav"
      },
      "customAirBrakeSound2": {
        "name": "customAirBrakeSound2",
        "class": "SFXProfile",
        "persistentId": "b0b0b411-7180-4da3-af0b-7550dec2f5b2",
        "description": "AudioDefault3D",
        "filename": "/art/air_brake2.wav"
      },
      "customAirBrakeSound3": {
        "name": "customAirBrakeSound3",
        "class": "SFXProfile",
        "persistentId": "b0b0b411-7180-4da3-af0b-7550dec2f5b3",
        "description": "AudioDefault3D",
        "filename": "/art/air_brake_hard_1.ogg"
      },
      "customAirBrakeSound4": {
        "name": "customAirBrakeSound4",
        "class": "SFXProfile",
        "persistentId": "b0b0b411-7180-4da3-af0b-7550dec2f5b4",
        "description": "AudioDefault3D",
        "filename": "/art/air_brake_hard_2.ogg"
      },
      "customAirBrakeSound5": {
        "name": "customAirBrakeSound5",
        "class": "SFXProfile",
        "persistentId": "b0b0b411-7180-4da3-af0b-7550dec2f5b5",
        "description": "AudioDefault3D",
        "filename": "/art/air_brake_hard_3.ogg"
      }
    }
    
    Code:
    {
      "customAirBrakeSound": {
        "name":"customAirBrakeSound",
        "class":"SFXPlayList",
        "persistentId": "b0b0b411-7180-4da3-af0b-7550dec2f5b0",
        "description":"AudioDefault3D",
        "random":"StrictRandom",
        "numSlotsToPlay": 1,
        "slots": [
          {
            "track":"customAirBrakeSound1",
            "volumeScale": 4
          },
          {
            "track":"customAirBrakeSound2",
            "volumeScale": 4
          },
          {
            "track":"customAirBrakeSound3",
            "volumeScale": 4
          },
          {
            "track":"customAirBrakeSound4",
            "volumeScale": 4
          },
          {
            "track":"customAirBrakeSound5",
            "volumeScale": 4
          },
          {},
          {},
          {},
          {},
          {},
          {},
          {},
          {},
          {},
          {},
          {}
        ]
      }
    }
    Note that these are two files: the bottom one needs to load after the top one. You can use a *_stage1.materials.json, *_stage2.materials.json, etc. format as the loading happens in alphabetical order.




    upload_2024-12-1_14-56-32.png

    The SFXPlaylist object also gives you a lot more controls for the sounds themselves which you can use:
    upload_2024-12-1_14-31-29.png
    However, one playlist can only support up to 16 tracks. You can chain playlists together by using one as a track in a slot, but the random number generator will not account for the additional slots.
    If you want to use different sounds for different intensities, that is a different question and would require modifying the airbrake Lua code.
     
    • Like Like x 3
  4. MrRadYT

    MrRadYT
    Expand Collapse

    Joined:
    Jan 18, 2023
    Messages:
    221
    Wow, I was not expecting that. I will try later when I get back to my PC. Does this work for the handbrake sounds or with the indicator sounds too? Because with the handbrake sound, It just doesn't work, and when calling upon the indicator start and stop events, they loop rather than one shot, or play once.

    Could this also be used for custom sounds of screeching brakes when braking?

    Thread link for screenshots:
    https://www.beamng.com/threads/i-need-some-help-with-custom-soundscapes.101748/

    Thank you for all of your help anyway, I never thought someone would know if it requires internal code
     
    #4 MrRadYT, Dec 1, 2024
    Last edited: Dec 2, 2024
  5. DaddelZeit

    DaddelZeit
    Expand Collapse

    Joined:
    Jul 17, 2019
    Messages:
    3,462
    Yes, use the SFXProfile name for those. Using this method works around the looping issue, too.
    Yes, although a file path should work fine for that. Just add "brakeSquealLoop" to the pressureWheels section.
     
  6. MrRadYT

    MrRadYT
    Expand Collapse

    Joined:
    Jan 18, 2023
    Messages:
    221
    Hey there again! I know this is random, but will this work for the gearbox input whine event too? Currently I use a single sample that loops and is modulated by the engine RPM for each gear, but the way the gearbox that I am trying to recreate sounds in real life, it has a different timbre depending on RPM, such as high RPM, theres more of a screaming sound. So can this SFXProfile create an event for the ZF sound depending on the RPM of the gearbox input?
    upload_2025-1-3_19-40-22.png
    I know the photo isn't what you'd do, but its an example of what I mean?
     
  7. MrRadYT

    MrRadYT
    Expand Collapse

    Joined:
    Jan 18, 2023
    Messages:
    221
    Forgot to ask too, but can this be used to change the sample used for the output shaft (hub, axle, differential etc) on the gearbox depending on the speed that the vehicle is travelling?

    For example, start with a kind of muffled tone at low speeds, and then change the sample to a less muffled tone where there is more high frequencies at speeds around 40-60kmh, and then switch to a sample that has less of a volume at 65kmh+?

    It sounds advanced, but it would be good if it can be done. It would make my sound mods way more realistic. I am trying to make the sounds for the W3A more realistic in my transmission pack.

    Thanks for all of your help!
     
  8. DaddelZeit

    DaddelZeit
    Expand Collapse

    Joined:
    Jul 17, 2019
    Messages:
    3,462
    Unfortunately no, this doesn't let you blend between samples without doing so manually with Lua logic. You're still limited by that.
     
  9. MrRadYT

    MrRadYT
    Expand Collapse

    Joined:
    Jan 18, 2023
    Messages:
    221
    Damn. That sucks. How hard would the lua scripting be for that? Probably very hard because you'd need to rewrite the whole sound engine right? There's no way to use FMod editor to create custom events and banks too is there?

    But, just quickly, is there a script to switch the automatic gearbox to neutral once the speed reaches 5kmh and there's no throttle being applied? I'm trying to emulate the NBS feature on a ZF Gearbox, where it switches to neutral once the bus is stopped. I tried asking in the discord but no reply
     
  10. MrRadYT

    MrRadYT
    Expand Collapse

    Joined:
    Jan 18, 2023
    Messages:
    221
    Hey there! I tried this, and unfortunately it didnt work. I even tried taking the coef from the Covet's race brakes and it still doesnt work. The actual airbrakes sound works fine though
    upload_2025-1-14_15-11-45.png
     
  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