gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > DS MIDI interface options...

#87677 - nerd of nerds - Thu Jun 15, 2006 12:04 am

Hey all.

I was just contemplating how wonderful it would be to use my ds lite as a drum machine AND midi sequencer. I know there is a drum machine app out already for the ds and its pretty nice and looks to be quite promising. But so far there have been no attempts to add midi to my knowlege.

What are our options for creating such an interface? I know that natrium42 has creaded a serial interface for passme but i'm not a huge fan of bare pcbs that might harm my precious ds. I thought i had seen something on his site about Dserial or something like that. I guess i'm not just dead sure as to what this does. Is it a modified passme to allow easier serial interfacing or just a strickly a serial interface?

For me and most people the gba port is out of the question until a ds slot flash cart comes out.

Thoughts, ideas, suggestions?

#87697 - tepples - Thu Jun 15, 2006 2:37 am

nerd of nerds wrote:
For me and most people the gba port is out of the question until a ds slot flash cart comes out.

Pak Swapping. (Remember from the N64?)

Or use the "Xport" card that has both flash memory and I/O on the same GBA card.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#87706 - TheRain - Thu Jun 15, 2006 3:31 am

nerd of nerds wrote:
Is it a modified passme to allow easier serial interfacing or just a strickly a serial interface?


It makes serial interfacing easier only because he tells you exactly where to solder on a passme and then gives you some prototype code to mess with.

It sounds like you already have a grasp of this, but MIDI is a serial interface. You could use natrium's passme hack to output this data, but on the programming end you will have to take a couple of things into consideration... this is from a site I used when I did a MIDI device design for school http://www.media.mit.edu/physics/pedagogy/fab/fab_2002/personal_pages/david/mit.edu/circuit.html#MIDIOUT :

-The baud rate is 31,250 baud (bits per second)
-The impedence of the output circuit is 660 Ohms
-The bit order of data coming out of the MIDI interface must be LSB first
-The resting point when data is not being transmitted HIGH
-Start bit (telling MIDI that a byte is about to be sent) should be LOW
-The stop bit (signaling the end of the byte being transmitted) is HIGH

So, for example... if I want to send 10010000 which in decimal is 144 and in MIDI is translated as a NOTE ON message... I would put a 0 as a start bit and a 1 as an stop bit and send it out in this order (left to right) 0 00001001 1 so here you can see the start bit and stop bit added in, and the order of transmitting.


Last edited by TheRain on Thu Jun 15, 2006 7:35 am; edited 2 times in total

#87711 - TheRain - Thu Jun 15, 2006 3:55 am

Another quick note...

I haven't gone through Natrium's code completely, but it's possible that it adds start bits and end bits or something... so you'll proabably want to look through that.

Also, if you look at his code he is using card.h from dskit to perform output and input.

The pins he's using on the passme could be directly accessed from the port if you wanted to make your own PCB. What I ended up doing was, after putting flashme on my DS, I used my passkey2 device by hacking off everything but the card insert pins and kept the housing mostly intact... then I soldered wires from there to connector on a cheap proto-board PCB from radioshack . This gives complete access to all of the pins from the card slot.

on the subject of the high rest state of the MIDI output, you can use an inverter IC which will give you that high rest state as well as perform the inversion of the logic... this is what many people do when creating MIDI devices.

#87719 - nerd of nerds - Thu Jun 15, 2006 5:45 am

TheRain wrote:
nerd of nerds wrote:
Is it a modified passme to allow easier serial interfacing or just a strickly a serial interface?


It makes serial interfacing easier only because he tells you exactly where to solder on a passme and then gives you some prototype code to mess with.

It sounds like you already have a grasp of this, but MIDI is a serial interface. You could use natrium's passme hack to output this data, but on the programming end you will have to do a couple of things... this is a direct quotation from a site I used when I did a MIDI device design for school (take note especially the baud rate 31,250 baud, impedence of the output circuit 660ohms , bit order LSB first, resting point when data is not being transmitted HIGH, start bit is low, data bits are inverted meaning a HIGH is a 0 and a LOW is a 1. http://www.media.mit.edu/physics/pedagogy/fab/fab_2002/personal_pages/david/mit.edu/circuit.html#MIDIOUT :
"MIDI is basically serial data transmitted at 31,250 baud (bits-per-second) through a circuit with a resistance of about 660 ohms. Parity must be set to NONE, the number of stop bits must be set to 1 and finally the number of data-bits must be set to 8. The baud rate MIDI uses means that during transmission each bit should last for 32 micro-seconds. MIDI is transmitted in chunks of 3 bytes (each byte is 8 bits) and each transmitted byte is padded with a start bit (0) before it and a stop bit (1) after it. The three bytes of the typical MIDI message consist of one status byte and 2 data bytes (in that order). There is a lot of information online about what makes up valid status/data bytes. The bits in each byte are transmitted Least-Significant-Byte (LSB) first.
So if I wanted to transmit the number 144 (this is the code for a NOTE-ON in MIDI), the bit-pattern would be:

what I want to tranmit: 10010000
what bits get put on the line (read left-to-right): 0 00001001 1
(note: the spaces are just to show that there is a start and stop bit)

I was doing some testing while I developed my circuit, and I was sending the following bytes down the MIDI line: 144 144 144

This sequence caused me a lot of headache, because I didn't realize for the longest time that IT'S NOT VALID MIDI. It's three control bytes in a row and no data bytes. So even when I had the hardward constructed correctly, the computer was still not registering any MIDI messages coming through. Be careful of that.

Read my notes from this testing session here (note that in Hexidecimal format, 144 is 0x90)

Since MIDI is really just serial data, it's pretty easy (in theory) to transmit it, since many microcontroller development languages have routines for transmitting and receiving serial built-in. The signaling in MIDI is based on current rather than voltage though, which means that in order to transmit a message, you have to have a certain amount of current flowing through the circuit. For longer MIDI cables, you'll need more current pushing through the circuit.

Resting state on the line is when no current is flowing. This is actually a logical 1. So I think about it like this:

Want to transmit a 1 -> no current flows
Want to transmit a 0 -> flow that current! "


WOW! While a lot of that was a bit over my head i hope that it soon won't be. I'm going to study general serial and midi stuff before i even consider undertaking this project as my knowledge is just to limited at this point. Although i wouldn't be against creating my own pcb (this i've done before several times) ready for midi ports to be soldered to it.

Any documents that you would recomend my reading? I have always wanted to creat my own midi interface with something and this seems like a great way to dive in and learn, but for the mean time i think i'll keep working on my simple beat counter program ;-)

#87725 - TheRain - Thu Jun 15, 2006 7:05 am

Hey, I can try to give you some places to get a start... but can I ask what your background is... or what parts of that information are new ideas to you? If you're here, I'll guess you're a programmer so it's probably more of the electronics stuff that's getting you...

I modified the original message above so hopefully it is easier to read the requirements of MIDI now.

#87786 - nerd of nerds - Thu Jun 15, 2006 6:01 pm

TheRain wrote:
Hey, I can try to give you some places to get a start... but can I ask what your background is... or what parts of that information are new ideas to you? If you're here, I'll guess you're a programmer so it's probably more of the electronics stuff that's getting you...

I modified the original message above so hopefully it is easier to read the requirements of MIDI now.


Well, idk exactly what my background is...I've done some simple programming and a lot of analog electronics stuff but i have yet to start messing with any digital stuff. This seemed like a really fun project to start honing both of said skills over the summer.

I don't exactly expect a lot out of myself on this. If i can get my synthesizer to make some tones while being controlled by the ds i'll be pretty giddy.

Do you have aim or any kind of IM service?

EDIT:

Based on your second post it sounds like, if one were so inclined, i could just make my own pcb without the cart connector, just the bare stuff needed for midi. Am i correct in assuming this? If so, GREAT! I could probably just get it to fit in a metroid demo case or something...

#87827 - TheRain - Thu Jun 15, 2006 8:08 pm

nerd of nerds wrote:

Based on your second post it sounds like, if one were so inclined, i could just make my own pcb without the cart connector, just the bare stuff needed for midi. Am i correct in assuming this? If so, GREAT! I could probably just get it to fit in a metroid demo case or something...


yah, that's correct. i have msn messenger, i'll pm you my e-mail for that. I'm getting ready for finals right now, but after next wed I should have some time. Actually, I wouldn't mind working on this with you as I had the same thoughts of midi control and sequencing.

#88177 - TheRain - Sat Jun 17, 2006 10:50 pm

I need to correct something I said here... people keep talking about natrium42's "DSerial" and I keep thinking they're talking about Natrium's Passme hack where he added a serial interface for it.

I just read natrium's blog and he is doing something VERY cool with a completely new, non-passme related serial expansion for the DS... it looks like it's going to be a very useful device with a lot of features. Anyway, wanted to get that straight and on the record here as I might have confused or missinformed some people.

http://natrium42.com/blog/

#90291 - bjoerngiesler - Thu Jun 29, 2006 9:52 am

Hi,

this MIDI interface stuff is all very interesting. Has anyone thought of doing MIDI via Wireless/UDP? The ping time for my DS in my home net is about 30ms roundtrip, so one-way package travel shouldn't exceed 20ms, which makes real-time MIDI from other DS's or PCs well possible. A virtual MIDI interface for Mac/PC could be written that converts between wired MIDI and network.

What do you think?

Regards,
Bj?rn

#90596 - TheRain - Sat Jul 01, 2006 5:36 am

That's an interesting idea... have you seen MIDI over LAN programs before?? I've coded a really poor implimentation of this idea for PC to PC communication but had some issues. This guy over at the Harmony Central Keyboard forum (where I hang out also) coded a good PC to PC implimentation of this and it looks like he was working on an open source protocol for it as well... maybe something that could be carried over to the DS. -----> http://acapella.harmony-central.com/forums/showthread.php?s=&threadid=989612&highlight=MIDI+over+LAN

#90634 - bjoerngiesler - Sat Jul 01, 2006 12:26 pm

Interesting. Can't test it since it's Win only and I'm on a Mac, but I took a quick look at the forums/README.

Unfortunately, it uses UDP. UDP with Wifilib is a bit flakey for me (about 20% packet loss, means lots of hanging notes), so TCP will probably be the way to go. I'll do some performance test later today and see if that's workable.

#90697 - bjoerngiesler - Sat Jul 01, 2006 9:16 pm

OK, after a couple of tests, I'm seeing an average turnaround time of 60ms (min. ~20ms, max. ~600ms) for a TCP connection. (Explanation: This is just the PC sending a timestamped packet (of about 100 bytes) to the DS and the DS sending it straight back; no waiting for VBlank is done, and TIMER3 controlling Wifi is at 100Hz. Tried 50Hz too, didn't make too much difference.)

Assuming both legs of the journey have the same length, an average turnaround of 60ms means a one-way time of 30ms, which as delays go is at the limit of audibility. Net result of the test: Yes, I think MIDI over TCP is feasible, but not optimal.

UDP would be much better, but right now there's too much packet loss for that to be an alternative. Example: A ping shows between 3 and 26ms round-trip time, which is great, but 11% packet loss, which is very bad for music. Does anyone know if that's dswifi's fault or just a fact of life for the DS?

I'm going to hack up a prototype MIDI-over-LAN driver for the Mac in the next couple of days and see how far I get.

#92886 - TheRain - Sat Jul 15, 2006 5:46 am

MIDI interfacing from the DS has been established! thanks guys for all of the programming advice these past few weeks. A MIDI demo is forthcoming.