Game Development Community

Sound engine

by Vern Jensen · in Torque Game Builder · 08/28/2006 (3:42 pm) · 24 replies

We really need a lot more built-in support for having control over sounds, without having to do dump(), or look at the C source, to figure out what's going on. For instance:

- Ability to specify the stereo panning of a sound (its balance in left vs. right speakers)
- Function to tell if a given sound is currently playing, and if so, how long (in milliseconds) it has been playing
- Option to play a sound in such a way that it stops any previous playback of that same sample

Hmm, I'm sure there's more.... But this would be a good start.

Currently, if you have an event trigger a sound to play, and lots of that event occur at almost the same time, then you get a huge amplification in sound volume for that sound, because all the sounds are overlapping and playing at nearly the same time, which sounds terrible. Two of the above suggestions are intended to allow the developer to avoid this problem.
Page «Previous 1 2
#1
08/28/2006 (4:35 pm)
Check out the TGBReference.pdf ... you can find it in the Documentation Overview (also the path is TGB/documentation/reference/)... go to "Console Functions->Audio"... There is a list of functions for audio :)
#2
08/28/2006 (4:36 pm)
Btw just about the only thing we don't have in the reference is every single GUI control... though in 1.1.1 we added the base GuiControl and GuiCanvas.
#3
08/29/2006 (12:49 am)
Yes, I've looked at the audio function reference in TGBReference.pdf, but it leaves many questions to be answered, and it also apparently lacks some basic features. For instance:

1) Is there any way to change the pitch of a sound effect? (i.e. play it at different rates)
2) Is there any way to change the stereo panning of a sound?

Also, the documentation is incomplete. There are functions for changing a channel's volume, but no apparent way of getting a pointer to a channel. What am I supposed to pass in the %channel parameter to these methods? (A friend of mine suggested I set the "type" field in the AudioDescription to some custom-defined type, and pass this same thing as the channel. Is that the appropriate way to use these functions that accept a channel parameter?)

In short, unless there is a way to change the pitch of sounds, and their stereo panning, then these are features I hope you'll consider adding, as they're SO useful in many types of games, and without them, your audio engine is very sparse when compared to all the features you've put into the rest of Torque.

And as for sound channels, that could use some further explaining in the documentation and tutorial. (The sound tutorial is very basic, and doesn't say anything about channels.)
#4
08/29/2006 (4:31 pm)
You're right about the type field. The channel argument is an integer from 0 to 31, much like layers, and corresponds to the 'type' field of an 'audioDescription' object.
#5
08/30/2006 (8:02 am)
You'll want to look at the alxSourcef and other simialrly named functions (alxSource3f, etc), which allow manipulation of various audio properties. For example:

alxSourcef(%activeSoundID, AL_PITCH, %newPitch);

Pass in a currently-playing sound ID (the result from an alxPlay call) and a pitch (1.0 is default, big changes from small numbers (e.g. 1.2 is a noticable jump up in pitch)) to alter the pitch of a particular sound.

Using AL_POSITION with alxSource3f can effect sound position, but it's a bit tricky.
#6
08/30/2006 (8:36 am)
I don't know of any engine that lets you change the pitch of sounds. EAX might do it but I've never looked in to a game that did that engine wise. It starts to really suck up cpu cycles.
#7
08/30/2006 (9:56 am)
Yes keep in mind the AL_PITCH adjustment I mention previously is really an adjustment to the playback sample rate so the pitch does change but the sound also plays proportionately faster.
#8
08/30/2006 (1:15 pm)
Thanks Luke, that's all I was looking for, something to adjust playback rate. I haven't tried alxSourcef yet, but I will soon! I just hope that the method is very fast, so that it changes the pitch *before* the sound starts playing, so we don't hear it suddenly change in pitch at the start.

How can I find out more about alxSource3f, such as what parameters it takes? I'm sure there's a Console command for this, but I'm not sure what it is. (I'm only aware of using dump() for objects, but alxSource3f is a function, not an object.)
#9
08/30/2006 (1:58 pm)
Try: This
#10
08/30/2006 (2:03 pm)
If you create the sound and immediately adjust the pitch, it happens before you hear anything (at least in my experience.)

I think there's a command to dump all console functions, ideally with function parameters included, but I've not used it in a long time and I can't recall what it is (just dump() maybe?). I actually use an old TGE reference guide for a lot of the oldest console functions called TGE_Console_Cmds.rtf that Ron Yacketta had written. Its ancient, probably largely outdated, but at least the sound call documentation is still relevent. I think you can get a copy here.

Edit: Scott's link is way better than the old reference doc I mention above.
#11
08/31/2006 (4:12 pm)
So the caviat here is that the functions (and to some extent the docs) were originally written for TGE and the 3D environment. Some things don't work quite the same way (or at all in a few cases) as the docs would have you believe.

Panning is possible. I toyed with it for a side project awhile back. What I found that worked was to use:

alxSource3f(%audioHandle, "AL_POSITION", 0.03125, 0, 0);

The key was the incredibly small values. For me, 0.03125 was far-right without getting so far away that the volume diminished to nothing. It's not traditional sound panning where you're simply dividing the amplitude between left and right channels; you're really specifying relative three-dimensional distance between the listener and the sound producer.

Edit: Ok, I swear I'm not talking to myself, there was a post here before mine asking about sound positioning, just for the record.... ;-)
#12
08/31/2006 (4:17 pm)
Haha, sorry luke. I deleted my post. I'm going to try what you just posted and get back to you.
#13
08/31/2006 (4:21 pm)
Okay, I tried your posted code (changing %audioHandle to my own handle name of course) and I get nothing. No change in position.

I'm starting to wonder if this is a Mac-related problem? Because if I use large values, the volumes don't diminish to nothing. They stay just the same as before. Which leads me to believe the function is having no effect.

P.S. Sorry about the deleted post. For the record, I DID ask about stereo positioning, then deleted the post to re-write it after having done more experiments, but caught Luke's reply mid rewrite.
#14
08/31/2006 (4:25 pm)
It could very well be Mac-specific, I do know the audio behaves differently on the Macs to some degree. Let me verify that the example I posted above still works for me in the latest version (my stuff was done back on 1.0.2) and if it does, I'll try to boot my Mac and try it there too and see what happens.
#15
08/31/2006 (4:26 pm)
One more thing... do you think it's possible you used any other functions to set things up, before playing the sound, such as alListener3f? I've tried experimenting with this too, but it doesn't seem to help, but I could be trying to use it incorrectly...
#16
08/31/2006 (4:27 pm)
Alright, thanks for being willing to check you code on the latest version of Torque, and the Mac... I appreciate it! I'll hold off further tests until hearing back. (I've basically run out of things to try, anyway...)
#17
08/31/2006 (4:39 pm)
Glad to help out, the audio functions are a bit cryptic and mysterious.

I never changed the listener at all, I left it default. Of course the 'default' could have changed between then and now, hopefully trying it out on the latest will prove/disprove that. The specific code that had the positioning stuff in it also had pitch and gain_linear adjustments too, but I'm sure pitch didn't do anything and the gain was a minor fluctuation and shouldn't have done anything special.

I'll be able to give it a shot tonight, will post my findings then. :)
#18
08/31/2006 (10:20 pm)
I just confirmed with the 1.1 release that the above still works. I did the following with the GravDemo running, in the console:

alxStopAll();
$testID = alxPlay(rainAmbientSound);
alxSource3f($testID, "AL_POSITION", -1, 0, 0);
alxSource3f($testID, "AL_POSITION", 1, 0, 0);
alxSource3f($testID, "AL_POSITION", 0, 0, 0);

rainAmbientSound is a looping audio so its good for this test. For the first two calls to alxSource3f, the sound panned to the left and right respectively. The third call puts it back dead-center. So this still works in the latest versions.

Unfortunately I forgot that I had hijacked my Mac's keyboard/video for another machine so I've not been able to try this there, however you should be able to reproduce the steps above and see whether or not it works, since this is with a completely unmodified 1.1 release. Just run the Grav demo, let it run for a few seconds so the items stop spawning, and enter those commands at the console.
#19
09/01/2006 (1:03 pm)
Okay, this is weird. I booted into Windows XP that I have installed on my Intel-based iMac. I installed Torque 1.1.1 on it. There is no Grav demo however, so I tried the scrollerDemo:

alxStopAll();
$testID = alxPlay(ambient1Audio);
alxSource3f($testID, "AL_POSITION", -1, 0, 0);
alxSource3f($testID, "AL_POSITION", 1, 0, 0);

And I get nothing. No change whatsoever. Can you confirm that it *works* for you on the scrollerDemo specifically, using 1.1.1?

If it does work for you, then it's clearly something with my computer, since stereo positioning fails to work regardless of operating system. (Although I DO get stereo positioning when listening to music in iTunes, so I know my computer CAN do it. It just doesn't want to do it with Torque for some reason.)
#20
09/01/2006 (1:06 pm)
Huh. I just tried it on a non-looping sound, playerFireAudio, and managed to type in the 2nd line before the sound had faded completely. And it worked!

My guess is that there is something fundamentally different about the sound effects. Certain ones work for stereo positioning, others don't. But I'm not sure what that difference is. I'll be looking into it. Anyone else have any ideas?
Page «Previous 1 2