My quick 'n' dirty Midi and softSynth doc

Post fully complete "how to" guides and tutorials here. This is a great place to get feedback on stuff you might put in the wiki.

Moderators: MattKingUSA, khz

Post Reply
User avatar
Linuxmusician01
Established Member
Posts: 1524
Joined: Mon Feb 23, 2015 2:38 pm
Location: Holland
Has thanked: 756 times
Been thanked: 137 times

My quick 'n' dirty Midi and softSynth doc

Post by Linuxmusician01 »

I recently acquired a midi keyboard and it took me quite a while to figure out how to get even one tone out of it. :wink: Even though there are a few good how-to's on the 'net. Personally on e of the biggest problems was to check if the Midi keyboard was even sending Midi information over the USB cable. This is my quick 'n' dirty text doc on how to make some sounds w/ a Midi keyboard and a softsynth.

[http://tedfelix.com/linux/linux-midi.html]
[https://wiki.archlinux.org/index.php/USB_MIDI_keyboards]


CONTENTS
A. Summary
B. Download and install
C. Check midi port numbers
D. Jack audio server
E. Fluidsynth
F. Connect physical and virtual Midi devices
G. Bristol
X. Troubleshooting


A. SUMMARY
Midi works with port numbers that you 'connect' to eachother. Alsa provides the driver for Midi (as well as for your sound card). Jack is a server on top of Alsa which must be used as if it was your sound card driver (for low latency). Fluidsynth behaves like a Midi synthesizer/device (a 'softsynth'). One connects an inputdevice (likea physical Midi keyboard) to an outputdevice (like the softsynth) w/ aconnect. Bristol is a standlone application that emulates various classic analogue synthesizers which you can play with your typing keyboard. But you can also use a Midi keyboard and assign buttons etc. from said Midi keyboard to Bristol's ones.


B. DOWNLOAD AND INSTALL
1. Download a midi file (ex.: song.mid).
2. Download a sound font (ex.: soundfont.sf2)
3. Download a wav file (ex.: test.wav). Or make one yourself with: sox -b 16 -n test.wav rate 44100 channels 2 synth 1 sine 440)
4. Disable pulseaudio:

Code: Select all

sudo mv ~/.pulse ~/.pulse-backup
sudo rm -rf ~/.pulse
Then edit the file '/etc/pulse/client.conf' and add:

Code: Select all

autospawn = no
daemon-binary =/bin/true
Restart PA with:

Code: Select all

pulseaudio --start
5. Install jack-tools
6. Install patchage
7. Install aconnectgui


C. Check midi port numbers
1. cat /proc/asound/cards
~~~~~~~~~~~~~~~~~~~~~~~~~

Code: Select all

0 [CMI8738        ]: CMI8738-MC6 - C-Media CMI8738
                        C-Media CMI8738 (model 55) at 0xd000, irq 20
   1 [PCH            ]: HDA-Intel - HDA Intel PCH
                        HDA Intel PCH at 0xf7c10000 irq 45
   2 [v2             ]: USB-Audio - USB Oxygen 8 v2
                        M-Audio USB Oxygen 8 v2 at usb-0000:00:1a.0-1.1, full speed
So card number hw:2 (or: hw:v2) is the Midi keyboard. Card hw:0 (or: hw:CMI8728) is the card that outputs the audio to the amplifier.
2. aplaymidi -l
~~~~~~~~~~~~~~~

Code: Select all

Port     Client name                      Port name
    14:0    Midi Through                     Midi Through Port-0
    16:0    C-Media CMI8738                  C-Media CMI8738 MIDI
    17:0    OPL3 FM synth                    OPL3 FM Port
    24:0    USB Oxygen 8 v2                  USB Oxygen 8 v2 MIDI 1
   128:0    FLUID Synth (3726)               Synth input port (3726:0)
So on midi port number 24 is the midi keyboard. Fluidsynth's daemon (see furtheron) is running on midi port 128.


D. Jack audio server
1. Start jack daemon
~~~~~~~~~~~~~~~~~~~~

Code: Select all

jackd -d alsa --device hw:0 --rate 44100 --period 128
Meaning: 44.1 kHz (needeed for Fluidsynth), period 128 frames (= latency of 3 ms). Or simply:

Code: Select all

jackd -d alsa --device hw:0
2. Test Jack
~~~~~~~~~~~~
Make sure the Jack daemon is running and:

Code: Select all

export JACK_PLAY_CONNECT_TO=system:playback_%d
Meaning: %d" is expanded to the channel number while connecting. So, with a stereo WAV file and the above value, jack.play will connect to system:playback_1 and system:playback_2.

Code: Select all

jack.play test.wav

E. Fluidsynth
1. Test

Code: Select all

fluidsynth --audio-driver=alsa -o audio.alsa.device=hw:0 soundfont.sf2 song.mid
2. Start as server using Alsa

Code: Select all

fluidsynth --server --audio-driver=alsa -o audio.alsa.device=hw:0 soundfont.sf2
3. Start as server using Jack

Code: Select all

fluidsynth --server --audio-driver=jack --connect-jack-outputs soundfont.sf2
4. Test Fluidsynth when used as Midi server
Determine fluidsynth's Midi port mumber with:

Code: Select all

aplaymidi -l
If Fluidsynth's midi port is 128 then play a wav file w/ (Jack and) Fluidsynth with:

Code: Select all

aplaymidi -p 128:0 song.mid



F. Connect physical and virtual Midi devices
1. Determine the Midi port number of your input device. Type in a terminal:

Code: Select all

aconnect -i
This returns:

Code: Select all

client 24: 'USB Oxygen 8 v2' [type=kernel]
   0 'USB Oxygen 8 v2 MIDI 1'

Which means that the Midi port number of the Oxgen keyboard is 24.
2. Determine output device Midi port

Code: Select all

aconnect -o

   client 128: 'FLUID Synth (11332)' [type=user]
   0 'Synth input port (11332:0)'
3. Connect input to output:

Code: Select all

aconnect 24 128
Or:

Code: Select all

aconnect 24:0 128:0
4. Now play Fluidsynth via the pysical Midi keyboard.


G. BRISTOL
1. Start Jack:

Code: Select all

jackd -d alsa --device hw:0
2. Start monobristol.
3. Configure > Easy mode > radio button 'Jack' > checkbox 'Jack auto connect'.
Click 'Apply'!
4. Use (your regular typing) keyboard for playing notes.
Midi:
5. Configure > Advanced mode > Midi driver: alsa
Click 'Apply'!
6. 'aconnect -o' will show that Bristol has Midi port number 128.
7. 'aconnect 24 128' (you can check w/: aconnectgui).
8. Assign buttons from your (hardware) Midi keyboard to Bristol's software ones by middle clicking on them in the GUI.
9. Bristol is (very) querky. If it don't work: restart monoBristol.


X. TROUBELSHOOTING
1. Watch midi keyboard output:

Code: Select all

aseqdump -p 24
If the port is 24. Determine port w/:

Code: Select all

aconnect -i
2. Use a powered USB port or plug your laptop in power socket because the the Midi keyboard might loose its connection, even though all lights are burning.
Post Reply