modding:developerinfo:soundsets

Sound sets

Overview

A sound set specifies a set of audio files and how their gain/pitch should be modified when played, depending on some input values. They are stored in .lua files in the folder res\config\sound_set\.

The file has the following format:

function data()
return {
  -- specify resources
  tracks = {
    { name = "vehicle/ship/engines.wav", refDist = 25.0 },	
  },
  events = {
    horn = { names = { "vehicle/ship/horn.wav" }, refDist = 50.0 },	
  },
 
  -- update function: here you can modify gain/pitch, depending on input
  updateFn = function (input)
    return {
      tracks = {
        { 
          gain = soundeffectsutil.sampleCurve({ { 0.0, 0.8 }, { 1.0, 1.0 } }, input.power01),
          pitch = soundeffectsutil.sampleCurve({ { 0.05, 0.8 }, { 1.0, 1.1 } }, input.power01)
        },			
      },
      events = {
        horn = { gain = 1.0, pitch = 1.0 },			
      }
    }
  end
}
end

Tracks

A track consists of a file name and following attributes:

  • gain: ground level, will be multiplied with gain resulting in updateFn
  • refDist: reference distance
  • rolloffFact: roll off factor
  • hasVelocity: indicates whether source is moving
{ name = "vehicle/ship/engines.wav", gain = 0.9, refDist = 25.0, rolloffFact = 1.0, hasVelocity = true },

Events

An event is defined by its key word (see below for a reference). You can specify a list of audio files and the same attributes as for tracks. Every time the event is triggered, an audio file is randomly picked from the list.

clacks = {
  names = {
    "vehicle/clack/modern/part_1.wav",
    "vehicle/clack/modern/part_2.wav",
    -- as many as you want...
  },
  refDist = 15.0,
  -- other attributes
},

Update function

In this function you can modify the gain/pitch of the audio sources, depending on input. In the above example a ships engine sound is implemented by altering the gain/pitch of an engine sound source depending on its power output.

Note: the number of entries in the table tracks on top of the file has to match the number of entries in the table tracks in updateFN. The same holds for events.

Reference

In the following you can find for each model type, that can emit audio, a complete list of available input parameters and event keys.

Parameters with Appendix 01 are normalized to be between 0 and 1.

Aircrafts

Input parameters

  • speed
  • topSpeed
  • speed01
  • powerOutput
  • power
  • powerIdle
  • power01

Events

  • land
  • sonicBoom

Rail vehicles

Input parameters

  • speed
  • topSpeed
  • speed01
  • weight
  • brakeDecel
  • powerOutput
  • power
  • power01
  • chuffStep
  • curveRadius
  • curveSpeedLimit
  • sideForce
  • maxSideForce
  • numAxles
  • axleRefWeight
  • gameSpeedUp

Events

  • chuffs
  • clacks
  • horn
  • openDoors/closeDoors

Road vehicles

Input parameters

  • speed
  • topSpeed
  • speed01

Events

  • openDoors/closeDoors

Ships

Input parameters

  • speed
  • topSpeed
  • speed01
  • powerOutput
  • power
  • power01

Events

  • horn

Constructions

Input parameters

Industry: production01, level.

Stations: crowd01, crowd, cargo01, cargo, terminals.

Town buildings: underConstruction.

Events

Constructions trigger random events at different frequencies, which can be used to play arbitrary sound sources regularly. They are named randomX, where X is a number between 1 and 64. For example random16 is an event, triggered randomly at an average frequency of 16 seconds.

Soundeffectsutil

Transport Fever provides a number of scripts with utility functions. The soundeffectsutil.lua contains functions for creating soundsets:

  • sampleCurve(nodes,x)
  • makeRoadVehicle2(speeds, idleSpeed, idleGain0, driveSpeed, speed01)
  • squeal(speed, sideForce, maxSideForce)
  • chuffs(speed, chuffStep, chuffsFastFreq, weight, refWeight)
  • clacks(speed, weight, numAxles, axleRefWeight, gameSpeedUp)
  • brake(speed, brakeDecel, maxGain)

Some of these functions are described below.

makeRoadVehicle2(speeds, idleSpeed, idleGain0, driveSpeed, speed01)

This function provides gain and pitch curves for a two track sound set of a motorized road vehicle. The first track is for the idle sound, the second one for the drive sound. The function requires the following parameters:

  • speeds: a list of 3 speed fractions between 0 and 1 to determine the “keyframes” for the sound curves.*
  • idleSpeed: parameter for the pitch of the idle noise
  • idleGain0: parameter for the gain of the idle noise
  • driveSpeed: parameter for the pitch of the drive noise
  • speed01: speed parameter (usually input.speed01)

* The three values are used for:

  1. point at which the idle noise can be heard at full volume
  2. point at which the driving noise starts and the idle noise subsides
  3. point at which only the driving noise can be heard at full volume

An exemplary call to this function:

soundeffectsutil.makeRoadVehicle2({ .05, .1, .3 }, .075, .6, .4, input.speed01),

squeal(speed, sideForce, maxSideForce)

This function provides a gain and pitch value depending on the current side force of a rail vehicle. An exemplary call to this function:

soundeffectsutil.squeal(input.speed, input.sideForce, input.maxSideForce),
modding/developerinfo/soundsets.txt · Last modified: 2019/06/24 15:58 by yoshi