Spatial sounds?
by AzraelK · in Torque Game Builder · 11/13/2006 (3:34 pm) · 5 replies
I was wondering is there any way to add a sound to an object in the level? I have a fountain in the middle of the level and it would be great to be able to hear the fountain when you aproach to it and then hear it fading out as it gets far.
Is there a way to do this?
Is there a way to do this?
#3
Next you create a listener which would be set to the same position of the player and simply leave it up to openAL to determine the volume based on the listeners distance from the various sources you've created, with a little extra effort you can get doppler effects up and running too. The one cavet is that if your player moves, you need to ensure you keep updating your listeners position too.
Use alxPlay and alxStop to start/stop the sound. You'll probably want it set in the profile to loop and may need to have it set as 3d even though you'll only be using two of the coords with the third fixed.
You can also update AL_VELOCITY and various other options, although to use doppler effects you may need to tweak the engine, I can't remember what change I had to make last time I used it (and it was in TGE so may not be applicable anyway)
It shouldn't take too much work to extend sceneObject to update the position of listeners or sources for moveable objects.
It's probably also feasible to create the source and listener as well as keep the positions updated via a timer totally in script if you want to avoid engine modifications. How effective it will be, you'd have to try it and see. Have a look in audioFunctions.cc for the various openAL functions accessable from script.
For example, updating positions every so often you might use something like (Note: I've no idea if this will actually work and havn't tested it in anyway way)
That said, I've never tried using openAL fully in TGB outside of playing standard sound effects, but it should be possible to do.
11/13/2006 (4:26 pm)
With a bit of engine tweaking you should be able to accomplish what you want. Use "alxCreateSource" to create sources for your various static objects but fix the 3rd coordinate so you're dealing with 2d coords only. If you want the source objects to be able to move around, then you'd need to ensure you keep updating the position of the sound source you created. Next you create a listener which would be set to the same position of the player and simply leave it up to openAL to determine the volume based on the listeners distance from the various sources you've created, with a little extra effort you can get doppler effects up and running too. The one cavet is that if your player moves, you need to ensure you keep updating your listeners position too.
Use alxPlay and alxStop to start/stop the sound. You'll probably want it set in the profile to loop and may need to have it set as 3d even though you'll only be using two of the coords with the third fixed.
You can also update AL_VELOCITY and various other options, although to use doppler effects you may need to tweak the engine, I can't remember what change I had to make last time I used it (and it was in TGE so may not be applicable anyway)
It shouldn't take too much work to extend sceneObject to update the position of listeners or sources for moveable objects.
It's probably also feasible to create the source and listener as well as keep the positions updated via a timer totally in script if you want to avoid engine modifications. How effective it will be, you'd have to try it and see. Have a look in audioFunctions.cc for the various openAL functions accessable from script.
For example, updating positions every so often you might use something like (Note: I've no idea if this will actually work and havn't tested it in anyway way)
alxSource3f( $player.listenerHandle, "AL_POSITION", $player.getPositionX(), $player.getPositionY(), 1 );
That said, I've never tried using openAL fully in TGB outside of playing standard sound effects, but it should be possible to do.
#4
11/14/2006 (3:21 pm)
Hmm.. I was looking for a solution that didnt involve the source code since I only have the indie version of TGB, how can I modify the sound volume? or check the distance of an object in the scene?
#5
As for volume - I've only done a little with audio in TGB. I know you can set the volume in the audio description - it must be settable while it's running too.
Edit: Yep - check TGB Reference for alxSetChannelVolume
11/14/2006 (3:34 pm)
The distance between two objects (in pseudo-script) is t2dVectorLength(t2dVectorSub(%obj1.getPos, %obj2.getPos))As for volume - I've only done a little with audio in TGB. I know you can set the volume in the audio description - it must be settable while it's running too.
Edit: Yep - check TGB Reference for alxSetChannelVolume
Associate Tom Eastman (Eastbeast314)
Hope that's a good starting point!