How to use alsa loopback Device with jack audio backend?

Hi, this is as far as I’ve got:

Created /etc/modules-load.d/snd-aloop.conf with this contents:

snd-aloop

Created /etc/modprobe.d/snd-aloop.conf with following contents:

options snd-aloop pcm_substreams=2 # This limits the devices to 2, default is 8

Do sudo reboot to get the virtual loopback devices created.

I got this in my ~/.asoundrc:

# playback PCM device: using loopback subdevice 0,0
pcm.amix {
  type dmix
  ipc_key 219345
  slave {
    pcm "hw:Loopback,0,0"
    rate 48000
    period_size 2048
    buffer_size 32768
    period_time 0
    buffer_time 0
  }
}

# capture PCM device: using loopback subdevice 0,1
pcm.asnoop {
  type dsnoop
  ipc_key 219346
  slave {
    pcm "hw:Loopback,0,1"
    rate 48000
    period_size 2048
    buffer_size 32768
    period_time 0
    buffer_time 0
  }
}

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

# ------------------------------------------------------
# for jack alsa_in and alsa_out: looped-back signal at other ends
pcm.ploop {
  type plug
  slave {
    pcm "hw:Loopback,1,1"
    rate 48000
    period_size 2048
    buffer_size 32768
    period_time 0
    buffer_time 0
  }
}

pcm.cloop {
  type dsnoop
  ipc_key 219348
  slave {
    pcm "hw:Loopback,1,0"
    rate 48000
    period_size 2048
    buffer_size 32768
    period_time 0
    buffer_time 0
  }
}

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

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

Then in one session, run:

alsa_in -j cloop -dcloop

This should create the ALSA Jack bridge client, you should see it in patchage, you should connect it to system playback ports.

Then if you run for example:

mplayer -ao alsa some.mp3

it should play through the loopback device, then go through the ‘cloop’ Jack client, and then to system playback output, if connection was made.

The Pulseaudio backend, used for browsers, seems to interfere a bit with the loopback devices, as it starts forwarding the loopback devices to the system output somehow. You can disable Pulseaudio by creating ~/.config/pulse/client.conf:

autospawn=no

and run pulseaudio -k to stop the Pulse audio backend.

Anyway, even though ALSA gets forwarded to the system playback via Jack, there’s still work to be done probably with .asoundrc, they playback is stuttering and seems to be playing at the wrong rate, so it must have something to do with the buffer sizes and sampling rate.