Using Yoshimi Software Synthesizer on the Raspberry Pi 3B

The RaspberryPi 3B is an amazingly powerful computer for the price. It provides quad-core computing power for just $35. This makes it more than capable for music experimentation and learning, and experimenting with Software Synthesizers is a fun way to learn about sound.
 

Yoshimi Software Synthesizer running on the Raspberry Pi 3B


This article gives some hints for setting up a Software Synthesizer on your Raspberry Pi. We’ll talk about installing and configuring Yoshimi. Of course, this “software synth” works great with McLaren Labrtpmidi, so you can experiment with a network of Raspberry Pi synthesizers too.

Install Yoshimi

Installing Yoshimi is simple. If you are running Debian Stretch for Raspberry Pi, use the apt-get command.

$ sudo apt-get install yoshimi

About Software Synthesizers

The output of a software synthesizer is sound waveforms that play through a sound device on your Raspberry Pi. The Raspberry Pi has a built-in sound card whose quality is very average. A better option is to plug in an external USB-based sound device. The good news here is that the Raspberry Pi operating system is capable of managing multiple sound cards, but you need to know how to find them. We’ll show you that here.
The input of software synthesizer is MIDI note information that can either come from an externally connected keyboard, or another software program that generates the notes of a song. The MIDI implementation on the Raspberry Pi is sophisticated enough to route MIDI information from either kind of input device to the synthesizer But as with sound cards, you need to know how to find out what is connected to your system. We’ll show you here how to list the MIDI keyboards connected to your system and how to use them with Yoshimi.

Sound Cards

Computer sound cards need to be configured by an application before it uses one of them. There are a lot of parameters that control a sound card. Choosing parameters correctly is a balancing act between performance and latency.
For a sound card to produce sound, an application needs to deliver audio samples in “chunks”. The chunk size is related to how often the synthesizer can begin new notes. We want a note to sound as soon as we hit the key — which means we want a small chunk size. However, too small of a chunk size will not give enough time to the synthesizer before the sound card wants the next chunk.
In the Linux ALSA (Advanced Linux Sound Architecture) sound system, the chunk size is called the “period size” and is related to the buffer size allocated by the audio application.
With experimentation, we have found that a buffer size of 1024 gives a pretty good tradeoff between performance and latency on the Raspberry Pi 3B.
Yoshimi can be started with a preselected buffer size using the “-b” option.

$ yoshimi -b 1024

If you just installed Yoshimi and you start it without this parameter, you’ll notice that the instrument sounds are garbled and sound “buzzy.” This is because the default buffer size is not tuned to the capability of the Raspberry Pi.

Listing your Sound Cards

Use the aplay command (audio play) command to list the audio devices on your system. The aplay command is used for playing audio files, but it also lists available audio devices.

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 1: MGXU [MG-XU], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 2: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

On our Raspberry Pi at McLaren Labs, we have one external USB audio card connected to the system. This appears as “Card 1” in the list above and is described as “USB Audio” device, which is a Yamaha MG-XU mixer.  The default built-in audio device is called “bcm2835 ALSA”.
To select that audio device used by Yoshimi use the “–alsa-audio” flag. The following command would start Yoshimi on our external USB audio device. Notice how the audio card selected is done using the number shown in the list above.

$ yoshimi -b 1024 --alsa-audio=hw:1,0

Starting Yoshimi on the built-in Raspberry Pi audio device would be done this way.

$ yoshimi -b 1024 --alsa-audio=hw:2,0

Listing the MIDI Keyboards attached to your System

Use the aconnect command to manage the MIDI connections on your system. aconnect can create MIDI connections from keyboards to synthesizers, and between applications. But it can also be used to list information about the MIDI devices on your system.

$ aconnect -i -o -l
client 0: 'System' [type=kernel]
    0 'Timer '
    1 'Announce '
client 14: 'Midi Through' [type=kernel]
    0 'Midi Through Port-0'
client 16: 'Launchkey 25' [type=kernel,card=0]
    0 'Launchkey 25 MIDI 1'
    1 'Launchkey 25 MIDI 2'

Here at McLaren Labs, we have a Novation Launchkey hooked up to our Raspberry Pi. We can see that the client number of that device is 16. (This keyboard also has two ports — 0 and 1 — we will only use port 0).
To start Yoshimi accepting keyboard input from an external MIDI device use the “–alsa-midi” option. To select our Novation Launch key, we would add this argument to Yoshimi.

$ yoshimi --alsa-midi=16:0

Putting it All Together

Now we’re ready to play Yoshimi.

$ yoshimi --alsa-midi=16:0 -b 1024 --alsa-audio=hw:2,0

This will start the synthesizer listening for not information from our keyboard, and rendering output waveforms at a rate appropriate for the built-in audio card of the Raspberry Pi!  I think you will be amazed too at the musical capabilities of this little $35 computer.

See Also

The Yoshimi Sourceforge page: http://yoshimi.sourceforge.net/

3 thoughts on “Using Yoshimi Software Synthesizer on the Raspberry Pi 3B”

  1. As a matter of interest, current versions of Yoshimi can auto-detect MIDI sources. Also on the Pi4 I run it with a 128 frames buffer size.
    Although the command line options are useful for a first time start, Yoshimi will save these settings and will restore them just starting with $ yoshimi

    Current versions also come with a built-in HTML user guide.

Leave a Reply to Chrissy Swain Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.