Zend certified PHP/Magento developer

Configuring ALSA using loopback to output audio through both audio jack and program simultaneously

I’m having a lot of trouble configuring ALSA and loopback on my system [ubuntu 22.04]. I want to combine the headphone and loopback streams so that when I play any audio, I can hear it from the audio jack as well as it being looped back which I can use with a program. [To analyze it’s frequency pattern]

I was following instructions from https://github.com/maximtrp/spectrumLED and loaded a loopback kernel snd-aloop

aplay -l outputs the following;

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones]
  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: 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 1: 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

and I tried to create a asound.conf in /etc as follows;

pcm.!default {
    type plug
    playback.pcm "out"
    capture.pcm "loopin"
}
pcm.out {
    type plug
    slave.pcm {
        type multi
        slaves {
            a { channels 2 pcm "output" }
            b { channels 2 pcm "loopout" }
        }
        bindings {
            0 { slave a channel 0 }
            1 { slave a channel 1 }
            2 { slave b channel 0 }
            3 { slave b channel 1 }
        }
    }
    ttable [
        [ 1 0 1 0 ]   # left  -> a.left,  b.left
        [ 0 1 0 1 ]   # right -> a.right, b.right
    ]
}

pcm.loopout {
    type dmix
    ipc_key 1025
    slave.pcm "hw:1,0,0"
    slave {
        period_time 0
        period_size 1024
        buffer_size 8192
        channels 2
    }
    bindings {
        0 0
        1 1
    }
}

pcm.loopin {
    type plug
    slave.pcm "hw:1,1,0"
}

pcm.output {
    type dmix
    ipc_key 1024
    slave.pcm "hw:0,0"
    slave {
        period_time 0
        period_size 1024
        buffer_size 8192
        channels 2
    }
    bindings {
        0 0
        1 1
    }
}

However, whatever I do, the loopback doesn’t seem to work simultaneously along with the playback; so I can either hear the playback using

$ aplay file.wav

[or]

$ mpv music.mp3

which only provides audio output from the headphone jack nd doesn’t send a stream to the program Im trying to use to analyze the freq…

The only method that seems to work is using

$ aplay file.wav -D hw:1,1

but this doesn’t play any output from the audio jack;

is there something wrong with my asound.conf?

I tried scouring thru the net but I cudn’t find anything that worked;

I tried a basic version from https://stackoverflow.com/questions/7002423/how-to-mix-multiple-pcm-streams-using-alsa

asound.conf

pcm.!default {
              type plug
              slave.pcm "dmixer"
}
pcm.dmixer  {
            type dmix
        ipc_key 1024
        slave {
          pcm "hw:1,0"
          period_time 0
              period_size 1024
          buffer_size 4096
          rate 44100
        }
        bindings {
          0 0
          1 1
        }
}
ctl.dmixer {
       type hw
       card 0
}

but this doesn’t seem to work either;

I’m also really confused as to why there are 2 loopbacks;

Can anyone clear this for me? How does this dmix and multi plugin even work? the docs seem so confusing