Discussion for Tutorial 9 - Sound Manager

Discussions for all the iPhone Screencast Tutorials.

Discussion for Tutorial 9 - Sound Manager

Postby jonny » Sun Aug 23, 2009 3:19 am

In this tutorial I create a simple sound manager class that can play back multiple sounds using OpenAL. It also allows you to play background music as well using the AVAudioPlayer class.

The reason for writing my own sound manager was to see how OpenAL works. Commenters on this blog provided some great links, see the “Sound of music… explosions and lasers”, so I decided to work through them and get something working.
jonny
Site Admin
 
Posts: 11
Joined: Wed Apr 22, 2009 4:50 am

Re: SIGABRT error - Sound Manager TUTORIAL 9

Postby PavanK » Wed Sep 08, 2010 3:45 pm

Hi mike i would like to say a big thank you for taking the time and effort to create a video explaining exactly what youre code does. I’ve learnt more about OpenAl in the past 2 hours then i have in the past two days (that’s when i started)

Guys and Ladies, I am creating a drum application at the moment for the iphone, and have been using PlaySystemSound obviously that is not apropriate for game sounds as it does not play straight away and sometimes doesnt even get played.
So i transitioned over to OpenAL to give it a go mainly because i can change the pitch of a sound live.

This morning i followed tutorial 9 – Sound Manager
All i did was start up a window based application, added 2 view controllers. on one of the view controllers i added abutton so i could play the sound.

I added the 2 sound manager files. And there were no errors upon build.
now i just needed to load the sounds.
I dont have a game loop so i couldnt initialise it there.
So in my BlueViewController i did this:

Code: Select all
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
sharedSoundManager = [SingletonSoundManager sharedSoundManager];
[sharedSoundManager loadSoundWithKey:@"NormalGe" fileName:@"NormalGe" fileExt:@".caf" frequency:22050];
[sharedSoundManager loadSoundWithKey:@"NormalNa" fileName:@"NormalNa" fileExt:@".caf" frequency:22050];
[sharedSoundManager loadSoundWithKey:@"NormalKe" fileName:@"NormalKe" fileExt:@".caf" frequency:22050];
[sharedSoundManager loadSoundWithKey:@"LoudGe" fileName:@"LoudGe" fileExt:@".caf" frequency:22050];
[sharedSoundManager loadSoundWithKey:@"LoudNa" fileName:@"LoudNe" fileExt:@".caf" frequency:22050];
[sharedSoundManager loadSoundWithKey:@"LoudKe" fileName:@"LoudKe" fileExt:@".caf" frequency:22050];
[sharedSoundManager loadSoundWithKey:@"LoudRa" fileName:@"LoudRa" fileExt:@".caf" frequency:22050];
}
return self;
}


I get no warnings the app gets successfully installed on my iphone, but when it runs it. a SIGABRT error.

if i take the initialization out of the sounds my app works fine.
could you please tell me whats going on?
thank you
and i appreciate everything that you are doing for the community
PavanK
 
Posts: 1
Joined: Wed Sep 08, 2010 3:39 pm

Re: Discussion for Tutorial 9 - Sound Manager

Postby A Person » Thu Sep 09, 2010 2:38 am

The only thing i can think of off the top of my head are passing incorrect names for the sound files (probably not though) or forgetting to add the MyOpenALSupport.c and .h my sound manager (may be out of date) is from tutorial 10 or 9 awhile back so it can't be that out of date. If you don't already have them imported then import them, unless there is no #import MyOpenALSupport.h in the SoundManager.m file.

Hope this helps. :)
there's no place like ~/
A Person
 
Posts: 161
Joined: Fri Sep 25, 2009 3:45 am
Location: Canada

Re: Discussion for Tutorial 9 - Sound Manager

Postby mike » Wed Sep 15, 2010 2:24 pm

Hmm, not sure if there is a problem with the forums as I'm sure this discussion had got further and was resolved. The problem was that the extension for the filename being used was .caf and it should have just been caf.

Mike
mike
 
Posts: 670
Joined: Fri Aug 21, 2009 2:10 pm

Re: Discussion for Tutorial 9 - Sound Manager

Postby badweasel » Mon Sep 27, 2010 4:19 pm

hey Mike.. hope you're recovering ok and feeling good.

Thanks again for all your tutorials. They have been very helpful and have saved me a lot of time over the last few months.

With your soundManager I'm having a couple of iOS4 issues and was wondering if you've had a chance to play with this code in a newer app? Specifically with regard to being able to play background audio like iPod music and other background music, like a radio app or streaming music in mobile safari.

The second issue is that if the user gets a phone call (even if they cancel and don't take the call) when they return to the app the sound can't be heard.

Any ideas?
badweasel
 
Posts: 7
Joined: Mon Sep 27, 2010 3:24 pm

Re: Discussion for Tutorial 9 - Sound Manager

Postby mike » Thu Sep 30, 2010 8:58 am

Hi ya

I've just given this a go and also found that for some reason on iOS 4 the sound does not return after an interruption. I'm going to take a look at this and get back to you ASAP.

Mike
mike
 
Posts: 670
Joined: Fri Aug 21, 2009 2:10 pm

Re: Discussion for Tutorial 9 - Sound Manager

Postby mike » Thu Sep 30, 2010 9:23 am

Hi badweasel

I've checked the code in SoundManager and found an important line of code is missing from the SoundManager code in the tutorials and in the book.

If you check our the errata forum for the book you'll see that I've posted the correction which will causes sounds and music to play after an interruption.

Let me know if that works for you.

Mike
mike
 
Posts: 670
Joined: Fri Aug 21, 2009 2:10 pm

Re: Discussion for Tutorial 9 - Sound Manager

Postby badweasel » Thu Sep 30, 2010 12:08 pm

Thanks I'll check that out.

I tried the idea of also shutting down the sound manager when the app goes in the background, or say when the user turns off sound effects, and then re-initalizing it when coming back to the fg or when the user turns sound effects back on. Then in my local "play sound effect" method only actually playing it if the sound was currently initalized.

Currently I have something like this in my game code to handle sound being on or off:
Code: Select all
-(void)playSoundWithKey: (NSString *) soundKey {
   if (soundOnOff==OPT_SOUND_ON) {
      [sharedSoundManager playSoundWithKey:soundKey gain:soundVolume pitch:1.0f shouldLoop:NO];
   }   
}


It was a mod I tried to pull of quickly against a deadline and got some crashing (probably my fault) so I just left it alone for now and put it back to the above code. My primary goal in it was to mainly fix the thing that your errata will fix. My secondary goal was to provide a some way to have sound if the user wants it and also provide the option for users to play background music by just turning off sfx - it was only a short term solution idea until I figured out 'the right' way.

Do you have any info on iOS 4 and mixing audio with the background... In the WWDC session 412 they discuss the AVAudioSession and setting a category for your app which sets up how your sound is mixed with other sounds. Being able to play ipod music or listen to streaming music while playing my game has been a big request. Good info online and code examples for sound effects managers is hard to find and yours is the best I've found. But I'd love to be able to add this capability.

If I figure it out on my own I'll post it here. Thanks again.
badweasel
 
Posts: 7
Joined: Mon Sep 27, 2010 3:24 pm

Re: Discussion for Tutorial 9 - Sound Manager

Postby badweasel » Thu Sep 30, 2010 12:38 pm

ahh.. nevermind..

I purchased the rough cuts book very early on and i'm a watcher more than a reader.. so I must have taken source either from the video or from a version before you had the iOS4 code in there. I just downloaded the final copy of the book and see that YOU DO have the AVAudioSessionCategorySoloAmbient code in there. My version of init doesn't have any of the AVAudioSession stuff in there. So this will fix me.

Thanks so much Mike for writing this book and providing these tutorials!
badweasel
 
Posts: 7
Joined: Mon Sep 27, 2010 3:24 pm

Re: Discussion for Tutorial 9 - Sound Manager

Postby badweasel » Tue Nov 02, 2010 8:45 pm

Mike.. I implemented your new sound manager library (the one from the book where I was previously using a modified version of the one from the tutorial) including the fix in the errata. Now I get a slight static noise burst when playing sounds but it's only happening in the simulator. Seems to be happening about when the sound is finishing or near finishing. I have not done extensive testing on devices to see if I can make it happen there, but so far I'm not hearing the noise on the devices - only in the sim.

Since it seems to be a simulator only thing I wasn't going to worry about it. Still I was wondering if you had ever heard it or knew what might be causing it. I noticed that in your newer library you don't specify the bit rate of the sound files. My actual sound effects have more than one bit rate.. meaning that some have are like ~22k and some are like 44.1. I can't think of anything else that might be relevant.

-michael
badweasel
 
Posts: 7
Joined: Mon Sep 27, 2010 3:24 pm

Next

Return to iPhone Game Tutorials

Who is online

Users browsing this forum: No registered users and 0 guests

cron