Raspberry Pi Audacity



In the first few articles of this series:

Get started with Raspbian Jessie and RPi2
Get started: Linux ALSA and JACK
Raspberry Pi soft synthesizer: Get started

Audacity A free multi-track audio editor and recorder Brought to you by: jamescrook, martynshaw, vjohnson. ReSpeaker 4-Mic Array for Raspberry Pi. ReSpeaker 4-Mic Array for Raspberry Pi is a quad-microphone expansion board for Raspberry Pi designed for AI and voice applications. This means that we can build a more powerful and flexible voice product that integrates Amazon Alexa Voice Service, Google Assistant, and so on.

we used the built-in, 3.5mm audio output from the Raspberry Pi 2 (RPi2) to produce sound through powered monitors. If you tried this with your own RPi2, you realize that the sound quality is good enough for initial experiments, but not good enough for production — unless you’re into lo-fi.

This article starts with background information about the built-in audio circuit and why it is lo-fi. Then, I briefly mention a few alternative approaches for high quality audio output and audio input. Finally, I describe my experience bringing up the Behringer UCA-202 USB audio interface on RPi2 and Raspbian JESSIE.

Built-in audio

The Raspberry Pi Foundation has not yet published a schematic for the Raspberry Pi 2. However, Adafruit (and others) claim that the audio circuit is the same as the earlier, first generation Raspberry Pi. Let’s take a look at that.

The Raspberry Pi drives a pulse width modulated (PWM) signal into a passive low pass audio filter. (See the schematic below. Click on images to enlarge and get full resolution.)

The PWM technique produces OK audio, but not good, clean audio. The software performs RPDF dithering and noise shaping to improve quality. Later RPi models (like the B+ and generation 2) have better power regulation and produce less digital noise at the audio output. There is much on-line debate about further improvements, but the PWM technique seems is limited by the 11-bit quantization. (This latter point alone is subject to debate!)

JACK seems to modify the audio sample stream as well. I can hear a loud hiss from my speakers when JACK is running and sending audio through the built-in DAC circuit. Ideally, the speaker should be completely silent.

Raspberry Pi 2 does not have an audio input. Thud!

Alternatives to built-in audio

If you want better audio quality or need to record an external audio signal, there are two approaches:

  1. Buy and install an audio board.
  2. Buy and install a USB audio interface.

With respect to the first approach, I briefly explored two of the available Raspberry Pi add-on audio boards:

  1. Cirrus Logic Audio Card
  2. HiFiBerry DAC Pro+

The Cirrus Logic board is well-specified with a WM5102 audio hub, WM8804 S/PDIF transceiver, and two WM7220 digital microphone integrated circuits. Those in the know will recognize these parts as Wolfson designs. The HiFiBerry DAC+ Pro is output only and uses an equally well-respected Burr Brown digital-to-audio converter (DAC).

Potential users are advised to be careful and to check compatibility with their particular model of Raspberry Pi. Adafruit cautions that the Cirrus Logic board may not be compatible with Raspberry Pi 2.

Both boards have drivers. However, both vendors eshew device configuration and prefer to distribute full OS images that include the requisite drivers. This approach puts existing users at a disadvantage. Now that I have Raspbian JESSIE installed and running, I would like to build and install the driver by itself, not write another micro SD card and go through the bring up process again.

Raspberry Pi Audacity

With these issues in mind, I decided to go the USB audio interface route. It’s also the lowest cost option for me because I already have a Behringer USB audio interface in hand.

Behringer UCA-202 audio interface

Audacity

The Behringer UCA-202 is an inexpensive ($30 USD) USB audio input/output interface. Analog signals are transfered on RCA connectors (left/right IN and left/right OUT). The UCA-202 also has a headphone output and an S/PDIF optical output. The UCA-202 is bus-powered and class-compliant. Conversion is 16-bit at 32kHz, 44.1kHz or 48kHz. The UCA-202 has a sister, the UCA-222, with the same spec.

I have used the UCA-202 as a plug-and-play audio interface with both Windows and Mac OS X. Now, I can claim success with Raspbian JESSIE Linux, too. This thing is the “pocket knife” of low-cost USB audio interfaces.

Even though I’m using a Behringer UCA-202, the directions below should also apply to other class-compliant USB audio interfaces. It never hurts to search the Web for directions, problems and tips for your particular audio interface. Just sayin’.

Raspberry Pi Audacity

Before plugging in the UCA-202, run aplay -l and aplay -L to see a list of the sound cards (-l) and PCMs (-L) that are installed on your machine.

Raspberry Pi Audacity

Next, plug the UCA-202 into one of the USB ports. Run the aplay commands, again, and look for a new audio device. On my machine, a new sound card appears in the aplay -l output:

The new sound card is named “CODEC”, it is ALSA card number 1, and it has one subdevice (number 0). The aplay -L output lists a whole slew of new PCMs:

Not all of these PCMs are defined and configured by the way. Take note of the PCM named “hw:CARD=CODEC,DEV=0”. This is essentially the raw interface to the UCA-202. This PCM, at the very least, is defined.

Connect the audio outputs of the UCA-202 to powered monitors. Test the audio output interface by playing an audio (WAV) file:

or:

Please note that you need to pass in the entire PCM name “hw:CARD=CODEC,DEV=0“.

Connect an audio source to the inputs of the UCA-202. Test the audio input interface by recording to an audio (WAV) file:

I had trouble with the duration (-d) option. YMMV. Type Control-C to stop recording. Then, play back the test audio file through the UCA-202.

That’s all there is to it! The UCA-202 is truly plug and play.

Configure JACK and other applications

Raspberry

You need to tell the JACK audio server to use the UCA-202 instead of the RPi’s built-in audio device. Run qjackctl and click the Settings button. Select “hw:CODEC” as the Input Device and Output Device. (See the image below.) Click OK to return to the main control panel and start the JACK server. The server routes digital audio to and from the UCA-202 and JACK clients. Launch amsynth and click its Audition button. You should hear sound from the powered monitors that are connected to the UCA-202.

ALSA’s aplay and arecord commands are OK for testing, but are clunky for practical use. Let’s install Audacity:

Audacity is the well-known cross-platform, open source, audio editing tool.

Edit Audacity’s preferences to set the audio interface. (See the following image.) If you want to use ALSA directly, set the interface Host to ALSA. Then set the Playback and Recording Devices to “USB Audio CODEC”. Audacity should now be able to play and record through the UCA-202.

If you prefer to use JACK instead, once again edit Audacity’s preferences. (See the following image.) Set the interface Host to “JACK Audio Connection Kit”. Set the Playback and Recording Device to “system”. Make sure the JACK audio server is running. You may need to restart Audacity at this point. Play back an audio file or try recording a new file. JACK should serve the UCA-202 audio to/from Audacity.

On this episode of This Week in Linux, the Raspberry Pi Foundation announces a new 8GB RAM version of the Raspberry Pi and there’s a new release of Kali Linux. We’ve also got some big updates for two audio editors in Ardour 6.0 and Audacity 2.4.1. We’ve got a new version of the Enlightenment window manager with 0.24 and a new tool for making Bootable USBs called Ventoy. We’ve got an update on the GNOME “Patent Troll” Case, it’s been resolved. EA is releasing Source Code for 2 Command & Conquer Games. Microsoft is back in the news with 2 new items this week . . . one shows they may be really changing announcing DirectX for Linux . . . yea not really, of course there is a catch, it’s Microsoft. Also Microsoft figured that pretending they are doing something good for Linux wasn’t enough so they created a name collision with the Maui Project. All that and much more on Your Weekly Source for Linux GNews!

Downloads & Media

Notice: there seems to be an issue with our MP3 downloads provider so if you are experiencing issues then please go over to YouTube or LBRY, alternatively you can wait for the MP3 service issue to be addressed. Unfortunately, we do not have an ETA for this to be resolved at the moment.

[tdpodcast mode=”subscribe” podcast=”thisweekinlinux”]

Segment Index

Raspberry Pi Audacity Command Line

  • 00:01:22 = New TuxDigital & TWinL Merch in the DLN Store · [link]
  • 00:02:48 = Raspberry Pi 4 Now With 8GB of RAM · [raspberrypi.org]
  • 00:07:28 = Ardour 6.0 Released · [Links: ardour.org, Unfa video]
  • 00:13:27 = Audacity 2.4.1 Released · [audacityteam.org]
  • 00:18:12 = Sponsored by Digital Ocean · [do.co/dln]
  • 00:19:56 = Enlightenment 0.24 Released · [enlightenment.org]
  • 00:23:26 = Kali Linux 2020.2 Released · [kali.org]
  • 00:26:44 = Ventoy 1.0.12 – Make Bootable USBs · [Links: ventoy.net, reddit.com, github.com]
  • 00:33:05 = Destination Linux · [Links: destinationlinux.org, DL173, DL174, DL175]
  • 00:34:11 = Become a Patron of TuxDigital & TWinL · [tuxdigital.com/contribute]
  • 00:35:46 = GNOME Patent Troll Case Resolved · [Links: gnome.org, zdnet.com]
  • 00:46:34 = EA Releasing Some Source Code · [ea.com]
  • 00:49:50 = Windows: DirectX & Linux Apps on WSL · [Links: microsoft.com, airlied.blogspot.com, zdnet.com, phoronix.com]
  • 00:57:57 = Microsoft’s Name Collision with MauiKit · [Links: nxos.org, medium.com, microsoft.com, github.com, reddit.com]
  • 01:05:08 = Outro