rPi MIDI via GPIO (or USB)?
Nat Fowler (1676) 6 posts |
Hello everyone, Some more info if it would help: I have a specific MIDI task that I’m attempting and I’m hoping that the process can also open up the rPi with RISC OS to some other MIDI uses: |
Rick Murray (539) 13840 posts |
From my earlier post, it looks like slowing down the UART clock would be the simplest way. You’ll still need an interface board to convert the Pi’s serial (0v-3.3V) into real-world serial (approx +/- 9V). The two are very much incompatible. As for slowing down the serial port, hopefully somebody more familiar with the internals of RISC OS will have an idea if this is easily doable.
A USB dongle isn’t any good under RISC OS unless a RISC OS driver exists.
A digital serial link is basically a series of pulses. Running at a specific speed, the serial port will have a start bit, a series of data bits, and a stop bit. If you can “wiggle” any digital output at the right speed, it will look to the other end of the wire as if it is a serial link. I have used a similar method to this to do my own IIC through a parallel port, but since the IIC master device also supplies the clock pulses, it is a lot less time sensitive. With true serial, it must be exactly to time, no hiccups. But that isn’t the hard part. The hard part is reading the serial using a bit-bang method. In this case, you will need to sample the GPIO pin at 2x (and better, 4x) the clocking rate so you can be assured of a detection of a change of state, not just a glitch or transient in the wire. You’ll need code to match up the framing so you can reliably detect the start, data, parity (if any), and stop bits. To run at MIDI speeds, you’ll need to be able to read data at thirty thousand bits every second, which with oversampling will mean running the samples at around 120,000 times a second for good detection. I suspect you’d burn a lot of time/effort/power doing just that. You can bit-bang just about anything through a GPIO (for instance, PCM data), but doing such a thing on a general purpose microprocessor should probably be the last idea you consider. Complication. As RISC OS was written very much in the days when single-tasking was still widespread (it predates Windows 3), there are parts of the OS code that disable interrupts around “critical sections”. Well, bang goes your serial link if the OS does something to require it to disable interrupts…
USB fires a lot of events which need to be handled. The GPIO solution is using UART pins. Since the UART (serial hardware) is already present inside the chip, most of the hard work can be tasked off to the hardware with the UART raising an interrupt once per byte received. This is childishly simple for the host hardware, so much so that you could expect an 8MHz machine to handle MIDI without breaking into a sweat (think of the Acorn BBC I/O and Midi podule stuck in the back of an A310). If you can find out how to change the serial rate, and get an interface board sorted, the UART method would be the most responsive and least laggy on the system. |
Rick Murray (539) 13840 posts |
Why laugh? Susumu Hirasawa, who did the music for “Papurika” (as well as “Millennium Actress” and “Paranoia Agent”) frequently uses Amigas. Why not? If it works for him to use Amigas, and for you to use Atari, then why not? Meditational Field (Paprika OST): http://www.youtube.com/watch?v=aQIZKbyPtXc Whole bunch of MP3s on his own website to listen to (needs script & flash): http://noroom.susumuhirasawa.com/modules/opus/index.php/category/7/ |
Nat Fowler (1676) 6 posts |
I fully and totally endorse anyone using Amigas or Ataris or any obsolete hardware for new purposes, and I do it with real STs right now, but I’ve encountered a few people that I’ve approached with my problem who think I should just learn a new program on an iPad, which isn’t the point, and nothing I need to go into here anyway ;) |
Rick Murray (539) 13840 posts |
iPad? They are useful for something other than for executive-wannabees to make pie charts to point at?
Exactly. Why do we bother with RISC OS? Why not jack it in and spend our time on a more productive environment? It’s because that misses the point entirely. Feelings and emotions, which I’m sure we all have (hell, look at the package manager thread) don’t have any basis in logic. How can you be productive if you jack in your Atari and use something completely alien? You know I still write webpages in a plain text editor? It doesn’t even colourise. Because that is what feels right for me. I don’t need logic or rationality when talking about “feeling”.
Yup! I posted that link in a different thread here … um … six hours ago. (^_^) Looking further into the datasheet, it seems as if it will be possible for the Beagle to output MIDI rate. The serial speed is defined as: So you’d need to work out to divide by 13 or by 16, and then the further divisor. If the MIDI speed is 31.25kbps, then a quick calc would mean you should program the first divisor to be 16, and the main divisor to be 96. That should get you bang on the right speed. As for the Pi… don’t have its datasheet to hand (swapped SD cards for Naniwa Shônen Tanteidan). |
Nat Fowler (1676) 6 posts |
And I’m the guy “7thheaven” that commented there 10 days ago! Ok so what do you do with this information of serial speed in RISC OS in order to access UART? Sorry, I just dont know here where to go next. |
Ben Avison (25) 445 posts |
I don’t have any pearls of wisdom about MIDI, sorry, but:
Hardware drivers with very tight interrupt latency requirements are what FIQs were invented for… |
Stephen Unwin (1516) 154 posts |
YES! Finally some success! Using the official release, a minor addition to CONFIG/TXT, two resistors and a transistor and little BASIC I’ve got a simple rythm running. In CONFIG/TXT I have the line: init_uart_clock=813802 Derived from 3000000*31250/115200 Then a bit of BASIC using the initial post from this thread to get me started, then some numbers from something I started years ago for a portable drum machine using a DB50XG MIDI card. HAL_UARTTransmitByte=70 Circuit I used:- Hardware is 256Mb RPi, dodgy circuit into DB50XG card fitted to PowerWAVE Podule on RISCPC. EDIT. |