Monday, April 27, 2009

Sound Served

At work I played around with our sound server and sound messaging and I was excited to get variable engine sounds working working. When we first started doing sound on the PC, the system couldn't keep up with the simulation and play the sound at sync. None of us had any sound programming experience and could not get it to work well. We had some balancing issues so we made a sound server that could run on a remote machine where the processor wasn't consumed. This was good for a lot of reasons, but ultimately is ugly today IMO because it adds complexity and lots of messaging. Hopefully I can integrate sound directly into our simulation this summer. Meanwhile, since we are simulating some boats I added the ability to control volume and pitch and volume on indexed sounds that are attached to vehicles, and send messages with the corresponding values. The code looks something like this.

pitch = 0.75 + 0.5*currentSpeed/maxSpeed;
volume = 0.50 + 0.5*currentSpeed/maxSpeed;

//send message "vehicle index soundname x y z h p r volume pitch"

Its pretty simple and it works quite well. Essentially as the vehicle increases in speed the volume and pitch of the motor sound increases. It proved the concept, which I'm sure is how some games do it. Next I want to add an idling sound and modify it something like this.

if currentSpeed < 0.25*maxSpeed {
volumeIdle = 1.0 - 1.0/0.25*currentSpeed/maxSpeed; //goes from 100% to 0%
volumeEngine = 0.5 + 1.0*currentSpeed/maxSpeed; //this should max at 0.75
}
else{
volumeIdle = 0.0;
volumeEngine = 0.75 + 0.25*currentSpeed/maxSpeed;
}
pitch = 0.75 + 0.5*currentSpeed/maxSpeed;

//send message "vehicle index soundnameIdle x y z h p r volume pitch"
//send message "vehicle index soundnameEngine x y z h p r volume pitch"

This should let the engine idle sound be heard when the vehicle is not moving, or moving very slow. I don't know if this will work, but I bet with some tweaking it will sound ok.

Also, since this is for a boat it makes sense as there is no shifting or gears; the engine just ramps up. But if I want to apply this to another type of vehcile with a more complicated engine, it could be modified this:

pitch = 0.5 + 0.25*gear + 0.75*currentSpeed/maxSpeed;
volume = 0.5 + 0.75*gear + 0.25*currentSpeed/maxSpeed;

Where gear is used to make the sounds see-saw some for that vroom-vrooooom-vrooooom sound of changing gears.


No comments: