• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Audio queues...again
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Audio queues...again


  • Subject: Re: Audio queues...again
  • From: Doug Wyatt <email@hidden>
  • Date: Mon, 27 Apr 2009 20:11:43 -0700


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

_______________________________________________
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


  • Follow-Ups:
    • RE: Audio queues...again
      • From: Etienne Gignac <email@hidden>
References: 
 >Re: Audio queues...again (From: Etienne Gignac Bouchard <email@hidden>)

  • Prev by Date: Re: Audio queues...again
  • Next by Date: Error when adding AVAudioPlayer to SpeakHere sample
  • Previous by thread: Re: Audio queues...again
  • Next by thread: RE: Audio queues...again
  • Index(es):
    • Date
    • Thread