Record audio with the button

Hi, reviving an old idea here, though reading through the forum I couldn’t find a solution.

I’m looking to use my rpi headless and trigger recording from the the audio input to a file on a sd card using a button script?

Looks like using jack_capture is the way to go and I’ve got this working from the command line but would like to trigger recording using the button.

Reading around, sounded like starting jack_capture from the button might not be straightforward, for example :

Wondered if anyone has developed a successful approach to recording in this way?



1 Like

Hey, your script could just terminate the old recording process and start a new one, to the new file. That can be done by either keeping the PID of the recording process in a temporary file in /tmp, or simply doing killall jack_capture, but it could interfere if you’re or something is running jack_capture manually while the button is being triggered.

Feel free to show what you have so far in your script, so we can provide accurate suggestions. :slight_smile:

Thanks @Giedrius, will look at that.

I’m a way off writing a script, just trying to figure it what it needs to do. For example, a few things I want to do that may live outside the script:

  • mount a USB thumbdrive at boot (bu+y editing fstab)
  • start the jack daemon (as a cron job?)
  • start /stop jack_capture (button script)

I came across this little project which looks pretty neat :

Basically does what I want, but wonder if its as easy to specify the pisound button config in the py script above, or will this likely conflict with the pisound button functionality built into patchbox os?

This one’s easy - Patchbox OS has it started by default :slight_smile:

The linked project could be helpful, the most important parts of it is starting jack_capture:

/usr/local/bin/jack_capture -O 7777 --format mp3 --mp3 --filename-prefix /home/pi/recordings/ --port system:capture_1 --port system:capture_2 --timemachine --timemachine-prebuffer 300

(looks like I had to build it from source myself, I used some time ago)

As I’ve built without mp3 support I had to start it like this:

mkdir ~/recordings
/usr/local/bin/jack_capture -O 7777 --filename-prefix /home/patch/recordings/ --port system:capture_1 --port system:capture_2 --timemachine --timemachine-prebuffer 300

Then the other important thing in the linked project are the ‘start’ and ‘stop’ messages. It’s possible to send them using a shell command too:

sudo apt install liblo-tools # First get the 'oscsend' utility installed

oscsend localhost 7777 /jack_capture/tm/start
oscsend localhost 7777 /jack_capture/tm/stop

So having these pieces, what’s remaining is to get jack_capture started in the background, possibly, and then writing 2 simple scripts to start and stop recording using oscsend and map the scripts to Pisound’s button.

Thanks @Giedrius will give that all a try, was having permissions issues when starting jack _capture with anything other than root before but will try the above. Assume 7777 after Jack _capture will resolve this though…

1 Like

I’m really interested to see what can be done with this.
I’m currently planning out a tiny pedalboard with a Pi4 equipped with a Pisound and a second Pi with 7" touchscreen to run Reaper or another DAW to give me a portable recording platform with effects.
It’ll be awesome if I can also capture audio reliably on the Pisound, then I can perhaps adjust the setup to allow transferring those sound files to DAW.
I could also perhaps change my audio signal chain too.

1 Like

@Giedrius can’t find liblo-utils is the repository? Is it in some other repo? Or do I need to build from source?

Oops, the package name is actually liblo-tools. :slight_smile: I’ll edit my previous post too.

1 Like

@Giedrius, thanks!

OK so that all works, broadly speaking. I’ve tested from the the command line
jack_capture works using the command about and it was easy to get the button working to start/stop recording.

However, for some reason jack is starting on boot, so had to manually start from the command line would you suggest?

1 Like

Hi again @Giedrius so I managed to get jackd starting at boot by adding jackd as a service to systemd. Now starts on boot fine.

Next I added a button script to launch jack_capture as per your original code above as follows:

#! /bin/bash
. /usr/local/pisound/scripts/common/
/usr/local/bin/jack_capture -O 7777 --filename-prefix /home/patch/recordings/ --port system:capture_1 --port system:capture_2 --timemachine --timemachine-prebuffer 300

This seems to start jack_capture but just fills my recordings folders with hundreds of tiny. Wav files until I kill the jack_capture process. Jack_capture (the process) is owned by root though. When I launch from the CLI it is owned as user: patch. Not quite sure, what I’m doing wrong here. Can I launch my script as patch from the button or will it alwways launch as root?

Actually you should have the jack_capture with the -O 7777 and --timemachine --timemachine-prebuffer 300 flags running in the background.

The button should toggle sending start recording / stop recording OSC messages to the background jack_capture process.

Did you have to run sudo systemctl enable jack or something more elaborate? Was this after installing blokas-jack package?

Hi Giedrius,

Yep, I ran sudo systemctl enable jack

which got jack starting at boot.

The button mappings to start/ stop recording so work already, if I launch jack _capture manually from the command line. It runs in the terminal, starting with time_machine and waiting until I got the button to start recording.

I’m not really sure how to start jack_capture in the background, run from a script at startup?

Thanks again

A systemd .service file can be created to get jack_capture running automatically, loosely basing it on modep-mod-host.service as an example:

Description=osc controlled jack_capture

ExecStart=/usr/bin/env sh -c "/usr/bin/mkdir -p /home/patch/recordings && exec /usr/local/bin/jack_capture -c 2 --daemon -O 7777 --filename-prefix /home/patch/recordings/ --port system:capture_1 --port system:capture_2 --timemachine --timemachine-prebuffer 300"


Put it in /etc/systemd/system/jack_capture.service

Then run:

sudo systemctl enable jack_capture
sudo systemctl start jack_capture

Then recording can be started & stopped using the OSC messages.

Btw, looks like jack_capture creates a place holder .wav file for the next recording session, I was a little
surprised to see 01.wav there as soon as it’s started, but it gets data inserted only during recording. :slight_smile:

1 Like

@Giedrius as ever thanks, nearly there I think! jack_capture now starts automatically via systemd. I can see jack _capture process is running but for some reason the OSC commands don’t start the recorder now - not using the button script not from the command line.

No. Wav file being created in my recordings directory either. Weird as I followed instructions exactly as above. Any thoughts?

What is the output of:

sudo systemctl status jack_capture

Are you just running oscsend localhost 7777 /jack_capture/tm/start ?

Hi @Giedrius - ah so I’m getting:

jack_capture.service: Main process exited, code=exited, status=255/EXCEPTION
jack_capture.service: Failed with result ‘exit-code’

So it seems to start and then fail, and try and restart again.

I’ve checked the .service field and its s=exactly the same as yours below, any ideas what might be going wrong here, or are there any logs to see in more detail whats happening? I’ve looked at journal systemctl jack_captutre.service but tells me nothing more than the exit code message above…


Are you running this on Patchbox OS or the Raspberry Pi OS? If the latter, you’d have to change ‘User=patch’ to ‘User=pi’ and same for Group

I’m using Patchbox os :grin:

Does it work if you start the jack_capture from a terminal like this:

/usr/bin/env sh -c "/usr/bin/mkdir -p /home/patch/recordings && exec /usr/local/bin/jack_capture -c 2 --daemon -O 7777 --filename-prefix /home/patch/recordings/ --port system:capture_1 --port system:capture_2 --timemachine --timemachine-prebuffer 300"

hi @Giedrius , ok so it does work from the terminal. Just looking again at the jack_capture.service file, After/BindsTo= jack.service - I don’t have jack.service. I have a jackd.service (which I created). Is this an issue?