Solved

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

Posted on 2009-05-11
4
1,275 Views
Last Modified: 2013-12-14
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.
0
Comment
Question by:hirnsieb
4 Comments
 
LVL 20

Accepted Solution

by:
ikework earned 500 total points
ID: 24369352
i guess your application is in a loop, where it receives the data, even if it does not receive anything, it is in that loop. put it to sleep for some milliseconds with "Sleep"

http://msdn.microsoft.com/en-us/library/ms686298(VS.85).aspx

ike
0
 
LVL 1

Author Closing Comment

by:hirnsieb
ID: 31580063
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!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now