• 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: How to delay AudioQueue playing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to delay AudioQueue playing


  • Subject: Re: How to delay AudioQueue playing
  • From: Doug Wyatt <email@hidden>
  • Date: Thu, 1 Oct 2009 07:45:35 -0700

AudioQueue example code tends to always re-enqueue the completed buffer from the callback, but that's because it's illustrating file playback, where this is an efficient and simple technique. A streaming example might have a different buffer management strategy; it could allocate and enqueue new buffers as data arrives from the network and dispose them when they are complete. So you can enqueue buffers whenever you like, whether it's from the buffer callback or triggered by some other event. You will, however, need some other triggering event if you don't enqueue new buffers when old ones are completed.

Yes, you can call AudioQueueEnqueueBufferWithParameters with a timestamped buffer to schedule a buffer to be played following a gap. (Note: you should call AudioQueueFlush preceding a gap; if the format is compressed this is necessary for correct management of the decoder.)

Probably the simplest way to schedule buffers is using the sample time: if you know you want to play, say, 25000 samples and then you want to leave a gap of 10000 samples, you would schedule the subsequent buffer to play at a sample time of 35000 samples (these sample times are relative to when the queue was started).

You can do it via host time too, but as you mention, that is trickier...

Doug


On Oct 1, 2009, at 3:39 , Michael Becker wrote:

Thanks for the reply! The "lag" you are talking about should be fine for me, as long as I get the playback working. The user is not really supposed to switch samples on or off in realtime. But I will keep Audio Units in the back of my mind in case I will have to use them.

Here's my problem with what you suggest about the buffer: If the time has come to "play silence" for the duration of one sample, you say, I should either not enqueue the next buffer or play zeroes. But if I don't call AudioQueueEnqueueBuffer, the callback is never called again for that AudioQueue. In other words: how can I resume playback after the one-sample-pause? My idea was to user AudioQueueEnqueueBufferWithParameters and pass a certain AudioTimeStamp for its starttime, but I cannot wrap my head around how to set that timestamp. I think at that moment the "lag" you are talking about might become a problem - the AudioQueue's timestamp I can only get in real-time whereas the buffer playback will be sometime in the future.

I have the gut-feeling that my simple setup (all samples are same length and type) should make this all easier...

Regards,
Michael

Am 01.10.2009 um 02:07 schrieb Steven Winston:

AudioQueue unfortunately isn't the best way to go about doing this.
It inherently creates a queue that's buffered ahead of the PCM data
that's played.  You'll notice a "lag" on anything that you alter in
your buffering callback which is what you'd expect from that type of
application.  Might I recommend using AudioUnits?  They'll give you
quicker feedback.

That said, here's the trick that will solve your current question of
how to play silence:

in AudioQueueServices you have a buffer callback and somewhere a call
to AudioQueueEnqueueBuffer. Don't call that when you don't want audio
from that AudioQueue to play. That or you can pass it a buffer full
of 0.


On Wed, Sep 30, 2009 at 9:06 AM, Michael Becker <email@hidden > wrote:
Hello list, this is my first post!

I have been searching a lot on the web and in the list archives, but I have
not found anything that helped me, although I guess that my question has
been asked a zillion times before: I am trying to build an audio sequencer,
i.e. an 8 track sequencer that plays audio samples. The concept is fairly
easy: Every sample is exactly the same length, the user can only switch
samples on or off for a complete duration.


I am using the AudioQueue API and I think I understand that I should use one
Audio Queue for each track. So far I have managed to have two queues loop
two samples synchronously. I basically stuck to the Apple documentation
("Looping audio files"). It works great, they are perfectly in sync.


Now comes the problem: How do I omit individual samples during playback? I
think the solution either comes down to "playing silence" for the duration
of one or more samples, or delaying the playback of the next sample for a
time that is a multiple of a sample length.


On a sidenote: Is this the right way to go about this? Or should I somehow
create a "main clock" that ticks and only play samples according to this
"clock"? (Instead of rigorously looping the samples back to back).


Maybe I am phrasing my question the wrong way, but please bear with me as I
am really new to Core Audio and Sound programming in general.


Kind regards,
Michael
_______________________________________________
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


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
@apple.com


This email sent to email@hidden

_______________________________________________ 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
References: 
 >Re: How to delay AudioQueue playing (From: Michael Becker <email@hidden>)

  • Prev by Date: AU, Obj-C and names
  • Next by Date: Re: What is the cheapest way to play an AAC or mp3 on iphone
  • Previous by thread: Re: How to delay AudioQueue playing
  • Next by thread: AU, Obj-C and names
  • Index(es):
    • Date
    • Thread