Solved

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

Posted on 2009-05-11
4
1,284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

733 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