Audio mixer of two or more sound cards on realtime Linux and Reaper

When you play in a group, you need to rehearse somewhere. Let's try at home to assemble your own mixer with effects from what is at hand. And at hand I have a 2-core computer with a built-in and 2 additional audio cards, ESI Juli @ and C-Media CM8738. Total 6 channels for recording.
If 2 channels are enough, then you can no longer read, because 2 channels can be mixed through Reaper under Windows with asio4all (or native drivers), it will play without problems. All complexity begins when you want to make one virtual and multi-channel from 3 cards. Through asio4all, simultaneously recording 6 channels at an acceptable level of quality (even for rehearsals) did not work (due to different clock sources on the cards, as well as due to rare slowdowns), which is why I had to go this difficult way.

We will all be running under Linux with a realtime kernel. Realtime patch is desirable, but not necessary, without it it will also work, except with a longer delay and not so stable. The distribution will be Debian, not RemixOS, because, firstly, I want to understand what is happening, whether it is possible to twist something and nothing will break, secondly, it will be necessary to patch wineasio a bit, and thirdly, remixos has a terrible desktop . I won’t tell you how to install Debian, a lot has already been written on this topic. So, we have a freshly installed Debian 6.0.3 with the desktop. It will look almost like this, except that there will be no icons on the desktop:

First, update (if Debian was not installed with netinstall). In the root console (Applications-> Accessories-> Root Terminal)
#aptitude update && aptitude safe-upgrade

Now we put the pengutronix kernel, already compiled by realtime, again in the root console:

#wget -O /etc/apt/sources.list.d/pengutronix.list http://debian.pengutronix.de/debian/pengutronix.list 
#aptitude update
#apt-get -q --allow-unauthenticated install pengutronix-archive-keyring
#aptitude update
#aptitude install linux-image-2.6-rt-osadl-686

We reboot on it, look what uname will say:

root@debian:/home/vasiliy# uname -a
Linux debian 2.6.33.7.2-rt30-1-686 #1 SMP PREEMPT RT Mon Jan 17 14:22:44 UTC 2011 i686 GNU/Linux
root@debian:/home/vasiliy# 

Next, we optionally delete update-notifier (or turn it off somehow):

#aptitude purge update-notifier update-notifier-common

Now we put the necessary packages. The first is the JACK daemon. It is to him that audio applications will connect. And he, in turn, through ALSA connects to the sound card.

#aptitude install jackd2 qjackctl jackeq

Audacity, for checks

#aptitude install audacity

Packages to collect wineasio

#aptitude install build-essential libjack-jackd2-dev libwine-dev

And Wine to run Reaper. Wine can be delivered from repositories, or you can compile it yourself with the rt patch. The patch is needed so that wine can give realtime priorities to the necessary streams. Those. with ordinary wine, all reaper-a flows will be in sched_other, no matter how the application you want to run (or everything in sched_fifo, if all wine is run through schedtool), and with a patch, the ripper will tell itself which flows are critical (which process sound) and which threads are not (this is a graphical interface and everything else). In short, from the point of view of the scheduler, a thread can have a class and a priority. A class is sched_fifo, sched_rr, sched_other (aka sched_normal), sched_batch, and some others. There are two points of interest in terms of sound, these are ordinary (sched_other) and real-time (sched_fifo). A thread that runs with the sched_fifo class, cannot be interrupted by a stream with the sched_other class. Those. all sched_other will fail until someone from sched_fifo has something to do. It's good that most of the time sched_fifo-streams wait for something, a signal from the equipment, for example. In our case, the sound streams (sched_fifo) will wait until the incoming audio buffer is full, when the signal arrives that the buffer is ready to process it quickly, quickly, put the result in the outgoing buffer and wait again. And during these breaks, a graphical interface, etc. will be drawn. when the signal arrives that the buffer is ready it will be processed quickly and quickly, they will put the result in the outgoing buffer and will wait again. And during these breaks, a graphical interface, etc. will be drawn. when the signal arrives that the buffer is ready it will be processed quickly and quickly, they will put the result in the outgoing buffer and will wait again. And during these breaks, a graphical interface, etc. will be drawn.
So, option 1, put the usual wine (not desirable):

#aptitude install wine schedtool

And option 2, we collect wine 1.2.3 with a patch (I’ll say right away that this is not the correct debian-way, in the right way you need to collect the package and install it, but it's just a little more complicated):

#aptitude build-dep wine
#exit
$wget http://ibiblio.org/pub/linux/system/emulators/wine/wine-1.2.3.tar.bz2     #Ссылка с официального сайта winehq.com
$tar xjvf wine-1.2.3.tar.bz2   #Ясно что, распаковываем
$cd wine-1.2.3
$wget http://dl.dropbox.com/u/879835/wine-rt-101107.patch    #Собственно, сам патч. Ссылку взял с http://wiki.cockos.com/wiki/index.php/Installing_and_configuring_Wine
$patch -p1 -i wine-rt-101107.patch     #Патчим
$./configure --prefix=/usr && make depend && make # make depend важен!
$su
#make install



Since we will run Reaper, jackd, and so on, not from the root, but from our user, we need to adjust the limits, otherwise the operating system will not let us run so much software, eat a lot of memory and get realtime priorities. Edit /etc/security/limits.conf

#gedit /etc/security/limits.conf 

and write there (naturally, instead of vasiliy you need to put your login in the system)

vasiliy	-	memlock	unlimited
vasiliy	-	rtprio	99
vasiliy	-	nice	-20

For the limits to apply, you need to log in or reboot. We check that everything is ok with limits:

vasiliy@debian:~$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 40
file size               (blocks, -f) unlimited
pending signals                 (-i) 16382
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 99
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) unlimited
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
vasiliy@debian:~$ 

We look that max locked memory unlimited and move on. Now we will configure and verify ALSA and JACK. It is logical to start with ALSA, start Audacity, go to settings:

select ALSA, start Audacity to record, see what works, listen to what happened (here I just touched the jack with my finger):

If something doesn’t work, for example, it plays, but doesn’t writes (you can import any mp3-shku into Audacity for verification), or writes with great noise, you need to look at the ALSA settings, System-> Options-> Sound. On my Juli @, everything worked right away, but with the built-in and c-media cards, it worked out:
C-Media Electronics Inc CM8738 (rev 10)




Built-in Intel Corporation 82801JI (ICH10 Family) HD Audio Controller





Interestingly, even the built-in card on the linear input gives a pretty good signal. The only thing is that it must be powerful enough, otherwise it makes noise. The volume level for “Capture”, the “Record” tab of Intel’s HDA, is specially at 25%, so I have the least noise. An electric guitar, for example, doesn’t write like that, but if you pass the same guitar through some preamplifier (in my case it’s ART Tube MP), you get very nothing, you can even turn on the program distortion.

Now configure JACK. Launch qjackctl through Applications-> Audio and video-> JACK Control (or in the qjackctl terminal), click on “Parameters”:

Select the main interface, I have it juli @, it is on hw: 2 (you can see the list of cards and what numbers they received) in / proc / asound / cardsThe sound card number is not always saved after a reboot, even if all the cards are pci). We turn on real-time mode, set the buffer size, discretization, run jackd, and through Audacity we check what works (in the Audacity settings, do not forget to switch to JACK). It is also advisable to check the recording (and sound output) on other cards through JACK.
And now the interesting part begins. We will connect the remaining audio interfaces to the main one. Still, run qjackctl, start and write in a separate terminal:

$alsa_in -d hw:0 -j hda-intel -p 512 -n 2

hw: 0 is a built-in card, hda-intel is just a tag, you can without it, 512 is the size of the buffer, 2 is their number. The size of the buffer and the number are selected minimally working (normally working means that alsa_in does not constantly display “delay = <anything>”), ​​in my case it turned out 512 (and then 128) samples and two buffers, not bad. For the rest (the rest) the sound is the same.


You can verify that everything works through jackeq (Applications-> Audio and video-> JackEq or, like me, in the jackeq terminal). We select the input ports, output ports, raise the volume of the channels, the master volume, watch and listen. At this step, you can experiment with the sizes of the JACK and alsa_in buffers (jackeq will have to be restarted).


Actually, some kind of simple mixer is already there. But you want more, a lot of effects, vst-plugins and so on. You can install Ardor, you can rebuild ardor with support for windows VST plug-ins, you can install Mixbus. All this is DAW (Digital Audio Workstation), through them it is quite possible to mix for rehearsals. I preferred Reaper because, firstly, it’s more familiar to me, secondly, it has quite good built-in effects in it, thirdly, it has a convenient mixer, you can put effect control knobs on the main mixer, fourthly, you can set up hotkeys in the mixer for almost everything, fifthly, it works with VST; sixth, Reaper is a live software that is constantly evolving.
Download and install from reaper.fm, you can trial version. It’s too early to launch Reaper itself, we don’t have a bunch of jack-asio. You need to download, patch, compile and install wineasio (http://sourceforge.net/projects/wineasio/). You can download the stable version (0.9.0), or you can download development from git. The version that lies in git differs slightly from the stable one, but it started with my 32-sample JACK buffer, so it’s better to download it:

git clone git://wineasio.git.sourceforge.net/gitroot/wineasio/wineasio

In order to build wineasio, you need the asio.h file, which is contained in the Steinberg ASIO SDK. Unfortunately, Steinberg forbids distributing this file, so we download it ourselves from the Steinberg website (http://www.steinberg.net/en/company/developer.html), and put it in the folder with the unpacked wineasio. Now you need to patch asio.c:
/* Находим такую строчку */
This->jack_input_ports = jack_get_ports(This->jack_client, NULL, NULL, JackPortIsPhysical | JackPortIsOutput); 
/* и заменяем её на такую: */
This->jack_input_ports = jack_get_ports(This->jack_client, NULL, NULL, JackPortIsOutput); 
/* И с такой тоже самое, найти */
This->jack_output_ports = jack_get_ports(This->jack_client, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
/* Заменить на */
This->jack_output_ports = jack_get_ports(This->jack_client, NULL, NULL, JackPortIsInput);


In this patch we will remove the JackPortIsPhysical flag so that wineasio immediately connects to all JACK ports, including virtual ones that we created through alsa_in.
We compile, install:

$make
$su
#make install
#exit
$wine regsvr32 wineasio.dll


Test run of Reaper, check that wineasio has appeared:

wineasio is configured through the registry:

$wine regedit


Of the interesting settings, there is only Number of inputs / ouputs, you can put some amount more similar to reality. It is advisable to leave Fixed buffersize at “1” so that the size of the buffer determines JACK.
We start Reaper again, depending on whether the patched wine is or not, the launch command will be different:

$wine 'c:\program files\reaper\reaper.exe' # Это по обычному, с классом sched_other, приоритет 0 (обычный)
$nice -n -20 wine 'c:\program files\reaper\reaper.exe' # То же самый класс, только самый большой приоритет
$schedtool -F -p 10 -e wine 'C:\program files\reaper\reaper.exe' # Весь Reaper запускается в realtime. Может иногда предпочесть перерисовать интерфейс вместо того, чтобы обработать аудио.
$env WINE_RT=15 WINE_SRV_RT=10 wine 'C:\program files\reaper\reaper.exe'  # Самый предпочтительный вариант, Reaper сам укажет что важно, а что не очень.

Set it up for better work under wine:
Uncheck “Preferences-> Buffering-> Use native events for syncronizing”, and in “Preferences-> Appearances-> UI updates” select “Lazy always”.



Well, now it remains only to add the required number of tracks to the Reaper, turn them on for recording and monitoring, add effects and play:


Successful rehearsals for you!

PS:
  • Under this version of wine 1.0.1, I only started the 3rd Guitar Rig, the 4th and 5th are not installed. Although rehearsing and the third is enough. With GuitarRig, you need to be somewhat careful, if you quickly switch presets, then it flies out with the ripper. I would like to find some alternative that works more stably under wine.
    Under version wine 1.2.3 Guitar Rig 5 is installed, it works fine, it does not crash.
  • With wineasio 0.9.0, delays on the main card with buffer 256 turned out to be about 20 ms, on the additional about 30 ms (corrected, thanks egorinsk ).
    But on git versions wineasio and smaller sizes work, now on the main card there is a buffer size of 32, which gives a delay of 1.4 ms, and alsa_in buffer 128, i.e. on additional cards it turned out 6 ms.
  • It also works in four cards, I connected the EMU-0202 USB.
  • I did not find the VST feedback suppressor, it is necessary to press the whistling frequencies manually through the equalizer.
  • I don’t know how to properly install the nvidia driver on the realtime kernel.
  • There is a feature in Reaper that it does not prioritize streams during startup, but as soon as playback / recording starts. Those. if you make a project with a mixer, after opening it you will have to press play / stop. See what streams are, what class and priority they have through
    
    ps -emo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm 
    


    It can be seen that reaper.exe has 3 FF (sched_fifo) streams, one with a priority of 5 (this is the one that jack created for it, this priority can be configured via qjackctl), and two (I have two cores) with a priority of 20, this effects processing threads, their Reaper requested with priority THREAD_PRIORITY_HIGHEST.


In general, do not be lazy to put the realtime kernel, wine with the realtime patch, and the wineasio version with git. The results should be very good.

Links:
debian.org
pengutronix.de/software/linux-rt/debian_en.html
reaper.fm
sourceforge.net/projects/wineasio
www.steinberg.net/en/company/developer.html
wiki.cockos.com/wiki/index .php / How_to_run_Reaper_in_Wine_on_Linux

Also popular now: