How can I tell when the ScheduledAudioFileRegion registration is finished?

On iOS, I have an Audio Unit of type kAudioUnitSubType_AudioFilePlayer

wrapped by AUNode and connected to a multichannel mixer and remote IO (output) in the Audio Graph.

While playing the graph, I want to compile the file and detect when the AudioFilePlayer has reached the end of the file, so that I can perform the operation before it starts the next iteration of its loop.

When looking at AudioUnitProperties.h, when there is a completion callback - mCompletionProc

- it is only called when the disc has read the file and scheduled it to play, not when it has actually finished playing the audio.

So, I thought about storing the audio length (packets / frames) as a property and in the input callback connected to another mixer input to check if we are at the end of the file. But this callback is not called every frame, so I would probably skip the actual end of the file.

Has anyone encountered this problem before and solved it, or had any ideas on how I might approach it?

Thanks in advance.

+3


source to share


2 answers


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));

      

+1


source


If you want to know when the track reaches the end, you can use RenderNotify

(notification callback to be called when the audio block requests rendering). In the render callback, you get the number of frames processed and you can add them to the frame property. With a simple check, if this property is greater than the number of frames, you can tell when your track is finished.



0


source







All Articles