Closed admsyn closed 10 years ago
this seems to be mainly a problem when working with a large quantity of sound files.
calling ofSleepMillis(20) after each filePlayer.loop() call does not help either.
Just stumbled accross a note in AudioUnitProperties.h
that seems very relevant:
Priming You should set kAudioUnitProperty_ScheduledFilePrime after scheduling initial file regions to be played and before starting playback. This SetProperty call will begin reading the audio files and not return until the number of frames specified by the property value have been read.
Which is currently not a thing that ofxAudioUnit is doing. It sounds simple enough, a blocking call to AudioUnitSetProperty
with the kAudioUnitProperty_ScheduledFilePrime
property that returns whenever the file player is good-to-go. Would probably be good to expose this as a separate function void ofxAudioUnitFilePlayer::prime()
that can be called after setting files (and that gets called by default by play()
if it hasn't primed yet).
Reopening, as this still seems to be an issue
After a week of constant use, I can confirm that calling prime() followed by two play()s results in no dropped tracks.
You're killing me here :D
Well, for now I'll assume that calling play()
on it multiple times reduced the chances of it happening by a substantial amount, but it's still possibly a bug. I'd like to find something I'm doing conclusively wrong before saying this is fixed again
Ha! I was hoping this strange behaviour might offer insight to the problem, and in no way insinuating that it was a fix!
Ok, I think this is fixed now. Probably the combination of always calling prime()
and the fact that I initially messed up the implementation of prime()
when attempting to close this issue in the first place (see #12).
On occaision, an ofxAudioUnitFilePlayer will refuse to start when play() or loop() is called. Several attempts may eventually wake it up, but this is not an acceptable workaround.
Calling play() / loop() by dispatch_async on the main queue doesn't seem to help, neither does a dispatch_after to give it some time to boot up.