Latest Sound Manager Class
I’ve finally managed to upload the latest version of the SoundManager class. This is the same version I am using in Sir Lamorak’s Quest. There are a few changes from the class in the tutorials. I’ve added some new methods
- (void)playNextTrack; - (void)addToPlaylistNamed:(NSString*)aPlaylistName track:(NSString*)aTrackName; - (void)startPlaylistNamed:(NSString*)aPlaylistName; - (void)removeFromPlaylistNamed:(NSString*)aPlaylistName track:(NSString*)aTrackName; - (void)removePlaylistNamed:(NSString*)aPlaylistName; - (void)clearPlaylistNamed:(NSString*)aPlaylistName; - (void)fadeMusicVolumeFrom:(float)aFromVolume toVolume:(float)aToVolume duration:(float)aSeconds stop:(BOOL)aStop;
Also new class properties have been defined as well
BOOL isExternalAudioPlaying; // YES if music was playing before the sound engine was initialized i.e. BOOL isMusicPlaying; // YES if music is currently playing BOOL usePlaylist; // YES if tracks in the playlist should be played one after the other BOOL loopPlaylist; // YES if the playlist should loop when it reaches the end BOOL loopLastPlaylistTrack; // YES if you want the last track of the playlist to be looped forever
Some of the changes made have been due to readers comments. isExternalAudioPlaying for example is set when the SoundManager is first initialized. If iPod music is playing at that point then the sound category is set to Ambient. If no music is playing then its set to SoloAmbient. I check this flag in SLQ and if it is YES then I don’t play any background music, just sound effects as the player is listening to their own music.
Some methods signatures have also been changed e.g.
- (NSUInteger)playSoundWithKey:(NSString*)aSoundKey gain:(ALfloat)aGain pitch:(ALfloat)aPitch
location:(CGPoint)aLocation shouldLoop:(BOOL)aLoop sourceID:(NSUInteger)aSourceID;
This method used to take a vector2f for the location and is now taking a CGPoint. I did this to make the manager a little more portable with no need for any non-standard types or structures.
TIP: When using the play lists, you need to have the tracks that are going to be in your playlist to the sound managers music library before added a track to the play list.
I’ve not done a ton of testing around memory leaks, but this version does seem to have fixed the memory leaks that the previous tutorial version had.
I will try to get a new tutorial up at some point about the new sound manager class, but the comments etc should make it reasonably easy to drop into your projects.
I hope you find this useful and let me know how you get on.
Mike
UPDATE 02/02/10: I’ve added the supporting files to the zip i.e. SynthesizeSingleton.h, MyOpenALSupport.h and MyOpenALSupport.m. Thanks to the those who commented on this :o)
UPDATE 01/02/10: I’m running through the sound manager for the book at the moment so I’m giving it a lot of attention at the moment. In doing so I’ve ripped out the C based interruptionListener and replaced it with the Objective-C-based AVAudioSession API. This is nicer to use that the C based one and means I’m not mixing C and Objective-C. This makes it cleaner for the book :o) The link above now points to the new version of the manager. I’ve also added more checking for errors as OpenAL can be a little fussy and so knowing when an error has occurred is useful.
94 Comments
Simon on January 29th, 2010
Good work on this, it all seems to be coming along nicely. Looking forward to the book. Is it up on rough cuts yet in draft format?
OpenAL Sound Manager Class Updated | iPhone Development Tutorials and Programming Tips on January 30th, 2010
[...] Some cool functionality has been added for playlists, and all memory leaks are gone, you’ll love this thing it’s easy to use. You can download the updated version here: Latest Sound Manager Class [...]
RoberRM on January 30th, 2010
Hello, Mike:
I’m sorry if you already answered this question, but now that you are talking about memory leaks I have to ask: are you going to include in your book or in a tutorial any information on how to find memory leaks? I know Apple includes an application to do that (and other applications to do a lot things more), but I cannot make them work (they usually make my game crash on start-up). :(
Thank you in advance for your answer and for keeping us up to date. ;)
RoberRM
OpenAL SoundManager at Under The Bridge on January 30th, 2010
[...] If you’re looking at using OpenAL in your iPhone project, you probably want to check out the handy wrapper here. [...]
glen on January 30th, 2010
Hi Mike
Just wondered if the AngelCodeFont could be altered to run in landscape mode?
Great Tutorials not understanding everything but then i dont think i need too, to make use of them.
I’ve heard other people comment about a book your doing any idea when this will be available?
Cheers
mike on January 30th, 2010
Hi glen
You don’t need to alter AngelCodeFont to run in landscape mode, all you would need to do is rotate the OpenGL coordinates using glRotate before rendering the text. That would allow you to render text at any angle :o)
Mike
mike on January 31st, 2010
Hi RoberRM
I am hoping to include some information in the book about using instruments. It will be light but hopefully be useful to show people how to get the basics from Instruments.
I’ll also look at doing a tutorial on it at some point.
Mike
mike on January 31st, 2010
Hi Scott
Thanks for the comment. The code for the complete SLQ game will only be available with the book. I am releasing some elements to the blog, such as the sound engine, but the core will be available with the book.
I’ll also keep you in the loop re reviewing the book.
Mike
mike on February 1st, 2010
Just to let you know that I’ve made changes to the sound manager. I’ve removed the C-based interruptionListener with the Objective-C-based AVAudioSession which I prefer :o)
Also added more regular error checking in the OpenAL side of things.
Have fun
Mike
mluelmo on February 1st, 2010
So great. Can’t wait for your book!!!
Tanks for your great job.
CC on February 2nd, 2010
Thanks again. We used this latest version of the sound manager class in the Global Game Jam this past weekend, so it came in handy for making a game quickly.
You might consider including the SynthesizeSingleton.h and MyOpenALSupport.h files with the download, or where to acquire them; it’s not clear where to get those files.
Anyway, thanks for the improvements!
mluelmo on February 2nd, 2010
CC, SynthesizeSingleton.h and MyOpenAlSupport.h are both on Chapter 10. Just yesterday I was on the same issue!!! :-D
With my low level iPhone development skills, I’ve made a very important part of my project in about 3-4 hours thanks to these api.
Very good job!!!
Your book is the second in my wish list (sorry, iPad is the first… :-D)
Mike on February 2nd, 2010
Thanks for the comments guys. I completely forgot about the supporting files so I’ll get them added to the Zip. Great feedback.
Mike
Mike on February 2nd, 2010
CC. Where abouts was the global game jam?
CC on February 2nd, 2010
The Global Game Jam is a global 48-hour game development challenge, so it’s anywhere you want to participate. The web site is http://globalgamejam.org.
If you’d like to see info about the game we came up with, our team’s site is http://globalgamejam.nmsu.edu. We made “Vile Haberdashery”, an nasty little game of murder and intrigue in an old Victorian manor. We had a blast making it – there were four of us, and we got the thing designed, programmed, and all the art assets made for a fully playable version in less than 48 hours. And it’s FUN! It’s a turn-based strategy game where you take your turn and hand the iPhone to the next player to take their turn. Audio cues give you a clue as to what they’re doing, so it’s a fun little game to play over dinner with friends, while watching TV, riding the bus or subway, etc. Be sure to check it out on the App Store when it hits.
Benoit on February 2nd, 2010
Hi Mike,
Thank you very much, VERY useful as always! A while ago you mentioned that you also changed the way of rendering graphics since the tutorials… Do you plan to give us an update on that or is it going to be exclusive to the book? Thank you!
Benoit
Starra on February 2nd, 2010
Hi Mike,
Thanks for the update. It is very useful. However, I did notice that musicVolume is not initialized in init. It doesn’t get set until setMusicVolume is called. Did you do that on purpose or it’s a small error?
~Charles
mike on February 3rd, 2010
Hi Starra, well spotted. musicVolume should be set to 0.5 in init as a default value.
Thanks
Mike
mike on February 3rd, 2010
@CC Nice, I checked out the website and you certainly managed to get tons done in 48 hours. I’m looking forward to giving it a try when its on the App Store.
Mike
mike on February 3rd, 2010
I have updated the zip file so that it now includes the associated files i.e. SynthesizeSingleton.h, MyOpenALSupport.h and MyOpenALSupport.m.
Mike
mike on February 3rd, 2010
@Benoit, the rest of the changes I’ve made will be in the book. Almost every aspect of the engine I developed through the tutorials has been updated and improved. The tutorials taught me a great deal and the books code take advantage of that.
I want the book to be a bonus over and above what is on the website hence I’m keeping most of the new code for the book.
The sound manager was such an easy stand alone element though I wanted to share it early as sound does seem to cause people problems :o)
Mike
Benoit on February 3rd, 2010
Ok Mike, thanks, I really can’t wait for the book then. :)
CC on February 3rd, 2010
@Mike, thanks. Hope you enjoy it when it comes out. I submitted it to the App Store last night, and it uses the new Sound Manager class in it.
I can’t tell you how handy your Sound Manager articles have been – audio is the one part of the iPhone development that has been a recurring headache, and now, it’s easy. Thanks.
Keith on February 5th, 2010
Hi Mike,
Thanks for all the tutorials. I finally released my game on the App Store using your tutorial sample codes. And even this latest Sound Manage class. Many thanks. If you would like to check out the game there is the link to iTune store:
itune link:
http://phobos.apple.com/WebObj.....=353421193
video: http://www.youtube.com/watch?v=wG8qlioLB5g
Please send me your email address so that I can send you a promotion code.
Many thanks for your great work.
Cheers,
Keith
mike on February 5th, 2010
Hi Keith, that is a nicely executed game. I love the retro feel to it :o)
There are a few games that people have finished recently that I need to get mentioned on the blog, I’m a little behind on that at the moment. I’ll add yours to the list as well :O)
I would love to use your promo code but as I’m based in the UK they won’t work :(
For future use those my email is mike@71squared.com
Mike
aaronsullivan on February 8th, 2010
Some unexpected behavior in the stopSoundWithKey: method. It doesn’t just stop the source playing the sound it goes the extra step of removing the sound from the buffer library! Maybe a copy paste mistake from removeSoundWithKey: because they are so similar. :)
aaronsullivan on February 8th, 2010
Also, you might want to have an option of using an enumerated list to use as the keys. Passing strings around every time you play a sound is sort of overkill if you can avoid it.
Because I’m shoehorning this into existing code I just made an alternate play method that takes a bufferID instead of the key.
BTW, thanks for the code and the site. It’s been a great time saver.
mike on February 9th, 2010
Hi aaronsullivan, thanks for the feedback. You are absolutely right. The stop sound method does include the removal of the sound as well which is because I copied and pasted the method. Schoolboyish error on my part there. I’ll get the source fixed.
I hadn’t considered using an enumerated list before but its a nice idea, I’ll have to give that a go.
Glad its helping you out and thanks again for the great feedback.
Mike
aaronsullivan on February 10th, 2010
I guess all it would take is changing your buffer library and using NSUIntegers as keys instead of NSStrings. Then, each game gets its own enumerated list of sound key names. Either way the dev has to keep track of a list of names.
Passing pointers to an NSString doesn’t cost more than passing an uint, but dictionary lookups and object management with NSStrings sort of has to, doesn’t it?
Anyway, I just decided to clarify what I said about using enumerated types in case anyone wanted to try it out. My original wording was pretty clumsy.
Jeremiah on February 10th, 2010
I would like to use your sound manager, But I’m having trouble getting it to work in my app. I built a new project and tried to integrate it into that, and still couldn’t seem to get it to work. Could you post a source project that has just the sound manager playing a loop and button press. Thanks much!
mluelmo on February 10th, 2010
Jeremiah, why don’t you explain your problems on a new post? It will be usefull for other people.
Jeremiah on February 10th, 2010
Thanks for the swift reply,
Basically I downloaded the “SoundManagerV3.zip”
http://www.71squared.com/iPhone/SoundManagerV3.zip
Added the files to a new xcode project and set it up to play a background sound and a touchesBegan sound, similar to the the setup in OGLGame Tutorial 9. But it doesnt seem to want to work. Im probably doing something wrong.
I’m wondering if you could post just an xcode project, like OGLGame Tutorial 9, but with just the SoundManagerV3 working in it, and nothing else. This way we could focus on just the SoundManager and not get confused with all the other game logic/code you have written in your other tutorials. I hope that makes scene.
Thanks again.
Chris on February 12th, 2010
YESSSS!!! exactly what Jeremiah said I am also looking for. Always I find demos with many other stuff i dont need, and as long i am beginner its hard to differenciate what i need and not.
So just a SIMPLE XCode Project with only the Files needed and a most simple demo (not buttons even.. just a code of line comment // playsound (xxx) // stopsound (xxx)
to see how i have to call it, would be amazing.
There are so many tutorial.. all without an xcode demo.
There are so many cool classes .. see:
http://www.surina.net/soundtouch/
all without xcode demo!
So I really would appreciate a simple xcode Demo :)
thx
chris
Chris on February 13th, 2010
:) hope someone can help
I got luckily working now the first soundmanager
with the old: SingletonSoundManager.h
#import “SingletonSoundManager.h”
- (void)viewDidLoad {
SingletonSoundManager *sharedSoundManager;
sharedSoundManager = [SingletonSoundManager sharedSoundManager];
[sharedSoundManager loadSoundWithKey:@"laser" fileName:@"laser" fileExt:@"caf" frequency:44100];
[sharedSoundManager playSoundWithKey:@"laser" gain:1.0f pitch:0.12f location:Vector2fZero shouldLoop:NO];
}
COOL!!!! But I was interested to keep up to date and installed your ‘latest soundmanager”
#import “SoundManager.h”
- (void)viewDidLoad {
SoundManager *sharedSoundManager;
sharedSoundManager = [SoundManager sharedSoundManager];
[sharedSoundManager loadSoundWithKey:@"laser" fileName:@"laughcartoon" fileExt:@"caf" frequency:22050];
//[sharedSoundManager loadSoundWithKey:@"laser" fileName:@"laser" fileExt:@"caf"];
//[sharedSoundManager playSoundWithKey:@"laser" gain:1.0f pitch:1.0f location:CGPointMake(100,100) shouldLoop:NO sourceID:-1];
But here I always get a
‘Soundmanager may not respond to “-loadSoundwithKey:filename …. ” ???
And I dont find how to fix it … what I am doing wrong ? :)
thx for your hard work
chris
mike on February 13th, 2010
Hi Chris, check the SoundManager.h file. You will be able to see the methods that are supported in the SoundManager class.
The loadSoundWithKey method now only takes the key and name of the file, it doesn’t take frequency anymore. This is now worked out for you. The method looks like this now:
- (void)loadSoundWithKey:(NSString*)aSoundKey musicFile:(NSString*)aMusicFile;
Mike
Jeremiah on February 15th, 2010
This is how Im trying to get the sound to play, and I get some warnings.
‘SoundManager’ may not respond to ‘-playSoundWithKey:shouldLoop:’
// TestViewController.h
#import
#import “SoundManager.h”
@interface TestViewController : UIViewController {
// Sound Manager
SoundManager *sharedSoundManager;
}
@end
// TestViewController.m
#import “SoundManager.h”
#import “TestViewController.h”
@implementation TestViewController
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
//[sharedSoundManager setListenerPosition:Vector2fMake(160, 0)];
// Initialize the sound effects
[sharedSoundManager loadSoundWithKey:@"sound1" fileName:@"1" fileExt:@"wav"];
[sharedSoundManager loadSoundWithKey:@"sound2" fileName:@"2" fileExt:@"wav"];
// Initialize the background music
[sharedSoundManager loadBackgroundMusicWithKey:@"backgroundMusic" fileName:@"backgroundMusic" fileExt:@"wav"];
[sharedSoundManager setMusicVolume:0.75f];
[sharedSoundManager playMusicWithKey:@"backgroundMusic" timesToRepeat:-1];
// Set the master sound FX volume
//[sharedSoundManager setFXVolume:1.0f];
[super viewDidLoad];
}
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
[sharedSoundManager playSoundWithKey:@"sound1" shouldLoop:NO];
}
Mike/Chris, if you get this working could you post a link to an XCode Project??
Thanks
Mic2000 on February 15th, 2010
Hee Mike,
First of all: thank you for such great classes and to make it available for public(developers) use. Until now, I only ren into one problem. When I use the MPMoviePlayerController class to play a cutscene in my game, the sound engine doesn’t work anymore. I’m not able to relaunch (alloc] init) the soundengine, the init function does not want to work anymore… Do you have any solution for it, a way to close the sound engine and restart it after finishing the movie?
Thank you for everything already!
Jeremiah on February 15th, 2010
Ok, so I have no warnings now, builds fine, but plays no sound.
NSLog(@”start loading sounds”);
[sharedSoundManager loadSoundWithKey:@"backgroundMusic" musicFile:@"backgroundMusic.wav"];
[sharedSoundManager loadSoundWithKey:@"sound1" musicFile:@"1.wav"];
NSLog(@”play loop”);
[sharedSoundManager playSoundWithKey:@"backgroundMusic" gain:1.0f pitch:1.0f location:CGPointMake(100,100) shouldLoop:YES sourceID:-1];
Any thoughts?
Thanks
mike on February 15th, 2010
Hi Jeremiah, where is the listener positioned? You are positioning the sound at 100,100. If the listener is not close enough, the sound will not be heard.
Mike
Jeremiah on February 16th, 2010
Mike, I guess I am not quite understanding this. Im not sure if I need to set “location:CGPointMake(100,100)” or how to place a listener. I was looking at how Chris, in the above post was doing it.
I’m use to playing sounds with AVAudioPlayer, where you define the file you want to play, and then tell it to play. Like this.
NSString *path = [[NSBundle mainBundle] pathForResource:@”2″ ofType:@”wav”];
theAudio2 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio2.delegate = self;
[theAudio2 play];
I guess this is why I was asking for a sample xcode project, with a simple background loop and a button press sound effect. Then I could look at that and study what everything is and how it all works together.
I’m basically looking for an alternative to using AVAudioPlayer as it is a little slow at playing the audio back (high latency), such as in the case of a piano or drum machine type of application.
Thanks for all your help, and sorry for flooding your comments section like its a forum.
aaronsullivan on February 16th, 2010
You are looking for setListenerPosition:(CGPoint)aPosition
Just set the listener to the same coordinates you want the sound to played back and it will come out right in the center of your speakers and you don’t have to worry about the positional thing. You’ll only have to set the listener position once in that case.
If you WANT to mess with positioning, make them different. You are probably leaving the listener at 0,0 and playing the sound at 100, 100 which is far away so the listener can’t hear it.
Yes, using this method should drastically reduce any latency you were experiencing with AVAudioPlayer.
Mic2000 on February 16th, 2010
Hi Mike,
I found the way around the Videoplayer thing. At other forums they are talking about interrupting the audio session when starting the video. After some testing I found the awnser by adding some code. Before you start the movie pause de soundengine, after resume:
- (void) pause
{
NSLog(@”Pause AL”);
// Deactivate the current audio session
AudioSessionSetActive(NO);
// set the current context to NULL will ‘shutdown’ openAL
alcMakeContextCurrent(NULL);
// now suspend your context to ‘pause’ your sound world
alcSuspendContext(context);
}
- (void) resume
{
NSLog(@”Resume AL”);
// Reset audio session
UInt32 category = kAudioSessionCategory_AmbientSound;
AudioSessionSetProperty ( kAudioSessionProperty_AudioCategory, sizeof
(category), &category );
// Reactivate the current audio session
AudioSessionSetActive(YES);
// Restore open al context
alcMakeContextCurrent(context);
// ‘unpause’ my context
alcProcessContext(context);
}
The soundengine works fine, only loading background music gives back the hick in framerate/performance…
I hope the code is helpfull to you!
mike on February 16th, 2010
Thanks Mic2000, that is really good to know. I’ve not used the videoplayer, so knowing you have to suspend the context and rebuild it after is very useful.
Mike
Mic2000 on February 16th, 2010
Your welcome, found it at: http://groups.google.com/group.....&pli=1
Jeremiah on February 16th, 2010
Thanks aaronsullivan, I see that the SoundManager.m has this code in it.
- (void)setListenerPosition:(CGPoint)aPosition {
listenerPosition = aPosition;
alListener3f(AL_POSITION, aPosition.x, aPosition.y, 0.0f);
}
Is this where the listener is being set at 0,0?
If I were to switch the “location:CGPointMake(100,100)” to “location:CGPointMake(0,0)” should the audio play?
mike on February 16th, 2010
The listener is actually being set to 0,0 in the initializer of the sound manager. That is its default location. If you make the change you mention above then the sound will play at the same location as the listeners default location and you should be able to her it.
The method you mention is used to set the listeners position if you want to move it. the 0.0f in the command is setting the z coordinate of the listener to 0 as the sound manager is not working in 3D.
Mike
Jeremiah on February 16th, 2010
Mike, thanks for your help. So I set the location to 0,0 and I still get no sound, no errors/warnings, Here is a zip file that contains the xcode project, if you could take a look at it that would be great.
mluelmo on February 16th, 2010
Hi Jeremiah.
You haven’t initialized sound manager.
It uses Singleton pattern, but Singleton doesn’t means “magically” initialized… ;-D
try this line on your viewDidLoad method:
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
sharedSoundManager = [SoundManager sharedSoundManager];
[sharedSoundManager loadSoundWithKey:@"BGmusic" musicFile:@"music.mp3"];
…
sorry for my english.
Jeremiah on February 17th, 2010
mluelmo, thanks for spotting that, still seems Not to work.
I get this in Console building to Sim 3.1.3,but still No sound.
Finished initializing the sound manager
Loaded sound with key ‘BGmusic’ into buffer ’2416′
Loaded sound with key ‘sound1′ into buffer ’2417′
start loading sounds
play loop
I get this in Console when I build to device 3.1.3 then it crashes.
Finished initializing the sound manager
Program received signal: “0”.
warning: check_safe_call: could not restore current frame
Any thoughts?
aaronsullivan on February 17th, 2010
In your touchesBegan method are you ALSO fixing the incorrect call to sharedSoundManager? You need to fix it there like mluelmo showed you to fix it in viewDidLoad.
I fixed your project this way and it works fine.
Jeremiah, it seems like most of these issues would have been VERY clear if you just took the time to watch the tutorial video on SoundManager again and maybe read the well commented header files. This last issue seems like you didn’t try very much before coming on here and posting another question. Just sayin’.
Or maybe there is some other issue I’m not aware of.
Jeremiah on February 17th, 2010
aaronsullivan, I have tried several things and and still get no results/sound. Ive watched the video about 3 times, and must have just overlooked the sharedSoundManager = [SoundManager sharedSoundManager];But other than that, I think there is some other issue, maybe my xcode. Would you mind posting the project you built so I could try building that one? Thanks
Chris on February 17th, 2010
Hi,
i had also some problems before and finaly got it work.
You may find a full functional XCode Demo (its on 3.2.2)
on my HP: http://2t4u.com/playopenal.zip
I added also a small function: checkSoundWithKeyPlaying(soundID)
Just look at the Source and when you start your Project
look into your CONSOLE !! to see if the Sound is still playing or not!
Enjoy and Thanks to Mike for the Base.
Greets
Chris
Jeremiah on February 17th, 2010
Chris, I downloaded your playopenal.zip and when I build it to the Sim it doesn’t play sound. When I build it to device I hear the “hallelujah” sound play on load. I wonder If my problems are due to installing 3.2.2 then installing 3.1.3. And maybe that’s messing up my sim. Id still like to try getting the project I started built at least to my device.
aaronsullivan would you mind posting the project you built so I could try building that one?
Thanks
Chris on February 17th, 2010
i dont know… do you work on a real MAC or on a Hackintosh.. so it may a soundcard problem.
I just can offer you a full working xcode (here its also working in my simulator on a iMac.
but finaly now you can experiment on your device :)
all the best
mike on February 17th, 2010
The simulator is notoriously bad an playing sound, especially OpenAL sound. I have had periods where its played fine, then not. At the moment I get nice little sound glitches in the OpenAL sounds themselves when they play on the sim. On the device they are fine.
Apple even mention in their docs that sound on the sim may not play when using OpenAL.
It could be you have a codec on your Mac that is causing the sim to have issues. That is something I’ve seen before. If its working fine on the device but not on the Mac, I would say the sim in the problem.
Mike
Jeremiah on February 17th, 2010
Thanks Mike/Chris, The sim seems to be the issue in the case of the project that Chris posted. But in the case of the project I posted, there must be something else wrong that I am doing. Ill keep plugging away at it until I understand all of this a Little Better. Thanks again for all your help, and the Sound Manager Base that your wrote.
aaronsullivan on February 17th, 2010
Your project, working:
http://buzzabit.com/test/MySoundTest.zip
As far as I remember, the only thing I changed is what you said you have fixed now. Compare and contrast.
For a long time, my MacBook wouldn’t play OpenAL sound in the simulator AT ALL. The simulator has since been updated and works fine now for me.
Jeremiah on February 18th, 2010
Aaron, Thanks for posting the file, Im now really stumped…
First, Im not really sure whe the “*sm” is that you added to
SoundManager *sm = [SoundManager sharedSoundManager];
Second, When I build to my sim It seems to build fine, no errors, but with no sound, so my sim seems to be broke and just sucks.
Thirdly, when I build to device it crashes showing
Sound Manager: Finished initializing the sound manager
Program received signal: “0”.
warning: check_safe_call: could not restore current frame
This is odd, and super frustrating! It should “just work” I think I might try installing the 3.2.2 sdk, and see if that fixes things, right now I dont see any other option.
Oddly enough the example that Chris posted above, http://2t4u.com/playopenal.zip, builds just fine.
Jeremiah on February 18th, 2010
OK, I am sorry for any inconvenience or head ache I may have caused you all, It looks like a simple restart of the phone and my laptop did the trick. Thank you all for having patience and helping me trouble shoot the issues that a simple restart could have fixed long ago. Who knew. Thanks again.
aaronsullivan on February 18th, 2010
Glad it’s working for you, now.
*pulls hair out, moves on*
The *sm is a pointer to a soundManager. Using a pointer is the basic way to track and message all objects in Objective-C.
It’s the same thing as using that sharedSoundManager pointer you defined in the MySoundTestViewController class. I guess I didn’t notice it or trust it, so I just made my own locally in those methods called “sm”.
Jeremiah on February 18th, 2010
So I seem to be experiencing the same error. Just last night I built the project to my phone just fine, as is downloaded from Aaron above. Now Im getting that same error, when the app is loading, it seems to crash.
Sound Manager: Finished initializing the sound manager
Program received signal: “0”.
warning: check_safe_call: could not restore current frame
I shutdown, macbook, and phone twice, disconnected phone from computer, built it to 3.0, and 3.1.3 phone, and the same thing, it crashes. Tried to sync my phone, restart and then rebuild, and the same crash. I even tried reinstalling the iphone_sdk_3.1.3_with_xcode_3.2.1__snow_leopard and still no luck. This is strange because after simply restarting my computer and phone last night, it built fine.
If anyone has any thoughts please let me know. Thanks
Jeremiah on February 22nd, 2010
After being completely frustrated, I narrowed it down to my computer, the sdk, and xcode being the problem, I completely removed the sdk/xcode and reinstalled it. Things seem to be working fine now. Again a huge thanks to all of you who helped me, I just wish I could have known that it was really all related to my computer crapping out.
Thanks
Jeremiah on February 22nd, 2010
Is there any further explanation that you could provide on controlling the volume and or pitch of the sounds via a UISlider?
I have a slider set up but im not to sure how to get it to talk to the “setFxVolume” or the pitch.
This is how I have my slider set up.
-(void)volume {
[sharedSoundManager setFxVolume:volumeSlider.value];
NSLog(@”volume level changed”);
}
-(void)pitch {
[sharedSoundManager setFxVolume:pitchSlider.value];
NSLog(@”pitch level changed”);
}
Here is an example of how I am playing the sound,
SoundManager *sm = [SoundManager sharedSoundManager];
[sm playSoundWithKey:@"sound1" gain:3.0f pitch:1.0f location:CGPointMake(0,0) shouldLoop:NO sourceID:-1];
I’m setting the gain and the pitch for each sound to a specific value, would I need to set them like “gain:(float)aGain and pitch:(float)aPitch” then have the slider value equal the “aGain” and “aPitch”?
Thanks for any elaboration you can supply.
Jeremiah on February 24th, 2010
I have been looking around for a bit and tried many things but i cant seem to figure out how to get the FxVolume to go any louder than “1.0f”.
I see that your setting the default fxVolume = 0.5f; in the SoundManager.m and your also setting
alSourcef(sourceID, AL_GAIN, aGain * fxVolume);
and
- (void)setFxVolume:(float)aVolume {
fxVolume = aVolume;
}
which aVolume = 1.0f;
I got my slider to work, but when I have the phone hardware volume set to half, and my slider volume set to max, the effects sounds dont seem to be loud enough to play over the ipod music.
Im setting my slider values up like this
volumeSlider.minimumValue = 0.0f;
volumeSlider.maximumValue = 1.0f;
volumeSlider.continuous = YES;
volumeSlider.value = 0.5f;
And when I change the maximumValue to be greater than 1.0f; it doesnt get any louder.
Is there a way to set a global minimumValue, and maximumValue for the fxVolume?
Thanks
mike on February 24th, 2010
Hi Jeremiah
The maximum value for the gain in OpenAL is 1.0f, if you use a larger number it is clamped to 1.0. Not being able to hear the sound effects is a common problem over iPod music. You need to make sure that the original sound effect was loud when recorded and you may have to have the volume up higher on the phone to hear them.
There is also a common problem with some types of sounds not mixing well with others e.g. iPod playback. It is always worth testing to make sure that the sounds you are using sound good on not only headphones but the devices internal speaker as well. Some sounds the speaker does not play well.
There is no way that I am aware of to set a global min and max volume.
Mike
JJ on February 24th, 2010
Thanks Mike, I did find a post stating that you can set the AL_GAIN / volume of the source to max and min.
Like this.. But I think that will also increase the ipod sound as well, i could be wrong. And when I tried to implement this It didnt like the soundID which in your manager is set to “-1″ I believe.
//—————————————-
// To set the volume of the source to max
alSourcef(sourceID, AL_GAIN, 1.0f);
// To set it to min
alSourcef(sourceID, AL_GAIN, 0.0f);
// And halfway
alSourcef(sourceID, AL_GAIN, 0.5f);
etc etc.
You can set a value of higher than 1.0f, which will (on some cards i think) increase the volume of the source past the volume of the buffer applied to it.
http://www.devmaster.net/forum.....php?t=1225
If this triggers any thoughts please share.
//—————————————-
Ill try amplifying the source sounds .wavs, and see if that will help.
Thanks
Jeremiah on February 25th, 2010
Thanks Mike,
I Found this on some blog..
In OpenAL gain means volume. So you have to change the AL_GAIN state to change the volume of a source (you can’t change the volume of a buffer as far as I have seen, and it seems strange why you would).
So
// To set the volume of the source to max
alSourcef(sourceID, AL_GAIN, 1.0f);
// To set it to min
alSourcef(sourceID, AL_GAIN, 0.0f);
// And halfway
alSourcef(sourceID, AL_GAIN, 0.5f);
etc etc.
You can set a value of higher than 1.0f, which will (on some cards i think) increase the volume of the source past the volume of the buffer applied to it.
But I think that will set the master gain for both the sound effects and the ipod music, so Im not sure this will help.
I can set the volume and pitch on my slider before I trigger the sounds to play, but I notice that while the sound is playing/looping I cant change its fxVolume or pitch. Is there any reason for this?
Thanks again.
aaronsullivan on February 26th, 2010
When you play a sound you get back the actual sourceID used. Store that and pass it into your alSourcef calls as the sourceID. That way it effects the volume of that source (there are many sources)
If you read the comments you’ll see that passing a -1 for a sourceID means you are letting the play method find an available source and use that. It then returns whatever available sourceID it found.
Hope that helps.
Jonathan on March 17th, 2010
Hi people,
For all you people out there who are having problems with Oal playback in the simulator… I have found a solution.
Go to your Applications/Utilities/Audio MIDI setup.
In the ‘Built-in Output’ tab make sure your ‘Format’ is set to – 41100.0 Hz (mine was 48)
My simulator was not playing any Oal sounds. I changed this setting and now everything works normal.
Hopefully this helps someone… cause it’s much quicker testing on the simulator (although dont stop testing the hardware)
Thanks Mike and everyone who contributes to 71Squared!
Jeremiah on March 17th, 2010
Jonathan
That worked great! Thanks, you have a little typo though, its 44100.0 Hz ;)
TheGoldenGunman on March 17th, 2010
This class has a number of memory leaks when alcMakeContextCurrent(context); is called. Have there been any updates to the code to remedy this?
Rudifa on March 17th, 2010
Hi Mike
Running clang static analyzer on SoundManager.m caught an error
“Pass-by-value argument in message expression is undefined”
in removeFromPlaylistNamed :
- (void)removeFromPlaylistNamed:(NSString*)aPlaylistName track:(NSString*)aTrackName {
NSMutableArray *playlistTracks = [musicPlaylists objectForKey:aPlaylistName];
if (playlistTracks) {
int indexToRemove;
for (int index=0; index < [currentPlaylistTracks count]; index++) {
if ([[currentPlaylistTracks objectAtIndex:index] isEqualToString:aTrackName]) {
indexToRemove = index;
break;
}
}
[currentPlaylistTracks removeObjectAtIndex:indexToRemove];
}
}
Indeed, if aTrackName is not found in currentPlaylistTracks, indexToRemove remains undefined.
I would suggest the following fix (untested) :
- (void)removeFromPlaylistNamed:(NSString*)aPlaylistName track:(NSString*)aTrackName {
NSMutableArray *playlistTracks = [musicPlaylists objectForKey:aPlaylistName];
if (playlistTracks) {
for (int index=0; index < [currentPlaylistTracks count]; index++) {
if ([[currentPlaylistTracks objectAtIndex:index] isEqualToString:aTrackName]) {
[currentPlaylistTracks removeObjectAtIndex:index];
break;
}
}
}
}
Triggerfish on May 14th, 2010
Hello Mike,
This was a fantastic tutorial. Thanks, man. Extremely clear and precise. I’m looking forward to your book.
I do have one question. How do I stop the call to stopMusic from also cutting off all the sound effects? I’ve tried out a few suggestions, but can’t seem to get my head around it.
Thanks
Triggerfish
Mic2000 on June 8th, 2010
Hey Mike,
Got two questions for ya! First of all, in the newest OS coming out soon, “alcMakeContextCurrent(context);” makes the ipod music stop on the 3GS. Do you know how to solve this?
Second: Besides of the issue we use the sound manager class with big effort and would like to add you or your company name in the credits, if you would allow/prefer!
Greetings,
Michiel Krol
mike on June 8th, 2010
Hi Michiel
I’ve not had a chance to try the sound manager on the latest iOS 4. I’ll take a look and see what needs to be changed and get back to you ASAP.
As for the mention, it would be great if you could put a mention into your credits :o)
Mike
Melvin Rivera on June 9th, 2010
First of all thank you much for this class. It’s incredible how responsive the UI remains despite playing so many sounds.
I have resolved one issue I encountered in my app. After the max number of sounds is hit, soundengine finds the first available non looped sound. This tends to create undesirable results since that sound could be a sound that recently started playing. I was able to fix this by creating a mutable array that keeps track of the order in which the soundIDs are used.
Here’s what I added to the SoundManager.h file:
In the interface:
NSMutableArray *soundSourcesHistory;
Here’s what I added to the SoundManager.m file:
in init:
soundSourcesHistory = [[NSMutableArray alloc]init];
in dealloc:
[soundSourcesHistory release];
at the end of – (NSUInteger)playSoundWithKey:(NSString*)aSoundKey gain:(float)aGain pitch:(float)aPitch location:(CGPoint)aLocation shouldLoop:(BOOL)aLoop sourceID:(NSUInteger)aSourceID
// add sourceID to history
[soundSourcesHistory addObject:[NSNumber numberWithUnsignedInt:sourceID]];
if ([soundSourcesHistory count] == 33) {
[soundSourcesHistory removeObjectAtIndex:0];
}
This adds the soundID to at the end of the array and checks to see if the array has now more than 32, if it does it removes the first item in the array which is the oldest one.
And in – (NSUInteger)nextAvailableSource I replaced the nonloop search with the following:
// search the played sound history staring with the oldest and grab the first non looping sound
NSUInteger sourceID;
NSInteger looping;
for (int i=0; i<[soundSourcesHistory count]; i++) {
NSNumber *sourceNumber = [soundSourcesHistory objectAtIndex:i];
alGetSourcei([sourceNumber unsignedIntValue], AL_LOOPING, &looping);
if(!looping) {
sourceID = [sourceNumber unsignedIntValue];
alSourceStop(sourceID);
break;
}
}
This goes through the history array and find the first non looping item. My app has a virtual piano and this has tons of very short audio files. THi approach seems to work for my purposes. Hope it helps.
The resources of cocos2D remember them « 凡达空间 Avatar Space on June 12th, 2010
[...] iPhone Custom Made Sound Manager: http://www.71squared.com/2010/.....ger-class/ [...]
Steve Mulligan on June 14th, 2010
iPod music was stopping for me in 3.1.3 (worked fine in 3.1.2)
Setting the category before initializing openAL seems to fix it.
-(id) init {
UInt32 category = kAudioSessionCategory_AmbientSound;
if (self = [super init] ) {
OSStatus result = AudioSessionInitialize(NULL, NULL, interruptionListener, self);
if (result) NSLog(@”Error initializing audio session! %d\n”, result);
else {
result = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category);
if (result) NSLog(@”Error setting audio session category! %d\n”, result);
result = AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange, RouteChangeListener, self);
if (result) NSLog(@”Couldn’t add listener: %d”, result);
result = AudioSessionSetActive(true);
if (result) NSLog(@”Error setting audio session active! %d\n”, result);
}
if ([self initOpenAL])
{
self.bufferStorageArray = [[[NSMutableArray alloc]init]autorelease];
self.soundDictionary = [[[NSMutableDictionary alloc]init]autorelease];
}
return self;
}
[self release];
return nil;
}
Mic2000 on June 14th, 2010
Hey Steve Mulligan,
I don’t really see how this codes fits into the code of 71squared. I had trouble since the iphone os 4.0 where the ipod stops playing and won’t turn on again until I shutdown the app or put it in the background. You have any experience with this?
Thnx!
mike on June 14th, 2010
Hi guys
I’ve just got around to testing SLQ on iOS 4 and the sound engine is working fine. If your playing iPod music then the game keeps it playing and just plays sound effects else you get the background music and sound effects.
I’ve not had a chance to look at the tutorial code, but I’ve zipped up the sound manager from SLQ which can be found at http://www.71squared.com/iPhone/SoundManagerV4.zip
That should work fine but let me know if you spot something not working right.
Mike
Mic2000 on June 14th, 2010
Hey Mike,
It works like a charm! Super thnx, could you contact me by mail about how you would like to be presented in the credits?
Thanks!
Benoit on June 14th, 2010
Hi Mike and everyone,
I get many leaks coming from the “AudioToolbox” library on iOS4 GM. I tried the latest version of the sound manager, same thing. No problem on 3.2 (iPad) though. Am I the only one? Thanks a lot!
Benoit
Mic2000 on June 15th, 2010
I had leaks in the simulator, but on the iPhone allmost none. You should Hove it a try, I will test it today on leaks, wou will hear from me!
Mic2000 on June 15th, 2010
Hi Benoit,
I keep my fingers crossed, but so far testing my app on my iPhone, iPod Touch and iPad gives me no leaks on the soundmanager class, or anything sound related.
Good luck!
Benoit on June 15th, 2010
Hi Mic2000,
Thanks for responding. Do you have iOS4 on (one of) those devices? I had no problem with previous versions of the iPhone OS either… I just found the cause of the leaks: it’s one line, in the initOpenAL method: alcMakeContextCurrent(context). When I comment it out, I get no leaks at all on the device, but the sounds won’t play, obviously (the music does, though). I really don’t know why it’s causing leaks, so I have no idea how to fix it. :S
Benoit
Mic2000 on June 15th, 2010
Hi Benoit,
I used the latest iOS 4.0 GM Seed (well there is only one). The funny story is that when I changed the soundmanager class from V3 to V4, I did not had it changed properly, because the files were referring towards an other directory.
But hey, try starting a new openGL project, add the classes (just download them again from Mike’s comment to be sure) and let it work in the new xcode project. I gave it a try yesterday evening and everything worked well in a new project.
Goodluck!
Benoit on June 15th, 2010
Hi Mic2000,
I get weird errors when I try to add the classes to an empty project. I added all the required frameworks (OpenAL, AudioToolbox, CoreAudio) but I get errors like these:
“_AVAudioSessionCategorySoloAmbient”, referenced from:
_AVAudioSessionCategorySoloAmbient$non_lazy_ptr in SoundManager.o
“_OBJC_CLASS_$_AVAudioSession”, referenced from:
objc-class-ref-to-AVAudioSession in SoundManager.o
“_AVAudioSessionCategoryAmbient”, referenced from:
_AVAudioSessionCategoryAmbient$non_lazy_ptr in SoundManager.o
I really don’t understand what’s going on. Haha sorry for disturbing you… I’m not even able to create a new project correctly. xD
Anyways, I guess I’ll try to figure it out later. Thank you very much for your help. Very appreciated.
Benoit
Benoit on June 15th, 2010
Uhm… oops. Haha. Yeah. I forgot the AVFoundation framework. Well I finally tested it, and you’re right, no leaks. I guess I have some debugging to do. If anyone has a clue what could be wrong with my other project causing a leak with the line “alcMakeContextCurrent(context)”, please let me know because I’m clueless! lol. Thank you!
sacculi on July 23rd, 2010
Hi
I’ve been enjoying using soundManager to load sounds into a comic I’m making but I’ve hit an issue. I have an error after the sixth file tries to load. I am calling the contents of a directory, names of files, and passing them in as strings converted to NSStrings (I should add I am writing using openFrameworks http://www.openframeworks.cc) in which most of my code is c++ and into which I am dropping handling sound.
So my idea is:
a vector of strings..
vector justSounds;
and in my main code, to load and play a first sound:
for (int i = 0; i= 40-radius && touch.x = 430-radius && touch.y <= 430+radius){
currentImage++;
currentImage %= nImages;
images[0].clear();
images[0].loadImage(IMG.getPath(currentImage));
[sharedSoundManager removeSoundWithKey:stringToNSString(justSounds[currentSound])];
currentSound++;
cout << SOUND.getName(currentSound) << " sound name value\n";
[sharedSoundManager loadSoundWithKey:stringToNSString(justSounds[currentSound]) musicFile:stringToNSString(justSounds[currentSound])];
[sharedSoundManager playSoundWithKey:stringToNSString(justSounds[currentSound]) gain:1.0f pitch:1.0f location:CGPointMake(0, 0) shouldLoop:NO sourceID:-1];
This is where the console shows the first few sounds appearing to load and play fine (and they do in the simulator) I hit the crash at image 6, and I don't understand what I'm doing wrong
console:
2010-07-23 23:18:32.035 Sobras1[657:207] ERROR – SoundManager: Error setting audio session category! -50
2010-07-23 23:18:32.037 Sobras1[657:207] INFO – Sound Manager: Initializing sound manager
AudioStreamBasicDescription: 2 ch, 44100 Hz, 'lpcm' (0x00000C2C) 8.24-bit little-endian signed integer, deinterleaved
2010-07-23 23:18:32.083 Sobras1[657:207] AddRunningClient starting device on non-zero client count
2010-07-23 23:18:35.659 Sobras1[657:207] INFO – Sound Manager: Finished initializing the sound manager
2010-07-23 23:18:35.673 Sobras1[657:207] INFO – SoundManager: Loaded sound with key '001-1' into buffer '2416'
OF_VERBOSE: setFrameRate 60.000 using NSTimer
2010-07-23 23:18:35.677 Sobras1[657:207] INFO – SoundManager: OpenAL Active
2010-07-23 23:18:35.677 Sobras1[657:207] ERROR – SoundManager: Unable to set the audio session category
OF_NOTICE: Device orientation changed to 1
2010-07-23 23:18:41.649 Sobras1[657:207] INFO – SoundManager: Removed sound with key '001-1'
002-1 sound name value
2010-07-23 23:18:41.653 Sobras1[657:207] INFO – SoundManager: Loaded sound with key '002-1' into buffer '2417'
2010-07-23 23:18:51.780 Sobras1[657:207] INFO – SoundManager: Removed sound with key '002-1'
003-1 sound name value
2010-07-23 23:18:51.784 Sobras1[657:207] INFO – SoundManager: Loaded sound with key '003-1' into buffer '2418'
2010-07-23 23:18:54.619 Sobras1[657:207] INFO – SoundManager: Removed sound with key '003-1'
004-1 sound name value
2010-07-23 23:18:54.626 Sobras1[657:207] INFO – SoundManager: Loaded sound with key '004-1' into buffer '2419'
2010-07-23 23:18:57.531 Sobras1[657:207] INFO – SoundManager: Removed sound with key '004-1'
005-1 sound name value
2010-07-23 23:18:57.536 Sobras1[657:207] INFO – SoundManager: Loaded sound with key '005-1' into buffer '2420'
2010-07-23 23:19:04.746 Sobras1[657:207] INFO – SoundManager: Removed sound with key '005-1'
006-1 sound name value
2010-07-23 23:19:04.750 Sobras1[657:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
*** Call stack at first throw:
(
thanks for any help!
sacculi
sacculi on July 23rd, 2010
sorry last post was scrambled, trying again:
Hi
I’ve been enjoying using soundManager to load sounds into a comic I’m making but I’ve hit an issue. I have an error after the sixth file tries to load. I am calling the contents of a directory, names of files, and passing them in as strings converted to NSStrings (I should add I am writing using openFrameworks http://www.openframeworks.cc) in which most of my code is c++ and into which I am dropping handling sound.
So my idea is:
a vector of strings..
vector justSounds;
and in my main code, to load and play a first sound:
for (int i = 0; i= 40-radius && touch.x = 430-radius && touch.y <= 430+radius){
currentImage++;
currentImage %= nImages;
images[0].clear();
images[0].loadImage(IMG.getPath(currentImage));
[sharedSoundManager removeSoundWithKey:stringToNSString(justSounds[currentSound])];
currentSound++;
cout << SOUND.getName(currentSound) << " sound name value\n";
[sharedSoundManager loadSoundWithKey:stringToNSString(justSounds[currentSound]) musicFile:stringToNSString(justSounds[currentSound])];
[sharedSoundManager playSoundWithKey:stringToNSString(justSounds[currentSound]) gain:1.0f pitch:1.0f location:CGPointMake(0, 0) shouldLoop:NO sourceID:-1];
This is where the console shows the first few sounds appearing to load and play fine (and they do in the simulator) I hit the crash at image 6, and I don't understand what I'm doing wrong
console:
2010-07-23 23:18:32.035 Sobras1[657:207] ERROR – SoundManager: Error setting audio session category! -50
2010-07-23 23:18:32.037 Sobras1[657:207] INFO – Sound Manager: Initializing sound manager
AudioStreamBasicDescription: 2 ch, 44100 Hz, 'lpcm' (0x00000C2C) 8.24-bit little-endian signed integer, deinterleaved
2010-07-23 23:18:32.083 Sobras1[657:207] AddRunningClient starting device on non-zero client count
2010-07-23 23:18:35.659 Sobras1[657:207] INFO – Sound Manager: Finished initializing the sound manager
2010-07-23 23:18:35.673 Sobras1[657:207] INFO – SoundManager: Loaded sound with key '001-1' into buffer '2416'
OF_VERBOSE: setFrameRate 60.000 using NSTimer
2010-07-23 23:18:35.677 Sobras1[657:207] INFO – SoundManager: OpenAL Active
2010-07-23 23:18:35.677 Sobras1[657:207] ERROR – SoundManager: Unable to set the audio session category
OF_NOTICE: Device orientation changed to 1
2010-07-23 23:18:41.649 Sobras1[657:207] INFO – SoundManager: Removed sound with key '001-1'
002-1 sound name value
2010-07-23 23:18:41.653 Sobras1[657:207] INFO – SoundManager: Loaded sound with key '002-1' into buffer '2417'
2010-07-23 23:18:51.780 Sobras1[657:207] INFO – SoundManager: Removed sound with key '002-1'
003-1 sound name value
2010-07-23 23:18:51.784 Sobras1[657:207] INFO – SoundManager: Loaded sound with key '003-1' into buffer '2418'
2010-07-23 23:18:54.619 Sobras1[657:207] INFO – SoundManager: Removed sound with key '003-1'
004-1 sound name value
2010-07-23 23:18:54.626 Sobras1[657:207] INFO – SoundManager: Loaded sound with key '004-1' into buffer '2419'
2010-07-23 23:18:57.531 Sobras1[657:207] INFO – SoundManager: Removed sound with key '004-1'
005-1 sound name value
2010-07-23 23:18:57.536 Sobras1[657:207] INFO – SoundManager: Loaded sound with key '005-1' into buffer '2420'
2010-07-23 23:19:04.746 Sobras1[657:207] INFO – SoundManager: Removed sound with key '005-1'
006-1 sound name value
2010-07-23 23:19:04.750 Sobras1[657:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
*** Call stack at first throw:
(
thanks for any help!
sacculi
Mic2000 on July 23rd, 2010
I can not say much about it, but my problem with simulator of hardware is: in simulator files do not have to be written case sensitive, on the iPhone it does. So on iPhone the next thing does not work:
[NSString alloc] init:@”sound.wav”];
this does not work if the file is “Sound.wav”
Correction:
[NSString alloc] init:@”Sound.wav”];
I don’t think it is the problem, but just had to type it!
sacculi on July 23rd, 2010
:( looks like I got the formatting wrong sorry maybe there are tags which I should use. If anyone can help my code is here! thanks so much
sacculi
http://www.sacculi.co.uk/Sobras1_4.zip
the data folder has subfolders where the image and sounds are kept
as I was saying above, it’s trying to load by using a vector of strings passed in when needed using a stringtToNSString function, as I’m mostly writing in c++




Scott on January 29th, 2010
Sorry if I missed it — I know the book is due to come out soon, but is the code for SLC available pre-publish or do we have to wait? If no, are you looking for any (more/different) reviewers for either the book or the code, I’d be more than happy to give them a thorough review. btw — the vids of the game are pretty impressive.