• 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
defining value of inOffsetSampleFrame in MusicDeviceMIDIEvent?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

defining value of inOffsetSampleFrame in MusicDeviceMIDIEvent?


  • Subject: defining value of inOffsetSampleFrame in MusicDeviceMIDIEvent?
  • From: Skinny Tod <email@hidden>
  • Date: Wed, 07 Mar 2012 11:48:26 -0500

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


  • Prev by Date: Audio Unit versioning
  • Next by Date: defining value of inOffsetSampleFrame in MusicDeviceMIDIEvent?
  • Previous by thread: Audio Unit versioning
  • Next by thread: defining value of inOffsetSampleFrame in MusicDeviceMIDIEvent?
  • Index(es):
    • Date
    • Thread