Playing Ogg files.
by Bradley Crawford · in Torque Game Builder · 03/08/2005 (3:58 am) · 6 replies
Heya all, got T2D this afternoon and spent a little bit of time playing around with it..very nice :)
Anyway, first thing I wanted to do was get some ogg's playing in it and couldn't really find how to do it so once I did I figured I'd post here in case others were having the same trouble.
After checking the forums for TGE (figured that would be the best bet) I came across this thread which had what I was after, so playing around I found that the following changes need to be made to 2 .cs files and you're under way with streaming ogg's :)
Following is in reference to the spacescroller directory
In Torque 2D\SDK\example\spacescroller\client\audioDatablocks.cs add the following
and of course change ingame.ogg to whatever you are using.
Then in Torque 2D\SDK\example\spacescroller\client\client.cs change
Hope this is a help to some and iff not, sorry for the wasted bandwidth :)
Anyway, first thing I wanted to do was get some ogg's playing in it and couldn't really find how to do it so once I did I figured I'd post here in case others were having the same trouble.
After checking the forums for TGE (figured that would be the best bet) I came across this thread which had what I was after, so playing around I found that the following changes need to be made to 2 .cs files and you're under way with streaming ogg's :)
Following is in reference to the spacescroller directory
In Torque 2D\SDK\example\spacescroller\client\audioDatablocks.cs add the following
new AudioDescription(AudioMusic)
{
volume = 1.0;
isLooping = true;
isStreaming = true;
is3D = false;
type = $GuiAudioType;
};
new AudioProfile(InGameMusic)
{
filename = "~/client/sounds/ingame.ogg";
description = "AudioMusic";
preload = false;
};and of course change ingame.ogg to whatever you are using.
Then in Torque 2D\SDK\example\spacescroller\client\client.cs change
$spaceAmbientAudio = alxPlay( ambient1Audio );to
$spaceAmbientAudio = alxPlay( InGameMusic );and there you have streaming, looping ogg music in your game.
Hope this is a help to some and iff not, sorry for the wasted bandwidth :)
About the author
#2
03/08/2005 (8:00 am)
Will definately have to add this to the FAQ (though might have to wait till after GDC)... thx for sharing Bradley
#3
03/08/2005 (10:36 am)
Thanks for the tip, Bradley. I am about to start messing with sound, and this might save me some digging.
#4
03/08/2005 (10:57 am)
Using non-streaming Ogg files will not affect performance at all. They get decompressed into memory and work exactly like WAV files. The streaming Ogg decodes on the fly, but since you're usually only using one streaming track, it shouldn't impact performance much.
#5
Usually, playing sounds rarely, you wouldn't ever push the 16-source limit that Torque has, but I have hit it with my shooter. (All those explosion/laser sounds, after all. :)
As a dirty hack, I've modified audio.cc (in engine\audio) like so:
03/08/2005 (3:30 pm)
A word of warning about streamed sound sources: Seems that Torque's sound code will cull out streaming sources if the maximum number of voices ("sources" in OpenAL parlance) are played. This will cause your music to cut out (and in my particular case) seem to be replaced with another sound, looping over and over. It's rather annoying.Usually, playing sounds rarely, you wouldn't ever push the 16-source limit that Torque has, but I have hit it with my shooter. (All those explosion/laser sounds, after all. :)
As a dirty hack, I've modified audio.cc (in engine\audio) like so:
static bool cullSource(U32 *index, F32 volume)
{
alGetError();
F32 minVolume = volume;
S32 best = -1;
for(S32 i = 0; i < mNumSources; i++)
{
[b] StreamingList::iterator itr = mStreamingList.findImage(mHandle[i]);
if (itr && !(mHandle[i] & AUDIOHANDLE_INACTIVE_BIT)) {
continue ;
}[/b]
if(mScore[i] < minVolume)
{
minVolume = mScore[i];
best = i;
}
}(My additions are in bold.) Basically what this does is check to see if the source is in the streaming list, and if so and its active, skip culling it. I think something is broken in Torque's scoring code (or more accurate, not implemented), as I do not think the intended behavior is to kill a streaming, looping source like that.
#6
Goes to show, if you aren't sure--try it to find out. :)
03/28/2005 (10:16 pm)
I just wanted to mention that there was some confusion about OGGs possibly not playing from zip files, but I have done this without modifications to the c++ source, and it works fine. Just in case anyone was confused by all the various (mis)information like I was.Goes to show, if you aren't sure--try it to find out. :)
Torque Owner Philip Mansfield
Default Studio Name
Mine are only 2 second loops of music, and I'm not streaming them, but they play just fine.
Check out my Biplane Battle game to hear them in action.