Table of Contents

Sound Sets

Sound sets are configuration files that group several sounds together to get an appropriate sound background. This is used e.g. for vehicles. The sound sets are defined in .snd.lua files. They need to have a data() function that returns a data struct like below:

function data()
  return {
    tracks = { ... },
    events = { ... },
    updateScript = {
      fileName = "::/scripts/soundset_default.script@updateSoundSet",
      params = { ... },
    },
  }
end

The sound set data struct has three properties:

Tracks are looped sounds, whereas events are only played once per trigger.

Update Script

The script function referenced with updateScript receives three parameters:

The function is expected to call the two functions provided by the soundTransfOutput:

Soundset Util

To facilitate the creation of soundsets, there is a soundsetutil that is used in most sound sets. Therefore the effective structure of the sound set files is mostly like this:

local soundsetutil = require "/scripts/soundsetutil.lua"
 
function data()
  local data = soundsetutil.makeSoundSet()
 
  soundsetutil.addTrackParam01(
    data, "vehicle/tram_old/drive.wav", 18.0,                 
    { { .0, .0 }, { .1, .32 }, ... }, { { .0, 1.0 } }, {"vehicle", "speed01"} 
  )	
  ...
 
  soundsetutil.addEvent( data, "openDoors", { "vehicle/tram_old/bell.wav" }, 5.0 )
  ...
 
return data
end

The soundsetutil.lua provides a couple of functions that can be used:

makeSoundSet

The soundsetutil.makeSoundSet() function is the basic function that sets up the internal structure of the soundset for the use of other util functions. It is required to be used before the other functions.

addEvent

The soundsetutil.addEvent(data, key, names, refDist) function is used to add an unconditionally event to the sound set. The parameters are:

If there is more than one sound file referenced, one is chosen randomly.

addEventParam01

The soundsetutil.addEventParam01(data, key, names, refDist, gainCurve, pitchCurve, infoAndParamGain, infoAndParamPitch) function is used to add an event to the sound set in dependence of input conditions. The parameters are:

addTrackParam01

The soundsetutil.addTrackParam01(data, name, refDist, gainCurve, pitchCurve, infoAndParamGain, infoAndParamPitch) function is used to add a track to the sound set in dependence of input conditions. The parameters are:

addSimpleTrackParam01

The soundsetutil.addSimpleTrackParam01(data, name, refDist, infoAndParamGain) function is a simplified version of the function above. Pitch is constant at level 1, while gain is equal to the input value. The parameters are:

addTrackSqueal

The soundsetutil.addTrackSqueal(data, name, refDist) function is a specialised function to add a track in dependance of the speed and side force. It usually can be heared when a train drives over switches. The parameters are:

addTrackBrake

The soundsetutil.addTrackBrake(data, name, refDist, maxGain) function is a specialised function to add a track in dependance of the speed and brake intensity. It usually can be heared when a vehicle decelerates. The parameters are:

addEventClacks

The soundsetutil.addEventClacks(data, names, refDist, axleRefWeight) function is a specialised function to add an event in dependance of the speed, weight and number of axles. It usually can be heared as small clack sounds when a train runs along tracks and the wheels run over imperfect welding seams or screwed track ends. The more weight lasts on an axle, the louder the sounds can be heared. The parameters are:

addTrackCustom

The soundsetutil.addTrackCustom(data, name, refDist, gainCurve, pitchCurve, infoAndParamGain, infoAndParamPitch, customUpdateScript) function is used to add a track with a custom update function to the sound set. The parameters are:

A custom update function receives the following parameters:

The content/vehicle/bus/shared/sound/bus_electric.snd.lua sound set is an example using this function to restrict a track to only play during acceleration and not during deceleration.

addEventCustom

The soundsetutil.addEventCustom(data, key, names, refDist, gainCurve, pitchCurve, infoAndParamGain, infoAndParamPitch, customUpdateScript) function is used to add an event with a custom update function to the sound set. The parameters are:

A custom update function for events receives the following parameters:

The trigger flag should be true only one frame, otherwise the sound will be triggered multiple times in short succession. Hence it is good to use transitions between previous and current state to be precise.

makeRoadVehicle2

The soundsetutil.makeRoadVehicle2(data, speeds, idle, idleSpeed, idleGain0, drive, driveSpeed, refDist, infoAndParamGain, infoAndParamPitch) function is a specialized function to add sounds for a road vehicle. The parameters are:

makeSteamTrain

The soundsetutil.makeSteamTrain(data, idle, fast, tracksRefDist, chuffNames, chuffsRefDist, chuffsFastFreq, refWeight) function is a specialised function to add sounds for a steam engine. The parameters are:

Event Keys

Depending on the type of object, there are several keys available for the sound events defined in sound sets:

Event Key Town Buildings Stations Industries Road Vehicles Rail Vehicles Water Vehicles Air Vehicles Description
"random<n>" ✔ ✔ ✔ occurs approx. every n seconds (n is one of 1, 2, 4, 8, 16, 32, 64)
"openDoors" ✔ ✔ ✔ ✔ occurs after arrival at a station
"closeDoors" ✔ ✔ ✔ ✔ occurs before departure from a station
"horn" ✔ ✔ occurs at station departure
"clacks" ✔ occurs regularily while moving (for axle clacks)
"chuffs" ✔ occurs regularily while moving (for steam chuffs)
"sonicBoom" ✔ occurs when speed gets larger than the speed of sound
"land" ✔ occurs when the weels touch the ground

Adding custom events is currently only supported through triggers from edge objects.