Main menu:

Sponsoring

Please consider a small donation:

 

 

Or you can donate bitcoin:

 

Thanks to TekLinks in Birmingham, AL, for providing colocation and bandwidth.

Page Rank

Fame

FOSS Force Best Blog--2013 Award

Recent posts

Recent comments

About this blog

I am Eric Hameleers, and this is where I think out loud.
More about me.

Search

My Favourites

Slackware

Calendar

October 2014
M T W T F S S
« Sep    
 12345
6789101112
13141516171819
20212223242526
2728293031  

RSS Alien's Slackware packages

RSS Alien's unofficial KDE Slackware packages

RSS Alien's multilib packages

Meta

Setting up Jack Audio in Slackware

If you are using your computer as a Digital Audio Workstation (DAW) then the ALSA sound subsystem is just not up for the task. Musicians and audio professionals prefer to use Jack Audio on Linux. Let me quote from the Jack Audio web site:

What is JACK?

Have you ever wanted to take the audio output of one piece of software and send it to another? How about taking the output of that same program and send it to two others, then record the result in the first program? Or maybe you’re a programmer who writes real-time audio and music applications and who is looking for a cross-platform API that enables not only device sharing but also inter-application audio routing, and is incredibly easy to learn and use? If so, JACK may be what you’ve been looking for.

JACK is system for handling real-time, low latency audio and MIDI.

We “ordinary” users of Slackware don’t usually have a need for Jack. It makes your computer’s sound subsystem more complex, meaning that more things can go wrong (where you end up with distorted or even no sound) and that fixing things requires more knowledge.

However there are cases even for non-musicians to want to install Jack Audio. I am one of them. As I explained in my previous post, I want to record videos of programs running on my desktop, along with the comments I may record through a microphone. When I selected SimpleScreenRecorder as my tool for doing this, I found out that it needs Jack in order to record the audio (but come to think of it… after reading bradpit’s comment in the previous post I realize that there may be a way around Jack – something I will check out soon and report if I find anything worth mentioning).

This article is meant to show you how to install and configure Jack Audio, and how to configure ALSA so that applications will still have sound even if they are unaware of Jack (Jack grabs the computer’s sound hardware and won’t allow ALSA applications to use it).

The article will center around you, being the one behind the physical computer. No system file needs to be changed, all configuration is done in your own home directory, for your use only. If someone else logs in, he or she will not be bothered by Jack and everything will work as before.

 

Installing Jack Audio

In order to install Jack Audio, you need the following packages: jack and qjackctl.

The qjackctl package contains the “de facto” configuration utility for Jack Audio, also called qjackctl. It is a Qt-based graphical program which allows you to configure “several JACK daemon parameters, which are properly saved between sessions, and a way control of the status of the audio server daemon” according to the program description. It also allows you to configure and autoload the patchbay and offers full connection control.

qjackctl_main

Configuring ALSA

The goal is to have a configuration where ALSA applications can access a “audio hardware” device even when the real device is locked by Jack Audio. That way, ALSA applications will not complain about unavailable audio hardware. I will show you how to provide ALSA with such a virtual hardware, and ensure that all sound which goes into that virtual hardware will be picked up by Jack and played through your speakers (hence the phrase “bridged”).

This “virtual hardware” is provided by the ALSA loop driver. When loaded into the kernel, this driver provides a pair of cross-connected devices, forming a full-duplex loopback soundcard.

First: load the kernel module (as root)

# /sbin/modprobe snd-aloop

You should add the above command-line to the file “/etc/rc.d/rc.modules” or to “/etc/rc.d/rc.local” so that the module will be loaded automatically on every boot.

The driver creates 8 independent substreams by default, but we need only two. Therefore you can add the following line to a (new) file called “/etc/modprobe.d/alsaloop.conf”:

options snd-aloop pcm_substreams=2

Next: write an ALSA configuration file which uses the new loopback devices

Create your ~/.asoundrc file as follows – if this file exists in your home directory, please back it up first!

# ------------------------------------------------------
# hardware 0,0 : used for ALSA playback
pcm.loophw00 {
  type hw
  card Loopback
  device 0
  subdevice 0
  format S32_LE
  rate 44100
}

# ------------------------------------------------------
# hardware 0,1 : used for ALSA capture
pcm.loophw01 {
  type hw
  card Loopback
  device 0
  subdevice 1
  format S32_LE
  rate 44100
}

# ------------------------------------------------------
# playback PCM device: using loopback subdevice 0,0
pcm.amix {
  type dmix
  ipc_key 196101
  slave {
    pcm "loophw00"
    buffer_size 8192
    period_size 4096
    periods 2
  }
}

# capture PCM device: using loopback subdevice 0,1
pcm.asnoop {
  type dsnoop
  ipc_key 196102
  slave {
   pcm loophw01
   period_size 4096
   periods 2
  }
}

# ------------------------------------------------------
# software volume
pcm.asoftvol {
  type softvol
  slave.pcm "amix"
  control { name PCM }
  min_dB -51.0
  max_dB   0.0
}

# ======================================================

# ------------------------------------------------------
# duplex device combining our PCM devices defined above
pcm.aduplex {
  type asym
  playback.pcm "asoftvol"
  capture.pcm "loophw01"
  hint {
    description "ALSA->JACK Loop Bridge"
  }
}

# ======================================================

# ------------------------------------------------------
# Mixer control definitions to keep JACK and some other apps happy
ctl.amix {
    type hw
    card Loopback
}

ctl.asnoop {
    type hw
    card Loopback
}

ctl.aduplex {
    type hw
    card Loopback
}

# ======================================================

# ------------------------------------------------------
# for jack alsa_out: looped-back signal at other end
pcm.ploop {
  type hw
  card Loopback
  device 1
  subdevice 1
  format S32_LE
  rate 44100
}

# ------------------------------------------------------
# for jack alsa_in: looped-back signal at other end
pcm.cloop {
  type hw
  card Loopback
  device 1
  subdevice 0
  format S32_LE
  rate 44100
}

# ======================================================

# ------------------------------------------------------
# default device

pcm.!default {
  type plug
  slave.pcm "aduplex"
}

When you save that file, its content will re-define your ALSA configuration with immediate effect. KDE may complain about hardware that was added or went missing, you can ignore that for now.

What these definitions do for ALSA, is to create a new full-duplex PCM device called “pcm.aduplex” with a description (which you will see mentioned in your programs’ ALSA device selectors) of “ALSA->JACK Loop Bridge”. What these definitions also do, is to create additional PCM devices for capture (pcm.cloop) and playback (pcm.ploop) which we will connect Jack to. That way, your ALSA applications are going to pipe their audio into one end of the loopback device and Jack will see this as incoming audio and play it on your speakers.

 You can test your new ~/.asoundrc file even though you will not hear a thing because the new virtual device is not yet connected to a real audio device (we will come to that in the next section). If you run the following command (under your own account – not as root) you should not see any error message:

$ aplay /usr/share/sounds/alsa/Front_Center.wav

Playing WAVE ‘/usr/share/sounds/alsa/Front_Center.wav’ : Signed 16 bit Little Endian, Rate 48000 Hz, Mono

If you see errors instead of the above text, then there is something wrong with the ~/.asoundrc file you just created.

Configuring Jack Audio

You should use qjackctl to configure the jack daemon. Jack installs a D-Bus service which qjackctl will connect to. Qjackctl can launch the daemon by itself or attach to an already running jack daemon (the qjackctl tray icon will be green if it had to start jackd and orange if it connected to an already running jackd).

qjackctl_setup_misc

Qjackctl will write the jack daemon configuration to a file in your homedirectory: ~/.jackdrc .It will write its own configuration to a different file: ~/.config/rncbc.org/QjackCtl.conf

I found out that I needed to have a sampling frequency of 44100 (the Jack default) instead of what musicians usually use (48000) in order to prevent distorted sounds coming from ALSA applications (youtube flash videos!). Whatever frequency you choose, you will need to use the same sampling frequency in ~/.asoundrc (see above) and for jackd.

qjackctl_setup

Using qjackctl, you can easily configure jack to use the soundcard hardware to which your speakers are connected: it shows a list of available devices in a dropdown menu. If you want to construct the jackd command-line manually, the names of all hardware devices can be obtained by running the following command:

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: NVidia [HDA NVidia], device 0: VT1708S Analog [VT1708S Analog]
  Subdevices: 2/2
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
card 0: NVidia [HDA NVidia], device 1: VT1708S Digital [VT1708S Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

The content of my ~/.jackdrc file looks like this:

/usr/bin/jackd -r -m -dalsa -r44100 -p1024 -n2 -m -H -D -Chw:NVidia -Phw:NVidia

The various jackd parameters all correspond to selections in the qjackctl dialog window.

Now when jack starts, it will still not know what to do with our modified ALSA configuration. A few commands need to be executed to form a bridge between ALSA and Jack using  the loopback driver. This is done most easily by creating a script file (for instance as user root create the file “/usr/local/bin/loop2jack” so that other users of your PC can use it as well) and in that file, add the following:

#!/bin/sh
#
# script loop2jack, located in /usr/local/bin
#
# Start jack if it is not already running:
/usr/bin/jack_control start
# loop client creation
/usr/bin/alsa_out -j ploop -dploop -q 1 2>&1 1> /dev/null &
/usr/bin/alsa_in -j  cloop -dcloop -q 1 2>&1 1> /dev/null &
# give it some time before connecting to system ports
sleep 1
# cloop ports -> jack output ports
/usr/bin/jack_connect cloop:capture_1 system:playback_1
/usr/bin/jack_connect cloop:capture_2 system:playback_2
# system microphone to "ploop" ports
/usr/bin/jack_connect system:capture_1 ploop:playback_1
/usr/bin/jack_connect system:capture_2 ploop:playback_2
# done
exit 0

Don’t forget to make the script executable:

chmod +x /usr/local/bin/loop2jack

This script should to be started after jackd has been started, but if jackd is not yet running, the script will start it for you. You can run it manually to see if there are any errors in your ~/.asoundrc file that you have to fix first. You can use qjackctl to run this script automatically when it starts:

qjackctl_setup_options

In the above screenshot you will also notice how the patchbay definitions are made persistent – I will show why this is important when I get to the section on SimpleScreenRecorder.

 

Starting Jack Audio

You will want to start the  jack daemon before any of your ALSA applications start! The ALSA driver grabs the audio hardware as soon as an application tries to make a sound using ALSA. Desktop Environments like KDE and XFCE have a feature called “session restore” which means that programs which were running when you logged out, will be started again – automatically – when you login again. A program like Skype, or even the startup sounds of your KDE desktop, will prevent Jack from launching properly.

If you are in runlevel 4 (graphical login) then you can start jackd by adding an appropriate command line in the following file: ~/.xprofile

If you are in runlevel 3 then you can start jackd from your normal login, using the file: ~/.profile

For instance, I have added this text to my ~/.xprofile :

# Create the bridge between ALSA applications and JACK output:
/usr/local/bin/loop2jack

… which will solve all timing issues: the loop2jack script will start the Jack daemon if it was not yet running, and it will bridge the ALSA and Jack in- and output channels using our virtual loopback device. This way, qjackctl does not even have to start anything (but we will not change the qjackctl configuration, in case you need to stop and restart Jack during a desktop login session).

 

Caveats

You have to keep in mind that running Jack is now required after making these modifications to your ALSA setup! When Jack is stopped (or not started) your ALSA sound system is no longer bridged to the physical sound card and you’ll hear nothing.

Also note that you may have a system-wide ALSA configuration file “/etc/asound.conf” which may interfere with your setup. Your own ~/.asoundrc definitions are added on top of the definitions in /etc/asound.conf and do not replace them.

 

Reverting this bridged ALSA-Jack setup

Reverting to the original Jack-less configuration is easy.

  1. Stop the Jack daemon using the qjackctl menu, and then stop qjackctl

  2. Remove or rename the file ~/.asoundrc (and restore your backup if you had an earlier version of this file)

  3. Remove or rename the file ~/.jackdrc

  4. Remove the invocation of “/usr/local/bin/loop2jack” from your ~/.xprofile and/or ~/.profile scripts.

The steps (1) and (2) are sufficient to restore the default ALSA behaviour and steps (3) and (4) ensure that Jack will not interfere at next login.

Getting audio into SimpleScreenRecorder (SSR)

In the “connections” window of qjackctl, my computer’s audio layout looks like this when I have started SimpleScreenRecorder (read my earlier post about this video recording tool):

qjackctl_connections_ssr

It’s a fairly simple layout with just a single Jack input client (being SSR) and a single output client (the entry “alsa-jack.jackP5161.0” which is the VLC program playing music).

The connections you see here between Jack’s “monitor” outputs (which were activated by checking the “Monitor” box in qjackctl’s setup dialog) and SSR’s inputs are automatically created when SSR connects to the Jack server. This happens because I defined these connections in qjackctl’s “patchbay” and let them be automatically activated. It seemed to be necessary this way because I could not get the monitor’s output to start inputting into SSR except by creating manual connections everytime.

qjackctl_patchbay_ssr

This is how I was finally able to record videos of (programs running on) my Slackware Linux desktop. Feedback highly appreciated!

Eric

 

A simpler solution (but not as robust)

There is another way to route the audio to and from ALSA-using applications when Jack is the sound server. In http://jackaudio.org/routing_alsa you can see how to use the “ALSA Jack PCM plugin” which creates a new PCM type called “jack”. This is a lot simpler to setup than the above article but it is not as robust and flexible. I used this solution for a little while and was happy with it – until I found out that it will not enable me to record audio with the SimpleScreenRecorder. So I had to abandon it.

You will need my alsa-plugins package for this. This package has two dependencies: jack (naturally) and ffmpeg. Note that if you want to use alsa-plugins and you are running 32-bit software which plays or records audio (think of Skype, Steam games) and you are on a 64-bit Slackware system, then you will additionally need multilib (of course) as well as “compat32″ versions of the 32-bit ffmpeg and jack packages.

 

References

These pages have been helpful (most important info in the first link):

Comments

Comment from bratpit
Posted: January 2, 2014 at 22:02

Hi Bob

Nice but too complex for me for simple capture sound+video :-)
I add some things like mixer to my custom asoundrc .

http://privatepaste.com/3e709d37b2

and checked it on 14.1 multilib :

“ffmpeg ………..-f alsa -i looprec ……………”

Works like charm recording from sound card output redirected to loop device .
Apart from 13.37 in recent slackware ALSA luckily not blocking sound from multiple sources the same time.

Comment from Brad
Posted: January 4, 2014 at 18:20

This works really well, and for youtube, etc I am having fewer audio problems with 64bit apps. I am not hearing any sound in 32bit apps run through wine though. If I installed a compat32 version of jack, would I need an additional loopback for that?

Comment from alienbob
Posted: January 4, 2014 at 19:10

Hi Brad

The only dependency for sound in Wine would be a “compat32″ package of OpenAL. I can’t think of any other package you’d need.

Perhaps you can start you WIne application in a terminal to see if there are any errors with regard to missing libraries.

Eric

Comment from Brad
Posted: January 4, 2014 at 21:16

Installed compat32 version of OpenAL, although the app had worked before without it. Also re-ran winecfg and set audio devices to the loopback. Sound is now working. Thanks again for a great post.

Comment from Mestigoth
Posted: January 9, 2014 at 13:18

Running loop2back fails cause jack_control seems to be missing. What package is it included?

Comment from alienbob
Posted: January 9, 2014 at 22:00

Hi Mestigoth,

The /usr/bin/jack_control program is part of my jack package.

Eric

Comment from Mestigoth
Posted: January 9, 2014 at 23:14

For some reason I could only see packages for slackware-13.0. Now I can see jack2 packages. Thanks mate. Recording TF2 while playing worked already like a charm. Now I can work on the sound.

Comment from alienbob
Posted: January 9, 2014 at 23:23

Yeah I have been making more of these silly mistakes recently… forgetting to upload parts of my repository. I guess I am becoming overworked, I’ll have to look out.
What was also missing is qjackctl, and I am fixing that now.

Eric

Comment from Mestigoth
Posted: January 9, 2014 at 23:31

Shows you’re only human. Had doubts about that, looking at all the work you have done sofar. :)

Comment from Alan Aversa
Posted: January 10, 2014 at 17:10

I get this error:

Could not connect to JACK server as client. – Overall operation failed. – Unable to connect to server. Please check the messages window for more info.

It sounds like a permissions issue…

Thanks

Comment from Alan Aversa
Posted: January 10, 2014 at 19:41

Also, why can’t we just use Jack and not ALSA? And what about Phonon? Does what backend I choose Phonon to use have matter here?

Comment from Alan Aversa
Posted: January 10, 2014 at 19:43

Okay, I got rid of the “Could not connect to JACK server as client” error by explicitly supplying my input and output devices in Qjackctl’s settings, but now only only my right channel outputs audio, and it’s very distorted.

Comment from Alan Aversa
Posted: January 10, 2014 at 19:51

Also, is setting up MIDI with Jack easy? What’s a good Linux MIDI synthesizer? thanks

Comment from Alan Aversa
Posted: January 10, 2014 at 19:52

Running “aplay /usr/share/sounds/alsa/Front_Center.wav” I only hear audio on my right channel…

Comment from Alan Aversa
Posted: January 10, 2014 at 20:05

HTML5 YouTube videos don’t playback very fluently in Firefox through Jack… I wonder why.

Comment from Alan Aversa
Posted: January 10, 2014 at 20:11

Okay, now for some reason both output channels work, yet YouTube videos go silent after about 20 seconds, and they’re somewhat crackly.

Comment from alienbob
Posted: January 10, 2014 at 23:39

Hi Alan

Your quick-fire posts triggered the blog’s spam protection and I had to move yours out of the spam bin.
This blog is not an interactive IRC channel or forum. If you need interaction, please visit one of the Freenode IRC channels I am in.

Sinc eI have no detail at all about your system setup I am unable to comment on your reports. All I can say: it works for me.

About your question “hy can’t we just use Jack and not ALSA” – that is perfectly possible if all your applications are jack-aware. Most are not. IN particular, everything in Slackware is not, and the packages in my own repository are not, either.

Eric

Comment from Alan Aversa
Posted: January 11, 2014 at 02:06

Well, with a little tweaking, it all works now! Man, Jack is awesome. ☺

I got SimpleScreenRecorder working, too, and it recorded the video plus the Jack audio of my system flawlessly, much better than Record My Desktop!

The only thing I need to figure out how to do now is make a mic loopback device so I can do voice-overs.

Comment from Alan Aversa
Posted: January 11, 2014 at 02:50

So, I figured out all I had to do was connect my system captures to my ploop playbacks in Qjackctl’s Connections box.

Sorry for all the messages, but Jack is very awesome. ☺

Comment from Brad
Posted: January 14, 2014 at 22:22

I ended up making this change globally on my laptop. My sound experience overall is greatly improved. Having a flash app using sound in a browser tab no longer stops all other system sounds from working. This is a great improvement for me anyway.

Comment from alienbob
Posted: January 14, 2014 at 23:13

Hi Brad, great to hear :-)

Eric

Comment from Alan Aversa
Posted: February 5, 2014 at 04:42

I’m having trouble getting a Bluetooth headset to work with Jack (and Phonon etc.). I read that Pulseaudio is required; is that true?
thanks

Comment from alienbob
Posted: February 5, 2014 at 12:19

Hi Alan

Where did you read that?
I do not own a bluetooth headset so I can not really comment on that, but I seriously doubt that pulseaudio is required for anything when Jack is concerned.

Eric

Comment from Alan Aversa
Posted: February 10, 2014 at 20:39

Jack seems to default to my laptop’s built-in microphone over my USB microphone. How do I make my USB microphone default?

Comment from Dave Williams
Posted: February 11, 2014 at 00:28

Hi Eric,

Thanks for putting this together. Very helpful.

For the benefit of whomever else may read this, here are some notes from my experience on a Toshiba P55-A5312 with the following devices (as reported by lspci):

00:03.0 Audio device: Intel Corporation Device 0a0c (rev 09)
00:1b.0 Audio device: Intel Corporation Lynx Point-LP HD Audio Controller (rev 04)

- I had to tell JACK to use hw:1,0 so it would use the correct card
- I had better luck leaving out the “rate” specs in .asoundrc. If I included them, even if they matched the rate in JACK, I would get complaints from alsa_out
- I had to set period_size less than 2048, or I got bad distortion (this took an age to figure out)

With those mods, it’s working great.

Dave

Comment from Gerardo Zamudio
Posted: February 11, 2014 at 23:11

Thank you for this great tutorial. Just tried it out and it works perfectly. I got a bit confused regarding where to place the jack start up script because I log in using the console then manually do startx’. Placed it in ~/.xprofile and it worked. Here’s a short test I did using my Microsoft LifeChat LX-3000 USB headset as a microphone and capturing the audio playing through my desktop speakers: https://db.tt/egGuBITB

Comment from Dwiyan Galuh W
Posted: March 18, 2014 at 02:56

Yeah… thanks for configuration. it’s work…. :))

Pingback from ALSA USB dmix help – hogs soundcard
Posted: April 26, 2014 at 14:51

[…] you may want to read this it really helped me with multiple devices. http://alien.slackbook.org/blog/sett…-in-slackware/ […]

Comment from Alan Aversa
Posted: April 29, 2014 at 16:45

I followed all the instructions for “Reverting this bridged ALSA-Jack setup”, but JACK, loopback, etc. sound devices still show up in Phonon. I’ve even reverted to a default .asoundrc, yet the devices still don’t go away.

thank

Comment from alienbob
Posted: April 29, 2014 at 21:00

Hi Alan

KDE’s Phonon remembers the sound devices it once found. Usually KDE will be triggered by the removal of a sound device with “do you want KDE to remove these sound devices” with an option not to ask again in future. You may at one point have indicated not to be asked again.

Check the file: ~/.kde/share/config/phonondevicesrc
and delete the non-existent sound devices there.

Eric

Comment from Drakeo
Posted: May 30, 2014 at 10:00

Followed everything you said on slackware64 (14.1-current)
and everything went smooth as Slackware64-14.1.
so right now seems your repo is the only slackware for protobuf latest build.which is used in MIXXX 1.12-alpha
Great Job made mine easier.
TY

Comment from alienbob
Posted: June 14, 2014 at 21:38

Note to self:

If you upgrade the kernel and have added the “modprobe snd-aloop” command to the file “/etc/rc.d/rc.modules” then be aware that “/etc/rc.d/rc.modules” is in fact a symlink to “/etc/rc.d/rc.modules-$(uname -r)”. Upgrading to a new kernel means that this symbolic link is changed to point to the new rc.modules file matching the new kernel.

Therefore, the “modprobe snd-aloop” line must be added to the new rc.modules flle !!
If you forget this, your sound will stop working for all applications that use the ALSA-to-JACK bridge when you boot into the new kernel.

Comment from Davide
Posted: July 10, 2014 at 08:27

Hi Eric, long time no ear… I’m trying to set up Jack on my system but installing your packages on top of the default ones leves some thing broken: the jack_alsa.so complains about the wrong LIBC configuration, also, jack_firewire and jack_oss can’t be loaded. This makes qjackctl not starting. I removed the .so files from there and recompiled jack_alsa from sources. Not sure if it works yet because haven’t tried it yet….

Comment from alienbob
Posted: July 10, 2014 at 15:18

Hi Davide, long time indeed! Hope you are doing well.
Did you install the jack package for the Slackware version you are running? Do you still have the exact LIBC error message so that you can post it? Normally, this should not happen unless you have a hybrid system, a mix of the very old and newer stuff.

Eric

Comment from haha
Posted: August 17, 2014 at 19:03

Thanks a lot for sharing. But I always get failure in Ubuntu trusty (14.04) when starting qjackctl with the message “D-BUS: JACK server could not be started. Sorry”.
I tried this solution “http://askubuntu.com/questions/224151/jack-server-could-not-be-started-when-using-qjackctl”,
But still failed. Does anyone meet the same issue like me?

Comment from Jerónimo Navarro
Posted: September 15, 2014 at 03:11

Hello Eric, thank you so much for this!
My recordings are real recordings now, with synched sound and everything :D

Write a comment