AUFilePlayer
AUFilePlayer
- Subject: AUFilePlayer
- From: Art Gillespie <email@hidden>
- Date: Fri, 1 May 2009 11:58:16 -0700
I have a simple AUGraph set up with an AUFilePlayer hooked up to the
Default Output unit. Everything works as I'd expect until I try to
pause/resume playback by calling AUGraphStop() followed by
AUGraphStart(). What I get in this case is silence for many seconds
and then I hear the file play back more or less from where it was when
AUGraphStop() was called.
Reading through the relevant headers, I thought I might have to reset
the AUFilePlayer audio unit and then set the ScheduledAudioFileRegion
property to start from where playback left off (as well as the
ScheduleStartTimeStamp property). This works better in that there's
no longer many seconds of silence on resuming playback, but there
doesn't seem to be much rhyme or reason to where playback picks back
up: I query the CurrentPlayTime position before resetting the
AUFilePlayer audio unit, and use this for the
ScheduledAudioFileRegion.mStartFrame member.
Am I approaching this the wrong way? Or the right way, but doing
something stupid? I notice that the MatrixMixerTest sample code
doesn't bother with the AUFilePlayer audio unit, but just uses the
AudioFile apis and feeds the render callback directly. Should I be
barking up that tree instead if I need suspend/resume behavior?
Here's the code from the togglePlayback method:
OSStatus err = noErr;
Boolean graphIsRunning = false;
err = AUGraphIsRunning(auGraph, &graphIsRunning);
if (graphIsRunning)
err = AUGraphStop(auGraph);
else {
AudioTimeStamp currentTime;
UInt32 propSize = sizeof(currentTime);
err = filePlayerAU->GetProperty(kAudioUnitProperty_CurrentPlayTime,
kAudioUnitScope_Global, 0, ¤tTime, &propSize);
UInt64 nPackets;
UInt32 propsize = sizeof(nPackets);
err = AudioFileGetProperty(audioFileID,
kAudioFilePropertyAudioDataPacketCount, &propsize, &nPackets);
CAStreamBasicDescription fileFormat;
propSize = sizeof(fileFormat);
err = AudioFileGetProperty(audioFileID,
kAudioFilePropertyDataFormat, &propSize, &fileFormat);
err = filePlayerAU->Reset(kAudioUnitScope_Global, 0);
ScheduledAudioFileRegion rgn;
memset (&rgn.mTimeStamp, 0, sizeof(rgn.mTimeStamp));
rgn.mTimeStamp.mFlags = kAudioTimeStampSampleTimeValid;
rgn.mTimeStamp.mSampleTime = 0;
rgn.mCompletionProc = AudioCompareRegionCompletionProc;
rgn.mCompletionProcUserData = self;
rgn.mAudioFile = audioFileID;
rgn.mLoopCount = 0;
rgn.mStartFrame = (currentTime.mSampleTime ==
-1)?0:currentTime.mSampleTime; //(hrm, sample time versus 'frame
time'?
rgn.mFramesToPlay = UInt32(nPackets * fileFormat.mFramesPerPacket);
err = filePlayerAU->SetProperty (kAudioUnitProperty_ScheduledFileRegion,
kAudioUnitScope_Global, 0,&rgn, sizeof(rgn));
//start playing on next render buffer, please
memset (&startTime, 0, sizeof(startTime));
startTime.mFlags = kAudioTimeStampSampleTimeValid;
startTime.mSampleTime = -1;
err = filePlayerAU->SetProperty(kAudioUnitProperty_ScheduleStartTimeStamp,
kAudioUnitScope_Global, 0, &startTime, sizeof(startTime));
/**
* Nice try, dumbass: CurrentPlayTime isn't writeable :(
* startTime.mFlags = kAudioTimeStampSampleTimeValid;
* startTime.mSampleTime = 260000;
* err = filePlayerAU->SetProperty(kAudioUnitProperty_CurrentPlayTime,
* kAudioUnitScope_Global, 0, &startTime, sizeof(startTime));
*/
err = AUGraphStart(auGraph);
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden