PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Audio issues with iPhone

Hi! I'm making a port of Flip Disc for the iPhone and I've run into some problems in the audio area and, after some struggling, I've decided to come here and ask.

The first problem I've encountered is that wav files don't loop. I'm executing the exact same code than the PocketPC and Windows Desktop versions, maybe an issue with the OpenAL wrapper or a missing flag in my code?

The second problem is that I cannot get mod files to work. Again, I'm using the same code than the other versions. More precisely, first I load the mod file inside an instance of ClassEFile making sure I'm using the EFOF_READONLYPATH flag. Then I allocate an auxiliary buffer using ClassEMemory::Alloc and read the file's contents in there. Finally, I use the LoadMusic method from ClassESound, but it fails returning E_ERROR. Any suggestion?

Thanks in advance,
--Nacho
Hi Nacho,

Currently the OpenAL wrapper is in beta status and doesn't support all features. For example, music is not supported. To make sound effects loop, you can try editing the sound wrapper code.

To play music, your best bet is to use mp3. There are the AudioToolBox and CoreAudio classes (old firmware), and the AVFoundation API for firmware newer than 2.2.
tinybulb.com · 26 Jan 2009, 10:58 UTC
Is there any plans to support tracker audio files in future on iPhone platform? I am going to order audio for my project and i need to choose the format etc. for this. I hope you will support tracke audo formats...
Hi edge,

Thanks for your reply. I tried editing the sound wrapper code. So far, I've managed to make a sound loop by adding the following lines of lines of code to the ESound_PlaySound method:

Code:

if(loopsound)
{
alSourcei(effect->source,AL_LOOPING,AL_TRUE);
} // End if.


Now, to stop a sound, I added the following lines of code to the ESound_StopSound method:

Code:

SOUND_EFFECT *effect = (SOUND_EFFECT *)object;
alSourceStop(effect->source);


Since the looped sound files kept on playing, I placed a breakpoint inside ESound_StopSound and found out that the method never gets called. Since I don't have access to that part of the code, can you check if ESound_StopSound is actually called?

Thanks for your help!

--Nacho
Hi Nacho,

Could you try calling ecd.snd->Close() in the OnExit() call of your framework? Does it stop the sounds?

Tinybulb:
An iPhone port of Hekkus is planned, however we can't give an estimate at the moment.
tinybulb.com · 27 Jan 2009, 08:30 UTC
Are you going to port it yourself? I asked Thomas(Hekkus developer) about iPhone version but he mentioned that he have no iPhone and even Mac, as result can't do iPhone version himself.
edge wrote:Hi Nacho,

Could you try calling ecd.snd->Close() in the OnExit() call of your framework? Does it stop the sounds?


Yes, it does. Calling FreeSound -which subsequently calls StopSound- also stops them.

In my case I load all the sounds associated with a certain game state at the beginning so that it doesn't affect performance during the game so, although I might work it around by calling FreeSound, I'd prefer to use StopSound.

As a side note, if I use the OpenAL wrapper in Visual Studio I get an "Assertion Failed" message when I exit the application.

Thanks for your answer.

--Nacho

Update: I managed to play an MP3 by using the AVAudioPlayer class. Please excuse my ignorance, but can I assume that most users out there will be using a 2.2 version of the firmware? More precisely: is it considered a "bad practice" to use code that will only work in the newest version of the firmware?
Second update: When I tried to play a looped MP3 there's a brief moment of silence between loops. Searching at google I've found this article, but the solution suggested by the author (not using a compressed format) would take my game's size to several MB. Do you have a workaround for this?
Hi Nacho,

When you call ClassESound :: StopSound directly, doesn't it work?

When an iPhone user attaches his device to his computer, iTunes will notify the user about the updated firmware. Unfortunately, we can't say how many users have the latest firmware. Perhaps it's a good idea to show that your application requires firmware 2.2 in the description on the appstore.

I know it's possible to loop mp3's with the AudioToolbox framework, by adding the music multiple times to the queue.

Tinybulb:
The current "wrapper" concept in ClassESound will be disbanded in future releases. We are working on adding a "real" and standalone sound class with .MOD support, planned for all supported platforms.
Hi edge,

edge wrote:When you call ClassESound :: StopSound directly, doesn't it work?


No, it doesn't. I put a breakpoint inside the function ESound_StopSound and it's never reached when calling ClassESound::StopSound. On the other hand, if I make a call to ClassESound::FreeSoundEffect, code execution actually reaches ESound_StopSound.

Thanks for your advice on the 2.2 firmware. If I use the AVAudioPlayer class I'll put it as a requirement, then.

Do you have sample code for queueing mp3s using the AudioToolbox framework?

--Nacho

Edit: In order to avoid opening a new thread, I'll post it here: I'm using the DOR_LANDSCAPE orientation but, to make my game work on the simulator (I don't have a real device to test the app yet) I had to swap the X and Y coordinates I receive through the OnStylusUp/Down/Move events and substract the X coordinate from 320 in order to get the Y coordinate (new_x = y, new_y = 320 - x). Do I have to use some flag in order to set the screen's origin at the upper-left corner of the device when using the landscape orientation? (That would be the upper-right corner when the device is in portrait orientation).
Hi Nacho,

For a good AudioToolbox example, search for the CrashLander game sample for the iPhone.

For handling the landscape orientation, it depends if you're using OpenGL or not. If you're not using OpenGL, using the DOR_LANDSCAPE flag for the iPhone simulator should work without having to manually convert coordinates.
Hi edge,

Thanks for your prompt replies.

The CrashLander sample has been removed from Apple's website because, from what I've read in some posts, it has some errors.

I've been asking about this whole issue in other forums and it seems that other developers are also struggling to play looped mp3's. So far, the workaround solution seems to be adding a fade out effect at the end of the file. I might try your suggestion using AudioToolbox and queueing the files, but it will surely take me many days, do you know for sure if that solution solves the silence gap between files?

Regarding the orientation, I'm attaching a very simple project to this post with a landscaped application. Noticed that I've to swap the coordinates and substract the X coordinate from 320 in order to get the Y coordinate. Maybe it's an emulator issue and the coordinates received via the pnt variable in the function callbacks work fine in the real device but, as I've said in a previous post, I don't have an iPhone to test it :(

Thanks again for all your help,

--Nacho
Attachments:
OrientationExample.zip (973 KB)
Hi Nacho,

Perhaps there is another way to get ahold of the CrashLander sample? The sound framework in that sample is really useful. If you can find it, the solution to loop mp3's, is to call the AudioQueueEnqueueBuffer function multiple times:
- When first playing your file, call it twice
- Manually handle a timer (it depends on the length of the song), if it's past a certain value then call it again (so it will always be two times in the queue)

We will get back about your sample next week.
Hi Nacho,

We've taken a look at your sourcecode, and it seems there is a bug in EDGELIB regarding mouse coordinates in combination with a different display orientation.

A fix will be available in the next EDGELIB release.
OK then, thanks for taking a look at the source code.

--Nacho