Game Development Community

TGB Audio System Update

by Rob Cain · in Torque Game Builder · 06/25/2010 (11:47 am) · 10 replies

The TGB audio system seems pretty barebones, lacking functionality like pausing, seeking, and pulling information like duration and whether the track is through playing.

Fortunately, it looks like someone tackled this issue about four years ago, here: http://www.torquepowered.com/community/resources/view/9385

UNfortunately this simple functionality improvement is only useful if you have the source code. Considering that it would be pretty easy for Garage Games to incorporate this functionality into a TGB build (just copy and paste, essentially), for those of us who can't afford the source, or don't want to pay another 150% just to add functionality that probably should be in the system to begin with, it would be a big help if they did so. I could justify buying the source if I wanted to make a really complex, audio-intensive game like Braid (where the audio's playback is tied to the direction of time, movement, etc.) or Guitar Hero, but just to be able to fade in an audio track? Heck, RPG Maker can do that.

Anyone else agree?

#1
06/25/2010 (12:14 pm)
Check out this thread:
www.torquepowered.com/community/forums/viewthread/70404

About halfway down, someone posted a sample script to fade audio. I empathize with your point, but you should never bank your hopes on future revisions of the engine.
#2
06/25/2010 (12:40 pm)
Yes, the link above was very useful. I used it awhile back to make gunfire sounds fade out as the camera moved farther away and get louder as the camera got closer.
#3
06/25/2010 (1:00 pm)
Suppose you have a background song with an intro file and a loop file. You want to play the intro, and when it's done, switch to the loop.

Or suppose you want a *pause* menu and you don't want music playing in the menu, but you don't want the music to start over every time the user exits the menu.

This is pretty basic functionality. Sort of like not being able to work with animations except to set them, play them, and stop them, unless you can change the source code.

...I've noticed that decent audio functionality seems to be overlooked by quite a lot of engines, actually...
#4
06/25/2010 (9:29 pm)
Would someone from Garage Games care to comment as to why this has not been built into the engine yet? It's been available for years.
#5
06/26/2010 (7:35 am)
@Rob,

For your first issue, you can fake a callback by using a schedule set to the length of the intro clip, that fires a function that starts the loop. Like so.

For your second issue why can't you just set the channel volume to 0 for the one playing your background music?

For instance, I start my background music with a profile named 'Music'. When I pause, I call:
alxSetChannelVolume(Music, 0);
When I unpause I call:
alxSetChannelVolume(Music, 1);
Works perfectly for me. If I wanted it to fade, I'd use the tween code here.

@Melv, I hope you find time to convert those tween to C++ for T2D (as you mentioned in the linked thread. :)
#6
06/26/2010 (8:05 am)
@Patrick,

First suggestion: that seemed like a good solution, so I tried it a while ago. The problem is that schedule timing is wonky and while little timing weirdnesses may not be noticeable in code, they are in audio. Give it a try yourself—you'll find that your intro track either gets cut off or (especially if anything happens to your frame rate, like the program goes into the background or the game gets paused), the scheduled play gets delayed, leaving a gap between tracks. Even if this method did work, it relies on manual input of milliseconds-accurate time length, which is incredibly error-prone.

Second suggestion: What you are having me do is silence the music. I need to be able to pause the music. The effect is similar but not the same. With an atEndOfClip()-equivalent callback, combined with a pause() function, the intro clip is paused on going into the start menu (or anytime the game is paused, like when it goes into the background). Then when the clip is resumed, it continues from the point of pause. When the clip ends, the atEndOfClip() callback fires (thankfully at the actual end of clip and not at some arbitrary scheduled time that may or may not coincide with the end of the track) and I use that to start the loop track. Simple and elegant.

I'm not really looking for hacks. Ultimately, if I NEED this functionality, I'll buy the source before I'll use hacks because hacks are ugly and error-prone. What I'm trying to get at is "This functionality should be in TGB." As Conor pointed out, it's been available here on the forums for four years, and I'm sure the author would have no problem with GG using it in the engine, leaving its inclusion a simple matter of copy and paste.
#7
06/26/2010 (3:42 pm)
Rob,

I completely agree with you on the first point. I've never tested it and your comment makes perfect sense.

The point I was trying to get across on the second part was that even with a reliable onSoundEnd callback you're going to run into the problem that the music will continue playing until it's end, which with a loop of length that gives reasonable variation musically, will be at least a second or two.

Player hits pause, music pauses immediately or music continues to loop end - maybe immediately, maybe 2 seconds depending on loop length. At which point it abruptly ends and sounds bad unless you fade it out anyways. Which you can do right now.

I'd hardly call a script based tween that offers several easing options adapted to control volume a hack.

The discussion's irrelevant on my part though, so sorry to derail. I didn't fully read your post and didn't realize that you were asking for consensus on whether it should be added in or not. I hope it makes it into T2D.
#8
06/26/2010 (11:20 pm)
On this link, it has a bunch of functions for creating sound.

www.torquepowered.com/community/forums/viewthread/8222
#9
06/26/2010 (11:28 pm)
@Dean: the link you posted targets a thread about dynamically changing meshes. I didn't see anything relating to audio, even in the link halfway down the thread, which goes to information on hiding nodes in a model. Did you past in the wrong link?
#10
06/30/2010 (4:54 am)
hi guys...

well, i worked with some other gameengines in the last years and changed now to TGB...but: "the audio thing" at TGB is really,really bad:

sometimes it works, sometimes not (and really no one can explain it...code checked by 5 different people);

playing the same sound more than once a time gives strange results like volumechanges...

playing more than 3,4 different sounds a time results in strange noise...

and so on, and so on...

THIS are ALL basic functions...and must WORK without any problems!!!

...and: this problems are not part of a specific hardware, i have this problems on all 8(!!!!) computers...

Dietmar