ALSA-Programs and JACK together

Post fully complete "how to" guides and tutorials here. This is a great place to get feedback on stuff you might put in the wiki.

Moderators: khz, MattKingUSA

User avatar
bluebell
Established Member
Posts: 1129
Joined: Sat Sep 15, 2012 11:44 am
Location: Saarland & Frankfurt, Germany

ALSA-Programs and JACK together

Postby bluebell » Sat Sep 22, 2012 6:41 am

Hi all,

JACK grabs the audio interface exclusively. Maybe it's handy for someone to know that ALSA can redirect ALSA-output to JACK. So you can have audio output from your browser with flash-plugin while running JACK. Just use the following ~/.asoundrc or /etc/asound.conf:

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

pcm.jack {
type jack
playback_ports {
0 system:playback_1
1 system:playback_2
}
capture_ports {
0 system:capture_1
1 system:capture_2
}
}
Linux – MOTU UltraLite AVB – Qtractor – https://soundcloud.com/suedwestlicht

User avatar
reteo
Established Member
Posts: 15
Joined: Thu Aug 11, 2011 10:07 pm
Location: Phoenix, AZ
Contact:

Re: ALSA-Programs and JACK together

Postby reteo » Tue Oct 16, 2012 10:36 pm

This setup does great if you want Jack to be the general sound system for your computer. However, the problem with this setup is that it is not persistent; once the sound source stops, its entry in the connection graph is gone, and the next time it appears, any changes you make is also gone, and it just points back to the speakers.

Originally, I wrote an article about using the alsa_in and alsa_out commands along with the ALSA loopback drivers in order to create a workaround to allow non-Jack programs to have a Jack-linkup device to use. (http://www.penguinproducer.com/2011/09/ ... jack-apps/) However, since then, a new set of tools have been released that can successfully supplant the alsa_in and alsa_out commands, called "zita-ajbridge." (http://apps.linuxaudio.org/apps/all/zita-ajbridge). These commands won't work with dmix-based devices like alsa_out does, but for the purpose of the bridge, they are excellent to use. I plan to be updating the article to include these commands.
Lampros Liontos (aka Reteo Varala)

The Penguin Producer - Tips, tricks and techniques for producing multimedia with Linux.

User avatar
Capoeira
Established Member
Posts: 1226
Joined: Tue May 12, 2009 1:01 pm
Location: Brazil

Re: ALSA-Programs and JACK together

Postby Capoeira » Wed Oct 17, 2012 2:09 am

reteo wrote:However, since then, a new set of tools have been released that can successfully supplant the alsa_in and alsa_out commands, called "zita-ajbridge." (http://apps.linuxaudio.org/apps/all/zita-ajbridge). These commands won't work with dmix-based devices like alsa_out does, but for the purpose of the bridge, they are excellent to use. I plan to be updating the article to include these commands.



ooh, didn't knew about that one.
very interested (though I only need it for Skype)

User avatar
reteo
Established Member
Posts: 15
Joined: Thu Aug 11, 2011 10:07 pm
Location: Phoenix, AZ
Contact:

Re: ALSA-Programs and JACK together

Postby reteo » Wed Oct 17, 2012 8:16 am

falkTX wrote:I'm working on a solution that is currently implemented in KXStudio, but should be ready for a wider audience soon.
It's basically using alsa-in/out with a very tweaked asoundrc file, but managed through a GUI.

hopefully it won't take much long for the first beta release... :D


I noticed that you included zita-ajbridge in your package collection... why not use that in place of alsa-in/out? Or were you planning to use dmix on this GUI tool? Either way, it promises to be very, very cool... as proud as I am about my articles on the bridge, more automation is always teh win.
Lampros Liontos (aka Reteo Varala)

The Penguin Producer - Tips, tricks and techniques for producing multimedia with Linux.

User avatar
reteo
Established Member
Posts: 15
Joined: Thu Aug 11, 2011 10:07 pm
Location: Phoenix, AZ
Contact:

Re: ALSA-Programs and JACK together

Postby reteo » Wed Oct 17, 2012 4:34 pm

falkTX wrote:
reteo wrote:I noticed that you included zita-ajbridge in your package collection... why not use that in place of alsa-in/out? Or were you planning to use dmix on this GUI tool? Either way, it promises to be very, very cool... as proud as I am about my articles on the bridge, more automation is always teh win.

I tried it, but it doesn't work for the target purposes, which are:
- having a bridge always present
- apps still working when jack is stopped (but no sound). Sound is restored when JACK starts again

I don't remember the exact details now, but I really tried to make zita-a2jbridge/j2abridge to work on this scenario, but it failed...
Honestly, on the few times that it worked it consumed too much CPU when compared to alsa-in/out. For something that will be (almost) always running, that's really bad (alsa-in/out doesn't go over 1% usage in my system)


Does it really need to be always present? I usually don't turn on the bridges unless there's an app that needs to use one; In those cases, I just add the associated command to the project I'm working on.

Come to think of it, a good start would be to create an ALSA tab in the Claudia launcher in which you can add ALSA devices to the current room with the appropriate alsa_* commands, while marking the Loopback devices as bridges.
Lampros Liontos (aka Reteo Varala)

The Penguin Producer - Tips, tricks and techniques for producing multimedia with Linux.

User avatar
Capoeira
Established Member
Posts: 1226
Joined: Tue May 12, 2009 1:01 pm
Location: Brazil

Re: ALSA-Programs and JACK together

Postby Capoeira » Sun Nov 25, 2012 4:36 pm

reteo wrote:I noticed that you included zita-ajbridge in your package collection... why not use that in place of alsa-in/out?


anybody got this working?

I can't manage to conect to the alsa devices:

Code: Select all

Can't open ALSA capture device 'cloop'.
Can't open ALSA playback device 'ploop'.

User avatar
Capoeira
Established Member
Posts: 1226
Joined: Tue May 12, 2009 1:01 pm
Location: Brazil

Re: ALSA-Programs and JACK together

Postby Capoeira » Sun Nov 25, 2012 5:02 pm

falkTX wrote:
Capoeira wrote:
reteo wrote:I noticed that you included zita-ajbridge in your package collection... why not use that in place of alsa-in/out?


anybody got this working?

I can't manage to conect to the alsa devices:

Code: Select all

Can't open ALSA capture device 'cloop'.
Can't open ALSA playback device 'ploop'.

I tried the zita stuff some time ago, it seems to work differently than expected.
For once, I could only start it if there was an alsa app running and using the loopback. I don't know if that's intended, but alsa_in/out already works fine, so I skipped this.



I found the solution here: http://web.archiveorange.com/archive/v/ ... jOLOoAUwbk

I had to adress directly to the Loopback device AND force 16bit

It runs GREAT
no cracling in Skype anymore
CPU usage is 1% also

The lines in your script I've changed are now:

Code: Select all

 
system("env JACK_SAMPLE_RATE=%i JACK_PERIOD_SIZE=%i zita-a2j -L -j alsa_in -d hw:Loopback,1,0 2>&1 1> /dev/null &" % (sample_rate, buffer_size))
  system("env JACK_SAMPLE_RATE=%i JACK_PERIOD_SIZE=%i zita-j2a -L -j alsa_out -d hw:Loopback,1,1 2>&1 1> /dev/null &" % (sample_rate, buffer_size))


perhaps you try it out again?

User avatar
Capoeira
Established Member
Posts: 1226
Joined: Tue May 12, 2009 1:01 pm
Location: Brazil

Re: ALSA-Programs and JACK together

Postby Capoeira » Sun Nov 25, 2012 7:01 pm

falkTX wrote:For once, I could only start it if there was an alsa app running and using the loopback..


this was mentioned in the link I posted.
Forcing zita bridge to 16bit (-L) solves this

User avatar
Capoeira
Established Member
Posts: 1226
Joined: Tue May 12, 2009 1:01 pm
Location: Brazil

Re: ALSA-Programs and JACK together

Postby Capoeira » Sun Nov 25, 2012 9:45 pm

I agree that it's kind of unstable


falkTX wrote:I added support for it in my script:
https://github.com/falkTX/Cadence/blob/ ... _daemon.py
(^This version is a lot more recent that the one you have, but requires python3 + PyQt4, and must be run locally to catch jacklib.py)


This only works with cadence, no?

User avatar
Capoeira
Established Member
Posts: 1226
Joined: Tue May 12, 2009 1:01 pm
Location: Brazil

Re: ALSA-Programs and JACK together

Postby Capoeira » Sun Nov 25, 2012 11:28 pm

I updated cadence here in Arch from git and changed "useZita = True" in /usr/share/cadence/src/cadence_aloop_daemon.py,
but starting the bridge in cadence it still uses alsa_in/out

User avatar
Capoeira
Established Member
Posts: 1226
Joined: Tue May 12, 2009 1:01 pm
Location: Brazil

Re: ALSA-Programs and JACK together

Postby Capoeira » Mon Nov 26, 2012 2:30 am

falkTX wrote:
Capoeira wrote:I agree that it's kind of unstable


falkTX wrote:I added support for it in my script:
https://github.com/falkTX/Cadence/blob/ ... _daemon.py
(^This version is a lot more recent that the one you have, but requires python3 + PyQt4, and must be run locally to catch jacklib.py)


This only works with cadence, no?

no, it works as a generic python(3) script. You just need to have jacklib.py at its side (and the asoundrc file set properly, of course).
The previous version had a small jacklib version built-in, but it's much easier to maintain and fix if it uses the the external jacklib.py.


now I got it. it's not using zita-bridge though, see my post above

User avatar
Capoeira
Established Member
Posts: 1226
Joined: Tue May 12, 2009 1:01 pm
Location: Brazil

Re: ALSA-Programs and JACK together

Postby Capoeira » Mon Nov 26, 2012 11:22 am

falkTX wrote:
Capoeira wrote:now I got it. it's not using zita-bridge though, see my post above

You don't need to edit the file manually, just run it with "--zita".
(Editing the file manually won't work, since it later checks for the "--zita" argv and changes 'useZita' accordingly).



I see, worked


BUT, how to do it in Cadence? there is no option to change to zita.

User avatar
lilith
Established Member
Posts: 1023
Joined: Fri May 27, 2016 11:41 pm
Location: bLACK fOREST
Contact:

Re: ALSA-Programs and JACK together

Postby lilith » Sun Jan 08, 2017 9:36 pm

Is there any update on this? I got cracking with the alsa in/out bridge which is totally gone with the zita bridge. However to get the zita bridge running after a reboot is not that straight forward. I stopped cadence and connections several times and re-opend firefox, etc. ... At some point it worked. CPU usage is < 1% (as seen in system monitor zita-j2a/a2j).

One more question: Do I need to do anything else (theoretically) besides starting jack and the alsa -> loop -> jack with zita? E.g. do I have to modify the .asoundrc - file? Once I did some changes in the file (replacing 44100 with 48000), but somehow it was overwritten again. Shoukd I add the zita bridge in this file somehow?

Code: Select all

# ------------------------------------------------------
# Custom asoundrc file for use with snd-aloop and JACK
#
# use it like this:
# env JACK_SAMPLE_RATE=44100 JACK_PERIOD_SIZE=1024 alsa_in (...)
#

# ------------------------------------------------------
# playback device
pcm.aloopPlayback {
  type dmix
  ipc_key 1
  ipc_key_add_uid true
  slave {
    pcm "hw:Loopback,0,0"
    format S32_LE
    rate {
      @func igetenv
      vars [ JACK_SAMPLE_RATE ]
      default 44100
    }
    period_size {
      @func igetenv
      vars [ JACK_PERIOD_SIZE ]
      default 1024
    }
    buffer_size 4096
  }
}

# capture device
pcm.aloopCapture {
  type dsnoop
  ipc_key 2
  ipc_key_add_uid true
  slave {
    pcm "hw:Loopback,0,1"
    format S32_LE
    rate {
      @func igetenv
      vars [ JACK_SAMPLE_RATE ]
      default 44100
    }
    period_size {
      @func igetenv
      vars [ JACK_PERIOD_SIZE ]
      default 1024
    }
    buffer_size 4096
  }
}

# duplex device
pcm.aloopDuplex {
  type asym
  playback.pcm "aloopPlayback"
  capture.pcm "aloopCapture"
}

# ------------------------------------------------------
# default device
pcm.!default {
  type plug
  slave.pcm "aloopDuplex"
}

# ------------------------------------------------------
# alsa_in -j alsa_in -dcloop -q 1
pcm.cloop {
  type dsnoop
  ipc_key 3
  ipc_key_add_uid true
  slave {
    pcm "hw:Loopback,1,0"
    channels 2
    format S32_LE
    rate {
      @func igetenv
      vars [ JACK_SAMPLE_RATE ]
      default 44100
    }
    period_size {
      @func igetenv
      vars [ JACK_PERIOD_SIZE ]
      default 1024
    }
    buffer_size 32768
  }
}

# ------------------------------------------------------
# alsa_out -j alsa_out -dploop -q 1
pcm.ploop {
  type plug
  slave.pcm "hw:Loopback,1,1"
}


Sry, I'm a noob :oops:
https://soundcloud.com/lilith_93

_____________________________
Debian 9 (XFCE) & KXStudio repos

rghvdberg
Established Member
Posts: 919
Joined: Mon May 12, 2014 7:11 am

Re: ALSA-Programs and JACK together

Postby rghvdberg » Mon Jan 09, 2017 6:28 am

Update cadence. There is a switch to use zita instead of alsa in / out in de alsa bridge.

User avatar
lilith
Established Member
Posts: 1023
Joined: Fri May 27, 2016 11:41 pm
Location: bLACK fOREST
Contact:

Re: ALSA-Programs and JACK together

Postby lilith » Mon Jan 09, 2017 9:03 pm

rghvdberg wrote:Update cadence. There is a switch to use zita instead of alsa in / out in de alsa bridge.


thanks, i'm using that already.
https://soundcloud.com/lilith_93

_____________________________
Debian 9 (XFCE) & KXStudio repos


Return to “HOW TOs, Tips & Tricks”

Who is online

Users browsing this forum: No registered users and 1 guest