CfgSFX

From Bohemia Interactive Community
Revision as of 21:33, 11 March 2017 by Killzone Kid (talk | contribs)
Jump to navigation Jump to search

Description

CfgSFX class is used to configure repeating and random sound effects with range of parameters. Currently sounds from CfgSFX could be played either directly with setSoundEffect command or indirectly with createSoundSource command. The config class can be used in mission config, campaign config or main config. Sound is searched in mission config first, then in campaign config and then in main config.

Class Structure

Each config consists of 2 main entries, the sounds[] param and empty[] param.

class CfgSFX
{
	class Owl
	{
		sound0[] = {"A3\Sounds_F\environment\animals\birds\owl1", db-10, 1.0, 1000, 0.2, 0, 15, 30};
		sound1[] = {"A3\Sounds_F\environment\animals\birds\owl2", db-10, 1.0, 1000, 0.2, 0, 15, 30};
		sound2[] = {"A3\Sounds_F\environment\animals\birds\owl3", db-10, 1.0, 1000, 0.2, 0, 15, 30};
		sounds[] = {sound0, sound1, sound2};
		empty[] = {"", 0, 0, 0, 0, 0, 0, 0};
	};
};

The required sounds[] array contains references to actual sound definitions, the naming of which is not important as long as they match both in the array and in entry. sounds[] can also be an empty array sounds[] = {};. empty[] is required param and serves as fallback sound definition.

Sound Definition Format

The sound definitions as well as empty[] param all have the following format:

{soundPath, soundVolume, soundPitch, maxDistance, probability, minDelay, midDelay, maxDelay}
  • soundPath String - the path to the sound file. In mission config, this is relative to the mission folder
  • soundVolume Number - the standard definition of sound volume
  • soundPitch Number - sound pitch, 1 - normal pitch.
  • maxDistance Number - how far the sound is heard
  • probability Number - how often the sound is chosen randomly. Range (0-1)
  • minDelay, midDelay, maxDelay Numbers - time to wait before playing next sound (or the same sound in the loop). The result is calculated according to Gaussian distribution, see random Alt Syntax

Note that probability is ignored when defined in empty[] param.

How It Works

The probability param is used as weight when calculating which sound to play randomly. The higher the value the more chance for the sound to be selected. If no sound is selected from sounds[], the sound defined in empty[] is played. Once the sound is selected, it is played and the next sound then queued to play after set delay is up.

time to next sound = duration of current sound + random delay

If delay is negative, the sound will not play until the end (depending on the value of negative delay) and next sound will start immediately after. It is possible to have just empty[] sound defined, in which case it will be repeated over and over with set delay. Delay only matters after 1st sound is played, when CfgSFX sound is started for the first time, there is no delay.

Multiplayer

The next sound is chosen randomly on each computer, therefore in multiplayer each client may hear different sounds.