![]() |
|
Implementing sound - Printable Version +- iDevGames Forums (http://www.idevgames.com/forums) +-- Forum: Development Zone (/forum-3.html) +--- Forum: Game Programming Fundamentals (/forum-7.html) +--- Thread: Implementing sound (/thread-6652.html) Pages: 1 2 |
Implementing sound - Muffinking - Oct 29, 2003 11:08 PM I need something really simple..and quick to implement. All I want to be able to do is play a few sounds.. nothing fancy... no stereo panning or anything.. no crazy effects.. just play 4-5 sounds at the most at the same time... I need a solution that is simple and easy to implement something requires very little time to get results.. Is this wishful thinking or is there something out there i can use for my uDev entry>? A little background music would add a lot to my game.. as would some simple sound effects.. any thoughts? same code is welcome.. hank- Implementing sound - kelvin - Oct 30, 2003 03:09 AM how much control do you want? NSSound is fairly straight forward. Code: [[NSSound soundNamed:@"soundinbundle"] play];Implementing sound - Bachus - Oct 30, 2003 04:05 AM And for background music, NSMovie is the way to go. Code: NSMovie *musicQT;Sound Manager is probably the easiest for Carbon, but it's still way more complicated than NSSound and NSMovie. Implementing sound - kelvin - Oct 30, 2003 09:43 AM if you want looping music CocoaBlitz has an NSMovie subclass CBMovie that has all the controls of NSMovieView. Good for looping and other things like that. Implementing sound - FCCovett - Oct 30, 2003 11:03 AM For a Carbon "almost-turnkey" solution, go to http://www.idevgames.com/forum/showthread.php?postid=51277#post51277 Implementing sound - MattDiamond - Oct 30, 2003 07:54 PM Quote:Originally posted by kelvin Could I use this in my uDevGame entry? Of course you would be credited and linked, but are there any other terms? [EDIT: never mind, I thought I could use this subclass separately from the CocoaBlitz framework. I believe you already have information posted about the terms for using the entire CocoaBlitz framework, so I can go look it up.] Implementing sound - MattDiamond - Oct 30, 2003 09:25 PM Okay, color me annoyed. I had hoped to add looping background music fairly easily, but: - no code samples do it on Apple's site (they used to, but now they just have a technical note that says "you can probably use Quicktime, maybe." - Quicktime seems to require a MovieView to give you looping. I can't figure out a way to do that without creating a visible MovieView object on a window somewhere. Either that or you poll to see if your movie has ended yet... I can't imagine I'll get seamless loops that way - CocoaBlitz CBMovie doesn't quite match my expectation (the methods all take the sender's id, it doesn't load by URL, there are no examples) though it was promising - searched CocoaDev, iDG FAQ, and Googled for an hour but didn't find what I need. Why is this difficult at all?? Hasn't this problem been solved a million times over? Is it actually easy but I'm in too much of a hurry to see it? I guess if I had a week to spare I'd figure it out. I can't believe I wasted an evening on this... I could have worked on my icon or something. But no, I had to get fancy and try and add music at the last minute.
Implementing sound - Damian - Oct 30, 2003 10:26 PM in the header: NSMovie *bgMusic; Movie *theMusic; NSTimer *checkMusicTimer; Code: bgMusic=[[NSMovie alloc] initWithURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/In_Touch_2.mp3"]] byReference:YES];Checking only one or a few times (or 100s, really) a second has no effect on performance. There is probably a techier way of doing this, but the above code works for me. Implementing sound - Bachus - Oct 31, 2003 01:10 AM Damian beat me to it. You use an NSTimer and just check to see if the movie is done. Then you restart it. NSMovieView is easier to use, but I think its looping is also buggy in Jaguar. You basically have to do the exact same thing when you use a View. Implementing sound - kelvin - Oct 31, 2003 06:52 AM I can't find the old thread on this topic but using timers to loop NSSounds or even using NSSound's notification callback will cause an audible pop as it skips. CBMovie on the other hand uses Quicktime callbacks and will loop the sounds smoothly. Also CBMovie has controls to change the rate(pitch) and time(playbackhead) of the sound.here's some code: Code: CBMovie* sound = [[CBMovie alloc] initWithFile:soundpath byReference:NO];[edit: who thinks I should post the source to CBMovie?] Implementing sound - MattDiamond - Oct 31, 2003 11:46 AM Quote:Originally posted by kelvin All these replies are helpful. I'm most worried about loop discontinuity, as I mentioned, so I think NSTimer polling won't work for me. This morning I finally remembered that I had a copy of Mac Game Programming, which has a Carbon sound looping solution (also using callbacks) and I was going to go with that. But now that I know that Quicktime has callbacks I was able to find some partial examples online just now. But let's talk CBMovie some more. What's "self" above? Would any Cocoa object do, or does it need to implement a particular interface? My game's objects are all C++ but I wouldn't mind defining a trivial Cocoa helper object to hold the music. I like the way you baked in the NSMovieView functionality into the CBMovie interface. Quote:who thinks I should post the source to CBMovie?I read this, and your thread about possibly open-sourcing CB, and I don't know what to tell you. If you posted the source to that one object I'd use it without CB but you and CB would get a nice thank-you from me in the game credits. But maybe you'd prefer to force people to use all of CB? It could be a marketing tool for you. I'll add that if you don't post the source I may decide not load your framework to use that one utility. Thanks to your hints I'm probably able to roll my own version now, though using CBMovie would certainly save me time. In short, I'd love you to release it but I can see why you wouldn't want to. And you won't get any lecture from me about open source, seeing as I've been using the restrictive iDG license for my source code. (I'm having second thoughts about that, but that's a topic for another day.) Do what you feel best, with my thanks either way. And thanks for all the help, everybody. I was pretty discouraged last night, and ready to move on to the icon and readme, but I think I'll give this another shot. Music would have a dramatic effect on the game, I think. Implementing sound - FCCovett - Oct 31, 2003 02:29 PM Matt, If you are considering a Carbon / C solution, check the source code on this thread: http://www.idevgames.com/forum/showthread.php?postid=51277#post51277 It's all done for you. You'd just need to interface the C code with your Obj C code, but that should be almost trivial ( I mean, if you are indeed working in Obj C ). Implementing sound - MattDiamond - Oct 31, 2003 03:23 PM Quote:Originally posted by FCCovett Obj C++ and straight C++, actually. No problem interfacing to some C code. You know, I looked at your code last night but for some reason I put it away again. I can't remember why. I'll look at it again and tell you if there was something specific that bothered me. Maybe it was something stupid, like I didn't understand the license. I'm treating all my thoughts from last night as highly suspect, now that I've gotten a little sleep. :-) Thanks! Implementing sound - kelvin - Oct 31, 2003 03:50 PM well... since I don't really have any qualms about CBMovie (as it's not really integral to CB) I'll post the source here for you as a favor though, I would like for you to write up a more professional looking tutorial perhaps. Something that is easier to read and more permanent than a forum post. Maybe even an iDG article... You can use my source files, just put credit where it's due.CBMovie source watch those fixed precision values! Implementing sound - FCCovett - Oct 31, 2003 04:42 PM License? Use it as you wish; my code is public domain. The part of it I got from Apple's documentation is not restricted, AFAIK. |