<p>I've written a cheap &amp; cheerful sound board in for my Mac, and I play the various sounds with NSSound like this:</p>

<pre><code>-(void)play:(NSSound *)soundEffect:(BOOL)stopIfPlaying {
    BOOL wasPlaying = FALSE;

    if([nowPlaying isPlaying])  {
        [nowPlaying stop];
        wasPlaying = TRUE;
    }   

    if(soundEffect != nowPlaying)
    {
        [soundEffect play];
        nowPlaying = soundEffect;
    } else if(soundEffect == nowPlaying &amp;&amp; ![nowPlaying isPlaying] &amp;&amp; !wasPlaying) {
        [nowPlaying play];
    }
}
</code></pre>

<p>Rather than just stop it dead, I'd like it to fade out over a couple of seconds or so.</p>

Something like this perhaps? You probably want a more linear dropoff, but the basic idea is make a loop and sleep the period of time till the next update.
```
```
if([nowPlaying isPlaying])  {
    for(int i = 1; i < 100; ++i)
    {
        [nowPlaying setVolume: (1.0 / i)];
        Sleep(20);
    }
    [nowPlaying stop];
    wasPlaying = TRUE;
}
```
```