Re: Syncing an lfo to bars
Re: Syncing an lfo to bars
- Subject: Re: Syncing an lfo to bars
- From: Olivier Tristan <email@hidden>
- Date: Tue, 14 Mar 2006 16:18:39 +0100
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