USB-MIDI Project up and running

Page: 123 > Showing page 1 of 3
Author
raichea
Starting Member
  • Total Posts : 67
  • Reward points : 0
  • Joined: 2008/01/18 06:33:30
  • Location: 0
  • Status: offline
2009/03/09 06:10:47 (permalink)
0

USB-MIDI Project up and running

I got some great supporton here when I first started playing with MIDI via USB so thought I'd pass the news along that my MIDI project (phase 1) is now complete and fully operational. I've written it up as a couple of articles that are being published in Nuts & Volts (Feb/Mar 2009 - www.nutsvolts.com).

I'll also be putting it up on my own site (www.grapevyne.com/pic.projects) once the April issue of the magazine is published and in print. If you dig around, you can find the source code already on the N&V site. Future enhancements will also go on my site as they occur.

The project is called mistralXG

Regards, Steve.
#1

53 Replies Related Threads

    synapsys
    Super Member
    • Total Posts : 247
    • Reward points : 0
    • Joined: 2006/01/06 15:19:18
    • Status: offline
    RE: USB-MIDI Project up and running 2009/03/09 07:38:36 (permalink)
    0
    Hi Raichea,
     
    First let me thank you for posting this project! I have a few questions concerning the MIDI USB interface. Has it been tested on Windows and MAC platforms? If so did you use the standard drivers?
     
    I have followed MIDI USB interface development using the 4550/2550 MCU for quite awhile now and have found no one that has succeeded in developing a fully working model! They all suffered from data loss at high load rates (i.e. passing large quantities of SYSEX data for example).
     
    Any further info you could provide would be appreciated. I'm looking forward to the N&V article.
     
    Regards,
    Synapsys
     
    #2
    chinzei
    Super Member
    • Total Posts : 2250
    • Reward points : 0
    • Joined: 2003/11/07 12:39:02
    • Location: Tokyo, Japan
    • Status: offline
    RE: USB-MIDI Project up and running 2009/03/09 17:40:34 (permalink)
    0
    I have followed MIDI USB interface development using the 4550/2550 MCU for quite awhile now and have found no one that has succeeded in developing a fully working model! They all suffered from data loss at high load rates (i.e. passing large quantities of SYSEX data for example).


    MIDI side
    USB MIDI converts standard MIDI message to 4 bytes chunks - 1 byte header + 3 bytes MIDI code. SYSEX messages, which put in variable length, are also converted to a number of 4 bytes chunks, with padding at the last chunk. If you transfer single chunk per USB packet, you can't get so much transfer speed. 64 bytes USB packet can hold up to 16 x 4 bytes USB MIDI chunks. When single USB packet is filled by MIDI chunks, you can continue it in the next USB packet. As the result, even if long SYSEX message may be split into two USB packet, the message is re-configured on the PC device driver (device -> PC) or on the firmware (PC -> device).

    USB side
    Full-speed bulk transfer goes to its max speed when just 64 bytes packets are exchanged, in either direction. When short packet (less than 64 bytes) is transferred, the transfer pauses until the next 1ms USB frame (on UHCI and OHCI host controller).

    Considering these conditions, next implementation is suitable for high load rates.

    MIDI IN
    The process is divided into two parts, MIDI and USB. Double buffer connects the data flow of these processes. MIDI process is executed in ProcessIO(). USB process is driven by USB interrupt.

    |<------------- MIDI process --------------->|<---------- USB process --------->|
    MIDI generator --> chunk converter --> double buffer --> bulk IN endpoint handler

    USB SOF (Start Of Frame) signaling is used for the time base to swap the double buffer. While MIDI process fills a buffer, USB process sends out another buffer. The buffer size is a multiple of 64 bytes, respectively. It determines the max transfer size on a single USB frame.

    Frame# 0
    MIDI process -------------------> buffer# 0

    Frame# 1
    buffer# 0 -----> USB IN endpoint
    MIDI process -------------------> buffer# 1

    Frame# 2
    MIDI process -------------------> buffer# 0
    buffer# 1 -----> USB IN endpoint
    Frame# 3
    buffer# 0 -----> USB IN endpoint
    MIDI process -------------------> buffer# 1
    ...


    MIDI OUT
    MIDI OUT is also divided into two processes, MIDI and USB. MIDI process is executed in ProcessIO(). USB process is driven by USB interrupt.

    |<------------- MIDI process --------------->|<---------- USB process --------->|
    MIDI player <-- chunk decoder <-- ring buffer <-- bulk OUT endpoint handler

    When a USB packet comes, USB interrupt is evoked. In USB ISR, the packet is unloaded from USB buffer to the ring buffer. In ProcessIO(), MIDI process polls the ring buffer status. When the ring buffer has data, MIDI process decodes it and passes it to MIDI player. The size of ring buffer determines the max transfer speed without any data drop.


    As this outline shows, the implementation eats up many memories.
    Then, PIC18F is tight for this implementation, PIC24F or PIC32 are recommended.

    Tsuneo
    #3
    raichea
    Starting Member
    • Total Posts : 67
    • Reward points : 0
    • Joined: 2008/01/18 06:33:30
    • Location: 0
    • Status: offline
    RE: USB-MIDI Project up and running 2009/03/10 05:56:32 (permalink)
    0
    ORIGINAL: synapsys
    First let me thank you for posting this project! I have a few questions concerning the MIDI USB interface. Has it been tested on Windows and MAC platforms? If so did you use the standard drivers?

    I've used it a lot on Windows, I've seen it correctly enumerate on Linux (but haven't used it), and I believe it works on MAC based on info received elsewhere.

    Yes, it uses standard drivers.


    I have followed MIDI USB interface development using the 4550/2550 MCU for quite awhile now and have found no one that has succeeded in developing a fully working model! They all suffered from data loss at high load rates (i.e. passing large quantities of SYSEX data for example).

    I've passed many megabytes of data through the mistralXG USB-MIDI interface, in both directions, without any data loss or corruption. Early versions of the PIC18F4550/2550 family had a problem with the EUSART that caused additional 0x00 bytes to be injected into the data stream with high bi-directional throughput, but this is (apparently, at least) resolved in the B6 silicon.

    There are also some issues with the standard Windows MIDI drivers that can cause problems:

  • The Microsoft driver isn't multi-client capable. This means, that only one program can allocate a MIDI port at the same time.
  • The Microsoft driver has to send a complete SysEx string from a single buffer. Corruption occurs if the SYSEX gets spread over multiple buffers. If you're using MIDI-OX to monitor MIDI data, you have to increase the Low level Output buffer size from 256 to a value larger than your largest SYSEX string.
  • The Microsoft driver doesn't allow the USB module to change the device name. Steve
  • #4
    raichea
    Starting Member
    • Total Posts : 67
    • Reward points : 0
    • Joined: 2008/01/18 06:33:30
    • Location: 0
    • Status: offline
    RE: USB-MIDI Project up and running 2009/03/10 06:10:29 (permalink)
    0
    ORIGINAL: chinzei
    Full-speed bulk transfer goes to its max speed when just 64 bytes packets are exchanged, in either direction. When short packet (less than 64 bytes) is transferred, the transfer pauses until the next 1ms USB frame (on UHCI and OHCI host controller).

    While I can't fault what you say, mistralXG currently uses the first implementation you describe, and I haven't noticed any specific timing issues when transferring data. Given that a single 3-byte MIDI command takes about 1ms to transmit, I wouldn't expect major problems that wouldn't also be apparent as MIDI choke due to large amounts of MIDI data being transmitted simultaneously over a normal MIDI link.

    That said, I'd prefer a double-buffered MIDI<->USB interface, so I plan to move to the 2.3+ version of the USB framework, which supports ping-pong, at some time.

    Steve.
    #5
    synapsys
    Super Member
    • Total Posts : 247
    • Reward points : 0
    • Joined: 2006/01/06 15:19:18
    • Status: offline
    RE: USB-MIDI Project up and running 2009/03/10 07:11:38 (permalink)
    0
    Thanks Chinzei and Raichea for your comments.
     
    I am planning on using the new 18F2650 MCU for the 8-bit version of my MIDI USB experiments. It has more RAM than the 18F2550. I also have on order a 24FJ256GB110 PIM to experiment with a 16-bit version. My target host is the MAC so I will let you know how this works out.
     
    Regards,
    Synapsys
    #6
    chinzei
    Super Member
    • Total Posts : 2250
    • Reward points : 0
    • Joined: 2003/11/07 12:39:02
    • Location: Tokyo, Japan
    • Status: offline
    RE: USB-MIDI Project up and running 2009/03/10 07:33:33 (permalink)
    0
    Original: raichea

    While I can't fault what you say, mistralXG currently uses the first implementation you describe, and I haven't noticed any specific timing issues when transferring data. Given that a single 3-byte MIDI command takes about 1ms to transmit, I wouldn't expect major problems that wouldn't also be apparent as MIDI choke due to large amounts of MIDI data being transmitted simultaneously over a normal MIDI link.

    The standard MID transfer rate is a little greater than a 3 bytes MIDI message / 1 ms / Jack, (31.25 kbps, 10bit/octet, 3 octet/message), as you said. But USB MIDI bundles up to 16 cables (Jacks) on a single USB endpoint. Above implementation counts in this max-scale transfer.

    For single Jack implementation, it fits to the RAM size of PIC18F.

    Tsuneo
    #7
    raichea
    Starting Member
    • Total Posts : 67
    • Reward points : 0
    • Joined: 2008/01/18 06:33:30
    • Location: 0
    • Status: offline
    RE: USB-MIDI Project up and running 2009/03/10 07:37:42 (permalink)
    0
    ORIGINAL: chinzei
    The standard MID transfer rate is a little greater than a 3 bytes MIDI message / 1 ms / Jack, (31.25 kbps, 10bit/octet, 3 octet/message), as you said. But USB MIDI bundles up to 16 cables (Jacks) on a single USB endpoint. Above implementation counts in this max-scale transfer.

    For single Jack implementation, it fits to the RAM size of PIC18F.


    Fair comment... mistralXG is single cable... as the number of cables increases, it would be very easy to run into timing issues.

    Steve.
    #8
    synapsys
    Super Member
    • Total Posts : 247
    • Reward points : 0
    • Joined: 2006/01/06 15:19:18
    • Status: offline
    RE: USB-MIDI Project up and running 2009/03/12 09:31:35 (permalink)
    0
    Hi Raichea,
     
    I experimented with USB MIDI using your descriptor and the latest USB stack code running on a PIC24 MCU. I am testing with Windows XP. The device appears to enumerate properly. I can see two devices in Device Manager: an Audio Device and a Composite Device. Device Manager indicates that both of these devices are working properly. Now the problem. The USB MIDI device does not show up in any MIDI application (e.g. MIDI-OX). Have you ever run into this problem? If so how did you solve it?
     
    Any help you can give would be appreciated.
     
    Regards,
    Synapsys
     
    #9
    raichea
    Starting Member
    • Total Posts : 67
    • Reward points : 0
    • Joined: 2008/01/18 06:33:30
    • Location: 0
    • Status: offline
    RE: USB-MIDI Project up and running 2009/03/12 10:10:03 (permalink)
    0
    ORIGINAL: synapsys
    I experimented with USB MIDI using your descriptor and the latest USB stack code running on a PIC24 MCU. I am testing with Windows XP. The device appears to enumerate properly. I can see two devices in Device Manager: an Audio Device and a Composite Device. Device Manager indicates that both of these devices are working properly. Now the problem. The USB MIDI device does not show up in any MIDI application (e.g. MIDI-OX). Have you ever run into this problem? If so how did you solve it?

    I don't think the Composite Device should be there... WinXP shows it as Audio Device. I have seen your symptoms in the past... where the Audio Device enumerates, but no MIDI port is visible. Even stranger, some machines did see the port, but my normal test system didn't.

    I found several dead-end solutions on the web. In the end, it was a combination of perseverance and luck that solved it for me. Here's what did it for me:

    I downloaded USBDeview from http://www.nirsoft.net/utils/usb_devices_view.html. This displays all USB devices that have been plugged into the computer, whether or not they are currently connected. The Options menu also lets you show Devices without Drivers. On my machine, there were three "Unknown devices" in this category. I deleted them and the entries for my own device. The next time I plugged in mistralXG, the MIDI port was available.

    I hope it works for you (I'll be interested to hear, either way).

    Steve.

    #10
    synapsys
    Super Member
    • Total Posts : 247
    • Reward points : 0
    • Joined: 2006/01/06 15:19:18
    • Status: offline
    RE: USB-MIDI Project up and running 2009/03/12 10:35:12 (permalink)
    0
    I downloaded USBDeview from http://www.nirsoft.net/utils/usb_devices_view.html. This displays all USB devices that have been plugged into the computer, whether or not they are currently connected. The Options menu also lets you show Devices without Drivers. On my machine, there were three "Unknown devices" in this category. I deleted them and the entries for my own device. The next time I plugged in mistralXG, the MIDI port was available.

     
    I tried what you suggested. There were 6 USB devices marked Unknown devices. I uninstalled them and I uninstalled my device. I reconnected my device and it enumerates the same (i.e. Composite and Audio devices). Still the MIDI does not show up in MIDI-OX devices [:@]
     
    I guess I will try another computer to see if the same things happens.
     
    Regards,
    Synapsys
     
    #11
    raichea
    Starting Member
    • Total Posts : 67
    • Reward points : 0
    • Joined: 2008/01/18 06:33:30
    • Location: 0
    • Status: offline
    RE: USB-MIDI Project up and running 2009/03/12 11:01:12 (permalink)
    0
    It's possible I'm not remembering correctly - maybe the Composite Device does show up, too, but I didn't think so. It's been a while since I completed the USB section of the code and so I haven't had to look at the device manager for a long time. Unfortunately, I don't have my mistralXG to hand at the moment, so I can't check - it may be a week or so before I can. I'll be sure to post when I find out.

    Certainly worth trying another system or two to see if you get different behaviour, as I did. I haven't tried the 2.3 framework at all, so I've no idea how easily or otherwise it should be to port to it. Nor have I used the PIC24 family, so not sure what ramifications, if any, there are from that direction.

    If you get no luck with the PIC24, and you have a PIC18 2550/4550 family chip to hand, it might be worth trying the code as is to see if that works.

    Steve.
    #12
    synapsys
    Super Member
    • Total Posts : 247
    • Reward points : 0
    • Joined: 2006/01/06 15:19:18
    • Status: offline
    RE: USB-MIDI Project up and running 2009/03/12 12:04:34 (permalink)
    0
    If you get no luck with the PIC24, and you have a PIC18 2550/4550 family chip to hand, it might be worth trying the code as is to see if that works.

     
    Somewhere I have a 2550 so I will try it too. It seems as if this is a rather common problem with the XP Audio driver. I have seen many posts on the Net about it.
     
    I'll be sure to post when I find out.

     
    I really appreciate your help.
     
    Regards,
    Bob
    #13
    chinzei
    Super Member
    • Total Posts : 2250
    • Reward points : 0
    • Joined: 2003/11/07 12:39:02
    • Location: Tokyo, Japan
    • Status: offline
    RE: USB-MIDI Project up and running 2009/03/12 13:34:37 (permalink)
    0
    I can see two devices in Device Manager: an Audio Device and a Composite Device.

    There are two possible configuration for USB MIDI interface.
    a) With Audio Control (AC) interface
    b) Without AC interface
    Both config work for Win and Mac.

    a) With AC
    This is the standard USB audio config, described in USB MIDI spec.
    http://www.usb.org/developers/devclass_docs/midi10.pdf
    Appendix B. Example: Simple MIDI Adapter (p37)

    Windows makes up two device instances on Device Manager.
    - USB composite device (under USB controller)
    - USB audio device (under Sound, Video and Game Controller)

    b) Without AC
    From above config, these descriptors are deleted.
    - B.3.1 Standard AC Interface Descriptor
    - B.3.2 Class-specific AC Interface Descriptor

    Of course, other parameters are tuned for this deletion.
    Config desc - wTotalLength, bNumInterfaces
    Standard MS interface desc - bInterfaceNumber

    For this config, Windows make single instance.
    - USB audio device (under Sound, Video and Game Controller)

    Tsuneo
    #14
    Guest
    Super Member
    • Total Posts : 80499
    • Reward points : 0
    • Joined: 2003/01/01 00:00:00
    • Location: 0
    • Status: online
    RE: USB-MIDI Project up and running 2009/03/12 14:17:32 (permalink)
    0
    interesting to read. I am also looking at MIDI format, software, and files (vgmusic.com)
     
    i have now a PIC controlled tone generator PCB, and want to write a small pattern player.
    data is transmitted to 8K RAM via serial port!
     
    on the PC side, i need my own software, it will be similar to common MIDI software, in terms of GUI.
     
    from what i understand, you need:
     
    -driver for the USB device, or implement generic device
    -software which can utilize the USB device via this driver, or generic Windows driver.
    -on the PIC side, suitable firmware to configure the device (enumeration),
    and to communicate via PC side driver (can work for different softwares).
     
    what's hard to understand is the exact standards which have to be implemented,
    and how to call the (generic) driver via PC software.
    for instance, storage devices "hide" via OS (Windows) layer.
     
    would it be possible for all USB devices just to have a file system?
    indeed interestingly it is not done that way, for reasons i do not know exactly.
     
    I've been looking a little at the PICKIT2 USB handler (creating 64bit build), skipped through the whole thing,
    reading documentation, then figured out it was coded correctly anyway.
     
    the point is, when the pattern player is working correctly, i will think of USB implementation!
    and also the point is, i do not want to create just a CuBase controlled toy synth PCB.
     
    *note
     
    it is a hardware-side pattern player, tough MIDI software is commonly doing smt. similar
     
    **note
     
    these days it is normal to have buggy USB devices:
    -some of them malfunctioning after a while, or with certain storage devices (at some days), only complete restart helps. different hub, the disk works normally.
    -others can not install at all (certain sound cards, network adapters)
    -there are the one's where first the driver CD must run, and then restart, and let install, and insert OS CD (ironically, the CD door is blocked).
    -others can not even start the software on the CD, but (luckily) can grab the driver files from the folder.
    -USB DVD (after three months) only reads single-side, writing still works normally. so the IDE DVD-ROM is actually essential, in addition to a third DVD drive.
     
    it can help to have different USB hubs, after a while you will know good combinations (was the good one a "full-speed" USB1.1 device?).
    on my old system, certain PCI cards would not be possible to operate in certain slots, over the years, they (again) worked in that slot. beyond any logic.
     
    so why you write this?
     
    if you implement USB, could you offer options for the transfer, i.e. the speed, or the type of protocol?
    if there is a problem, maybe it can help to change options.
    there are few USB devices (if any) which offer such adjustments, even if rather than full-speed 2.0,
    it would be essential to access that tiny 50 KB file, no matter how.

    aspforum.mchp.guest
    #15
    raichea
    Starting Member
    • Total Posts : 67
    • Reward points : 0
    • Joined: 2008/01/18 06:33:30
    • Location: 0
    • Status: offline
    RE: USB-MIDI Project up and running 2009/03/12 14:29:02 (permalink)
    0
    ORIGINAL: chinzei

    I can see two devices in Device Manager: an Audio Device and a Composite Device.

    There are two possible configuration for USB MIDI interface.
    a) With Audio Control (AC) interface
    b) Without AC interface
    Both config work for Win and Mac.

    According to the USB-MIDI spec, only a) is supported - that is the AC interface is mandatory. However, when developing my project, I found that config b) is used in some cases to resolve problems. I prefer to obey the spec, so went with a).

    Steve.
    #16
    raichea
    Starting Member
    • Total Posts : 67
    • Reward points : 0
    • Joined: 2008/01/18 06:33:30
    • Location: 0
    • Status: offline
    RE: USB-MIDI Project up and running 2009/03/12 15:17:43 (permalink)
    0
    It almost sounds like you want to reinvent MIDI for yourself to drive your tone generator.
    ORIGINAL: hybridpic

    what's hard to understand is the exact standards which have to be implemented,
    and how to call the (generic) driver via PC software.
    for instance, storage devices "hide" via OS (Windows) layer.

    would it be possible for all USB devices just to have a file system?
    indeed interestingly it is not done that way, for reasons i do not know exactly.

    Apologies if I've misunderstood, but I'm not sure quite what you're asking. I recommend you read some of the resouces referenced elsewhere to understand more about the way USB works. How would a MIDI device have a file system? I'm not talking here about MIDI files, but an interface such as the one in mistralXG. MIDI data is transmitted real-time and isn't stored anywhere (apart from temporarily as a complete MIDI message is assembled). USB implements a number of diifferent "standard" devices... MIDI is just one of them - MIDI, storage, serial port, etc. are all interfaces with their own unique characteristics.

    Steve
    #17
    Guest
    Super Member
    • Total Posts : 80499
    • Reward points : 0
    • Joined: 2003/01/01 00:00:00
    • Location: 0
    • Status: online
    RE: USB-MIDI Project up and running 2009/03/12 16:53:54 (permalink)
    0
    yes, i must give you right a little.
     
    i know it is a realtime protocol, from the software sequencer to the hardware synth (usually).
     
    so i am also looking at the MIDI protocol, especially the file format.
     
    a MIDI device could well-mannered have a file system, to replay patterns, or even complete MIDI arrangements independently.
     
    like digital camera, it can connect via stream, and act as PC camera, realtime, and then, also provide a FAT file system.
    it is the normal way to offer both of these features.
     
    yet, i do not have much USB experience, taking a look here and there.
     
    i have recently also understood USB implements "standard devices", even if i do not exactly know how, better say, how to build PIC based USB devices, so they act as standard devices. I have a number of relevant APP NOTES available, just touched the surface.
     
    i am just trying to get any available information about USB programming, yet it is difficult to decide exact terms and roles to assign to a USB PIC already mounted on PCB.
     
    eventually i hope to substitute the serial port interface with USB interface, so it would be a sort of pattern player connected to a tone generator IC.
    I am working at this right now, for instance the pattern player, there are only 2K altogether, not enough for full MIDI (means, to be able to replay a midi file independtly).
     
    I've got the I/O on the board working yesterday, LED chains, buttons, octave switching via IC.
    USB PCB could be connected to this in a matter of one or two days, if i find some really good information on the topics.
     
    until that, it can happen, USB wait for a month or so (wrong grammar, i know)
     
    eventually i want to use existing MIDI files to play on the PCB (even if there are only few channels).

    aspforum.mchp.guest
    #18
    raichea
    Starting Member
    • Total Posts : 67
    • Reward points : 0
    • Joined: 2008/01/18 06:33:30
    • Location: 0
    • Status: offline
    RE: USB-MIDI Project up and running 2009/03/13 06:06:58 (permalink)
    0
    ORIGINAL: hybridpic
    so i am also looking at the MIDI protocol, especially the file format.

    The MIDI File format spec is separate to the MIDI protocol spec.


    a MIDI device could well-mannered have a file system, to replay patterns, or even complete MIDI arrangements independently.

    As it happens, this is a possible extension I am planning to my design... I have left hooks in the hardware to allow access to storage. I haven't yet designed a number of things that would be needed to access the storage... one approach I'm considering is a second MIDI port that (hidden by the firmware) writes to the storage. A mass storage device interface would not be appropriate for the storage I'm planning on using.


    like digital camera, it can connect via stream, and act as PC camera, realtime, and then, also provide a FAT file system.
    it is the normal way to offer both of these features.

    Yes... but these are different USB interfaces...if a camera offers video and storage, this is two separate USB interfaces...some devices allow the user to switch between different configs, others provide access to both simulataneously. I haven't looked at this in detail, but I think this is what is called a Composite Device.


    eventually i hope to substitute the serial port interface with USB interface, so it would be a sort of pattern player connected to a tone generator IC.

    You could do this quite simply... one of the Microchip examples is a USB COM port.

    Steve.
    #19
    synapsys
    Super Member
    • Total Posts : 247
    • Reward points : 0
    • Joined: 2006/01/06 15:19:18
    • Status: offline
    RE: USB-MIDI Project up and running 2009/03/13 07:22:03 (permalink)
    0
    I took out the AC descriptors as suggested by Chinzei. Device Manager now only shows the USB Audio Device as he said. The device enumerates properly and USBDeview indicates everything is okay.  However, my problem is still the same, no MIDI devices show up in MIDI-OX (or any other applications).
     
    I will try an 18F2550 sometime this weekend but I suspect the results will be the same since Windows doesn't know anything about the actual hardware running the USB Stack code.
     
    Regards,
    Synapsys
    #20
    Page: 123 > Showing page 1 of 3
    Jump to:
    © 2017 APG vNext Commercial Version 4.5