On iOS, I have an Audio Unit of type kAudioUnitSubType_AudioFilePlayer wrapped by an AUNode and connected to a multichannel mixer and remote IO (output) in an Audio Graph.
While the graph is playing I want to loop the file and be able to determine when the AudioFilePlayer has reached the end of the file, so that I can perform an operation before it begins the next iteration of its loop.
In reviewing AudioUnitProperties.h, while there is a completion callback - mCompletionProc- it's only called when the disk has read the file and scheduled it for playback, not when it has actually finished playing back the audio.
So then I considered storing the length of the audio (packets/frames) as a property and, in an input callback attached to another input of the mixer, checking to see if we're at the end of the file. But that callback doesn't get called every frame, so it's likely I'd miss the actual end of the file.
How might I approach this?
please set ScheduledAudioFileRegion.mCompletionProc,
//
ScheduledAudioFileRegion playRegion;
playRegion.mTimeStamp.mFlags = kAudioTimeStampSampleTimeValid;
playRegion.mTimeStamp.mSampleTime = 0;
playRegion.mCompletionProc = XXXXXXXXXXXXXXXX(you proc);
playRegion.mCompletionProcUserData = NULL;
playRegion.mAudioFile = mAudioFile;
playRegion.mLoopCount = 0;
playRegion.mStartFrame = mStartSampleFrame;
playRegion.mFramesToPlay = UInt32(-1);
err = AudioUnitSetProperty(mFilePlayerAU, kAudioUnitProperty_ScheduledFileRegion,
kAudioUnitScope_Global, 0, &playRegion, sizeof(playRegion));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With