USB MIDI Interface

Post a reply

This question is a means of preventing automated form submissions by spambots.
:D :) :( :o :shock: :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen:
BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON
Topic review

Expand view Topic review: USB MIDI Interface

Re: USB MIDI Interface

Post by winelight » Mon Jan 19, 2015 10:00 pm

Thanks for that - looks great. I imagine it must be similar on Vista; will do some work on that when I get a chance.

(edit) On Vista the location is different (on mine it was 01f824) and the byte sequence is slightly different too:

3C 08 73 09 C6 86 1E 01 00 00 08

Note the two 08s are in the same relative position.

Re: USB MIDI Interface

Post by Eye » Mon Jan 19, 2015 8:04 pm

I've found a solution for the latency (slow interrupt transfer) problem in Windows 7 32-bit.
You have to patch usbport.sys file. USBPORT_OpenEndpoint() function in the USB port driver limits polling period to 8-32 range. Here is the lower limit checking code:
Code: Select all
00009e18: 3c08            cmp al, 8                    // compare with 8
00009e1a: 7309            jnc loc_00009e25             // skip if greater than or equal to 8
00009e1c: c6831a01000008  mov byte ptr [ebx+11ah], 8   // set interval to 8

So, for example, to change the limit to 1, search for the sequence:
3C 08 73 09 C6 83 1A 01 00 00 08
and change to:
3C 01 73 09 C6 83 1A 01 00 00 01

Tested with usbport.sys 6.1.7601.18251 and .18328 (offset for the sequence = 00009e18).

Warning: Windows 7 allows only signed drivers to be loaded, so you have to sign modified usbport.sys before replacing the original file.
1. copy C:\Windows\System32\drivers\usbport.sys to some folder
2. patch the copy of the file with a hex editor
3. run Driver Signature Enforcement Overrider (DSEO) and enable test mode
4. run DSEO again and sign the patched file (check if the file has changed its size after signing)
5. replace the original usbport.sys with the signed copy (use Se7en File Replacer)

Don't forget to change bInterval values in your project's Interrupt IN/OUT Endpoint Descriptors. bInterval=1 seems to work fine - tested with long sysex dumps.

Re: USB MIDI Interface

Post by winelight » Tue Apr 08, 2014 1:40 pm

There is nothing that can be done on Windows 7. I don't know about Windows 8.

Re: USB MIDI Interface

Post by Fabian » Tue Apr 08, 2014 1:25 pm


any improvements of the 8ms problem on windows? I saw tests some pages above with linux, but how is windows performing?

Thank you

Re: USB MIDI Interface

Post by winelight » Tue Jun 18, 2013 9:56 pm

Unfortunately that patch only helps mice, I eventually discovered. This is a real problem on Windows and really the only option is to use something else in most cases. Windows XP has a higher polling speed, but the application I run needs a minimum of Windows 7 and ideally Windows 7 64-bit.

Re: USB MIDI Interface

Post by Guest » Tue Jun 18, 2013 9:27 pm

I've used this library to build a little CV/Gate interface and it's working great on OS X (>= 10.6.3+ when they removed the "sanity check" on the poll interval), iOS and Linux, but on windows we are limited by the 8ms poll time. I am wondering if someone has successfully tried to patch system drivers to overcome this limitation - looks like it's a common practice among gamers who want to increase the poll rate of their mice.

Re: USB MIDI Interface

Post by Guest » Mon May 27, 2013 4:13 pm


how do usb midi work with windows 8?

thx georgiu

Re: USB MIDI Interface

Post by winelight » Mon Jan 14, 2013 12:10 pm

Hi thanks for that. Nice to have it confirmed that I wasn't doing something wrong!

I have my project all working now but the latency is too high. I'm using Windows 7 and know it would be better with Linux and its 2mS poll time, but to be honest I will probably go to a USB hardware solution like the Teensy in the end.

Re: USB MIDI Interface

Post by horo » Wed Jan 02, 2013 6:57 pm

winelight wrote:How many MIDI Event Packets can you send in one go?
So I guess I have my answer, but I'd like to know where it's documented please!

Hi winelight,

You're right, two packets with a total of eight bytes is the maximum.
USB MIDI transfers are defined as bulk transfers which are not allowed for low speed devices - but it's possible to change them into interrupt transfers in the device descriptor (see my post above

I've found a very good documentation (USB in a NutShell) which states about package size:
Interrupt Transfers
The maximum data payload size for low-speed devices is 8 bytes.

I've printed the NutShell docs along with the official USB MIDI docs and used them while I developed the VUSB MIDI interface. These papers are now quite crinkled and bear notes in different colors - but hey - the software works.

Ciao, Martin

Re: USB MIDI Interface

Post by winelight » Tue Dec 04, 2012 8:50 pm

Hi everyone

Thanks to everyone who's worked on V-USB and V-USB-MIDI and had posted great tips in this thread and other places. My MIDI project is now working, however, like everyone else I would love it to go faster!

One thing I cannot seem to find an answer on is:

How many MIDI Event Packets can you send in one go?

I've seen:
    Most (nearly all) examples only sending one packet
    A very few examples (and a couple of comments) suggesting two (for a total of 8 bytes) is OK
    Suggestions that you can have multiple packets - although this may only apply to bulk transfers.

Does anyone have a definitive answer please?

(edit) Well I've found by experimentation that if I return two packets, it's fine, but more than that, something somewhere goes wrong.

So I guess I have my answer, but I'd like to know where it's documented please!

Re: USB MIDI Interface

Post by Dex » Fri Jul 27, 2012 8:56 pm


This V-USB-MIDI project is great!
I want to make some MIDI controllers with it, but i dont know how to program in other languages than the used in the Arduino IDE...I saw that some guys installed the V-USB library for using it with the Arduino IDE, anyone here knows how to do this with the V-USB_MIDI library?

Thanks in advance!

Re: USB MIDI Interface

Post by horo » Thu May 31, 2012 10:07 am


some days ago I had an email discussion with Philipp (in german) about my hardware, maybe the conclusion will be helpful so I'll give a rough translation:

Q: what does the inductor do?
A: it formes a lowpass together with the two capacitors to filter out noise from 5v usb.

Q: what about 3.3V and 12MHz - aren't you out of spec?
A: I use ATMega16A - the data sheet (figure 27.1, Maximum frequency vs. Vcc) shows that we are slight out of spec at 3.3V but I measured Vcc to be in the range of 3.5..3.8V so it's ok again. I also use ATMega168A which is full in spec (figure 29.1). As these are worst case values over the full temperature range there is sufficent margin (up to 16 MHz).

The ATMegas work at incredible low Vcc (<1V), if you use the internal eeprom you MUST set the brown out detection fuses to avoid spurious data corruption due to (slowly) dropping Vcc (I learned it the hard way).

Ciao, Martin

Re: USB MIDI Interface

Post by Dallum » Sat Feb 04, 2012 7:05 am

Sorry for my English, it's not my native language :)

I want to create USB MIDI controller based on this project:
But i want to use encoders instead of potentiometers.
I need to get information about controllers position in host to display it on my device.

I know that i should use usbFunctionWriteOut, but don't understand how... Small number of examples does not give the right information about this.
Can somebody give a little piece of code for this function? How can i get this information from "data"?

I try to do this:

Code: Select all
void usbFunctionWriteOut(uchar * data, uchar len)

  uchar cable= (*data)
  uchar channel = (*(data+1))
  uchar CC = *(data+2);
   if (CC == 77){
         PORTB = 0x00;

I expect that if in host control number 77 is changed then my LEDs are light up. That's don't work.
Where is my mistake?


Re: USB MIDI Interface

Post by Oddgit » Wed Dec 28, 2011 7:03 pm

Hi @ all...

I've solved the problems on my own and finally, I got the whole thing running. I've built a foot controller for digital guitar effect software, based on the V-USB-MIDI project.

It works perfect with Win 7.

I've created a small blog for the documentation of the project:


Re: USB MIDI Interface

Post by Oddgit » Sat Sep 24, 2011 2:17 pm

Hi guys,

I'm very new to AVR programming, and my first big project is a midi controller. So I hope it's okay to post my questions in this threat. I've downloaded the latest version of V-USB-MIDI and I'm using an ATmega8 with AVR Studio 5 and AVRISP mkII. At the moment, I've only connected one potentiometer, one LED and one button to the device. But, unfortunately, it doesn't work. Both, Windows 7 and XP can't identify the USB device.

I've connected the USB-jack in this way:
In my case, D- goes to PD0 and D+ to PD2 (INT0). I've also adjusted this by editing "usbconfig.h".

But connecting the 1k5 pull-up resistor confuses me. In the schematic above, it's a pull-up to +5V, isn't it? Because in the comments of "usbdrv.h" I've read the following:
Hardware Prerequisites:
If you use Zener diodes to limit the voltage on D+ and D-, you MUST use a pull-down resistor, not a pull-up.

So, what to do?!
Anyway, if I don't connect the 1k5 resistor to a port of the microcontroller, how must I handle the "Optional Hardware Config" in "usbconfig.h"? Is it okay, to simply delete "#define USB_CFG_PULLUP_IOPORTNAME D" and "#define USB_CFG_PULLUP_BIT 4"? Do I have to change something else in the source code, if I use this way to connect the USB jack? Btw, I'm using those zener diodes:;ACTION=7;LA=3;OPEN=0;INDEX=0;FILENAME=A400%252FZF%2523MOT.pdf;SID=13Tmr58n8AAAIAADj1Ejc9346e0fe3139afadbe3f92f875a7f569

Next thing is linking the correct files to the project. I've copied all files of the folder "usbdrv-20090415" (except the ones, that don't fit to my 12 MHz clock rate) into my project folder. Then I've included all to my project by adding them to the folder tree in AVR Studio 5, except the files "" and "". They're only in the project folder, because in the comments I've read:
Do not link this file! Link usbdrvasm.S instead, which includes the appropriate implementation!
I hope, that's correct.
So far, so good. But where do I tell the compiler, which clock rate I've choosen?! Because unlike in "usbconfig-prototype.h" the "#define USB_CFG_CLOCK_KHZ (F_CPU/1000)" is missing in "usbconfig.h" of the V-USB-MIDI sample.

I promise, I didn't change anything in the source code (except the pin assignment)! Has anyone an idea, what I else could do, to get the thing working? Or what I do have to change in the source code when using an ATmega8?

As I said, I'm very new to that stuff, so it would be great if someone could help me.