defining value of inOffsetSampleFrame in MusicDeviceMIDIEvent?
defining value of inOffsetSampleFrame in MusicDeviceMIDIEvent?
- Subject: defining value of inOffsetSampleFrame in MusicDeviceMIDIEvent?
- From: Skinny Tod <email@hidden>
- Date: Wed, 07 Mar 2012 20:10:41 -0500
[sry for the repost - didn't see this come through]
Hi - simple question here: if I want to schedule a note on + a note off in
the render callback for an AUSampler, how to I determine the value for the
'inOffsetSampleFrame' param?
MusicDeviceMIDIEvent (inUnit, inStatus, inData1, inData2, inOffsetSampleFrame);
For example, in the code snippet below every second, I want to play a note
of .5 second duration and want it to start immediately. Also, is this bad
usage of either the render calllback or the MusicDeviceMIDIEvent method? Is
there another way to approach this?
--thanks!
--------------My render callback
OSStatus myCallback(void * inRefCon,
AudioUnitRenderActionFlags * ioActionFlags,
const AudioTimeStamp * inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList * ioData)
{
Float64 sampleTime = inTimeStamp->mSampleTime;
UInt64 hostTime = inTimeStamp->mHostTime;
[(__bridge AudioTest*)inRefCon audioEvent:sampleTime andHostTime:hostTime];
return 1;
}
----------------method to schedule sampler event
- (void)audioEvent:(Float64) sampleTime andHostTime:(UInt64)hostTime
{
OSStatus result = noErr;
Float64 nowTime = (sampleTime/self.graphSampleRate);
// test hack to play a .5 sec. duration note every second
if (nowTime - lastTime >= 1.) {
playCount++;
UInt32 noteCommand;
MusicTimeStamp noteOffTime;
MusicTimeStamp noteOnTime;
noteOnTime = 0;
noteOffTime = (sampleTime) / (self.graphSampleRate * .5); //this
is wrong
noteCommand = kMIDIMessage_NoteOn << 4 | 0;
result = MusicDeviceMIDIEvent (samplerUnit, 144, 60, 120, noteOnTime);
noteCommand = kMIDIMessage_NoteOff << 4 | 0;
result = MusicDeviceMIDIEvent (samplerUnit, 128, 60, 0, noteOffTime);
lastTime = sampleTime/self.graphSampleRate;
}
}
_______________________________________________
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