WiseSoundCast: HL2 Digital Sound
This tutorial was originally created by wisemx.
In this project we’ll use a Microphone in HL2 to alter the sound in a room and play that sound in another room far away with a variety of DSP filters.
What is DSP?
DSP, Digital Signal Processing is the science of using computers to understand and even alter types of media. There are a wide variety of methods: Filtering, Speech/Voice Recognition, Image Manipulation/Enhancement, Compression, etc. Back in the late 80’s Milan Spirko and I created a Voice Recognition system for the Hofu Japan Mazda plant. At that time DSP was brand new and there were very few resources available. The system we designed used a small PC/FM unit that could be worn on a belt and relay information that was collected from a person’s voice, digitally, through the air, (via FM signals), to a network that would then filter the digital signals and compare them to phonetics the network systems had been trained to understand. It wasn’t perfect but it worked very well for the time. DSP in HL2 works very much the same way as the initial systems mentioned above however it does a much better job and does not need to be trained.
You can record sounds in WAV and MP3 formats and play them back in HL2 with DSP filters. In this project I’m using Breen’s Instinct speech from HL2. We’ll have Breen talk as we switch to and from a variety of Microphones with DSP filters.
Sound supported in the HL2 Source Engine:
- 5.1 surround sound, 4 speaker surround
- High-quality 3D spatialization
- Custom software DSP
- Automatic DSP based on environmental geometry
- ADPCM decompression
- 16-bit 44KHz, stereo wave data with all features
- MP3 decompression
- Support for audio streaming
- Real-time wav file stitching
- Pre-authored Doppler Effect encoded wav
- Pre-authored distance variant encoded wav
Ways to control DSP in HL2:
dsp_off [0,1]- If set to
1, disables DSP. This may improve performance (cheat), but will reduce the richness of audio effects.
dsp_enhance_stereo [0,1]- If set to
1enhances the stereo effect, making sound richer and more atmospheric for a slight performance hit.
dsp_slow_cpu [0,1]- If set to
1, reduces the quality of DSP effects, improving performance on systems with slower CPUs.
dsp_volume [volume]- Determines the volume of the background DSP effects. If the volume is increased, the impact of DSP enhancement will be exaggerated with no performance impact.
snd_profile [0,1]- If set to
1, shows DSP usage stats in the console.
dsp_volumeextremely high because it will hurt your ears.
Shown below are the entities used to control the sound in this project. It does look rather busy doesn’t it?
- Speaker, Louder
- Speaker very small
- Loudspeaker, Echo
- Speaker small
- Speaker tiny
The DSP preset Speaker very small only played silence on my system. I looked through the SDK source code and couldn’t find the DSP settings for each of the Speaker DSP Presets so I don’t know why setting #7 wouldn’t work. (Porter's note: I also could not find it. Very weird.)The
game_textentities are used to display the DSP preset name to the player. Each
logic_relayis used to enable and disable the
env_microphoneentities as needed and to display the text. The speaker for playing sounds picked up by
env_microphonein this project is a simple
The player spawns in a small cube 3,241 units away from the room Breen and the mics are in. Inside that small cube is the
info_target that plays the sounds picked up by the mics. As the Player stands there the DSP preset name will be displayed on the screen. When you adjust the flags for your
env_microphone checking the flag Swallows sounds routed through speakers will cause your NPC’s to speak but not from their own mouths. Breen will be heard but his lips will not move if that flag is checked.
The download for this project contains the vmf and the bsp. For a closer look at each of the properties used in this project load the vmf in Hammer and experiment with the methods and properties. Add a few more sounds, turn on
noclip and watch Breen, that’s why I left the light on.