• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Completing a sound before continuing on
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Completing a sound before continuing on


  • Subject: Re: Completing a sound before continuing on
  • From: Don Yacktman <email@hidden>
  • Date: Sun, 17 Apr 2005 17:56:17 -0600


On Apr 17, 2005, at 3:12 PM, Chad Armstrong wrote:

Would something like a wait() or sleep() call (perhaps delayed for just a second or two) also do the trick? Generally the sounds I want to play don't last much longer than a second, I think that an application waiting an extra second while closing wouldn't be overly noticeable.

Nope. Don't do it that way. When the playback buffer empties, the sound will break up.


You have to go back to the main event loop so that it can handle the event(s) that will attempt to keep the buffer full. If the sound is small enough to fit in a single buffer then a sleep() might work, but most sounds will be longer than that. (Of course, feel free to experiment to see what will work; you'll probably learn a lot from the process.) Oh, and from my experimentation with it, even if you start sound playback from a separate thread, the buffer seems to get filled from the main thread. So for smooth playback you really must not ever allow the main thread to block while a sound is playing.

This became a big issue in the case of a game, where you want the sound to be stable. If you use NSSound, then anything that might take longer than a fraction of a second has to be spun off into another thread so that the main event loop can keep going. (Or else you need to move to using Core Audio directly or, a little easier, using OpenAL. Then you don't have this problem since everything is done in another thread. But that approach is much more complex than what you should need.) One way or another, the sound and the slow stuff have to be in separate threads, and since NSSound is already using the main thread, it can force some weird design decisions if you use it. But it is easy to use and not too bad to work around.

--
Later,

Don Yacktman
email@hidden

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: Completing a sound before continuing on (From: Chad Armstrong <email@hidden>)

  • Prev by Date: Re: Completing a sound before continuing on
  • Next by Date: Help for Buttons
  • Previous by thread: Re: Completing a sound before continuing on
  • Next by thread: Custom view, selection consistency with NSTableView
  • Index(es):
    • Date
    • Thread