Game Development Community

Sound Effects (Audio) on iTorque iPad

by Claudio Torres · in iTorque 2D · 06/02/2011 (2:57 pm) · 18 replies

I am trying to play sound effects on iTorque. I read the tutorials and documents and wrote the code bellow. The sound doesn't play running on iTorque, on iPad Simulation, and even loading on iPad there is no sound.

Can anyone help me finding the problem?


1. At the audio.cs file

new AudioDescription(AudioNonLooping)
{
volume = 1.0;
isLooping= false;
is3D = false;
type = $GuiAudioType;
};

// --------------------------------------------------------------------
// Single Blip.
// --------------------------------------------------------------------
new AudioProfile(mines)
{
filename = "./game/data/audio/mines.wav";
description = "AudioNonLooping";
preload = true;
};

2. At game.cs

exec("./audio.cs");

3. At the point I will play the sound effect

alxPlay(mines);

About the author

Electronic Engineer, MSc on System, Software Developer, Digital Marketing Consultant. Today I managing Torres Studios, a new Game and Entertainment Studio focus on create innovative iPad and XBOX 360 Games.


#1
06/02/2011 (4:15 pm)
Seems about right. Did you check "iPod Music Support" in the editor project panel? Is the function alxPLay() is in being called?


Torque audio has/was a bit buggy for me at the beginning and took me a while to get it, but it came. What you are doing does seem correct tho.

Good Luck.
#2
06/02/2011 (4:20 pm)
iPod music support is check.

As you see on 3. I use alxPlay(mines); at the point I must play the sound.

Is there any addtional library, file or struction I should include at the geme.cs?

Is there any way to test it? (part from run it)
#3
06/02/2011 (4:47 pm)
I would just set up an echo call in the function that is supposed to call the alxPlay() just to see if it is actually being called.
#4
06/02/2011 (6:34 pm)
I finally found the error:

is ~/data/audio/mines.wav

instead of ./game/data/audio/mines.wav

There is no error message for file not found. The sound just do not play.

#5
06/02/2011 (7:21 pm)
So it is playing now?
#6
06/03/2011 (1:56 am)
btw itorquue supports ogg too right?
#7
06/03/2011 (4:55 am)
I believe so.
#8
06/03/2011 (6:16 am)
No, iTorque does not support ogg. Only wav and mp3.
#9
06/03/2011 (6:39 am)
did it at one point? I thought I had read that. Anyhow, I only use wav.
#10
06/03/2011 (6:44 am)
The startiPhoneAudioStream function (only in Xcode iPhone builds) should also be able to play iPhone-supported audio formats which include:

*AAC
*HE-AAC
*AMR (Adaptive Multi-Rate, a format for speech)
*ALAC (Apple Lossless)
*iLBC (internet Low Bitrate Codec, another format for speech)
*IMA4 (IMA/ADPCM)
*linear PCM (uncompressed)
*µ-law and a-law
*MP3 (MPEG-1 audio layer 3

From http://stackoverflow.com/questions/1761460/supported-audio-file-formats-in-iphone
#11
06/03/2011 (6:47 am)
Torque2D supports OGG (for PC) but iTorque2D does not.
#12
06/03/2011 (8:51 am)
I see... thanx fellas :)
#13
06/03/2011 (10:36 am)
Yes, it works now. We must take with the Torque to iTorque differences when using tutorials, cause they are for Torque.

The correct code for iTorque 1.4.1. is:




1. At the audio.cs file

// Description for a sound effect
new AudioDescription(AudioNonLooping)
{
volume = 1.0;
isLooping= false;
is3D = false;
type = $GuiAudioType;
};

// --------------------------------------------------------------------
// Profile for a sound named mines.wav and store in /data/audio
// --------------------------------------------------------------------
new AudioProfile(mines)
{
filename = "~/data/audio/mines.wav";
description = "AudioNonLooping";
preload = true;
};

2. At game.cs

// never forget this
exec("./audio.cs");

3. At the point I will play the sound effect

// include this line qhere things happens and sound effect must play
alxPlay(mines);
#14
08/21/2011 (12:38 pm)
Thanks, Claudio!

I was able to add a sound effect in less than 5 minutes thanks to this thread!

#15
09/30/2011 (12:36 pm)
I thought I'd post an update to this thread for those using iTorque2D 1.5.

First of all, in case people need the reference, the TGB audio tutorial the above code examples are based on is here: docs.garagegames.com/tgb/official/content/documentation/Tutorials/Feature/Audio%...

1.
iTorque2D 1.5 does away with the common folder, and the audio.cs file along with it. You can put your AudioDescription and AudoProfile definitions in any script file you like, as long as it gets executed with the exec command.

2.
The filename path should now be specified without anything preceding the data directory.

filename = "data/audio/mines.wav";

3.
alxPlay() can only be used with .wav files. If you want to play .mp3 sounds you need to use startiPhoneAudioStream().

4.
Finally, the line:

type = $GuiAudioType;

does nothing, as $GuiAudioType is not defined anywhere in iTorque.

#16
10/15/2011 (12:53 am)
has the filename path format been changed in the final release of 1.5? I am not getting any sound at all.


Anyone else experiencing this?
#17
11/19/2011 (7:22 pm)
@Ray Della.

Quote:You can put your AudioDescription and AudoProfile definitions in any script file you like, as long as it gets executed with the exec command.


That was my problem. I just had it in the managed datablocks which I don't believe get executed.

Also make sure the filename has the extension and nothing preceding the data directory. It's easy to overlook.
#18
11/20/2011 (6:09 pm)
What's the recommended file format for compressed audio? We've been using .wav's with straight PCM, now we want to compress some of our sounds to get down to the 20M OTA limit.

Looking at the code, the wave parser only seems to handle WAVE_FORMAT_PCM. There are cases for IMA ADPCM and MP3, but they look unimplemented. There also seems to be code for .caf files, but the .caf extension is not registered; adding that code and passing in an IMA ADPCM caf gets an error farther in during OpenAL setup of the sound.

So, recommendations for the best way to compress? (Target is iPhone, iTorque 1.4.1).