Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
i have included several .aiff sound files to my app's resources, and they are simply called though out different classes in different action methods simply by writing something like this:

Code:
[[NSSound soundNamed:@"mySound.aif"] play];

they all play fine, but what i don't understand is that the first sound that is played always lags the IBAction it's apart of the first time that action executes... all sounds played afterward with other methods are played on time with out any lag for the IBAction, it's just the very first sound the app plays lags it's action, no matter which sound/action it is...

why is this happening?
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
Loading and playing uncached sounds is pretty slow :( It's something we've been struggling with in Adium.

it's strange, though, as it only happens to the first sound that is executed... it's more of a freeze than a lag, as the sound happens at the same time as the action, but the action freezes for about half a second before executing (if it's the first action of the app with sound)...

it seems that the app has to load NSSound for a first time, rather than the actual sound file, and then after the first sound (first NSSound) the NSSound is cached while the app remembers that NSSound is included and therefore plays other sounds without lagging their actions...

is that normal?
 

Catfish_Man

macrumors 68030
Sep 13, 2001
2,579
2
Portland, OR
Doesn't sound normal, but I could sorta see why it might happen. It might be setting up a lot of infrastructure that's left unused until an app tries to play a sound. You could probably "cheat" and play an empty sound on startup in a background thread to hide the delay.
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
Doesn't sound normal, but I could sorta see why it might happen. It might be setting up a lot of infrastructure that's left unused until an app tries to play a sound. You could probably "cheat" and play an empty sound on startup in a background thread to hide the delay.

thanks... loading an empty sound at launch seems to be doing the trick... :)
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
Have you tried to use the raw OpenAL API? That might be better for instantaneous playback.

humm... maybe for an update later down the road i'd use that... for now that trick seems to work well with NSSound... unless of course it's as easy to code OpenAL sounds as it is for NSSound i'd do it, but after a few minutes reading about OpenAL it seems like a much more complex process – albeit far more optimized for sure than using NSSound...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.