WiseSoundCast: HL2 Digital Sound

From Valve Developer Community
Jump to navigation Jump to search


This tutorial was originally created by wisemx. It was originally posted on SDKnuts.net.

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:

  1. 5.1 surround sound, 4 speaker surround
  2. High-quality 3D spatialization
  3. Custom software DSP
  4. Automatic DSP based on environmental geometry
  5. ADPCM decompression
  6. 16-bit 44KHz, stereo wave data with all features
  7. MP3 decompression
  8. Support for audio streaming
  9. Real-time wav file stitching
  10. Pre-authored Doppler Effect encoded wav
  11. Pre-authored distance variant encoded wav

Ways to control DSP in HL2:

  1. dsp_off [0,1] - If set to 1, disables DSP. This may improve performance (cheat), but will reduce the richness of audio effects.
  2. dsp_enhance_stereo [0,1] - If set to 1 enhances the stereo effect, making sound richer and more atmospheric for a slight performance hit.
  3. dsp_slow_cpu [0,1] - If set to 1, reduces the quality of DSP effects, improving performance on systems with slower CPUs.
  4. 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.
  5. snd_profile [0,1] - If set to 1, shows DSP usage stats in the console.
Tip.pngTip:We at the VDC recommend you do not hurt your ears by setting dsp_volume extremely 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?

WiseSoundCast setup.png

Notice there is 6 sets of game_text, logic_relay and env_microphone. One set for each of the DSP presets used in this project.

  1. Default
  2. Speaker, Louder
  3. Speaker very small
  4. Loudspeaker, Echo
  5. Speaker small
  6. 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_text entities are used to display the DSP preset name to the player. Each logic_relay is used to enable and disable the env_microphone entities as needed and to display the text. The speaker for playing sounds picked up by env_microphone in this project is a simple info_target.

Note.pngNote:Do not use an env_speaker for this.

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.

See also