VectorLinux
October 24, 2014, 12:20:09 am *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Visit our home page for VL info. To search the old message board go to http://vectorlinux.com/forum1. The first VL forum is temporarily offline until we can find a host for it. Thanks for your patience.
 
Now powered by KnowledgeDex.
   Home   Help Search Login Register  
Please support VectorLinux!
Pages: [1]
  Print  
Author Topic: HOWTO grant realtime priority to the Jack Audio Connection Kit  (Read 8986 times)
The Headacher
Louder than you
Global Moderator
Vectorian
*****
Posts: 1551


I like the bass to go BOOM!


WWW
« on: September 21, 2006, 05:34:38 am »

Why give Jack realtime priority?

Jack is used as a low-latency audio server. In order for it to provide low latency it must have enough processing power to do so. However, other programs sometimes need that processing power as well. This can reslut in stuttering audio during play or, even worse, during recording. To prevent this from happening we can give Jack a higher priority than other programs. This means it will get enough processing power even with high cpu loads.

What you need
-Jack (duh! Wink)
Comes with the latest Vector Linux Dynamites and might come with VL6. Packages are available for VL5.
-A program that uses Jack
-2.6 series kernel with realtime-lsm patch. Comes with Dynamite, might come with VL6. Some Dynamite might not have this feature, or in a different kernel (but hey, it's testing)!
If you don't have it, I guess you'll need to build a kernel with realtime-lsm patch yourself or get a Dynamite with realtime-lsm kernel.
-Working audio server. Currently Jack is able to work with the following soundservers:

   -Portaudio     (cross platform audio system. Not supported in my version of Jack)
   -CoreAudio   (Apple/Macintosh soundsystem. I don't think that's supported in any Linux)
        -OSS        (older soundsystem, still used very often. Supported by the Jack built for VL6/Dynamite) )
   -ALSA       (THE standard in audio for Linux. Supported by the Jack built for VL6/Dynamite)   
   -Freebob       (for use with Firewire audio devices using the bebob chipset. Not supported
                 with current VL versions of Jackd)

Step 1: make sure the realtime-lsm module is loaded on boot
The realtime kernel-lsm module grants higher priority to processess that belong to a certain group. Audio is the most usual (and logical) one. 

Audio is usually group 17 on VL (you can check in /etc/group what it is on your box).
To make sure the realtime-lsm module is loaded and gives higher priority to programs belonging to audio on boot I added this line to the end of /etc/rc.d/rc.local :
Code:
/sbin/modprobe realtime gid=17
You'll have to be root in order to edit /etc/rc.d/rc.local ! You can use 'su' to become root and then open /etc/rc.d/rc/local with your favourite text editor, like this
Code:
mcedit /etc/rc.d/rc.local

Step 2: make sure Jack belongs to the right group
Now, Jack must be part of the right group in order for it to get a higher priority. If you check the permissions on /usr/bin/jackd you'll probably see it belongs to group "root"
Code:
ls -al /usr/bin/jackd
Most of the programs on VL belong to this group by default, so giving that group higher priority would not necessarily mean better performance for your audio programs. So, we must change this to audio (only root can do this):
Code:
chgrp audio /usr/bin/jackd

Step 3: test if everything works fine
Well, let's load the realtime module (just for this once. We already made sure it was going to be loaded on boot in step 1). You'll have to do this as root.
Code:
/sbin/modprobe realtime gid=17
Now, we'll see if we can get jack to run with realtime priority. I'm assuming you're using Alsa here. If you don't substitute alsa with your audio server.
Make sure you do this as a 'normal' user that belongs to the group you gave realtime priority (normal users belong to the group audio by default on VL)!

Code:
jackd -R -d alsa
If all goes well, you'll get something like this:
 
Code:
jackd 0.100.0
Copyright 2001-2005 Paul Davis and others.
jackd comes with ABSOLUTELY NO WARRANTY
This is free software, and you are welcome to redistribute it
under certain conditions; see the file COPYING for details

JACK compiled with System V SHM support.
loading driver ..
creating alsa driver ... hw:0|hw:0|1024|2|48000|0|0|nomon|swmeter|-|32bit
control device hw:0
configuring for 48000Hz, period = 1024 frames, buffer = 2 periods
Note: audio device hw:0 doesn't support a 32bit sample format so JACK will try a 24bit format instead
Note: audio device hw:0 doesn't support a 24bit sample format so JACK will try a 16bit format instead
nperiods = 2 for capture
Note: audio device hw:0 doesn't support a 32bit sample format so JACK will try a 24bit format instead
Note: audio device hw:0 doesn't support a 24bit sample format so JACK will try a 16bit format instead
nperiods = 2 for playback
If not all is well, you might get these messages as well:
Code:
JACK: unable to mlock() port buffers: Cannot allocate memory
[b]cannot use real-time scheduling [/b](FIFO at priority 20) [for thread -1228088400, from thread -1228088400] (1: Operation not permitted)
cannot use real-time scheduling (FIFO at priority 10) [for thread -1236477008, from thread -1236477008] (1: Operation not permitted)
That's usally because the realtime kernel module was not loaded, or not loaded with the right gid. Make sure the module is loaded with the right gid and that /usr/bin/jackd belongs to the right group!

Now, for easy starting of jack you could place a script on your desktop. It could be as simple as this:
Code:
#!/bin/sh
jackd -R -d alsa
Make sure it's executable, otherwise you won't be able to run the script:
Code:
chmod +x /home/me/Desktop/name_of_your_script_here

Right, now we can start jackd with realtime priority by just clicking on an icon!

ps.     I hope to write more HOWTO's on connecting programs to eachother in the near future. Stay tuned.
« Last Edit: September 21, 2006, 05:39:27 am by The Headacher » Logged

Most music on my soundcloud page was arranged in programs running on VL.
GrannyGeek
Packager
Vectorian
****
Posts: 2567


« Reply #1 on: September 22, 2006, 10:15:14 pm »

Jack is used as a low-latency audio server.

What is a low-latency audio server? Why is it a good thing to have?
--GrannyGeek
Logged

Registered Linux User #397786

Happily running VL 7 Gold on  a Sempron LE-1300 desktop (2.3 GHz), 4 G RAM,  GeForce 6150 SE onboard graphics and on an HP Pavilion dv7 i7, 6 gigs, Intel 2nd Generation Integrated Graphics Controller
Triarius Fidelis
Vecteloper
Vectorian
****
Posts: 2399


Domine, exaudi vocem meam


WWW
« Reply #2 on: September 22, 2006, 10:24:12 pm »

Jack is used as a low-latency audio server.

What is a low-latency audio server? Why is it a good thing to have?
--GrannyGeek

Latency is a term used in the engineering/comp sci trade (Headacher is an engineer and might have taken this for granted, lol) that refers to the time between input to some facility and action on that input.

In this case, it's a good thing if you want real time or close to real time response from sound server. Compare the introduction of low latency multitasking in Linux 2.6.x. (I never noticed the change myself, but the most intensive game I ever play is original Doom.)
Logged

"Leatherface, you BITCH! Ho Chi Minh, hah hah hah!"

Formerly known as "Epic Fail Guy" and "Döden" in recent months
The Headacher
Louder than you
Global Moderator
Vectorian
*****
Posts: 1551


I like the bass to go BOOM!


WWW
« Reply #3 on: September 23, 2006, 04:05:57 am »

Quote
What is a low-latency audio server? Why is it a good thing to have?
--GrannyGeek
Good point. I'll try updating my Howto on that soon.
Logged

Most music on my soundcloud page was arranged in programs running on VL.
GrannyGeek
Packager
Vectorian
****
Posts: 2567


« Reply #4 on: September 23, 2006, 07:03:57 am »

In this case, it's a good thing if you want real time or close to real time response from sound server. Compare the introduction of low latency multitasking in Linux 2.6.x. (I never noticed the change myself, but the most intensive game I ever play is original Doom.)

Thanks for replying, but I don't know what "real time or close to real time response from sound server" means. Is it mainly a gaming thing? Since I don't play games, maybe I've never encountered a situation where I would have missed it. Does it have any relevance to typical uses like listening to music or watching videos?
--GrannyGeek
Logged

Registered Linux User #397786

Happily running VL 7 Gold on  a Sempron LE-1300 desktop (2.3 GHz), 4 G RAM,  GeForce 6150 SE onboard graphics and on an HP Pavilion dv7 i7, 6 gigs, Intel 2nd Generation Integrated Graphics Controller
The Headacher
Louder than you
Global Moderator
Vectorian
*****
Posts: 1551


I like the bass to go BOOM!


WWW
« Reply #5 on: September 23, 2006, 08:19:40 am »

Jack is mainly used for audio production. It allows you to interconnect programs. Thus you don't need one program that can do everything. Instead, you can use a couple of programs and use the output of one for the input of another (or multiple others). You don't want too much time to pass between input and output of signals, to keep your audio synchronized
Logged

Most music on my soundcloud page was arranged in programs running on VL.
GrannyGeek
Packager
Vectorian
****
Posts: 2567


« Reply #6 on: September 24, 2006, 12:00:21 pm »

Jack is mainly used for audio production. It allows you to interconnect programs. Thus you don't need one program that can do everything. Instead, you can use a couple of programs and use the output of one for the input of another (or multiple others). You don't want too much time to pass between input and output of signals, to keep your audio synchronized

I guess I've never done anything like that or wanted to do anything like that. So it's still quite vague to me, but at least I have the beginnings of understanding.<g> Thanks!
--GrannyGeek
Logged

Registered Linux User #397786

Happily running VL 7 Gold on  a Sempron LE-1300 desktop (2.3 GHz), 4 G RAM,  GeForce 6150 SE onboard graphics and on an HP Pavilion dv7 i7, 6 gigs, Intel 2nd Generation Integrated Graphics Controller
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!