El procesador del Arduino se encarga simplemente de parsear los mensajes MIDI: Genera los tonos y los silencios ante las tramas NOTE ON y NOTE OFF que detecta por la entrada MIDI.
#define MIDI_NOTE_LOW 16
#define MIDI_NOTE_HIGH 107
// midi frequencies from C0 to B7
int freq[] = {
21, 22, 23, 24, 26, 28, 29, 31,
33, 35, 37, 39, 41, 44, 46, 48, 52, 55, 58, 62,
65, 69, 73, 78, 82, 87, 92, 98, 104, 110, 117, 123,
131, 139, 147, 156, 165, 175, 185, 196, 208, 220, 233, 247,
262, 277, 294, 311, 329, 349, 370, 392, 415, 440, 466, 494,
523, 554, 587, 622, 659, 698, 740, 784, 831, 880, 932, 988,
1047, 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1864, 1976,
2093, 2217, 2349, 2489, 2637, 2794, 2960, 3136, 3322, 3520, 3729, 3951
};
#define MIDI_STATUS_WAIT_STATUS 0
#define MIDI_STATUS_WAIT_NOTE 1
#define MIDI_STATUS_WAIT_VELOCITY 2
#define MIDI_STATUS_WAIT_NOTE_OR_STATUS 3
#define SPEAKER_PIN 13
int midiStatus = MIDI_STATUS_WAIT_STATUS;
int midiNote = 0;
int midiVelocity = 0;
void setup() {
Serial1.begin(31250);
}
void parseMidi(int b) {
if (midiStatus == MIDI_STATUS_WAIT_STATUS) {
if ((b & 0xF0) == 0x90)
midiStatus = MIDI_STATUS_WAIT_NOTE;
}
else if (midiStatus == MIDI_STATUS_WAIT_NOTE) {
midiNote = b;
midiStatus = MIDI_STATUS_WAIT_VELOCITY;
}
else if (midiStatus == MIDI_STATUS_WAIT_VELOCITY) {
midiVelocity = b;
midiStatus = MIDI_STATUS_WAIT_STATUS;
if (midiVelocity == 0)
noTone(SPEAKER_PIN);
else {
if ((midiNote >= MIDI_NOTE_LOW) && (midiNote <= MIDI_NOTE_HIGH))
tone(SPEAKER_PIN, freq[midiNote - MIDI_NOTE_LOW]);
}
midiStatus = MIDI_STATUS_WAIT_NOTE_OR_STATUS;
}
else if (midiStatus == MIDI_STATUS_WAIT_NOTE_OR_STATUS) {
if (b < 0x80) {
midiNote = b;
midiStatus = MIDI_STATUS_WAIT_VELOCITY;
}
else if ((b & 0xF0) == 0x90)
midiStatus = MIDI_STATUS_WAIT_NOTE;
else
midiStatus = MIDI_STATUS_WAIT_STATUS;
}
}
void loop() {
while (Serial1.available() > 0) {
int b = Serial1.read();
parseMidi(b);
}
}
Como se puede ver, el parseado de las tramas MIDI se realiza mediante un sencillo autómata finito (DFA) de 4 estados.
[ añadir comentario ] ( 1333 visualizaciones ) | [ 0 trackbacks ] | enlace permanente | ( 3 / 3490 )
La web de la edición italiana de la revista Cosmopolitan ha usado un tema mío para un vídeo promocional. Al final del vídeo aparezco en los créditos.
http://www.cosmopolitan.it/moda/Shoppin ... e-a-Londra
[ 2 comentarios ] ( 1705 visualizaciones ) | [ 0 trackbacks ] | enlace permanente | ( 3 / 1710 )
La empresa de instrumentos electrónicos de medida PDI Meters (de EE.UU.) ha utilizado un tema mío como banda sonora en dos vídeos promocionales de uno de sus productos.
Estén atentos, que al final de los dos vídeos aparezco en los créditos PDI's torture testing of the DM-930 automotive meter
[ añadir comentario ] ( 1395 visualizaciones ) | [ 0 trackbacks ] | enlace permanente | ( 3 / 1823 )
Recién terminado y funcionando. Sólo falta meterlo en una caja :-)
[ 3 comentarios ] ( 10036 visualizaciones ) | [ 0 trackbacks ] | enlace permanente | ( 3 / 1981 )
He subido, tanto a la sección música como a mi cuenta de Soundcloud, un nuevo tema.
Espero que les guste :-)
avelino herrera - spring sun.mp3
http://soundcloud.com/avelinoherrera/spring-sun
[ añadir comentario ] ( 1141 visualizaciones ) | [ 0 trackbacks ] | enlace permanente | ( 3 / 1840 )