Solved

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

Posted on 2009-05-11
4
1,269 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

705 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

14 Experts available now in Live!

Get 1:1 Help Now