DAW Digital Audio Workstation

From ProAudioOverlay

Jump to: navigation, search

Contents

Introduction

This Howto was originally written by Paolo aka SteelRage and posted on the Gentoo forums:

It gives an overview about how it's possible to use Linux (I'll focus on Gentoo Linux) as a Hard Disk Recording/Mastering Workstation. I hope, after finishing that, to be able to give some misc tips, for example about how to use your Gentoo box as part of your multi-effects rack for live performances and stuff like that (any suggestions are VERY appreciated!)

I know very well there's A LOT of work to be done to reach the quality of the ultra-expensive Mac or Win professional softwares (and their quality continues to increase...), but you'll see that our penguin is already able to let us produce decent audio productions (demos, simple soundscores, etc)

Before starting I also want to warn you that most of the software I'll talk about is still in beta (or even alpha) state. So keep in mind they could crash or even lead your whole system to a crash.

Our Workstation will be made at least by the following elements:

  • Low Latency Sound Server (Jack)
  • SEQUENCER (Rosegarden) + DRUM MACHINE (Hydrogen)
  • MULTI-TRACK Editor/Recorder (Ardour)
  • DSP MultiEffects (LADSPA plugins and VSTi/VST Plugins under Rosegarden and Ardour)
  • AUDIO EDITOR (Rezound)
  • MASTERING Software (Jamin)

Prerequisites

  • I'll suppose your workstation has a working audio card, with working ALSA drivers.

This HOWTO has been written for Gentoo-Linux with 2.6 kernel, but could be easily adapted to other distros with different kernels (I'll discuss, for example, how to configure a 2.4 kernel, that were better than early 2.6 kernels regarding latency)

  • I HIGLY reccomend you to use the unstable (~arch) versions of all the programs I'll discuss here.

So be always ready to run a

nano /etc/portage/package.keywords

to add the application you want to install.

I know that this won't ensure you a 100% reliability, but the new features (an example was the introduction in some programs of DSSI, VST support, etc) introduced by the latest versions are often too much important if you want to be productive.

Another good reason to do that is that, if you find something wrong, you can make a good bug report that will help the whole community (the number of musicians doesn't seem to be too high, in fact)

Warning

We will not go into the dependency requirement of a particular application because Portage installs them when needed and we want to focus on practical matter, not to re-invent the wheel.

Consequently, if your Linux is that by Gentoo, please read the ebuilds (non-Gentoo users will find the overlay's ebuilds into the overlay SVN repository at the left). If you want to follow this HOWTO and are using another distribution than Gentoo, please follow the Install procedure of our distribution or from the source code when installing from the source.

Thank you for our comprehension!

Installation of Everminds proaudio overlay

What is this? See the Main Page
How to install? See the Usage Notes

Kernel configuration

Instructions for Kernel 2.4 (deprecated)

Before compiling it, we need to make the following modifications:

Processor type and features  --->
 [*] Preemptible Kernel
Device Drivers  --->
 Character devices  ---> 
 <*> Enhanced Real Time Clock Support     
 Sound  --->
  Advanced Linux Sound Architecture  ---> 
  <*> RTC Timer support

Because it's a good idea to use Jack (and all the applications that depend on it) as normal user, but we don't want to lose real time scheduling advantages, we need to activate "POSIX draft capabilities" (called, more commonly, caps). That's not difficult, we just need to modify a configuration file.

The file to modify is:

/usr/src/linux/include/linux/capability.h

Let's look for the following 2 lines:

#define CAP_INIT_EFF_SET    to_cap_t(~0 & ~CAP_TO_MASK(CAP_SETPCAP))
#define CAP_INIT_INH_SET    to_cap_t(0)

Now, change them to:

#define CAP_INIT_EFF_SET    to_cap_t(~0)
#define CAP_INIT_INH_SET    to_cap_t(~0)

If you don't like to edit files by hand, you can try this patch: http://nospoof.de/linux/patches/posix-draft-capabilities.patch (the link should be correct, but I've never tried it)

IMPORTANT: Every time we install/reinstall a new/different version of kernel sources, we need to remember to make this operation manually, or the new kernel won't be "caps-enabled", OK?


Instructions for 2.6 Kernels

The recommended method is to use sys-libs/pam with rt-limits activated.

install sys-libs/pam from the proaudio-overlay (only needed for <sys-libs/pam-0.99) to make sure realtime settings are possible with your installed version of sys-libs/pam try the following

strings /lib/security/pam_limits.so|egrep 'memlock|nice|rtprio'

if the result looks like this pam is will work

memlock
nice
rtprio

So next edit /etc/security/limits.conf and scroll down and add this settings (when using ebuild from the overlay this settings should already be there)

# REALTIME support for audio group users 
@audio          -       rtprio          100
@audio          -       nice            -10
@audio          -       memlock         250000 

After this relogin and the realtime stuff should work. If you don't like the "pam way" you can use instead the realtime modul described later in this section.

TODO: make next step clearer

If you already did the changes written above, then you better undo them :D If you don't want to do that, rimply re-emerge your favourite kernel-sources. (the command jackstart would work anyway, but I noticed performances were better with the following method)

In 2.6 kernels, in fact, there's a new way to allow users to perform real-time tasks; let's see how to enable it:

First let's compile the kernel we like with the following options (this is not the translation of the Italian guide I wrote, but it's taken from this link)


Low-latency specific configuration

For kernels starting with 2.6.25-rc1, you should check that the following options are *not* enabled, or you will not be able to run realtime processes using the RLIMITS method below:

General setup --->
        [ ] Group CPU scheduler
        [ ]    Group scheduling for SCHED_RR/FIFO # make sure this one is disabled

You should set these voices in the kernel configuration to achieve good low-latencies performances:

Processor type and features --->
        Preemption Model (Preemptible Kernel (Low-Latency Desktop))
    [*] Preempt The Big Kernel Lock                                 
        Timer frequency (1000 HZ)         

and:

Block layer  --->
    IO Schedulers --->
        <*> Anticipatory I/O scheduler
        <*> Deadline I/O scheduler
        <*> CFQ I/O scheduler
        Default I/O scheduler (CFQ)


JACK needs support for the tmpfs pseudo file system to achieve good performances:

File systems  --->
    Pseudo filesystems  --->
        [*] Virtual memory file system support (former shm fs)


The RTC can be needed by some applications, is better to compile it:

Device Drivers  --->
    Character devices  --->
        <M> Enhanced Real Time Clock Support
        <M> Generic /dev/rtc emulation
        [*]   Extended RTC operation     


The IDE sub-system can be a bottleneck if not properly configured. As pointed out by Con Kolivas in his Audio Hints, you should set the following config option for your ATA drive (relevant on and off options are showed):

Device Drivers  --->
    ATA/ATAPI/MFM/RLL support  --->
        <*> ATA/ATAPI/MFM/RLL support
        <*>     Include IDE/ATA-2 DISK support
        [*]       Use multi-mode by default
        [ ]     IDE Taskfile Access
        < >     generic/default IDE chipset support
        [*]     PCI IDE chipset support
        [*]       Generic PCI bus-master DMA support
        [*]         Use PCI DMA by default when available
        <*>         Intel PIIXn chipsets support


The latest config option is just an example and, almost certainly, you have to change it to reflect your hardware (again lspci -v will tell you which chip-set you have).


Finally, if you want to use the realtime-lsm module to grant realtime privileges to normal user you should also set:

Security options --->
    [*] Enable different security models
    <M>   Default Linux Capabilities   


If you don't find that voice, make sure in your /usr/src/linux/.config there are the following lines (as written in realtime-lsm documentation):

CONFIG_MODULES=y
CONFIG_MODULE_UNLOAD=y
CONFIG_SECURITY=y
CONFIG_SECURITY_CAPABILITIES=m
CONFIG_SECURITY_SELINUX=y

It's VERY IMPORTANT that CONFIG_SECURITY_CAPABILITIES is compiled as a module, or the patch WILL NOT WORK

Now let's compile the kernel as always, with a:

make && make modules_install

copy the new bzImage in /boot, reinstall the bootloader if you use lilo, etc etc, then let's install the realtime-lsm module (we need to redo that each time we recompile the kernel, make sure to set the link /usr/src/linux correctly)

emerge realtime-lsm

To have the patch working from boot time, I added this line to autoload.d

echo "realtime" >> /etc/modules.autoload.d/kernel-2.6
echo "options realtime gid=18" >> /etc/modules.d/realtime
modules-update

NOTE: The gid 18 is necessary, because it's the number given by default to audio group in Gentoo; you can experiment with any other group. An alternative approach would be to use the option any=1, but remember it could give some security problems, because you would allow every user to launch programs with realtime priority (and, if something goes wrong, it could crash the whole system :-D)

There are some other interesting options you can try, but I wont discuss them here. Simply take a look in /usr/portage/distfiles/realtime-lsm-number-version, or read jack FAQ


NOTES:

  • I read that aggressive settings for hdparm could increase latency too (somebody said at least 59 ms!! TOOO MUCH FOR A MUSICIAN!). Honestly, I use hdparm only to have DMA mode on My various Hard Disks, so I don't have problems.

So, if you find your latency too high, keep in mind this suggestion.

  • 'Important note about ALSA'

DON'T use alsa-modules included on your kernel sources. Just follow the official Gentoo guide (that suggests to use the alsa-driver package). Why? If you have a professional audio-card, maybe you'll need the package Code: alsa-firmware, whose version must be the same of the installed alsa-driver or you may have problems. Alsa modules included on your kernel sources may be older than current alsa-driver (and alsa-firmware)

Instructions for 3.x Kernels

With the current 3.x kernels series, we have one more possibility to get real-time operations to work: Control Groups, or cgroups in short. This method is not available with the rt-kernel.

For a general introduction, see cgroups kernel documentation.

From it: "Control Groups provide a mechanism for aggregating/partitioning sets of tasks, and all their future children, into hierarchical groups with specialized behaviour."

This is exactly what the real-time patch is doing: it provide a mechanism for aggregating the audio tasks, and for attributing them a higher priority than the other tasks. The same (and much more) can be done with the Control Groups, this with any recent kernel.

On the long run, I think many of us will use a vanilla or gentoo kernel with an audio related cgroups set-up. But the rt kernel will remain in use, firstly because it have proven to be a good working solution, secondly because the developers of the rt patch will continue to experiment new solutions, and thirdly because cgroups add a slight scheduling overhead, and some of us don't want it.

For a jack related explanation, see Some notes on CGroups.

RT scheduling cpu bandwidth and cgroups

In the kernel configuration, the minimal and sufficient cgroups set-up to get RT scheduling is:

General setup --->
        [*] Control Group support --->
                 [*] Group CPU scheduler --->
                           [*] Group scheduling for SCHED_RR/FIFO

As you can see in its help, this last option will give us CONFIG_RT_GROUP_SCHED. With this, we get access to RT scheduling cpu bandwidth controlled via cgroups. The root cgroup has this setup correctly. Remember, RT operations is all about bandwidth allocation of resources, more bandwidth for some task imply less bandwidth and responsiveness for the other.

cgroups set-up

We also need to install dev-libs/libcgroup, which provide tools and libraries to configure and manage kernel Control Groups.

emerge libcgroup

However when libcgroup is installed and the cgconfig service has been started, it creates a "sysdefault" cgroup and moves all tasks over there. The sysdefault group does not have RT bandwidth assigned to it. In this case jackd can not be started.

It is several methods to configure cgroups for our purpose (Some notes on CGroups). I started with the method 2, but it was necessary to add a namespace section. In consequence, the following set-up is a mix of method 2 and 3.

Edit /etc/cgroups/cgconfig.conf as follow:

namespace {
	cpu = /;
}

group rtaudio {
	perm {
		task {
			uid = root;
			gid = audio;
		}
		admin {
			uid = root;
			gid = root;
		}
	}
	cpu {
		cpu.rt_runtime_us = 950000;
	}
}

We create here a kernel cgroup named rtaudio. Root can manage it. The users in the audio group can use it. We use rtaudio to define the processor use of the RT processes. The members of the rtaudio cgroup (the RT threads of the programs which are member of rtaudio) can use the processor during 950000 us per second, the other tasks get the remaining time, 50000 us.

At that time, we need to explicitly add the programs that must get RT scheduling. For that, edit /etc/cgroups/cgrules.conf:

# One of the following line is needed for jack
#@audio:jackd		cpu	rtaudio/
@audio:jackdbus   	cpu	rtaudio/
# Comment the 2 following lines if not using snd-aloop
@audio:alsa_in   	cpu	rtaudio/
@audio:alsa_out   	cpu	rtaudio/
# Add one line for each RT software
@audio:mplayer		cpu	rtaudio/
@audio:ardour     	cpu	rtaudio/
@audio:jamin     	cpu	rtaudio/

You must add one line per application you want to be in the rtaudio cgroup. In the future, jack will provide a mechanism to move the RT threads of its clients into the cgroup of jackd.

We must configure PAM in /etc/security/limits.conf:

@audio   -  rtprio     99
@audio   -  memlock    unlimited

Starting chroups with our configuration:

# /etc/init.d/cgred start
* Starting cgconfig service ...                                           [ ok ]
* Starting CGroup Rules Engine Daemon ...                                 [ ok ]

Only the new processes will be managed by cgroups. It is best to start it at boot time:

rc-update add cgred default

Testing cgroups

To test your set-up, you can use the 2 following small scripts, findrtp and findrtt.

findrtt will output the running programs which are member of rtaudio. findrtt will output all their threads.

findrtp
#!/bin/sh
for i in `cat /sys/fs/cgroup/cpu//rtaudio/cgroup.procs`;
    do echo "Found pid $i which correspond at `cat /proc/$i/cmdline`";
done

and

findrtt
#!/bin/sh
for i in `cat /sys/fs/cgroup/cpu//rtaudio/tasks`;
    do echo "Find pid $i which correspond to `cat /proc/$i/cmdline`";
done

Save them in your path and make them executable.

Run them:

# findrtp
Trouvé le pid 1846 qui correspond à /usr/bin/jackdbusauto
Trouvé le pid 2123 qui correspond à /usr/bin/alsa_out-jploop-dploop-q1
Trouvé le pid 2124 qui correspond à /usr/bin/alsa_in-jcloop-dcloop-q1
Trouvé le pid 2162 qui correspond à timidity-iA-B2,8-Oj-EFreverb=0-s48000
Trouvé le pid 2259 qui correspond à mplayerdvb://2@
# findrtt
Trouvé le pid 1846 qui correspond à /usr/bin/jackdbusauto
Trouvé le pid 2116 qui correspond à /usr/bin/jackdbusauto
Trouvé le pid 2117 qui correspond à /usr/bin/jackdbusauto
Trouvé le pid 2118 qui correspond à /usr/bin/jackdbusauto
Trouvé le pid 2119 qui correspond à /usr/bin/jackdbusauto
Trouvé le pid 2123 qui correspond à /usr/bin/alsa_out-jploop-dploop-q1
Trouvé le pid 2124 qui correspond à /usr/bin/alsa_in-jcloop-dcloop-q1
Trouvé le pid 2128 qui correspond à /usr/bin/alsa_out-jploop-dploop-q1
Trouvé le pid 2129 qui correspond à /usr/bin/alsa_out-jploop-dploop-q1
Trouvé le pid 2130 qui correspond à /usr/bin/alsa_out-jploop-dploop-q1
Trouvé le pid 2131 qui correspond à /usr/bin/alsa_in-jcloop-dcloop-q1
Trouvé le pid 2162 qui correspond à timidity-iA-B2,8-Oj-EFreverb=0-s48000
Trouvé le pid 2170 qui correspond à timidity-iA-B2,8-Oj-EFreverb=0-s48000
Trouvé le pid 2171 qui correspond à timidity-iA-B2,8-Oj-EFreverb=0-s48000
Trouvé le pid 2172 qui correspond à timidity-iA-B2,8-Oj-EFreverb=0-s48000
Trouvé le pid 2259 qui correspond à mplayerdvb://2@
Trouvé le pid 2339 qui correspond à mplayerdvb://2@
Trouvé le pid 2340 qui correspond à mplayerdvb://2@
Trouvé le pid 2341 qui correspond à mplayerdvb://2@

To see which threads are RT, we can use ps:

ps -eLo rtprio,pri,cgroup,class,pid,pcpu,%mem,user,comm --sort pri|less
RTPRIO PRI CGROUP                      CLS   PID %CPU %MEM USER COMMAND
...
    -  19 2:cpu:/rtaudio              TS   2613  0.0  1.0 dom      jackdbus
    -  19 2:cpu:/rtaudio              TS   2613  0.0  1.0 dom      jackdbus
    -  19 2:cpu:/rtaudio              TS   2613  0.0  1.0 dom      jackdbus
   10  50 2:cpu:/rtaudio              FF   2613  0.4  1.0 dom      jackdbus
    -  19 2:cpu:/rtaudio              TS   2613  0.0  1.0 dom      jackdbus
...
    -  19 2:cpu:/rtaudio              TS   3642  0.0  1.0 dom      alsa_out
    -  19 2:cpu:/rtaudio              TS   3642  0.0  1.0 dom      alsa_out
    -  19 2:cpu:/rtaudio              TS   3642  0.0  1.0 dom      alsa_out
    5  45 2:cpu:/rtaudio              FF   3642  0.5  1.0 dom      alsa_out
    -  19 2:cpu:/rtaudio              TS   3643  0.0  1.0 dom      alsa_in
    -  19 2:cpu:/rtaudio              TS   3643  0.0  1.0 dom      alsa_in
    -  19 2:cpu:/rtaudio              TS   3643  0.0  1.0 dom      alsa_in
    5  45 2:cpu:/rtaudio              FF   3643  0.5  1.0 dom      alsa_in
    -  19 2:cpu:/rtaudio              TS   3664  0.0  1.3 dom      timidity
    -  19 2:cpu:/rtaudio              TS   3664  0.0  1.3 dom      timidity
    -  19 2:cpu:/rtaudio              TS   3664  0.0  1.3 dom      timidity
    5  45 2:cpu:/rtaudio              FF   3664  0.0  1.3 dom      timidity
    -  19 2:cpu:/rtaudio              TS  30170  6.1  1.4 dom      mplayer
    -  19 2:cpu:/rtaudio              TS  30170  0.0  1.4 dom      mplayer
    -  19 2:cpu:/rtaudio              TS  30170  0.0  1.4 dom      mplayer
    5  45 2:cpu:/rtaudio              FF  30170  0.1  1.4 dom      mplayer

The FF threads are the real-time one. We will see the same result with htop, but with other priority numbers (I prefer htop).

Another test is to lower jack latency. Run qjackctl and play with the parameters. With the Control Groups, I can lower jack latency with the gentoo-sources from 42,7 msec (1024 Frames/Period, 48kHz, 2 Periods/Buffer) to 0,667 msec (16 Frames/Period) without more xruns (only at applications start-up), which is as good than with the rt-sources.

Portage profile configuration

You can use any portage profile with the overlay. However, I will recommend the use of a desktop profile. Portage provide 3 of them, desktop, desktop-gnome and desktop-kde. The overlay provide 2 of them: desktop-proaudio and desktop-prodaudio-kde.

Those 2 last profiles provide additional audio related use flags. In addition, they are both *kit free. That mean they will not install or remove policykit and any package that depend on it, inclusive udisks, pulseaudio and the whole of gnome. The desktop-proaudio-kde profile doesn't install semaantic-desktop, which result in kde speed-up. See this forum thread for more explanations on an *kit free system, and this one for some background.

If you want a gnome *kit free desktop, you can install the soka overlay. It will work with Gnome2 on arch architectures. It don't think it is possible to make it to work in an ~arch installation without some hard work. To install it, follow those instructions.

In order to use a profile from the overlay, follow proaudio portage profiles.

Jack configuration

Jack is an audio-server made to work with low-latency. Unlike other famous sound-servers (Arts, ESD, Gstreamer, etc), it has some features (and we'll discover some of them, such low latency, flexible audio routing between applications, AUDIO/MIDI syncronization during this HOWTO) that make it a core compoent of a Linux DAW.

Installation of Jack

Once installed the new kernel, rebooted, etc etc, we're ready to install Jack. We'll need the following use flags

  • In /etc/make.conf you should have at least the following:
USE="alsa jack mmx sse"

As you will need it a lot. Note: mmx and sse are CPU optimizations which should have been set when you installed Gentoo. Your processor may also support mmx2 and sse2. To see what your processor supports, see

grep -i Flags /proc/cpuinfo

Then for jack do

echo "media-sound/jack-audio-connection-kit jack-tmpfs jackmidi" >> /etc/portage/package.use
  • Now let's install jack and its dependencies:
emerge --oneshot alsa-lib alsa-jack jack-audio-connection-kit

I repeat once again it's better to use the latest ~arch version... but it's up to you.

  • If you find too many xruns when working with audio-programs, you could add to try these lines to your /etc/fstab
shmfs       /dev/shm     shm    defaults        0       0
none        /tmp/jack    tmpfs  defaults        0       0

Then, after creating the /mnt/ramfs dir:

mkdir /mnt/ramfs

add this line too

none        /mnt/ramfs   tmpfs  defaults        0        0

For details refer to the Jack FAQ at http://jackit.sourceforge.net/docs/faq.php (very outdated).

  • Now let's test if jack works:
jackd -R -dalsa &

If you want, you can use jack from commandline (for example to launch it on boot time), so read carefully

man jackd

that can avoid you some future headcaches.

But, believe me... it's not too much comfortable! That's the reason why I suggest you to use qjackctl:

emerge -av qjackctl

This is a frontend to control Jack and its connections between programs. But we'll see that in the following part of the guide.

NOTE: Be sure to execute Jack BEFORE other audio apps (or they won't work.)

Under Settings in qjackctl, set Priority to 65 to avoid letting jackd run with a lower priority than your graphics card, serial port and other hardware that might interrupt the sound.

jack and alsa/oss applications

Alsa and oss applications can work with jack. The following will work with sound cards with hardware mixing capability (as exemple soundblaster live and audigy).

Alsa and jack

From How do I route audio to/from generic ALSA-using applications?: There are two ways of approaching this.

Using the ALSA JACK PCM plugin

You must install alsa-plugins with USE="jack".

Edit ~/.asoundrc or /etc/asound.conf and add the following

# convert alsa API to jack API
# use it with:
# % aplay foo.wav
# pcm type jack
pcm.rawjack {
    type jack
    playback_ports {
        0 system:playback_1
        1 system:playback_2
        }
    capture_ports {
        0 system:capture_1
        1 system:capture_2
        }
}
# jackplug
pcm.jack {
    type plug
    slave { pcm "rawjack" }
    hint {
  description "JACK Audio Connection Kit"
    }
}
# use following peripherical by defaut with alsa:
pcm.!default {
    type plug
    slave { pcm "rawjack" }
}

This will work with most alsa applications. Some applications will not work, as exemple beast with the alsa plugin. When starting an alsa application as usual, if jackd is started, the application will use by default the jack plugin and appear in the connection panel of qjackctl. Otherwise, it will generate an error message and start using alsa.

Using an ALSA Loopback device and zita-ajbridge

This approach is more complex but probably more robust. This method is also deprecated.

The loopback ALSA device is a virtual sound card that will let you to connect audio streams. We will use it to connect ALSA and JACK in full duplex. As the first sound card is the default ALSA sound card in most (if not all) systems, we will put the loopback virtual card as first sound card. That way, the ALSA only software will use the loopback by default.

zita-ajbridge is a software by Fons Adriaensen that provide 2 programs, zita-a2j and zita-j2a. They provide input and output ports for ALSA into JACK. They are the equivalent of alsa_in and alsa_out but archive a better sound quality, a lower and constant delay, as well than a much better jack stability (the most visible effect is no more xruns at jack program start or stop).

First, you must have snd-loopback into the kernel:

Device Drivers ->
  <M> Sound card support ->
    <M> Advanced Linux Sound Architecture ->
      {*} Generic sound devices ->
        <M> Generic loopback driver (PCM)

Now, we must add it into /etc/modprobe.d/alsa.conf (example for 2 sound cards, the loopback and an audiophile 192):

alias char-major-116 snd
alias char-major-14 soundcore

options snd-aloop index=0
options snd-ice1724 index=1
options snd-ice1724 model=ap192

alias snd-card-0 snd-aloop
alias snd-card-1 snd-ice1724

alias sound-slot-0 snd-card-0
alias sound-slot-1 snd-card-1

alias sound-service-0-0 snd-mixer-oss
alias sound-service-0-1 snd-seq-oss
alias sound-service-0-3 snd-pcm-oss
alias sound-service-0-8 snd-seq-oss
alias sound-service-0-12 snd-pcm-oss

alias sound-service-1-0 snd-mixer-oss
alias sound-service-1-3 snd-pcm-oss
alias sound-service-1-12 snd-pcm-oss

alias /dev/mixer snd-mixer-oss
alias /dev/dsp snd-pcm-oss
alias /dev/midi snd-seq-oss

options snd cards_limit=2

You can restart ALSA:

/etc/init.d/alsasound restart

We install zita-ajbridge:

emerge -a zita-ajbridge

Now, we made a simple script, I call it loop2jack

#!/bin/sh
# To launch it (from qjackctl):
# loop2jack %r %p
# where %r=<sampling rate>; %p=Periods/Frames

# ALSA period size: %p/2.
PSize=$(( $2/2 ))

## Launch and configure the ALSA <-> JACK loop
#  Clients creation
/usr/bin/zita-j2a -d hw:0,1 -r $1 -p "${PSize}" -J 2>&1 1> /dev/null &
/usr/bin/zita-a2j -d hw:0,1 -r $1 -p "${PSize}" -J 2>&1 1> /dev/null &

# wait 1 seconde before the ports connection
sleep 1

# Connect zita ports -> jack output ports 
jack_connect zita-a2j:capture_1 system:playback_1
jack_connect zita-a2j:capture_2 system:playback_2
# Connect jack input ports -> zita ports  
jack_connect system:capture_1 zita-j2a:playback_1
jack_connect system:capture_2 zita-j2a:playback_2

# done
exit 0

The -J option of zita-a2j and zita-j2a is needed by software like flash. You you get no sound, try to change the ALSA device to something like hw:0,0 or hw:0

Made it executable

chmod +X loop2jack

and put it somewhere in your path.

The ALSA user configuration file at ~/.asoundrc is also needed:

# playback PCM device: using loopback subdevice 0,0
pcm.amix {
  type dmix
  ipc_key 219345
  slave.pcm "hw:Loopback,0,0"
}

# capture PCM device: using loopback subdevice 0,1
pcm.asnoop {
  type dsnoop
  ipc_key 219346
  slave.pcm "hw:Loopback,0,1"
}

# duplex device combining our PCM devices defined above
pcm.aduplex {
  type asym
  playback.pcm "amix"
  capture.pcm "asnoop"
}

# ------------------------------------------------------
# for zita-a2j and zita-j2a: looped-back signal at other ends
pcm.ploop {
  type plug
  slave.pcm "hw:Loopback,1,1"
}

pcm.cloop {
  type dsnoop
  ipc_key 219348
  slave.pcm "hw:Loopback,1,0"
}

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

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

That's all, you can start jack with qjackctl. Don't forget to add "loop2jack %r %p" in qjackctl -> Setup -> Options -> Execute script after Startup.

If you get no sound into JACK with the ALSA programs, you can try to change the ALSA devices in the scripts (the hw:0,0) or to add the -L argument to zita-a2j and zita-j2a. Also, read the README for zita-ajbridge into its doc folder.

OSS and jack

Edit ~/.asoundrc and add the text in the preceding text box (alsa and jack) as well as the following:

# oss will use the alsa to jack API by default
# test it with
# % aoss mpg123 some.mp3
pcm.dsp pcm.!default

It will work the same as the alsa to jack converter. Some applications will not work, as exemple beast.

Note

mplayer will crash with this setting when jackd is started. To avoid it, start mplayer with native jack driver:

# mplayer -ao jack movie.avi

Link

  • Knowing JACK: Very informative reading on JACK and its configuration.

Installation of needed packages

Now it's time to install the most important packages from the overlay

VST Support

What is a VST plugin? Without getting technical, VST is a plugin format used by most Win/Mac audio-related applications. You can use it within other audio programs (called hosts) for real time effects, virtual synths and other things. If you are interested and want a more detailed explanation, take a look here. Do I really need that stuff? I hate Wincows, Micro$oft and Macintrash! Yes. You need it. Just take a look at http://kvraudio.com to see how many tons of free plugins (some are really really good!) you can have access to. How could it be? Sounds like magic; I suppose I didn't understand anything There are at least 2 systems to use VST plugins under Linux:

  • dssi-vst: it's a dssi plugin (so the host you're going to use must support DSSI!) that can make use of VST plugins. To do that, it uses Wine, DSSI headers and Steinberg VST SDK headers (VST protocol, in fact, was created by Steinberg)
  • fst: it's a server that, with the combination of Wine, Jack and Steinberg VST SDK, allows you to use VST plugins under Linux
  • Vst server. This should be the first program who gave VST support to Linux. I did never understand how to use it, so if you know how to, please write me a note, so I can add it to this documentation.

OK, it sounds cool. What do I have to do? First go here http://www.steinberg.net/532+M52087573ab0.html, read the agreement and download the 2.3 version of the SDK (or a following one, depending on what the overlay will require by the time you read this). If the link doesn't work anymore, go to Google to find the vstsdk2.3.zip file (it's part of the vst_sdk2_3.zip archive). Remember that YOU CANNOT REDISTRIBUTE IT, SO READ CAREFULLY THE AGREEMENT I told you above. If you don't like it, simply don't use it (and you won't have VST support).

Once you found vstsdk2.3.zip (good luck), copy it in /usr/portage/distfiles

Now add to your /etc/make.conf the following (new) useflags:

(I know you just need the vst USEFLAG, but I prefer to set them all at this stage). This should be enough to let you have that support in Ardour, rosegarden and other important applications.

NOTE: museseq may not compile with >=fst-1.7, so, if it gives you problems, try to install it with a Code: USE=-vst emerge museseq

Lash or Ladcca

Almost all the newest audio applications now use Lash, instead of Ladcca. After recommending you to take a look at their web sites, I also suggest to remove ladcca (emerge -C ladcca) and re-emerging your (~arch) version of vkeybd, jack-rack and museseq so they'll use Lash libraries.

You need to add 2 lines at the end of /etc/services:

lash            14541/tcp                       # Lash client/server protocol
lash            14541/udp

Rosegarden (sequencer) installation

With this one we can start to be a bit productive... Rosegarden is an audio and MIDI sequencer, based on KDElibs+QT (sorry for the users who hate this DE :-P). In the beginning it was written only to manage/edit MIDI files, but now audio support has been integrated (OK... it cannot be compared to Cubase or Sonar... But... It's growing quite well). It also have a good score editor, that allows you to export files to Lilypond and nice editing features.

So, if you want to start using it, you just need to do an Code: USE=”+jack +dssi” emerge rosegarden (remember I suggest you to use the latest ~arch version). On the overlay you'll also find rosegarden-9999 (svn-snapshot) ebuild. Take a look at it too, because audio support is getting better and better in newest relases
To enable snapshot ebuilds *-9999 read our FAQ about svn/cvs/whatever-ebuilds
Why did I add DSSI useflag? DSSI is a "temporary" API for virtual instruments with a GUI. Without going deep in details, I'll just tell you there are some nice virtual synths using it and that there's an extra-plugin that lets you use VSTi and VST plugins under rosegarden (or other DSSI-compatible hosts), but if you read this guide carefully, you already know that. Take a look at http://dssi.sourceforge.net/ for further informations.

Remember that, if you want audio support, you have to run jackd BEFORE Rosegarden. It would be a good idea to run it through qjackctl.

Ardour Installation (multi-track audio editor)

If you need VST support, you just have to do a

 USE=vst emerge ardour

If that gives you problems, try to emerge ardour-9999 (cvs) instead (I prefer the cvs version). You can also try to emerge ardour2 if you want a bunch of new features but less stabilty.
To enable snapshot ebuilds *-9999 read our FAQ about svn/cvs/whatever-ebuilds

Interesting Virtual synths

zynaddsubfx
Real time Virtual Analog synth
fluidsynth
MIDI virtual Synth based on SoundFont. You can use it either via qsynth (a nice QT GUI) or via his DSSI version, called fluidsynth-dssi
hexter
A Yamaha DX7 reprodution via DSSI. It can also import your old Yamaha DX5 and DX7 patches. Take a look if you need a nice FM synth
hydrogen
A very good drum machine
ams
Alsa Modular Synth (still have to try it)
amsynth
another virtual synth that seems to sound very nice (I found filters to be a bit "cold", but I still have to experiment well with it)
Csound
As the homepage says: "Csound is a sound and music synthesis system, providing facilities for composition and performance over a wide range of platforms". Ehm... Still have to try it too :D
aeolus
a synthesised pipe-organ instrument written by Fons Adriaensen. The default sounds have been skillfully programmed and are very realistic; this means that Aeolus can be very satisfying to play, or to listen with your favourite MIDI files. Aeolus Quickstart Guide
bristol
an excellent project written by Nicky Copeland. The project emulates twenty of the classic instruments from the 60's, 70's and 80's. The sounds are distinctive to the Bristol project and are not intended to be totally authentic, however they do sound great. Bristol home page Note that JACK support by Bristol is considered experimental.

Rezound (audio editor) installation

If you need to cut&paste samples, resample, apply offline effects, remove noise, to put quickly your latest demo on a CD, converting it to mp3, ogg and other things, a sequencer couldn't be enough... You need an audio editor! Lots of people use Audacity, because it's muti-platform, it's well known, etc etc. Well, I really hate it. That's why I suggest to try rezound. First because I find its GUI is more intuitive, second because it can use jack as an output.

To install it, a Code: USE=”+jack” emerge rezound should be enough. Feel free to add other USEFLAGS you may need (emerge -pv rezound to have a complete list). Once again, I recommend to put rezound and its deps to /etc/portage/package.keywords so you can use the latest version.


Jamin installation

Jamin is a "simple" mastering suite, made by a multi-band compressor and a 30-bands EQ. As all the other mastering suites, it requires you know very well what you're doing. You can install it with a simple

 emerge jamin

(or jamin-9999, if you want the cvs version). Remember that mastering is the final stage of the audio-production process, so, when you route the signal via qjackctl, insert jamin right before the output you want to send audio to. (Jamin is used as an audio effect, so it must be used in real time with jack! you cannot import, for example, wave files on it to modofy them!)

Mastering is a very important aspect of music production, because it decides how your music will sound when played all around the world (from the ultra-expensive stereo to the cheapest walkman or mp3 player). That's why you need a studio and amplification system made just for mastering. If you don't have it... Well... You better give your precious single to a studio specialized in mastering ;)

PulseAudio

PulseAudio is a networked sound server, similar in theory to the Enlightened Sound Daemon (EsounD). PulseAudio is however much more advanced and has numerous features.

PulseAudio comes with many plugin modules. Among them, 2 jack modules that make possible to interface PulseAudio with jack. It is also possible to interface alsa and Pulse Audio with an ALSA pulse plugin in ~/.asoundrc. The result will be that any alsa application will use jack trough this Pulse plugin.

To install it, just run

 emerge pulseaudio

Other programs that you may want to install at the same time are:

  • PulseAudio Volume Control
  • PulseAudio Volume Meter
  • PulseAudio Preferences

Those programs are GUI using gtk+.

To install all of them:

 emerge pavucontrol pavumeter paprefs

To take a look at some configuration and usage examples, read the PulseAudio How-To wiki article.

For serious audio work, it is better to avoid pulseaudio. The main raison is because pulseaudio make no gvaranty about the latency. The latency of pulseaudio will increase in case of xruns, and the only possibility to decrease it, is to stop and restart pulseaudio.

SEQ24

SEQ24 has 2 different ways of working with MIDI.

The default method is in the MIDI input page it will show all other MIDI connections and allow you to check boxes. (This can be pretty annoying).

To work with qjackctl to setup the MIDI connections and have seq24 have it's own input follow these steps:

1. Open then close seq24.

2. Open up the file .seq24rc

3. Find the section that looks like

[manual-alsa-ports]
# set to 1 if you want seq24 to create its own alsa ports and
# not connect to other clients
0

4. and make it look like this

[manual-alsa-ports]
# set to 1 if you want seq24 to create its own alsa ports and
# not connect to other clients
1

5. Reopen SEQ24 and you should see a MIDI port under the ALSA section (it doesn't support jack MIDI although using a2jmidid -e will expose all ALSA sequencer ports in JACK)

Other overlays of interest

Notes

Jack and sound level

Jack uses a floating point sample format, which allows values above 0 dBFS. When such a value is passed to a DAC, it will be clipped and cause distortion or worse. (A DAC in a sound card use fixed point values.)

Within JACK, 0 dBFS corresponds to a sample value of +/-1.0, and will emerge from the other side of your DAC with the maximum voltage level that the DAC can emit. Values above 0 dBFS are legal within JACK, but should probably never be routed to a physical output port.

Jack transport

From Robin Gareus on linux-audio-dev email list:

"Rolling" (like "Starting" and "Stopped") is a state of the jack-transport (SMPTE timecode) mechanism. (see the diagram on this page).

This has nothing to do with JACK audio-process callbacks which is/are always running. Every JACK application can *optionally* synchronize it's play position to jack-transport. Many jack aware application does not support this feature or have they own "motor" to do that (as example audacity).

Quoting Paul Davis on linux-audio-dev email list:

"Most JACK clients pay no attention to JACK transport status. Only those that wish to participate in a fully synchronized start/stop/move-to system do so, and there are few of them. Clients are free to completely ignore transport status without any side effects.

"rolling" means that transport-aware clients should think of themselves as moving along a linear timeline. JACK transport info tells them where they are."

Recommended books for new audio developers

What if you want to hack some linux sound software? Here are some books recommended by developers on linux-audio-dev mailing list:

  • Computer Music Tutorial by Curtis Roads (1995, 1254 pages) A misnamed classic. It's no tutorial, but it is crammed with information. It provides a background, a context, a way of thinking about the goals. Its certainly not useful directly for developers, but everyone writing audio software should know most (or at least a good chunk) of what is in there.
  • Computer Music: Synthesis, Composition, and Performance by Charles Dodge and Thomas Jerse (1997, 480 pages). Recommend to newbies to computer-assisted sound design and music-making.
  • Read the docs/source for things like ALSA, Jack, LADSPA/LV2, DSSI & LASH.
  • musicdsp.org has tons of examples for concrete tasks like oscillators and filters, often in a portable way, read pure c or c++ so it helps you on every OS.
  • The Science of Musical Sound by John Pierce. It only has a bit of material about computer music, and that is pretty light and pretty dated, but otherwise it's GREAT background for thinking about how sound works.
  • "Recording Studio Design" by Philip Newell.
  • Elements of Computer Music by F. Richard Moore. This book is for anyone interested in using computers to extend the boundaries of music.
  • Musical Signal Processing, 1997 Swets & Zeitlinger Publishers
  • Electronic and computer music by Manning Peter (2004)
  • Musimathics by Gareth Loy. An excellent introduction to anolog and digital signal processing, covering many basic concepts like filtering, convolution, sampling, and synthesis.
  • Digital Audio Signal Processing by Udo Zolzer
  • DAFX - Digital Audio Effects by direction Udo Zolzer

TODO

(flangers, reverbs, panning) and how/when to use them (help appreciated)

  • To insert other programs, after testing them: Wired (DAW with

nativeakai support), Seq24 (light sequencer for live performances), Bristol (moog emulator, etc)

Credits

Personal tools