Audio Datablocks and crossfades
by rennie moffat · in iTorque 2D · 07/22/2010 (6:55 pm) · 6 replies
Hi There I am wondering, where audio datablocks would go in the iTGB system? And also, if I wanted to have the ability to crossfade... is the VMPlayer usable in the iTGB system?
About the author
My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.
#2
07/23/2010 (12:18 am)
Just a thought. The above can be used with WAV files. I don't use MP3s, so I'm sure how you achieve the same using MP3 files.
#3
Thanks man, I appreciate that. I am going to have to look over this more later, but it looks straightforward.
Thanks.
07/23/2010 (1:21 am)
Yah, I thought MP3's were a no no anyway. Thanks man, I appreciate that. I am going to have to look over this more later, but it looks straightforward.
Thanks.
#4
at least not without you forcing the compression to happen on cpu and then you will get serious trouble cause you lose 15-20% cpu time more or less per compressed audio playback, that is on 3GS from what I recall. previous to 3GS, using cpu compressed audio playback meant 25%+ cpu time gone per track that runs at a time
07/23/2010 (3:07 am)
For mp3 / compressed audio there is no way to crossfade because they will never run in parallel at all.at least not without you forcing the compression to happen on cpu and then you will get serious trouble cause you lose 15-20% cpu time more or less per compressed audio playback, that is on 3GS from what I recall. previous to 3GS, using cpu compressed audio playback meant 25%+ cpu time gone per track that runs at a time
#5
I thought it would be hard to do with MP3s. I'm not using any MP3s, I use WAV for everything. Now that we have 20 MB to play with, I'm not too concerned about using WAVs anymore as there is plenty of room to fit everything I need.
07/23/2010 (3:27 am)
Marc, that's good to know, thanks for explaining that. I thought it would be hard to do with MP3s. I'm not using any MP3s, I use WAV for everything. Now that we have 20 MB to play with, I'm not too concerned about using WAVs anymore as there is plenty of room to fit everything I need.
#6
Also the gain of mp3 is not thaaaat large if we consider 22khz mono wav files and the zip compression which is applied anyway.
originally the reason for mp3 was that the amount of RAM available on the pre 3GS devices is small enough to make heavy wav usage especially for bg tunes a potential problem. but with 3GS+ that problem is quite a bit smaller
07/23/2010 (3:56 am)
Definitely.Also the gain of mp3 is not thaaaat large if we consider 22khz mono wav files and the zip compression which is applied anyway.
originally the reason for mp3 was that the amount of RAM available on the pre 3GS devices is small enough to make heavy wav usage especially for bg tunes a potential problem. but with 3GS+ that problem is quite a bit smaller
Torque Owner Mark Davies
You can change the volume of an audio channel on the fly. I use sometimes when I want to fade out the background music.
I define my background music an audio datablock like this:
new AudioDescription(AudioLooping)
{
volume = 0.75;
isLooping= true;
is3D = false;
type = 0;
};
and then when I want to fade out the music, I repeatedly call the following (using schedule or a timer):
//fade out music
if (alxGetChannelVolume(0) > 0 )
{
reduceAudioVolume(0, 0.05, 0);
};
where the reduceAudioVolume() is defined as:
function reduceAudioVolume(%audioType, %inc, %end)
{
%volume = alxGetChannelVolume(%audioType);
if (%volume > %end)
{
//echo("\n\nReducing volume...");
%volume -= %inc;
alxSetChannelVolume(%audioType, %volume);
}
};
Hope that helps. The above would be used to fade out one channel. You could then have another audio channel that is faded in as the other fades out.