One thing I enjoy is not having a laptop open as I play (I spend my working life staring at a screen). But I still want to be able to record audio as I experiment on the Digitakt and Digitone so I don’t lose cool music along the way. I came up with a neat way to use a Raspberry Pi3 as a background session recorder to capture 4 channels of audio from my mixer which is saved on the Pi’s memory card as mp3 files. Now when I’m experimenting in my home studio I’m constantly recording what I come up with so later on I can go back if I stumbled upon something really cool, and no laptop needed!
My goals for this little project:
- No laptop!
- Have it run automatically in the background as soon as I turn on my RaspPi
- Capture 4 channels of audio
- Create an MP3 file for each hour of studio session time.
Tutorial Video
Step-by-Step Guide
- Get a RaspPi and install Raspbian on it. I’ve tested this on a RPi3, but a Pi2 would work. My Pi3 has 4 USB ports on it; for the Digitone, Digitakt, Arturia MiniLab2 MIDI controller and USB audio output from my Behringer 404HD.
- Log into your RaspPi and open a command terminal.
- Install the ffmpeg package:
sudo apt-get install ffmpeg
I’m using the ffmpeg package to capture four channels of audio over USB from the mixer. - Install the lame package to process MP3 files:
sudo apt-get install lame
Lame is a Linux package that converts file formats to MP3, as to store 1 hour of 4 channel audio as a wav file takes a lot of disk space! The 4 channels of audio will be mixed down to a 2 channel stereo MP3 file. - Determine the USB device name of your mixer; run aplay -l and look for the audio mixer entry. For example, here’s what my output looks like:
pi@raspberrypi:~ $ aplay -l
**** List of PLAYBACK Hardware Devices **** card 1: U192k [UMC404HD 192k], device 0: USB Audio [USB Audio] Subdevices: 1/1 Subdevice #0: subdevice #0
In this case the name of my U404 appears as U192k - remember this for the next step! - Capture the audio channels and start recording manually:
ffmpeg -y -nostats -nostdin -f alsa -ac 4 -i plughw:CARD=U192k -t 3599 -acodec libmp3lame /home/pi/session_$(date +\%Y_\%m_\%d_\%H_\%M_\%S).mp3
This command looks complicated but it breaks down very simply; tell ffmpeg to use the ALSA sound input, with 4 channels, from the U192k (the Behringer), for 3599 seconds, and encode using the Lame codec (for MP3s) and save it to a file named after the current date and time. - Play music! The MP3 file will grow in size as you record. In my experiments an hour of recording gives a 57MB file.
- Make all of this happen automatically. For this you’ll edit a special file on the Pi called crontab which runs commands periodically. Run crontab -e and in the editor enter this line at the bottom of the file:
* */1 * * * ffmpeg -y -nostats -nostdin -f alsa -ac 4 -i plughw:CARD=U192k -t 3599 -acodec libmp3lame /home/pi/session_$(date +\%Y_\%m_\%d_\%H_\%M_\%S).mp3
Remember: keep this all on one line. - Now you can log out of the Pi and every hour a new session recording file will be created and stored on the Pi’s memory card as you play!
Hope this is useful to someone - the Raspberry Pi is a very versatile MIDI tool in the studio!
Jeremy
Aug 23, 2018 @ 01:05:10
hey mate, this was awesome and really helped me out. The question that i ahve for you this is really on 2 channels correct? I am trying to get 4 channels. I have 4 mics and want each of them to be a separate mp3 you seen anything like this??
Aug 24, 2018 @ 07:56:33
Thanks - glad to hear it was useful to you!
As I recall there was a limitation in the ability of the software to generate 4 channel audio files. I tried many times to get it to work, but it seemed that the code was fixed to two-channel stereo.