Game Development Community

Panning sounds

by Jason McIntosh · in Torque Game Builder · 04/20/2005 (8:37 pm) · 7 replies

So, has anyone figured out how to add support for panning sounds in 2D? Fading sounds would also be nice. :)

Just curious if anyone knows where to begin with this. Thanks!

#1
04/20/2005 (10:49 pm)
Yeah, it'd be cool to assign a sound to an object and have the X location dictate the stereo location of the sound. I don't know of it's possible or impossible, but if it's not in the engine, I'm definitely suggesting it.
#2
04/21/2005 (4:16 pm)
By stereo location I assume you mean balance to left/right speakers? Although I guess many pc's are equipped with surround sound these days... I haven't delved into T2D audio at all yet, but if there is any mixing (which should certainly be part of a final product) then it shouldn't be too hard to do with whatever channels are available.

Now, doppler effect would be great, but I'm not sure how well that would work. Granted I've not done any sound programming, but I would think that would have to be done at a low level to handle compressing/expanding the waves in any kind of smooth manner.
#3
04/21/2005 (6:35 pm)
Panning should be very easy. It could be a mono wave that plays in both channels. The panning would just require one channel's volume to lower for that wave, to focus the audio on the other channel. The further to the right the object is located on X, the lower the volume on the left channel, and vice versa. I don't know what control we have over each channel, but if we have volume control, it should be easy.

As far as a doppler effect goes, yeah, that'd be a bit harder.
#4
04/21/2005 (6:41 pm)
OpenAL supports doppler and 3d "panning" but it's getting that translated into 2d screen coordinates that is the problem, I think. I'm not sure how to do that.
#5
04/21/2005 (6:55 pm)
If you can control the volume in each channel, (which no one has clarified yet) then it should be possible without any special panning support. Let's say your scene is 400 units wide. Your object's location on X is 42. You'd divide 200 (the length in units from the center to the edge) into 42 (the absolute value of the location on X). That would come to 21%. Subtract 21 from 100, and you get 79. 79% should be the volume of the left channel. Right channel if it was a negative location on X.

Is this possible in script? You wouldn't need C++ at all if you can control the volume in script for each channel. However, for it to UPDATE the volume, you may need C++. This, I believe, would only work for the initial volume. To constantly update it would require specific updating functionality.

Again, I'm an artist, and know near nothing about coding AND Torque scripting. This is just the logic I'd use if I had to create that functionality. Can anyone clarify this functionality?
#6
04/23/2005 (12:09 am)
If openAL is built into torque, panning support should not be too difficult, the engine will have to translate 2D co-ordinates into 3D co-ordinates, with all objects having zero displacement on the z-axis,, and the listener facing into the z axis.

If and when this gets included in the t2d engine, it would be nice to be able to attach various sounds to objects so that they inherit the position and velocity of those objects :)
#7
04/23/2005 (11:55 am)
Yep, we'd like to do this too. :) It's lower on the list than a lot of other things, but I'd love to get a nice sound system set-up. We're dependent on the core TGE audio stuff, and that *may* get changed a little in the future, so we're holding off on this work a little as well because we don't want to have to duplicate effort if the core Torque audio stuff changes.