Game Development Community

How do I setup audio for both iphone sim + iphone

by Jereis Zaatri · in iTorque 2D · 12/31/2010 (9:17 pm) · 5 replies

Hello,

How do I setup the audio data structures and functions so it will work for both iphone and the sim? I had the audio working on TGB, but now that the project is moved over to iTGB, things are not working.

In other words what do I put in the empty brackets below to get audio to play?

%fileName = "~/data/music.mp3";

if($platform $= "iphone")
{
...
}
else
{
...
}

Thanks!

#1
01/02/2011 (1:47 am)
the else is not required as mp3 won't work anywhere else (TGB has no mp3 support and if you used it on the desktop you would have to pay the mp3 patent license fee)
#2
01/02/2011 (3:08 am)
So what format should i use and how do I get it to work on both?
#3
01/03/2011 (12:51 am)
Just to be on the sure side: with anywhere else I mean the "else case" in your code above, which would trigger when you are on a desktop build with TGB (iT2D can't do desktop builds). In such a case there is no way to make it work as the format just isn't supported, you would need distinct files for iT2D and TGB usage (or whole different code cause the iPhone audio commands only exist in iT2D, TGB only uses the audio blocks)

On Simulator and Device it should though work fine, at least within the given limitations the simulator has when it comes to audio.
#4
01/03/2011 (1:14 am)
Well there's a reason I said "sim" and not just desktop... I need to test my game both on the desktop and the iphone when I get there. Any hoot... I have to say it's getting a bit annoying with the back and forth... I just need it to work on both sides and I don't care if two audio formats are needed, I just need it to work. The documentation doesn't really help as it seems to be a cut and paste of TGB docs.

In short: I NEED A SIMPLE EXAMPLE OF GETTING IT TO WORK ON BOTH DESKTOP (WINDOWS) and IPHONE. I apologise if I'm being rude, but I REALLY need to get things on a roll on my end. I have a group of people hovering over my head who want to see results.
#5
01/03/2011 (5:03 am)
@Jereis,
The easiest way is to use wav files only. Mp3 doesnt work on the desktop. Use wav and you won't have to do any if statements. Any chance we can see what you're working on?

If space is a problem when converting to wav, use mono setting.
new AudioDescription(MusicLooping)
{
   // This will use the MusicLooping volume.	
   volume   = 0.8;
   isLooping= false;
   is3D     = false;
   type     = $musicAudioType;
};

new AudioProfile(musicMenu)
{  
   filename = "~/data/audio/cowboy.wav";
   description = "MusicLooping";
   preload = false;
};

Then in your game to play music.
alxplay(musicMenu);

to stop music
alxstop(musicMenu);