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:

39 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. The world has enjoyed their Prime membership on larger-screens. www.amazon.com/mytv has made it easy. MyTV App registration is your best option for streaming all of the Amazon Prime shows to your Smart TVs. The above article will solve all your registration, login, verification problems. Now all you have to do is put on your comfy clothes and enjoy the theatre-like experience at home. Log in with your Amazon Prime Login account to access all your favorite web series and original web shows on your smart television.
    amazon.com/mytv
    amazon.com/redeem
    amazon.com/mytv

    ReplyDelete
  11. The absolute most essential point to understand is that Google Play gift-cards may simply be utilised to obtain programs, movies, novels, along with other videogame or app-related purchases throughout the Google Play store. You shouldn't be duped. If anybody asks you to cover them with a Google Play gift-card , it is really a scam. Stage
    google play redeem code

    ReplyDelete
  12. 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
  13. NOTE:Amazon Prime membership grants you access to the Amazon Prime MyTV App. To get your Prime membership, you will need to create an account. You can stream on the big screen and enjoy an incredible selection of web series and other shows.
    amazon.com/mytv
    amazon.com/redeem
    amazon.com/code
    amazon.com/mytv

    ReplyDelete
  14. The world has enjoyed their Prime membership on larger-screens. www.amazon.com/mytv has made it easy. MyTV App registration is your best option for streaming all of the Amazon Prime shows to your Smart TVs. The above article will solve all your registration, login, verification problems. Now all you have to do is put on your comfy clothes and enjoy the theatre-like experience at home. Log in with your Amazon Prime Login account to access all your favorite web series and original web shows on your smart television.
    primevideo/mytv
    amazon.com/code
    amazon.com/redeem check balance
    amazon.com/redeem check balance

    ReplyDelete
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. The invocations of Lowe's aisles usually are a reference to their position within the stores, to help customers navigate their ways around. For instance the GC store's meaning is Garden Center and LW means Left Wall. Lowe's staff can assist you to identify the appropriate aisles
    PayPal Login
    PayPal Login
    eBay Customer Service
    netflix.com/activate
    netflix.com/activate

    ReplyDelete
  22. How do I verify my order? When your order is ready to be picked up, you can open the Lowe's app , and click"Like Us" and click the Tell Us We're On The Way tab. You can confirm this by clicking"I'm on My Way.
    amazon.com/redeem
    target.com/checkbalance

    ReplyDelete
  23. 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

  24. 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
  25. 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
  26. 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
  27. https://reallygoodemails.com/freedeliveryorderambien10mgonline
    https://reallygoodemails.com/freedeliverybuyambien10mgonline

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

    ReplyDelete
  29. 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.