Linux Audio Recording

Update: This page will now focus on audio recording. Check out our video recording page.

Licensing: For ones own personal use, licensing may not seem very important, but it becomes an issue to consider when planning commercial applications. We use unrestricted, unencumbered, free file formats and software for development work, avoiding the usual license and patent restrictions that stifle development and threaten to bring down civilization as we know it.

Our development platform is the free Fedora operating system, but most of these free programs are also available for Windows. The setup we tested is specially-designed for low-latency multimedia creation. It is available here: spins.fedoraproject.org/jam-kde/

Audio recording

If money is no object professional recording equipment is the way to go, but home PCs are capable of high-quality audio recordings with the right hardware and software. Built-in sound cards often suffer from noise and nonlinear A/D conversion, but quality audio recording devices may be added on for a reasonable price. An expensive audio card may not be necessary, depending on your taste. An old laptop, Arduino, or Raspberry Pi may have all the processing power we need.

Audacity, the free and open source multi-track recording software, is recommended. It has good online help.

We may also make a quick recording with sox

rec out.wav

or we can save hard drive space with compressed ogg audio format and .

gst-launch -e autoaudiosrc ! audioconvert ! vorbisenc ! oggmux ! filesink location=out.ogg

We would like to introduce our own software, master%20control as an easy way to edit, save, and share GStreamer pipelines. Master Control is a graphical user interface for gst-launch where GStreamer plugins like the level meter, spectrum analyzer, noise reduction, voice change effects, and filters can be tweaked in real-time.

A codec pack may be necessary to play the resultant audio track on Windows Media Player, but we can play it back with gst-launch, or master%20control by reversing the pipeline, like so:

filesrc location=out.ogg
 ! oggdemux ! vorbisdec ! audioconvert ! autoaudiosink

Any number of players like ffplay, mplayer, or totem can also do the job. We now have mastered a compressed audio track that we can later edit and convert to whatever other formats we need.

Removing noise

Pulseaudio is capable of noise reduction through webrtc echo cancellation. In Fedora, this is available in the webrtc-audio-processing package, installed through the system's package manager, Apper or yum. The echo cancellation module must be loaded in order to use it. Add the following to /etc/pulse/default.pa or create one for each audio user with mkdir -p ~/.pulse && cp -n /etc/pulse/default.pa ~/.pulse/

Append this to the end of the file, and then restart Pulseaudio with pulseaudio -k.

### Load echo cancellation module
load-module module-echo-cancel source_name=echosource aec_method=webrtc
set-default-source echosource

Noise Gate

We can use ladspa effects plugins with to add a noise gate to our microphone. The ladspa-gate is a mono effect, so we can not use it with stereo streams. (Gstreamer is capable of splitting the stereo streams into dual mono with deinterleave and later recombining them with interleave, but we do not want to get into that mess here.) We may query about other ladspa plugins on the system. Some of them support stereo. In master%20control, go to Help --> Plugins (Ctrl+Shift+P) and search for ladspa, or use gst-inspect from the command line.

gst-inspect |grep ladspa

Test the noise gate threshold first to see how it sounds. We may have to adjust it up or down, depending on the background noise level. Try Threshold=-32.0 or Threshold=-28.0. Choose Audio recorder, noise gate from the master%20control drop-down menu, or to preview without recording, paste the following into the editor and press F5.

autoaudiosrc ! audio/x-raw-float ! ladspa-gate Threshold=-30.0 \
Decay=2.0 Hold=2.0 Attack=0.1 ! queue ! audioconvert ! autoaudiosink

We can play with other ladspa live effects plugins just for fun. Here's a pitch shifter.

autoaudiosrc ! audio/x-raw-float ! ladspa-tap-pitch \
Rate-Shift----=-20 Wet-Level--dB-=20 ! queue ! audioconvert ! autoaudiosink

Now we are ready to master "lossy" compressed audio with the noise gate applied.

autoaudiosrc ! audioconvert ! ladspa-gate Threshold=-30.0 \
Decay=2.0 Hold=2.0 Attack=0.1 ! vorbisenc ! oggmux ! filesink \
location=out.ogg

Or, if we have lots of hard drive space, we can master to flac, a lossless compressed format, for the best quality professionals prefer.

autoaudiosrc ! ladspa-gate Threshold=-30.0 Decay=2.0 \
Hold=2.0 Attack=0.1 ! audioconvert ! \
audio/x-raw-int,rate=44100,channels=1 ! flacenc ! filesink \
location=out.flac

Audacity

We can use Audacity to edit and filter each audio track to remove noise. These steps may be automated somewhat.

Record or select some silence and get a noise profile as a first step. That way we can reuse the same noise profile for subsequent tracks. Select a quiet portion of audio. Navigate to Effects->Noise Removal and Get Noise Profile.

The default noise removal settings are rarely satisfactory. For best results, adjust the sliders and test. We made a particularly noisy mic sound much better with settings like these.

audio/noise_removal.jpg

Sox

Sox is also capable of noise reduction.

sox out.wav -n trim 0 .9 noiseprof | play out.wav noisered - 0.2 

Sox's noise reduction is fast, but it produces artifacts and distortion. We may construct a noise gate instead, which some people prefer.

play out.wav compand .2,.2 -30.1,-inf,-30,-20 0 -90 .1

This would attenuate everything below -30db and compress everything else into a 0-20db range with an attack/decay of .2.

The noise gate can be further enhanced by filtering out more of the high and low frequencies and boosting the middle.

play out.wav mcompand ".01,.2 -50.1,-inf,-30.1,-50" 100 \
".01,.2 -50.1,-inf,-30.1,-50,-30,-20" 1000 \
".01,.1 -70.1,-inf,-50.1,-70" 3000 \
".01,.1 -70.1,-inf,-40.1,-70"

Refer to the sox docs for more informaition.

Normalize sound levels

Audio tracks that are too quiet or too loud may invite unwanted noise or distoriton. The audio production should be at or near the same sound level as what comes before and after. Most recording software allows normalization of audio tracks to bring the volume to an acceptable level.

Sox can normalize audio by adding the "norm" keyword to the command line. Transients may affect the results, however; we should probably do the final cut (or boost) by ear.

Recording multiple tracks

Do not fret if results are not immediately satisfactory. Multiple takes are often necessary to get the best quality recordings.

Overdubbing is a technique to "sing along with yourself," but it may also be used to set up a "cue track" for narration or to select the best portions of several tracks.

After going through the tutorial it may become clear that the overdubs are out of sync. Correct that by doing a latency test. We discovered a latency of 157ms on our system.

Once the recording sounds good, go ahead and do a "mixdown" and export to a "lossless" format, such as a .wav or .flac file.

Systemwide EQ

On Fedora, install the pulseaudio-equalizer package using yum or Apper, the system package manager. There is no icon. You'll have to create one, or run pulseaudio-equalizer-gtk from the run menu or terminal.

[Desktop Entry]
Comment=
Exec=/usr/bin/pulseaudio-equalizer-gtk
GenericName=Pulseaudio EQ
Icon=view-media-equalizer
Name=Pulseaudio EQ
NoDisplay=false
Path[$e]=
StartupNotify=true
Terminal=0
TerminalOptions=
Type=Application
X-KDE-SubstituteUID=false
X-KDE-Username=

Getting to know Jack

Anyone who knows Jack about audio probably doesn't need this review. The rest of us may use this guide to get everything working properly.

How to use an external MIDI keyboard plugged into the PC to play a software synth (using the PC to generate the sounds):

These notes should be brief enough to get you started right away. For comprehensive instructions, please visit docs.fedoraproject.org/en-US/Fedora/18/html/Musicians_Guide/

Audio links

Audacity manual

Fedora Musicians Guide

Jack manual

Swap left and right audio channels

Gstreamer Cheat Sheet

Comparison of container formats

Raspberry Pi

List of single-board computers


CCBY Copyright © 2024 Henry Kroll III, thenerdshow.com This web page is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.