Module veloren_voxygen::audio::sfx

source ·
Expand description

Manages individual sfx event system, listens for sfx events, and requests playback at the requested position and volume

Veloren’s sfx are managed through a configuration which lives in the codebase under /assets/voxygen/audio/sfx.ron.

If there are errors while reading or deserialising the configuration file, a warning is logged and sfx will be disabled.

Each entry in the configuration consists of an SfxEvent item, with some additional information to allow playback:

  • files - the paths to the .wav files to be played for the sfx. minus the file extension. This can be a single item if the same sound can be played each time, or a list of files from which one is chosen at random to be played.
  • threshold - the time that the system should wait between successive plays. This avoids playing the sound with very fast successive repetition when the character can maintain a state over a long period, such as running or climbing.

The following snippet details some entries in the configuration and how they map to the sound files:

Run(Grass): ( // depends on underfoot block
   files: [
       "voxygen.audio.sfx.footsteps.stepgrass_1",
       "voxygen.audio.sfx.footsteps.stepgrass_2",
       "voxygen.audio.sfx.footsteps.stepgrass_3",
       "voxygen.audio.sfx.footsteps.stepgrass_4",
       "voxygen.audio.sfx.footsteps.stepgrass_5",
       "voxygen.audio.sfx.footsteps.stepgrass_6",
   ],
   threshold: 1.6, // travelled distance before next play
),
Wield(Sword): ( // depends on the player's weapon
   files: [
       "voxygen.audio.sfx.weapon.sword_out",
   ],
   threshold: 0.5, // wait 0.5s between plays
),
...

These items (for example, the Wield(Sword) occasionally depend on some property which varies in game. The SfxEvent documentation provides links to those variables, some examples are provided her for longer items:

// An inventory action
Inventory(Dropped): (
    files: [
       "voxygen.audio.sfx.footsteps.stepgrass_4",
   ],
   threshold: 0.5,
),
// An inventory action which depends upon the item
Inventory(Consumed(Apple)): (
   files: [
       "voxygen.audio.sfx.inventory.consumable.apple",
   ],
   threshold: 0.5
),
// An attack ability which depends on the weapon
Attack(DashMelee, Sword): (
    files: [
        "voxygen.audio.sfx.weapon.sword_dash_01",
        "voxygen.audio.sfx.weapon.sword_dash_02",
    ],
    threshold: 1.2,
),

Modules§

Structs§

Enums§

Constants§

  • We watch the states of nearby entities in order to emit SFX at their position based on their state. This constant limits the radius that we observe to prevent tracking distant entities. It approximates the distance at which the volume of the sfx emitted is too quiet to be meaningful for the player.

Functions§