Escuchando música en youtube me topé con un video sobre como tocar el tema Techno Syndrome. Así que fuí a buscar el controlador MIDI que tengo juntando algo de polvo, un AKAI MPK mini MK3, y a probar de utilizarlo en FreeBSD.
Empezamos viendo el sistema para quien quiera probar la guía:
$ freebsd-version
14.3-RELEASE-p8
Se conecta el controlador y se verifica que sea reconocido por FreeBSD:
$ doas dmesg
...
ugen1.2: <vendor 0x8087 product 0x8001> at usbus1
uhub2 on uhub1
uhub2: <vendor 0x8087 product 0x8001, class 9/0, rev 2.00/0.03, addr 2> on usbus1
uhub2: 8 ports with 8 removable, self powered
Limiting closed port RST response from 208 to 192 packets/sec
ugen0.5: <AKAI MPK mini 3> at usbus0
uhid0 on uhub0
uhid0: <AKAI MPK mini 3, class 0/0, rev 2.00/2.00, addr 4> on usbus0
uaudio0 on uhub0
uaudio0: <AKAI MPK mini 3, class 0/0, rev 2.00/2.00, addr 4> on usbus0
uaudio0: No playback.
uaudio0: No recording.
uaudio0: MIDI sequencer.
uaudio0: No HID volume keys found.
El hardware es detectado por el sistema. Se verifica que el dispositivo correspondiente fue creado y sus permisos:
$ ls -l /dev/umidi*
crw-rw-rw- 1 root operator 0x1a3 Feb 20 17:15 /dev/umidi0.0
Probamos de leer eventos MIDI enviados por el controlador para lo cual utilizamos el programa mididump incluido en el sistema base:
$ mididump /dev/umidi0.0
Note on channel=4, note=53 (F3, 174.61Hz), velocity=8
Note off channel=4, note=53 (F3, 174.61Hz), velocity=0
Note on channel=4, note=54 (F#3/Gb3, 185.00Hz), velocity=23
Note off channel=4, note=54 (F#3/Gb3, 185.00Hz), velocity=0
Note on channel=10, note=54 (F#3/Gb3, 185.00Hz), velocity=64
Note off channel=10, note=54 (F#3/Gb3, 185.00Hz), velocity=0
Note on channel=10, note=42 (F#2/Gb2, 92.50Hz), velocity=34
Note off channel=10, note=42 (F#2/Gb2, 92.50Hz), velocity=0
Control/Mode change channel=4, control=70 (Sound Controller 1), value=1
Control/Mode change channel=4, control=70 (Sound Controller 1), value=2
Control/Mode change channel=4, control=70 (Sound Controller 1), value=3
Control/Mode change channel=4, control=70 (Sound Controller 1), value=4
Control/Mode change channel=4, control=70 (Sound Controller 1), value=5
Control/Mode change channel=4, control=1 (Modulation Wheel), value=2
Pitch bend channel=4, change=8329
Control/Mode change channel=4, control=1 (Modulation Wheel), value=19
Pitch bend channel=4, change=8684
Control/Mode change channel=4, control=1 (Modulation Wheel), value=37
Pitch bend channel=4, change=9483
Control/Mode change channel=4, control=1 (Modulation Wheel), value=48
Pitch bend channel=4, change=10352
Pitch bend channel=4, change=10722
Control/Mode change channel=4, control=1 (Modulation Wheel), value=74
Control/Mode change channel=4, control=1 (Modulation Wheel), value=79
Pitch bend channel=4, change=12300
Pitch bend channel=4, change=12697
Control/Mode change channel=4, control=1 (Modulation Wheel), value=110
Pitch bend channel=4, change=13476
Control/Mode change channel=4, control=1 (Modulation Wheel), value=126
Pitch bend channel=4, change=14365
Control/Mode change channel=4, control=1 (Modulation Wheel), value=127
Pitch bend channel=4, change=15689
Pitch bend channel=4, change=16060
Pitch bend channel=4, change=16383
Control/Mode change channel=4, control=1 (Modulation Wheel), value=126
Control/Mode change channel=4, control=1 (Modulation Wheel), value=109
Control/Mode change channel=4, control=1 (Modulation Wheel), value=86
Pitch bend channel=4, change=13073
Control/Mode change channel=4, control=1 (Modulation Wheel), value=20
Pitch bend channel=4, change=8192
Control/Mode change channel=4, control=1 (Modulation Wheel), value=9
Control/Mode change channel=4, control=1 (Modulation Wheel), value=0
Control/Mode change channel=4, control=1 (Modulation Wheel), value=0
Ya comprobamos que el sistema está recibiendo eventos MIDI.
Para poder escuchar sonidos debemos instalar un sintetizador de software el cual será el encargado de convertir los eventos MIDI en audio. Utilizaremos el programa fluidsynth para ello, el cual requiere también la instalación de soundfonts:
$ doas pkg install fluidsynth fluid-soundfont
Indagamos donde se encuentran los soundfonts:
$ pkg info -l fluid-soundfont
fluid-soundfont-3.1:
/usr/local/lib/timidity/fluidr3_gm.cfg
/usr/local/lib/timidity/fluidr3_gs.cfg
/usr/local/share/doc/fluid-soundfont/README
/usr/local/share/licenses/fluid-soundfont-3.1/LICENSE
/usr/local/share/licenses/fluid-soundfont-3.1/MIT
/usr/local/share/licenses/fluid-soundfont-3.1/catalog.mk
/usr/local/share/sounds/sf2/FluidR3_GM.sf2
/usr/local/share/sounds/sf2/FluidR3_GS.sf2
Invocamos fluidsynth para que genere sonido a partir de eventos MIDI
utilizando soundfonts:
$ fluidsynth -s -a oss -m oss -o midi.oss.device=/dev/umidi0.0 /usr/local/share/sounds/sf2/FluidR3_GM.sf2
FluidSynth runtime version 2.5.2
Copyright (C) 2000-2025 Peter Hanappe and others.
Distributed under the LGPL license.
SoundFont(R) is a registered trademark of Creative Technology Ltd.
fluidsynth: warning: Failed to set thread to high priority
Type 'help' for help topics.
fluidsynth: warning: Failed to set thread to high priority
>
Los parámetros del comando anterior se determinan del
manual de fluidsynth a excepción de la opción
-o midi.oss.device=/dev/umidi0.0.
Esta debe agregarse ya que por defecto fluidsynth utiliza como dispositivo
MIDI /dev/midi lo cual puede verse mediante el comando fluidsynth -o help
que muestra las opciones existentes y sus valores por default.
$ fluidsynth -o help | grep /dev/midi
midi.oss.device STR [def='/dev/midi']
Si no se incluye esta opción fluidsynth intenta acceder a un dispositivo
inexistente y falla con el siguiente mensaje:
$ fluidsynth -s -a oss -m oss /usr/local/share/sounds/sf2/FluidR3_GM.sf2
FluidSynth runtime version 2.5.2
Copyright (C) 2000-2025 Peter Hanappe and others.
Distributed under the LGPL license.
SoundFont(R) is a registered trademark of Creative Technology Ltd.
/dev/midi: No such file or directory
Failed to create the MIDI thread; no MIDI input
will be available. You can access the synthesizer
through the console.
Type 'help' for help topics.
fluidsynth: warning: Failed to set thread to high priority
>
Ahora ya se pueden presionar teclas del controlador y probar el sonido generado, el cual corresponde a un piano.
Los sonidos disponibles en un soundfont se pueden listar utilizando
> inst 1
000-000 Yamaha Grand Piano
000-001 Bright Yamaha Grand
000-002 Electric Piano
000-003 Honky Tonk
...
Veamos de cambiar el sonido desde el prompt de fluidsynth, más específicamente
que el canal 0 pase a utilizar el sonido 81 correspondiente a Saw Wave.
> prog 0 81
Si no se escucha un cambio en el sonido es posible que el canal que está
enviando el evento MIDI no se corresponde con el canal que cambiamos.
Lo más sencillo para ver el canal es utilizar mididump (saliendo temporalmente
de fluidsynth).
Veamos un ejemplo de este caso:
$ mididump /dev/umidi0.0
Note on channel=4, note=60 (C4, 261.63Hz), velocity=90
Note off channel=4, note=60 (C4, 261.63Hz), velocity=0
Aquí se está utilizando el canal 4, en lugar del 1 que es donde se cambió el
sonido (usando prog 0 81).
Se debe presionar en el teclado MIDI las teclas PROG SELECT+PAD 1 y
verificar que se estén enviando eventos correspondientes al canal 1:
Note on channel=1, note=60 (C4, 261.63Hz), velocity=80
Note off channel=1, note=60 (C4, 261.63Hz), velocity=0
Viendo lo sencillo de los pasos anteriores puedo concluir que fué un éxito configurar el controlador MIDI en FreeBSD.