Where to start with Sound?

Member
Posts: 281
Joined: 2009.04
Post: #1
I'm developing a 2D game in C, and would like some sound. I've decided to use quicktime (It is my first game) but have no idea how to implement this. I will prepare .aiff sound files (Backround ditty, laser, blow up, etc etc) but how do I use these? Huh

Thanks Smile

~ Bring a Pen ~
Quote this message in a reply
Member
Posts: 260
Joined: 2005.05
Post: #2
This is rather a question of how to start with movies. It is almost the same code except that the audio doesn't need a window/view to be show in.

I don't think QuickTime is the best choice for instant sound effects. It is best used for background music and similar things.
Quote this message in a reply
Member
Posts: 281
Joined: 2009.04
Post: #3
OK, how do I start with movies? I've looked everwhere, but I can't find any tutorials. Oh, and should I make my audio into .mov?

~ Bring a Pen ~
Quote this message in a reply
Member
Posts: 260
Joined: 2005.05
Post: #4
No, you don't need .mov, it works nicely with mp3, AIFF etc.

I thought I should post some sample code, but that code was a bit old, it uses OpenMovieFile which is outdated. So I can post something that works, but I think both you and I want newer code.
Quote this message in a reply
Moderator
Posts: 623
Joined: 2007.09
Post: #5
Hmm, might you be using Cocoa?

If you are/can, you might look into QTMovie docs - should be fairly easy to work with.

- Lincoln Green
http://www.binkworks.com/
Quote this message in a reply
Member
Posts: 260
Joined: 2005.05
Post: #6
He said C, which to me means using QuickTime's stand-alone APIs. And there are updated calls, but I havn't figured out how to use them yet.
Quote this message in a reply
Member
Posts: 281
Joined: 2009.04
Post: #7
Ah, so the QT API is for C then eh? That's good, but my game's still silent. Smile

~ Bring a Pen ~
Quote this message in a reply
Moderator
Posts: 679
Joined: 2002.11
Post: #8
The general consensus is that QuickTime is evil. People usually use OpenAL for sound.

My web site - Games, music, Python stuff
Quote this message in a reply
Moderator
Posts: 623
Joined: 2007.09
Post: #9
Ingemar Wrote:He said C, which to me means using QuickTime's stand-alone APIs. And there are updated calls, but I havn't figured out how to use them yet.

Hmm, I was under the impression that you could access the Cocoa API with C, or just dip into Objective-C.

Ignore my post then. Smile

- Lincoln Green
http://www.binkworks.com/
Quote this message in a reply
Member
Posts: 260
Joined: 2005.05
Post: #10
This code works (which doesn't mean I want to do exactly this way):

Code:
/*  C translation from Pascal source file: MovieHack.p */
// Super simple movie player for playing sounds (like mp3)
// Plays a file named "Sample.mp3" in the same folder as the binary.

#include <QuickTime/Movies.h>
    
    Movie theMovie;
    OSErr err;
    FSSpec fileSpec;
    short resRefNum;
    SInt16 actualResId;
    Rect theMovieBox;
    WindowPtr w;

int main()
{
    err = EnterMovies();
    
    actualResId = DoTheRightThing;
    
// The following lines need replacing by FSRef-based calls
    err = FSMakeFSSpec(0, 0, "\pSample.mp3", &fileSpec);
    if ( err != noErr )
        printf("FSMakeFSSpec %d\n", err);
    err = OpenMovieFile(&fileSpec, &resRefNum, 0);
    if ( err != noErr )
        printf("OpenMovieFile %d\n", err);
    err = NewMovieFromFile(&theMovie, resRefNum, &actualResId, 0L, newMovieActive, 0L);
    if ( err != noErr )
        printf("NewMovieFromFile %d\n", err);
    
    // Try playing it
    StartMovie(theMovie);

    while ( ! IsMovieDone(theMovie) )
        MoviesTask(0L,0);
    
    DisposeMovie(theMovie);
    
    ExitMovies();
}

Does anyone has working (and reasonably simple) code for doing this with FSRefs?
Quote this message in a reply
Member
Posts: 281
Joined: 2009.04
Post: #11
Well, that code doesn't work on my mac. Sad Thanks anyway.

So, according to diordna, QT is evil. I should use OpenAL. I've two questions:

• I read somewhere that OpenAL will only work on the customers mac if they've installed OpenAL. This could be a problem.

• Is there a new(ish) tutorial/guide on OpenAL for mac?

Could someone please answer my questions, or post some sample code.

Thanks

~ Bring a Pen ~
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #12
FSSpec? WindowPtr? Blink

I don't think we should be recommending to new users that they use deprecated technologies. While the QuickTime C API might not be entirely deprecated yet, it's rapidly moving in that direction. Unfortunately, modern technologies like OpenAL and CoreAudio are somewhat more daunting...

mikey, I have some reasonably simple OpenAL code that I'll post here when I get home. Also, OpenAL is installed as part of the OS as of Mac OS X 10.3 (someone correct me if it's 10.4, but I was pretty sure it was 10.3), so you shouldn't need to worry about that.
Quote this message in a reply
Member
Posts: 281
Joined: 2009.04
Post: #13
Thanks everyone, I'll post my game when it's finished!

PS. I'm looking forward to ThemsAllTook's OpenAL Code.

~ Bring a Pen ~
Quote this message in a reply
Member
Posts: 260
Joined: 2005.05
Post: #14
ThemsAllTook Wrote:FSSpec? WindowPtr? Blink

I don't think we should be recommending to new users that they use deprecated technologies.
I feared that kind of replies. That is exactly why I initially didn't post the code at all, but I hoped someone would be helpful and patch it up with the new calls (which I tried but didn't have time to get to work). Did you at all notice that I clearly stated, three times, that the FSSpec should be replaced by FSRef-based calls? (And the WindowPtr is not used at all.)
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #15
Ingemar Wrote:Did you at all notice that I clearly stated, three times, that the FSSpec should be replaced by FSRef-based calls? (And the WindowPtr is not used at all.)

Sure, but even FSRef is still part of Carbon, which Apple has clearly stated is not and will not be supported on 64-bit architectures. To call Carbon's future even "uncertain" would be incredibly optimistic. The QuickTime C API is in the same boat. Apple's been recommending that all new development be done with Cocoa APIs for many years now, and they're finally starting to take steps to enforce that. In order to stay relevant to the Mac scene, iDevGames needs to be up to date on Apple's technological best practices, which really don't include anything Carbon anymore.
Quote this message in a reply
Post Reply