CSound
Header: include/sound.hpp
Implementation:
src/sound.cpp (DirectSound backend) and
src/soundbass.cpp (BASS backend, optional)
CSound is the audio system class. It loads and plays background music
and positional sound effects from .blp files in
gamefiles/SOUND/. Two backends are available, selected at compile time
via the _BASS flag.
Backends
| Backend | Flag | Source file | Status |
|---|---|---|---|
| DirectSound / MCI | _BASS=FALSE (default) |
src/sound.cpp |
Done |
| BASS + BASSMIDI | _BASS=TRUE |
src/soundbass.cpp |
WIP |
To switch backends, change #define _BASS in include/def.hpp
and rebuild. See Compile Flags.
DirectSound Backend
The default backend wraps DirectSound from DirectX 3. Via Free Direct / Free API, DirectSound calls are translated to SDL3_mixer.
- Loads
.blpsound files viasrc/wave.cpp(WAV parsing) - Supports 3D positional audio: sounds play louder when the source is near the player
- Vehicle sounds (helicopter, jeep) loop and change pitch based on movement state
- Music uses the MCI (Media Control Interface) path for
MUSIC*.blpfiles
BASS Backend
Implemented in src/soundbass.cpp using the BASS and BASSMIDI libraries
located in the bass/ subdirectory.
- MIDI music support via BASSMIDI
- Alternative to DirectSound for higher quality audio on non-Windows builds
Music
10 background music tracks are stored as MUSIC000.blp through
MUSIC009.blp. The track for each level is defined in
DescFile::music (0–9) and loaded when the level starts.
Music stops and restarts when transitioning between regions.
Sound Effects
93 sound effect files: SOUND000.blp through SOUND092.blp.
Filenames on disk have mixed case (e.g., Sound027.blp); the index directly
maps to the SOUND_* constant.
See Sound Effects Reference for the
complete SOUND_* constant table.
Key Methods
Full signatures from include/sound.hpp:
// Lifecycle
BOOL Create(HWND hWnd);
void SetState(BOOL bState);
BOOL GetEnable();
void Flush(int channel); // unload one channel
void CacheAll(); // preload all sound channels
BOOL Cache(int channel, char* pFilename);
// Volume
void SetAudioVolume(int volume);
int GetAudioVolume();
void SetMidiVolume(int volume);
int GetMidiVolume();
// Music
BOOL PlayMusic(HWND hWnd, int music);
BOOL RestartMusic();
void SuspendMusic();
void StopMusic();
BOOL IsPlayingMusic();
void SetSuspendSkip(int nb);
// Sound effects (positional)
BOOL Play(int channel, int volume = 0, int pan = 0);
BOOL PlayImage(int channel, POINT pos, int rank = -1); // called from CDecor/CEvent
BOOL StopSound(int channel);
PlayImage(),
not PlaySound(). The name is inherited from the original codebase.
CDecor calls it as m_pSound->PlayImage(SOUND_*, pos, rank).