BF2.US bf2-rsdeveloper wiki Parity Discord bf2.us
On this page

What goes into a sound

A sound is a template in the object's CON tree that names a sample file and says how to play it: how loud, how high, how far it carries, and how pitch and volume follow a game value such as the engine's revs.

BF22142Heroes

The template#

The jeep's tree holds 42 Sound templates as children of its parts (see the object tree). Their properties sit in the tweak:

Objects/Vehicles_server.zip bri_jeep_willys/bri_jeep_willys.tweak (retail, S_Willys_Engine_Idle)
ObjectTemplate.soundFilename "Sound\West\Vehicles\English\Jeep\West_SFX_Vehicle_GB_JEP_Bri_Jeep_Willys_StartIdleStop_01.wav"
ObjectTemplate.loopCount 0
ObjectTemplate.volume 0.7
ObjectTemplate.pitch 1.2
ObjectTemplate.pitchEnvelope 0/1/0/1.5/0/2/0.0/0.7/0/1/1.5/0/
ObjectTemplate.volumeEnvelope 0/1/0/1/0/3/0/1/0/0.5/1/0/1/1/0/
ObjectTemplate.minDistance 6
ObjectTemplate.halfVolumeDistance 20

bf2-audio template.rs models the template (SoundTemplate: BF2.exe's ObjectTemplate.Sound plus the BF2Audio.dll Sound it forwards to); its setters clamp and derive the attenuation the way the DLL does (set_min_distance, set_half_volume_distance, recompute).

The samples#

The jeep's three WAV samples and a music Ogg, as the engine loads them. StartIdleStop has loop points: the engine keeps it as a start block, a loop block and an end block.
The jeep's three WAV samples and a music Ogg, as the engine loads them. StartIdleStop has loop points: the engine keeps it as a start block, a loop block and an end block.

bf2-audio soundfile.rs load reproduces SoundFile::load of BF2Audio.dll:

  • WAV files are static: fully loaded, split into up to three buffers by the file's loop points (start block, loop block, end block). Above the quality level's rate cap (44100 / 22050 / 11025 Hz) they are decimated by an integer factor without filtering and keep only the first channel.
  • Ogg Vorbis files stream. bf2-vorbis is a bit-exact port of the libvorbis 1.0 decoder linked into BF2Audio.dll, down to its x87 precision: sample streams decode on the main thread at 24-bit precision, music on the music thread at 53-bit (SoundFile::pcm_at).

Heroes keeps BF2's choice: effects as WAV (Sound_client.zip West/...), music as Ogg (Music/*.ogg).

Envelopes#

The jeep engine's three layers against the revs: Idle stays at full volume, Rpm1 and Rpm2 fade in over the first 5-10 % of the revs; every layer's pitch rises with them (Idle 0.7 to 1.5, the rpm layers 0.25 to 1.0).
The jeep engine's three layers against the revs: Idle stays at full volume, Rpm1 and Rpm2 fade in over the first 5-10 % of the revs; every layer's pitch rises with them (Idle 0.7 to 1.5, the rpm layers 0.25 to 1.0).

An envelope string is xmin/xmax/ymin/ymax/random/count/ followed by count points x/y0/y1/ (bf2-audio envelope.rs EnvelopeSpec::parse, BF2.exe 0x007e4dd0). The control value comes from the game (an engine's rpm, a rotation speed); Envelope::eval interpolates linearly between the points and holds the end values outside them. With random set, 64 variants are precomputed from the C runtime's rand() and each loop of the sound picks one. The curves above are Envelope::eval samples, not a re-implementation.

3D settings#

LineMeaning
minDistancefull volume up to this distance (m)
halfVolumeDistancethe distance at which the volume has halved; the falloff curve follows from the two
soundRadius, coneInnerAngle, coneOuterAngle, coneOuterVolumesize of the source and directional cones
volumeGroupthe volume group the sound settings scale

The derived attenuation and the cone are bf2-audio template.rs (recompute_in, has_cone).

How it is tested#

  • Every shipped sound decodes (crates/bf2-audio/tests/retail_sounds.rs): every wave, Ogg and EAX file of an install, with the original's rules.
  • The Ogg decoder against the original's (crates/bf2-vorbis/tests/synthetic.rs): 300 generated streams covering the format's floors, residues and block sizes must decode as the original's decoder does.
  • Engine sounds (engine_sound_oracle.rs): 400 generated scenarios through the original's engine and rotation sound code, compared as a trace; run again in a 2142 process.

What a sound template does in play is on the sound engine and voices and space.

In the code#

WhatWhere
sound templates, the rolloff, the conecrates/bf2-audio (template.rs, math)
Ogg Vorbis decodingcrates/bf2-vorbis
voices, priority and stealingcrates/bf2-audio (voices and space)
radio lines and soldiers' voicescrates/bf2-audio (voice; radio)
the mixer of the browser clientcrates/bf2-audio-worklet
Source: docs/dev/assets/sound.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.