From: Aran Mulholland <email@hidden>
To: Beleg Da'Bear <email@hidden>
Cc: Robert Martin <email@hidden>; "email@hidden" <email@hidden>
Sent: Tuesday, July 24, 2012 7:43 PM
Subject: Re: How do you pause, stop and reset an AUFilePlayer in IOS5?
If you knew the host time that you started the region at you could get
the host time when you hit pause and work this out without asking the
API.
On Tue, Jul 24, 2012 at 11:47 PM, Beleg Da'Bear <
email@hidden> wrote:
> Thanks. after I took out the bits stopping the AuGraph as well as adding in
> a step I skipped (I forgot to do kAudioUnitProperty_ScheduleFilePrime) I get
> the pause play behavior that I am looking for, however as I expected pausing
> and then playing again causes the 8 tracks to get slightly out of synch. I
> suspect that this is happening because I have a for loop that cycles through
> my FilePlayer Audio Unit array to capture the current sample time and this
> must be introducing a slight delay for the time it takes to loop through all
> 8 tracks.
Do you know of a way to get the
sample time for all 8 files at
> the same time?
>
> From: Aran Mulholland <
email@hidden>
> To: Beleg Da'Bear <
email@hidden>
> Cc: Robert Martin <
email@hidden>;
> "
email@hidden" <
email@hidden>
> Sent: Monday, July 23, 2012
8:15 PM
>
> Subject: Re: How do you pause, stop and reset an AUFilePlayer in IOS5?
>
> Don't stop the AUGraph. The time it takes to
start is too long. the
> AUFilePlayer will just fill the buffer with 0's if it is not playing
> and probably sets the "norender" flag as well. This way when you start
> the player again it start playing straight away.
>
>
> On Tue, Jul 24, 2012 at 4:52 AM, Beleg Da'Bear <
email@hidden> wrote:
>> Upon closer inspection it looks like I am not always getting the value I
>> should for the sample frame.
>> When I do this the first time:
>> AudioTimeStamp ts;
>> UInt32 size = sizeof(ts);
>> AudioUnitGetProperty(myArrayOfFileUnits[count],
>> kAudioUnitProperty_CurrentPlayTime, kAudioUnitScope_Global, 0, &ts,
>> &size);
>> I get the number I would expect. the second time I hit pause
>>
ts.mSampleTime
>> = -1.
>> Any
thoughts on why this would be the case?
>> As a follow up question, Should I be worried about the time it takes to
>> looping through an array of FilePlayer units to get the sampleTime for
>> each
>> unit? In other words is it possible that I will capture the current play
>> head for each track at a slightly different time, thus making them
>> misaligned when I hit play again? If this is the case, how would I work
>> around that problem?
>>
>>
>> From: Beleg Da'Bear <
email@hidden>
>> To: Robert Martin <
email@hidden>; Aran Mulholland
>> <
email@hidden>
>> Cc: "
email@hidden" <
email@hidden>
>> Sent: Monday, July 23, 2012 2:01 PM
>>
>> Subject: Re: How do you pause, stop and reset an AUFilePlayer in IOS5?
>>
>> Thanks. I tried this method out this weekend and I am having trouble
>> making
>> it work. Should I be stopping and starting the AudioGraph each time?
>> Here is my aproch (My code complicates things a little because I am trying
>> to play/pause 8 files at the same time.)
>> If the user presses the play
button.
>> 1. Loop through the 8 FilePlayer audio units scheduling the start frame
of
>> each unit to 0;
>> 2. call AUGraphStart
>> If the user presses the pause button.
>> 1. Loop through the 8 FilePlayer audio units and get the sample frame of
>> the
>> curently playing tracks.
>> 2. Store this number for later (if the user hits pause a second time add
>> the
>> new number to the old number, i.e. SampleFrame=SampleFrame +
>> ts.mSampleTime;)
>> 3. call AudioUnitReset
>> 4. Stop the AuGraph
>> When the user unpauses the pause button
>> 1. Loop through the 8 FilePlayer audio units and set the startFrame to the
>> number we stored
>> 2. call AUGraphStart
>> When the user hits stop
>> 1. stop the AUGRAPH
>> 2. Reset the sampleFrame to zero for all FilePlayer audio units
>> The behavior I am seeing is that the music plays fine the first time that
>>
the play button is pressed. Pressing pause or stop stores the value I
>> expect
>> to see in the startFrame, however pressing play again does nothing. I hear
>> nothing. The odd thing is that If I press pause and then play realy really
>> quickly, it works as I want it to, however I think this is because I am
>> hitting play because the AUGraph had a chance to really stop. but I am not
>> sure. Any ideas what I am missing?
>>
>>
>> Thanks.
>>
>>
>> From: Robert Martin <
email@hidden>
>> To: Aran Mulholland <
email@hidden>
>> Cc: Beleg Da'Bear <
email@hidden>; "
email@hidden"
>> <
email@hidden>
>> Sent: Thursday, July 19, 2012 1:13 AM
>> Subject: Re: How do you pause, stop and reset an AUFilePlayer in IOS5?
>>
>> It's a bit more complicated than that.
>>
>> What you'll get from 'getting' kAudioUnitProperty_CurrentPlayTime is the
>> -offset- time from when you last set
>> kAudioUnitProperty_ScheduledFileRegion.
>>
>> If you schedule a new region with that time, you won't resume at
the
>> correct
>> place if you pause/resume more than once.
>>
>> Here is a copy of Doug Wyatt's note
on this from 2006, since I no longer
>> have the link:
>>
>> "To change the play position:
>>
>> [1] obtain the current play position:
>> AudioTimeStamp ts;
>> UInt32 size = sizeof(ts);
>> AudioUnitGetProperty(mFilePlayerAU,
>> kAudioUnitProperty_CurrentPlayTime, kAudioUnitScope_Global, 0, &ts,
>> &size);
>> Float64 sampleFrame = ts.mSampleTime;
>>
>> Now you know where playback is, relative to the beginning of the
>> event timeline that you scheduled. If you scheduled the beginning of
>> a file to play at the beginning of the timeline, then the play
>> position is the same as the position in the file (except in the case
>> of sample rate conversion, which is another wrinkle.....)
>>
>> [2] stop:
>>
>> AudioUnitReset(mFilePlayerAU, kAudioUnitScope_Global,
0);
>>
>> [3] start again. Here you can specify the starting sample offset in
>> the file.
>>
>> For example, to implement pause/resume, you'd obtain the play
>> position before pausing, and add that to the position in the file
>> where you last started. That would be the playRegion.mStartFrame when
>> scheduling the first event when you resume."
>>
>> Rob
>>
>>
>>
>> On Jul 18, 2012, at 7:36 PM, Aran Mulholland <
email@hidden>
>> wrote:
>>
>>> You can't pause the AUFilePlayer. What you can do is call something like
>>>
>>> AudioTimeStamp ts;
>>> UInt32 size = sizeof(ts);
>>>
AudioUnitGetProperty(filePlayerUnit_,
>>> kAudioUnitProperty_CurrentPlayTime, kAudioUnitScope_Global, 0, &ts,
>>> &size);
>>> Float64 sampleFrame = ts.mSampleTime;
>>>
>>> to get the currently playing sample frame, then call
>>>
>>> AudioUnitReset(filePlayerUnit_, kAudioUnitScope_Global, 0);
>>>
>>> To stop it and if you want to resume playback (from pause), schedule a
>>> new region with the sample time you had before you called
>>> AudioUnitReset. Be nice if it had a pause, but not hard to implement
>>> yourself.
>>
>>
>>
>>
>
>