You are not logged in.

#1 2022-05-25 11:19:51

danboid
Member
Registered: 2009-11-12
Posts: 16

Documenting ALSA's snd_aloop module for recording ALSA output

We have this old thread, which has since been closed:

https://bbs.archlinux.org/viewtopic.php?id=147852

I have tried with no success to replicate this ALSA config so that I might be able to record my ALSA devices output directly using arecord, sox or ffmpeg etc. I would like to see this example config documented slightly better so that I might be able to get it working and then we could add this better documented config to the Arch ALSA wiki page because I know I won't be the last person wanting to set this up to avoid having to use JACK or having to use PA, which really doesn't like running as root which I happen to require.

There are two main reasons I've not been able to use the example ALSA config as-is (apart from not fully understanding it) and thats because I need to use a USB audio device which is not the first ALSA device. I have also been unsuccessful in getting the snd_aloop daemon to load as a different, greater than 0 ALSA device via its index kernel module option. In fact, when I pass any kernel arguments to snd_aloop module it fails to load.

Here is the example ALSA config as provided by kokoko3k, with comments added by me where I require clarification. I get the impression that this config is tailored for users who have ALSA device 0 as their main physical sound card and device 1 as the snd_aloop virtual ALSA device:

In /etc/asound.conf or your local user ALSA config:

pcm.!default {
  type asym
  playback.pcm "LoopAndReal"
  #capture.pcm "looprec"
  capture.pcm "hw:0,0" # This points to the physical device we wish to use as our source?
}

pcm.looprec {
    type hw
    card "Loopback"
    device 1    # My guess is that this line and the line below should reference a snd_aloop virtual device?
    subdevice 0
}


pcm.LoopAndReal {
  type plug
  slave.pcm mdev
  route_policy "duplicate"
}


pcm.mdev { 
  type multi
  slaves.a.pcm pcm.MixReale
  slaves.a.channels 2
  slaves.b.pcm pcm.MixLoopback
  slaves.b.channels 2
  bindings.0.slave a
  bindings.0.channel 0
  bindings.1.slave a
  bindings.1.channel 1
  bindings.2.slave b
  bindings.2.channel 0
  bindings.3.slave b
  bindings.3.channel 1
}


pcm.MixReale {
  type dmix
  ipc_key 1024
  slave {
    pcm "hw:0,0"  # I presume this should point to your primary physical ALSA device?
    rate 48000
    #rate 44100
    periods 128
    period_time 0
    period_size 1024 # must be power of 2
    buffer_size 8192
  }
}

pcm.MixLoopback {
  type dmix
  ipc_key 1025
  slave {
    pcm "hw:Loopback,0,0"  # How should this be configured? Would it be different for my config where device 0 is snd_aloop and 2 is my USB card?
    rate 48000
    #rate 44100
    periods 128
    period_time 0
    period_size 1024 # must be power of 2
    buffer_size 8192
  }
}

I've tried various combos of the settings in question with no luck. I presume this config only works if your physical sound card is ALSA device 0 and snd_aloop is device 1. I presume it can be configured to work with any configuration/order of ALSA devices.

Thanks!

Offline

#2 2022-05-25 11:56:15

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 23,940

Re: Documenting ALSA's snd_aloop module for recording ALSA output

Well what are your actual device specifics? Post/check

aplay -lL
arecord -lL

to see what the setup is like and which indices/PCMs point to where exactly.

Afaik normally snd_aloop should create a distinct loopback device for every physical card you have and you need to "hook" them up correctly, but without looking at how this actually looks like we can only guess. Or rather all the ones you marked as being unclear should become much more clear if you actually check what the device states are currently.

Last edited by V1del (2022-05-25 12:01:20)

Offline

#3 2022-05-25 16:18:11

danboid
Member
Registered: 2009-11-12
Posts: 16

Re: Documenting ALSA's snd_aloop module for recording ALSA output

My /etc/asound.conf:

pcm.!default {
  type asym
  playback.pcm "LoopAndReal"
  #capture.pcm "looprec"
  capture.pcm "hw:2,0" # This points to the physical device we wish to use as our source?
}

pcm.looprec {
    type hw
    card "Loopback"
    device 0    # My guess is that this line and the line below should reference a snd_aloop virtual device?
    subdevice 0
}


pcm.LoopAndReal {
  type plug
  slave.pcm mdev
  route_policy "duplicate"
}


pcm.mdev { 
  type multi
  slaves.a.pcm pcm.MixReale
  slaves.a.channels 2
  slaves.b.pcm pcm.MixLoopback
  slaves.b.channels 2
  bindings.0.slave a
  bindings.0.channel 0
  bindings.1.slave a
  bindings.1.channel 1
  bindings.2.slave b
  bindings.2.channel 0
  bindings.3.slave b
  bindings.3.channel 1
}


pcm.MixReale {
  type dmix
  ipc_key 1024
  slave {
    pcm "hw:2,0"  # I presume this should point to your primary physical ALSA device?
    rate 48000
    #rate 44100
    periods 128
    period_time 0
    period_size 1024 # must be power of 2
    buffer_size 8192
  }
}

pcm.MixLoopback {
  type dmix
  ipc_key 1025
  slave {
    pcm "hw:Loopback,0,0"  # How should this be configured? Would it be different for my config where device 0 is snd_aloop and 2 is my USB card?
    rate 48000
    #rate 44100
    periods 128
    period_time 0
    period_size 1024 # must be power of 2
    buffer_size 8192
  }
}

aplay -lL

$ aplay -lL
null
    Discard all samples (playback) or generate zero samples (capture)
samplerate
    Rate Converter Plugin Using Samplerate Library
speexrate
    Rate Converter Plugin Using Speex Resampler
jack
    JACK Audio Connection Kit
oss
    Open Sound System
pulse
    PulseAudio Sound Server
upmix
    Plugin for channel upmix (4,6,8)
vdownmix
    Plugin for channel downmix (stereo) with a simple spacialization
default
LoopAndReal
mdev
MixReale
MixLoopback
hw:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    Direct hardware device without any conversions
hw:CARD=Loopback,DEV=1
    Loopback, Loopback PCM
    Direct hardware device without any conversions
plughw:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    Hardware device with all software conversions
plughw:CARD=Loopback,DEV=1
    Loopback, Loopback PCM
    Hardware device with all software conversions
sysdefault:CARD=Loopback
    Loopback, Loopback PCM
    Default Audio Device
front:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    Front output / input
surround21:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    4.0 Surround output to Front and Rear speakers
surround41:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
dmix:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    Direct sample mixing device
dmix:CARD=Loopback,DEV=1
    Loopback, Loopback PCM
    Direct sample mixing device
usbstream:CARD=Loopback
    Loopback
    USB Stream Output
hw:CARD=X96MAX,DEV=0
    X96-MAX, 
    Direct hardware device without any conversions
hw:CARD=X96MAX,DEV=1
    X96-MAX, 
    Direct hardware device without any conversions
hw:CARD=X96MAX,DEV=2
    X96-MAX, 
    Direct hardware device without any conversions
plughw:CARD=X96MAX,DEV=0
    X96-MAX, 
    Hardware device with all software conversions
plughw:CARD=X96MAX,DEV=1
    X96-MAX, 
    Hardware device with all software conversions
plughw:CARD=X96MAX,DEV=2
    X96-MAX, 
    Hardware device with all software conversions
sysdefault:CARD=X96MAX
    X96-MAX, 
    Default Audio Device
dmix:CARD=X96MAX,DEV=0
    X96-MAX, 
    Direct sample mixing device
dmix:CARD=X96MAX,DEV=1
    X96-MAX, 
    Direct sample mixing device
dmix:CARD=X96MAX,DEV=2
    X96-MAX, 
    Direct sample mixing device
usbstream:CARD=X96MAX
    X96-MAX
    USB Stream Output
hw:CARD=UACDemoV10,DEV=0
    UACDemoV1.0, USB Audio
    Direct hardware device without any conversions
plughw:CARD=UACDemoV10,DEV=0
    UACDemoV1.0, USB Audio
    Hardware device with all software conversions
sysdefault:CARD=UACDemoV10
    UACDemoV1.0, USB Audio
    Default Audio Device
front:CARD=UACDemoV10,DEV=0
    UACDemoV1.0, USB Audio
    Front output / input
surround21:CARD=UACDemoV10,DEV=0
    UACDemoV1.0, USB Audio
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=UACDemoV10,DEV=0
    UACDemoV1.0, USB Audio
    4.0 Surround output to Front and Rear speakers
surround41:CARD=UACDemoV10,DEV=0
    UACDemoV1.0, USB Audio
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=UACDemoV10,DEV=0
    UACDemoV1.0, USB Audio
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=UACDemoV10,DEV=0
    UACDemoV1.0, USB Audio
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=UACDemoV10,DEV=0
    UACDemoV1.0, USB Audio
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=UACDemoV10,DEV=0
    UACDemoV1.0, USB Audio
    IEC958 (S/PDIF) Digital Audio Output
dmix:CARD=UACDemoV10,DEV=0
    UACDemoV1.0, USB Audio
    Direct sample mixing device
usbstream:CARD=UACDemoV10
    UACDemoV1.0
    USB Stream Output
**** List of PLAYBACK Hardware Devices ****
card 0: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 0: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 1: X96MAX [X96-MAX], device 0: fe.dai-link-0 (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: X96MAX [X96-MAX], device 1: fe.dai-link-1 (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: X96MAX [X96-MAX], device 2: fe.dai-link-2 (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: UACDemoV10 [UACDemoV1.0], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

arecord -lL

$ arecord -lL
null
    Discard all samples (playback) or generate zero samples (capture)
samplerate
    Rate Converter Plugin Using Samplerate Library
speexrate
    Rate Converter Plugin Using Speex Resampler
jack
    JACK Audio Connection Kit
oss
    Open Sound System
pulse
    PulseAudio Sound Server
upmix
    Plugin for channel upmix (4,6,8)
vdownmix
    Plugin for channel downmix (stereo) with a simple spacialization
default
LoopAndReal
mdev
MixReale
MixLoopback
hw:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    Direct hardware device without any conversions
hw:CARD=Loopback,DEV=1
    Loopback, Loopback PCM
    Direct hardware device without any conversions
plughw:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    Hardware device with all software conversions
plughw:CARD=Loopback,DEV=1
    Loopback, Loopback PCM
    Hardware device with all software conversions
sysdefault:CARD=Loopback
    Loopback, Loopback PCM
    Default Audio Device
front:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    Front output / input
dsnoop:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    Direct sample snooping device
dsnoop:CARD=Loopback,DEV=1
    Loopback, Loopback PCM
    Direct sample snooping device
usbstream:CARD=Loopback
    Loopback
    USB Stream Output
usbstream:CARD=X96MAX
    X96-MAX
    USB Stream Output
hw:CARD=UACDemoV10,DEV=0
    UACDemoV1.0, USB Audio
    Direct hardware device without any conversions
plughw:CARD=UACDemoV10,DEV=0
    UACDemoV1.0, USB Audio
    Hardware device with all software conversions
sysdefault:CARD=UACDemoV10
    UACDemoV1.0, USB Audio
    Default Audio Device
front:CARD=UACDemoV10,DEV=0
    UACDemoV1.0, USB Audio
    Front output / input
dsnoop:CARD=UACDemoV10,DEV=0
    UACDemoV1.0, USB Audio
    Direct sample snooping device
usbstream:CARD=UACDemoV10
    UACDemoV1.0
    USB Stream Output
**** List of CAPTURE Hardware Devices ****
card 0: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 0: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 2: UACDemoV10 [UACDemoV1.0], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

Offline

#4 2022-05-25 16:28:54

danboid
Member
Registered: 2009-11-12
Posts: 16

Re: Documenting ALSA's snd_aloop module for recording ALSA output

When I'm not trying to use snd_aloop I need to use:

defaults.pcm.card 1
defaults.ctl.card 1

For my asound.conf to tell it to use my USB soundcard by default. ALSA device 0 only works via HDMI.

Thankfully the app I'm trying to record, moc, also supports JACK so I can use JACK instead if I don't get this working but I was hoping JACK could be avoided when all a user wishes to do is record the output of a single ALSA app.

Last edited by danboid (2022-05-25 22:36:43)

Offline

Board footer

Powered by FluxBB