Subject: MIDI
To: None <tech-kern@netbsd.org>
From: Lennart Augustsson <augustss@cs.chalmers.se>
List: tech-kern
Date: 08/06/1998 09:47:44
Hi!
I've had a MIDI driver for over a year now, and I've finally gotten
around to making the last few changes I wanted to make. Here's a quick
description of it.
The midi driver attaches to the sound card driver, just as the audio
driver attaches today.
The code for the device to support midi driver attachment might range
from very simple to very complex. If the hardware is just a MIDI port
it simply passes the bytes it recieve on to the serial line (simple).
If the card is a syntheziser it will need to decode the MIDI data and
play it (complex). You can see what the midi attach routines are
already today in /src/sys/dev/audio_if.h.
So we might have (most of these are dreams :-):
sb0 at isa0 # SB with MIDI port
audio0 at sb0
midi0 at sb0
awe0 at sb0 # Wavetable synth
midi1 at awe0
opl0 at isa0 # OPL3 FM synth
midi2 at opl0
com0 at isa0 # COM port
midi3 at com0
The midi driver can be accessed through /dev/rmidiN (N corresponds to
the attachment number). The access is completely raw; you can read
and write MIDI commands to/from the device. If your MIDI device is
just a port whatever is written to /dev/rmidiN will be passed verbatim
to the port. The midi driver is very simple, it just provides some
moderate amount of buffering and the code to allow read, write, poll,
ioctl, etc.
To make it easier to play music there is also a pseudo device,
/dev/music. This is a OSS (Linux) compatible device that allows
access to all the MIDI devices in a system. It also provides accurate
timing for playing. The latter that is hard to accomplish by writing
to the raw device. This pseudu device (which you can choose to have
or not have) is fairly complicated as it has to decode the commands
and take appropriate action (basically, pass on the data to the MIDI
driver or sleep). The API for /dev/music is taken straight from OSS
(Linux). It is not too bad, and seems to be used by many programs.
I've also considered having /dev/midiN ports that are not raw. The
idea is that you should be able to cat a .mid file directly to a
/dev/midiN device. I've not looked at how much code this might
involve, so I'm not sure if this is feasible to put in the kernel.
What exists today?
* midi attachment for SB (should be trivially adaptable to
other sound card that have an MPU401 port).
* midi driver
* /dev/music driver
* almost complete OSS MIDI emulation. The Linux Jazz MIDI sequencer
(http://www.jazzware.com/) works nicely.
I've also started of a driver for the OPL3 FM synth. It's a really
bad synth, but it's so common that we should have a driver for it.
If there are no objections I plan to commit this in the near future.
-- Lennart