ofxAudioUnit
ofxAudioUnit copied to clipboard
ofxAudioUnitFilePlayer::playAtSampleTime() acts the same as play()
Hi Adam,
I'm not sure if I've written about this before but recently noticed that calling playAtSampleTime(5 * 44100) will play the audio from the beginning of the file 5 seconds after the function call, which is exactly what play(5 * 44100) does. Logically, and from function definition, it seems like playAtSampleTime(5 * 44100) should start playing the audio file immediately from 5 seconds into the file. Is this correct? Is there a fix?
Ah I guess the wording is a bit confusing. I think the reason I added that was to sync playback across multiple file players.
It's been awhile since I've looked at this code. I think the bit that controls your start frame is _region.mStartFrame
, if you want to look into it yourself.
Ok so I walked through the code in the Xcode debugger:
playAtSampleTime(SR)
sets _seekSampleTime
to SR
then calls play()
play()
calls prime()
and then prime()
sets _region.mStartFrame
to SR
So: startTime = mach_absolute_time()
and _region.mStartFrame = SR
It seems like it should start playing immediately from 1 second into the track, but instead it starts from the beginning of the track, one second later.
Am I still misunderstanding? It seems like the intention of playAtSampleTime(SInt64 sampleTime)
is to choose which sample of the audio file to start playback on by setting _region.mStartFrame
to the desired frame when the region is primed as opposed to play(uint64_t startTime)
where startTime is used create a timeStamp to schedule playback via FillOutAudioTimeStampWithHostTime(startTimeStamp, startTime);