Building & installing the ALSA loopback device under Ubuntu

The ALSA Loopback sound card is a virtual soundcard that is created once the ALSA kernel module snd-aloop is loaded. This virtual soundcard device, as its name indicates, sends back the output signal of applications using it back to itself, so one has a chance to e.g. record this signal from the same device. Simply imagine that you have a physical link between one OUT and one IN of the same device. By default, the Loopback sound card consists of 2 devices, each composed of 8 subdevices. 

I required the ALSA Loopback device to re-route sound from one application to another when streaming Airplay to a Logitech Squeezebox see here. Read on to see how I installed the ALSA loopback on Ubuntu 10.04...


Once the kernel module snd-aloop is loaded, you can verify that the sound card has been created by using aplay -l

Which once the loopback device installed will return something akin to:


**** List of PLAYBACK Hardware Devices ****
card 0: NVidia [HDA NVidia], device 0: ALC887 Analog [ALC887 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 1: ALC887 Digital [ALC887 Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 3: NVIDIA HDMI [NVIDIA HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]
  Subdevices: 7/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: 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

Install the ALSA loopback device from source code

1. Check for you version of ALSA as the source code needs to match this version number
sudo  cat /proc/asound/version

2. Check if you already have the loopback device, if you get and error or no output it's safe to say you haven't.
sudo modinfo snd-aloop

3. Backup your current ALSA module to somewhere safe (home directory?)
cd ~
mkdir alsa-backup
cd alsa-backup
cp -a /lib/modules/`uname -r`/kernel/sound  .

4. As a prerequisite you need a compiler and other tools. In debian based distros, you can install a package called build-essential to provide a compiler
sudo apt-get install build-essential

5. Download the ALSA source code for your current version of ALSA, where XX is the version number
cd /usr/src/modules
sudo wget ftp://ftp.alsa-project.org/pub/driver/alsa-driver-1.0.XX.tar.bz2

6. Extract ALSA
sudo tar xjvf alsa-driver-1.0.XX.tar.bz2
cd alsa-driver-1.0.XX

7. Check which hardware drivers you already have installed
sudo cat /proc/asound/modules

For me this returned:

0 snd_hda_intel

8. Configure the new ALSA modules to be built with support with the hardware detected above

sudo ./configure --with-cards=hda_intel,loopback,hrtimer --with-sequencer=yes
sudo make 
sudo make install

9. Unload the old ALSA drivers / modules
sudo alsa force-unload

10. Detect your new ALSA loopback device
sudo modprobe snd-aloop

11. Check the loopback device has installed ok
lsmod | grep aloop

My successful install returned

snd_aloop               5913  4 
snd_pcm                70694  5 snd_aloop,snd_hda_intel,snd_hda_codec
snd                    54244  17 snd_aloop,snd_hda_codec_realtek,snd_hda_intel,snd_hda_codec,snd_hwdep,snd_pcm,snd_timer

Alternatively use aplay -l

12. Create the asound config file this verbatim from the ALSA JACK guide

vi ~/.asoundrc


The goal is to create a default ALSA plug device out of the Loopback card. For a complete software solution, we need one PCM playback, so ALSA apps can send audio to it, one PCM capture, so ALSA apps can get audio from it, and combine these 2 PCMs into a nice full duplex "plug" device.



# playback PCM device: using loopback subdevice 0,0
pcm.amix {
  type dmix
  ipc_key 219345
  slave.pcm "hw:Loopback,0,0"
}

# capture PCM device: using loopback subdevice 0,1
pcm.asnoop {
  type dsnoop
  ipc_key 219346
  slave.pcm "hw:Loopback,0,1"
}

# 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"
}

pcm.cloop {
  type dsnoop
  ipc_key 219348
  slave.pcm "hw:Loopback,1,0"
}

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

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


13. Load the alsa config

sudo killall pulseaudio
sudo alsa force-reload

14. In case anything went wrong and you wish to go back to your previous ALSA installation, no problem:

sudo rm /lib/modules/`uname -r`/kernel/sound

sudo cp -a ~/alsa-backup/sound /lib/modules/`uname -r`/kernel/
sudo alsa force-reload

Great source material that guided me through this experience:

33 comments:

  1. hi , I want redirect this raw data to file,
    so what should i do next...

    ReplyDelete
  2. Instantly play free online games, including solitaire, mahjong, hidden object, word, casino, card, and puzzle games. Play on your computer, tablet, or phone.

    pogo games sign in |
    www.pogo.com games |

    ReplyDelete
  3. For Venmo, QuickBooks, and yahoo mail login errors.

    venmo login |
    quickbooks login |
    yahoo mail login |

    ReplyDelete
  4. Watch anywhere, anytime, on an unlimited number of devices. Sign in with your Netflix account to watch instantly on the web at netflix
    Netflix Login
    tv.youtube.com/start

    ReplyDelete
  5. This is a good post. This post gives truly quality information. I really happy found this website eventually.
    hbomax.com/tvsignin |
    Twitch Activate

    ReplyDelete
  6. For instant charles schwab login, go to the official page of #CharlesSchwab and tap on the “Log In” option. Then, enter your User ID and password for login.

    ReplyDelete
  7. For venmo login with Venmo, Facebook, or PayPal login details, follow these guidelines. If you want to sign in to Venmo Groups, then use the details given here.

    ReplyDelete
  8. 192.168.0.1 is the default gateway that is used by routers and modems such as D​-Link as default IP address for logging the admin panel.
    192.168.0.1 | 192.168.1.1

    ReplyDelete
  9. This is really interesting do check Paypal Login

    ReplyDelete
  10. HBOMax.com/tvsignin is an American OTT video streaming system that gives films, television shows, and sports on consumer demand. It had been introduced last year by Warner Media, a digital entertainment media firm. Since that time due to its prevalence and amazing articles, it’s gained over 17million busy paid subscribers until the year’s ending, which will be enormous for a brand new enterprise.
    hbo max/tv sign in |
    animeflix

    ReplyDelete
  11. In this blog u give knowledge about virtual soundcard track that is very interesting and in my blog canon printer every major operating system, including Windows, Android, and iOS. If you want to scan ,fax etc. in this ijstartcannonn

    ReplyDelete
  12. Hello, Sharing for with Nice comment. If you are worried about the problem of Fix Lexmark Printer offline issue |. Then with the help of your Windows 10, go to your website and click below. So whenever you face this kind of problem then, first of all, you should check your printer's connection with your pc. To restart it power on and power off your printer.
    Visit us:- Lexmark printer to WiFi

    ReplyDelete
  13. How to Enter Code in amazon.com/mytv?
    First, turn on the preferred streaming device

    Go to applications to find out about Amazon Prime

    Once you have launched the app, click on Register on amazon website

    Or else complete the login process to get the www.amazon.com/mytv enter code

    Now note down the code and on your browser visit www.amazon.com/mytv

    Enter the necessary details and provide www.amazon.com/mytv login details

    Then finally enter the activation code.
    www.amazon.com/mytv enter code
    amazon.com/mytv
    www.amazon.com/mytv code
    amazon.com mytv code

    ReplyDelete
  14. Hi there, thank you for sharing such great piece of informative content with us. It is really amazing post it also helps me a lot.
    Google Chrome Dinosaur
    PyPDF2 Module
    Fix Audio services

    ReplyDelete
  15. 1. For hassle-free Login or Sign in to AOL mail, go through AOL Mail Login Official website. A part of Verizon Communications dates back to 1997 when it was one of the world’s largest email service providers with 9 million users from all across the world.

    2. For hassle-free Login or Sign in to AOL mail, go through www.aol.com login Official website. A part of Verizon Communications dates back to 1997 when it was one of the world’s largest email service providers with 9 million users from all across the world.

    3. For hassle-free Login or Sign in to AOL mail, go through AOL Mail Sign In Official website. A part of Verizon Communications dates back to 1997 when it was one of the world’s largest email service providers with 9 million users from all across the world.

    ReplyDelete
  16. You make so many great points here that I read your article a couple of times. Your views are in accordance with my own for the most part. This is great content for your readers. Feel free to visit my website; 카지노사이트

    ReplyDelete
  17. For hassle-free login or Sign in to Binance Exchange. Log into your Binance account. Click on Exchange and pick Basic on the taskbar. Pick a trading pair, as there is a lot to choose from. Choose the type of trade you want to make, like Limit Orders, Stop-Limit orders, or Market Orders. Choose the amount you want to trade.
    Read more about: Crypto Exchange Binance | Blockchain Wallet Login | Gemini Crypto Wallet | Phantom Wallet Download

    ReplyDelete

  18. Amazing website, Love it. Great work done. Nice website. Love it. This is really nice.
    Hbomax/tvsignin
    Disneyplus.com/Begin
    Disneyplus.com login/begin
    Fubo.tv/connect

    ReplyDelete
  19. Hi there, thank you for sharing such great informative post with us. It is really helpful.
    Dynamic Memory Allocation in C
    C Input and Output
    Declaration of C
    Understanding C Datatypes

    ReplyDelete
  20. Instagram video download serivce by MyInstaSave.com, allows to download Instagram videos and photos, reels online. It is a really simple Instagram video downloader, story saver etc.
    instagram video download
    instagram reels download
    instagram video downloader
    instagram story download

    ReplyDelete
  21. https://reallygoodemails.com/freedeliveryorderambien10mgonline
    https://reallygoodemails.com/freedeliverybuyambien10mgonline

    ReplyDelete
  22. What would you teach every girl on the planet about men if you had the chance? Masters Study

    ReplyDelete
  23. Ambien is available in various strengths and forms, Buy Ambien 10mg online without prescription with overnight delivery Ambien is available in various strengths and forms, Buy Ambien 10mg online without prescription with overnight delivery
    Buy Generic AMBIEN without Prescription
    Buy Generic 10mg Ambien Tablets Online
    Buy Generic Ambien(zolpidem) Online
    Buy Ambien 10mg Online First Day Delivery US
    Order Ambien Online USA Overnight Delivery
    Order [Ambien 10mg] Online
    Buy Ambien [Overnight COD in USA] Credit Card & PayPal

    ReplyDelete

Note: only a member of this blog may post a comment.