Interesting.
I'll give that a try somewhere i the next couple of days and I'll let you know how it goes.
Thanks Doug, thanks Bill !
> Subject: Re: Audio queues...again > From: email@hidden > Date: Mon, 27 Apr 2009 20:11:43 -0700 > CC: email@hidden; email@hidden > To: email@hidden > > > On Apr 27, 2009, at 1:53 PM, Etienne Gignac Bouchard wrote: > > > Thank for replying. > > > > I forgot to mention : iphone sdk 2.2.1, format is wav. > > > > I need 2 audio queues to start playing at the exact same host time. > > I tried enqueuewithparameters on the first buffers of the queues > > with a absolute hosttime but it is completely ignored. > > right, AudioQueueEnqueueBuffer (as the documentation implies by > talking only about the options that DO work) doesn't currently support > host time scheduling. > > > I have been looking into remoteIO. Although lower level, I heard > > people have had success with them to play files simultaneously with > > multiple audio units through a mixer. > > > > But if I can find a working case of enqueueing with host times, I > > might change my mind....do you have code that works in that fashion ? > > > Bill suggested an approach to a couple of us offlist. The following > ought to work aside from having no error-checking. > > // pick an arbitrary point in the near future at which to start > double secondsInFutureToStart = 0.25; // your constant here > > AudioQueueRef q1, q2; > > AudioQueueNewOutput(..., &q1); > AudioQueueNewOutput(..., &q2); > AudioQueueStart(q1, NULL); > AudioQueueStart(q2, NULL); > > while (1) { > AudioTimeStamp t1, t2, start1, start2; > AudioQueueGetCurrentTime(q1, &t1); > AudioQueueGetCurrentTime(q2, &t2); > > const double hostTimeFrequency = CAHostTimeBase::GetFrequency(); > UInt64 startHostTime = CAHostTimeBase::GetTheCurrentTime() + > secondsInFutureToStart * hostTimeFrequency; > > if (startHostTime > t1.mHostTime && startHostTime > t2.mHostTime) > // good, we picked times that are really in the future > break; > // error: the host time is in the past. try again, more conservatively > secondsInFutureToStart *= 2; > } > > // interpolate to convert the start host time to each queue's sample > timeline > start1.mSampleTime = t1.mSampleTime + > ((startHostTime - t1.mHostTime) / hostTimeFrequency // seconds > * q1sampleRate); > start2.mSampleTime = t2.mSampleTime + > ((startHostTime - t2.mHostTime) / hostTimeFrequency > * q2sampleRate); > start1.mFlags = start2.mFlags = kAudioTimeStampSampleTimeValid; > > AudioQueueEnqueueBufferWithParameters(q1, buf1, ...., &start1); > AudioQueueEnqueueBufferWithParameters(q2, buf2, ...., &start2); > > To be even more precise you can also factor in the rate scalars in the > sample times . > > hth > Doug >
|