• 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: Syncing an lfo to bars
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Syncing an lfo to bars


  • Subject: Re: Syncing an lfo to bars
  • From: Kenneth Weiss <email@hidden>
  • Date: Thu, 16 Mar 2006 15:47:09 +0200

Works perfectly ! Thanx,
:-)


On Mar 14, 2006, at 5:18 PM, Olivier Tristan wrote:

Kenneth Weiss wrote:

Hi,

I am trying to sync an LFO to the bars and I am having trouble finding the bar offset from the CallHostMusicalTimeLocation function.
Could any one share with me some sample code for extracting the next bar offset from within the render function?
If I use the CallHostMusicalTimeLocation to get the current beat offset how can I find out what is the first beat in the next bar?



Hi Kenneth,

Here is a fully working example.
I do not use uDeltaSampleOffsetToNextBeat as it still doesn t work in Logic, GarageBand and Live in certain cases and version, so...


Beware that numPPQ can be < 0 if the host do some prerolling (DP for example), in that case sampleToNextBeat and sampleToNextBar refers to the first beta and first bar.

if( mHostCallbackInfo.beatAndTempoProc ) {
Float64 fCurrentBeat= 0.0, fCurrentTempo= 0.0;
OSStatus err= mHostCallbackInfo.beatAndTempoProc ( BaseClass::mHostCallbackInfo.hostUserData, &fCurrentBeat, &fCurrentTempo );
if( err == noErr ) {
musicalContext.tempo = fCurrentTempo;
musicalContext.absolutePosInQuarterNote = fCurrentBeat;
}
}


if( mHostCallbackInfo.musicalTimeLocationProc) {
UInt32 uDeltaSampleOffsetToNextBeat= 0;
Float32 fTimeSig_Numerator= 0.0f;
UInt32 uTimeSig_Denominator= 0;
Float64 fCurrentMeasureDownBeat= 0.0;
OSStatus err= mHostCallbackInfo.musicalTimeLocationProc ( BaseClass::mHostCallbackInfo.hostUserData, &uDeltaSampleOffsetToNextBeat, &fTimeSig_Numerator, &uTimeSig_Denominator, &fCurrentMeasureDownBeat );
if( err == noErr ) {
musicalContext.meterNum = fTimeSig_Numerator;
musicalContext.meterDenom = uTimeSig_Denominator;
musicalContext.posInMeasureInQuarterNote = musicalContext.absolutePosInQuarterNote - fCurrentMeasureDownBeat;
double normSig = 4.0 * fTimeSig_Numerator / uTimeSig_Denominator;
double currentTempoBPS = musicalContext.tempo / 60.0;
double SamplePerBeat = GetSampleRate() / currentTempoBPS;
double numPPQ = fCurrentMeasureDownBeat + normSig - musicalContext.absolutePosInQuarterNote;


musicalContext.sampleToNextBeat = (numPPQ - (int)numPPQ) * SamplePerBeat;
musicalContext.sampleToNextBar = numPPQ * SamplePerBeat;
}
}



Hope this helps.

--
Olivier Tristan
Ultimate Sound Bank


_______________________________________________ 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: 
 >Syncing an lfo to bars (From: Kenneth Weiss <email@hidden>)
 >Re: Syncing an lfo to bars (From: Olivier Tristan <email@hidden>)

  • Prev by Date: detecting Logic's "record enabled" from Audio Unit plug in
  • Next by Date: audio2midi AU possible?
  • Previous by thread: Re: Syncing an lfo to bars
  • Next by thread: Some Basic Questions about MultiChannel Audio
  • Index(es):
    • Date
    • Thread