Playing sounds

Discussion in 'Mac Programming' started by larswik, Jun 29, 2011.

  1. macrumors 68000

    Sep 8, 2006
    I thought I would add some dice rolling sounds to my dice application but everything I find online is directed towards iphone. Is it the same process for a standard OS X app?

    Any doc's or where to look for this would be much appreciated.

  2. macrumors 6502a

    Dec 2, 2008

    Try NSSound. I've written a Mac bouncing ball app (not on the Mac App Store) that picks a song to play in the background. Each song is just an .aif file that I put in the Xcode project.

    [NSSound soundNamed:mad:"MySong.aif"];

    There's more that needs to get done to get this to play.

    If you're looking for a die roll sound the above might work (think of the die roll sound as a very short sound). But someone else may have a better way.
  3. thread starter macrumors 68000

    Sep 8, 2006
    Thanks, I will read up on NSSound tonight and take another step in learning.

  4. thread starter macrumors 68000

    Sep 8, 2006
    Cool, I got the sound to play when the dice roll button is clicked. But I am getting this weird result. I have a NSSlider that sets the minimum number that can be rolled, ie, 1 to 100 or 34 to 100, as an example. But that slider is also acting like a volume control. The higher the value the louder the roll?

    In the @interface I just have NSSound * sound; and Method deceleration.

        sound = [[NSSound alloc] initWithContentsOfFile: @"/Users/larspro/diceRollSound.aif" byReference:YES];
    [sound play];
    How could that slider even be connected to the audio?

  5. thread starter macrumors 68000

    Sep 8, 2006
    NEVER MIND! I found out the problem. I guess my degree in sound engineering paid off tonight. I placed the [self playAudio]; in the loop section with the dice. So every time the dice had to re roll to get above that number ir played the sound again, each iteration would amplifying the sound. Had nothing to do with the slider.


Share This Page