• 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
Audio Queue metronome
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Audio Queue metronome


  • Subject: Audio Queue metronome
  • From: Charlie Fuller <email@hidden>
  • Date: Wed, 30 Jun 2010 16:47:45 +0100

Hi,

I'm trying to build a metronome for my audio app on iOS 4. I'm using Audio Queues and have an NSTimer loop checking when the beat has incremented. When the beat has incremented I trigger the next beat's "click" to play at the precise time point in the future. I was hoping this would result in a perfectly synchronised metronome, and whilst it works reasonably well it still feels slightly off. The metronome maintains time correctly but upon visual inspection of the clicks in a test recording I can see they're not perfectly in sync (although they don't slip over time).

I've included a condensed version of my code to help explain what I'm trying to do. In short I'm setting the start time of an AQ player based on the mHostTime of the audio start point and the time point of the next beat. Note I've left out the code which keeps track of the current beat position as I don't think it's relevant. Any feedback would be much appreciated.

/* The below code is called every time beatPosition is incremented */

// Calculate time point to play next beat in nanoseconds.
int64_t nextBeatPositionInNanoSeconds = ( (int64_t)beatPosition+1 ) * 1000000000;

// Account for the device timebase.
int64_t nextBeatPositionInAbsoluteTime = ( ( (int64_t)nextBeatPositionInNanoSeconds / info.numer) * info.denom );

// Calculate absolute time to play next beat.
UInt64 absoluteClickTime = absoluteStartTime.mHostTime + nextBeatPositionInAbsoluteTime;
AudioTimeStamp nextBeatPositionTimeStamp = {0};
nextBeatPositionTimeStamp.mFlags = kAudioTimeStampHostTimeValid;
nextBeatPositionTimeStamp.mHostTime = absoluteClickTime;

// Trigger playback in advance.
AudioQueuePrime(queue, 1, nil);
AudioQueueStart(queue, &nextBeatPositionTimeStamp);

Many thanks,
Charlie
 _______________________________________________
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 Queue metronome
      • From: William Stewart <email@hidden>
  • Prev by Date: Re: crash-proof AU plugin scanning?
  • Next by Date: How can I get the MixerHost sample app?
  • Previous by thread: Re: Book recommendation
  • Next by thread: Re: Audio Queue metronome
  • Index(es):
    • Date
    • Thread