• 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
Question regarding MIDIPackets scheduling
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Question regarding MIDIPackets scheduling


  • Subject: Question regarding MIDIPackets scheduling
  • From: Vlad Litvinenko <email@hidden>
  • Date: Wed, 07 Oct 2015 17:53:58 +0200

Hi!

There's something in setting MIDIPacket's timestamp that I'm missing. 
I'm sending 2 events: "note on" and "note off", setting interval between them to 3 seconds.

My expectation is that events will be delivered with 3 seconds interval and I'll see 
a log of received events with 3 seconds interval in MIDIMonitor (or hear a sound with 
duration of 3 seconds).

Nevertheless, looking at MIDIMonitor, both events arrive exactly at the same time without any interval.

Could someone please point me to what is going wrong with my code (or maybe with my expectation)?

The test project (just a single file Command Line Tool) is at 
https://www.dropbox.com/s/5azsa43jy9zlg86/SendNotes.zip?dl=1

Here's excerpt of how MIDIPackets are created:
======================================================

ByteCount noteBytesCount = 3;
Byte onBytes[]  = {0x90, 0x3C, 0x7F}; // C3 on on 1st channel
Byte offBytes[] = {0x80, 0x3C, 0x7F}; // C3 off on 1st channel

UInt64 _onTime_ = mach_absolute_time();
UInt64 offTime = onTime + secondsToHostTime(3.0); //see below

ByteCount packetListSize = 1024;
    
MIDIPacketList *packetList = (MIDIPacketList *)malloc(packetListSize);
MIDIPacket *packet = MIDIPacketListInit(packetList);

packet = MIDIPacketListAdd(packetList, packetListSize, packet, onTime, noteBytesCount, &onBytes[0]);
packet = MIDIPacketListAdd(packetList, packetListSize, packet, offTime, noteBytesCount, &offBytes[0]);

MIDISend(port, endpoint, packetList);
    
// MIDIMonitor log:
// 08:46:58.362 To MIDI Monitor (Untitled) Note On     1 C3 127
// 08:46:58.362 To MIDI Monitor (Untitled) Note Off 1 C3 64

==========================================================

The conversion from seconds to host time format done this way:
==========================================================
UInt64 secondsToHostTime(Float64 inSeconds)
{
    Float64 nanoseconds_per_second = 1000000000.0;
    Float64 nanos = inSeconds * nanoseconds_per_second;

    struct mach_timebase_info theTimeBaseInfo;
    mach_timebase_info(&theTimeBaseInfo);

    return (UInt64)(nanos * (Float64)theTimeBaseInfo.denom / (Float64)theTimeBaseInfo.numer);
}
==========================================================

Thank you in advance!

Vlad.

 _______________________________________________
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: Re: Debugging AudioServerPlugIn on El Capitan
  • Next by Date: Re: MusicPlayer in iOS9
  • Previous by thread: Re: Debugging AudioServerPlugIn on El Capitan
  • Next by thread: Remote IO thread and concurrency
  • Index(es):
    • Date
    • Thread