Subject: [linux-audio-dev] Linux laptop MIDI attempt #1
From: David Topper (topper_AT_virginia.edu)
Date: ti marras 16 1999 - 21:02:56 EST
Hi folks,
I'm stabbing a bit in the dark here because I'm not all that savvy with
serial port issues. But I am happy to report *something* which is more
than I could previously.
Bascially, I have one of those SGI "Unwinder" serial MIDI (model UW-3)
adapters. My hunch is that they do precisely what Perry was suggesting
vis-a-vis baud rate (serial_port = 38400, MIDI = 31.250) conversion. So
I've got it plugged into my laptop and am trying to read byte triplets.
I do get data, but it seems heavily buffered. I tried using setserial
to change the baud rate of my serial port to various settings, but
anything below 38400 does not seem to work.
So I hit keys on my keyboard, then data scrolls by every couple of
seconds. When I try to hit only 1 key (eg., middle C) I don't get
anything at all. But if I do start to hit "random" keys or do an
arpeggio (eg., middle C, E, G, C) then I do get data. Here's a sample,
using the arpeggio.
count: 0
[0]:ff
[1]:ff
[2]:ff
count: 1
[0]:ff
[1]:ff
[2]:ff
count: 2
[0]:ff
[1]:ff
[2]:ff
count: 3
[0]:ff
[1]:ff
[2]:ff
count: 4
[0]:ff
[1]:e2
[2]:22
count: 5
[0]:ff
[1]:82
[2]:2
count: 6
[0]:ff
[1]:c4
[2]:ff
count: 7
[0]:c8
[1]:48
[2]:ff
count: 8
[0]:c4
[1]:44
[2]:ff
count: 9
[0]:c0
[1]:0
[2]:ff
count: 10
[0]:42
[1]:0
[2]:ff
count: 11
[0]:e2
[1]:0
[2]:ff
It spurts out bytes in somewhat random fashion. I would have been
happier if it somehow spit stuff out every 64 bytes or whatnot.
If anyone has ideas/comments/ANYTHING I'd love to hear them.
---- here's the code I'm using to generate the above output ----
#include <stdio.h>
#include <linux/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/soundcard.h>
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
main(int argc, char* argv[])
{
/* Misc stuff */
float start;
int count;
int debug;
char *cp;
/* MIDI stuff */
int i,midi_fd,len,midiChan,oct,pitch;
unsigned char datum[3];
unsigned char note_val;
unsigned char note_vel;
unsigned char note_on;
unsigned char note_off;
float opc;
/* Open the MIDI port */
if ((midi_fd = open("/dev/cua0", O_RDONLY, 0)) == -1) {
perror("/dev/cua0");
exit(1);
}
count = 0;
debug = 0;
while(1) {
printf("count: %d\n",count);
for(i=0;i<3;i++) {
datum[i] = 0;
}
if ((len = read(midi_fd, &datum[0], 1)) == -1) {
perror("MIDI read");
exit(1);
}
if ((len = read(midi_fd, &datum[1], 1)) == -1) {
perror("MIDI read");
exit(1);
}
if ((len = read(midi_fd, &datum[2], 1)) == -1) {
perror("MIDI read");
exit(1);
}
for(i=0;i<3;i++) {
printf("[%d]:%x\n",i,datum[i]);
}
if (datum[0] == 0x90) {
note_val = datum[1];
note_vel = datum[2];
printf("note_on: %d - %d\n",note_val,note_vel);
}
else if (datum[0] == 0x80) {
note_val = datum[1];
note_vel = datum[2];
printf("note_off: %d - %d\n",note_val,note_vel);
}
fflush(stdout);
count++;
}
close(midi_fd);
}
DT
-- Technical Director - Virginia Center for Computer Music http://www.people.virginia.edu/~djt7p
This archive was generated by hypermail 2b28 : pe maalis 10 2000 - 07:23:25 EST