Link to home
Start Free TrialLog in
Avatar of hirnsieb
hirnsieb

asked on

How to receive MIDI TimeCode (MTC) using DirectX / DirectMIDI?

My application uses the library DirectMidi to receive MIDI messages using DirectX. The main purpose is to receive MTC (MIDI TimeCode) that allows my application to sync to a master. Currently I am experiencing performance problems which I want to solve.

Setup:
1) Timing Master: Sonar LE, sending MTC over MIDI
2) MIDI Driver: MidiYoke (http://www.midiox.com/myoke.htm)
3) Client: myApp
4) OS: WindowsXP
5) Language: C++ using Visual Studio .NET 2003
6) MIDI lib: DirectMidi (http://directmidi.sourceforge.net/)

As you can see, I am currently not using any MIDI hardware, but a pure software solution. The MidiYoke driver is tunneling the MIDI messages from the master (Sonar) to the client (myApp). All applications reside on the same machine currently.

Although I can receive MIDI messages well and extract the TimeCode, my application is suffering from severe performance breakdowns. Whereas Sonar is using as little as 5% CPU load in playback, my application is consuming all the remaining CPU power. That means if I visualize the CPU load using the Windows task manager, it is up to 100% as soon as my application starts receiving the MIDI messages.

I tracked the performance consumption down to the location where I actually read the MIDI messages. It is the method "read" of the interface IDirectMusicPort8. So I can exclude that any of my top level processing inside my application is causing the high CPU load.

What I wonder now, is:

1) Could 100% CPU load be the normal behaviour? I mean, I am not only receiving MIDI notes, but tons of MIDI messages a second (MTC). But then, why does Sonar only consum 5% CPU load when it is sending those messages?
2) Could the problem be located in the MidiYoke driver? Does anyone have experience with that? If the driver is the problem, then it should not occur if I am using real MIDI hardware, i.e. an USB MIDI interface. However, I don't want to buy one yet.
3) Any other ideas? Did anyone successfully implement MTC reception over DirectX?


I hope one of the experts can help.
ASKER CERTIFIED SOLUTION
Avatar of ikework
ikework
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hirnsieb
hirnsieb

ASKER

Got it! ikework's suggestion was a good hint. Although the sleep() wouldn't do it (would delay the whole application), it made me have a closer look at the receiving loop in the DirectMidi library. And guess what!? There was a loop like "while (active) receive MIDI data". The actual event handling of receiving midi data that would put my thread to sleep until the next midi event is available was outside of that loop. Therefore it ran up to 100% all the time.

I should inform the guy who wrote that code. I guess he never handled MTC... ;-)

Thanks!