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:

47 comments:

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

    ReplyDelete
  2. This so super post Creative Testing With Statistical Significance.Such a very useful article. Very interesting to read this article. I would like to thank you for the efforts you had made for writing this awesome article.Thank you for sharing excellent information. Your website is so cool. I am impressed by the details that you have on this website. It reveals how nicely you understand this subject.

    For more information visit site :- Roku.com/link
    Cash App Login
    ij.start.cannon
    Computer Repair
    123.hp.com/setup
    192.168.l.l
    paypal sign In
    Roadrunner Email Login

    ReplyDelete
  3. Hi! this is nice article you shared with great information. Thanks for giving such a wonderful informative information. I hope you will publish again such type of post. Also, please check out about PayPal Login | PayPal Login.

    ReplyDelete
  4. 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
  5. It's the official roku.com/link that can activate the Roku Streaming device. Set up the device, get the roku link code, and visit this activation page to initiate the activation process. or roku.com/link create account, without having an access to a Credit card at the moment, he/she can follow these steps to set up an account.

    ReplyDelete
  6. cash app login error can be frustrating when you need to make an urgent payment. You get such errors on your mobile app and these can be fixed by applying the troubleshooting steps.

    ReplyDelete
  7. aol mail login - aol mail sign in is a free web-based email service provided by AOL. AOL webmail enables its users to check and send emails directly on a browser.

    ReplyDelete
  8. To Get to the Amazon account, you should simply to enlist from your gadget and utilize the www.amazon.com/mytv enter code Wii that is of 5 to 6 character and it is arranged in the Amazon video application on the TV or the gadget. In the event that you don't know what is Amazon Prime, it is a paid membership application to www.amazon.com/mytv which will give you admittance to an enormous scope of administrations with free quick conveyance and limitless video web-based features that are only accessible with the arrangements among the others. It in addition permits the clients to get to limitless spilling of movies and TV shows. It is critical to comprehend that the majority of the substance that is accessible on the stage known as Amazon Instant video can be transferred for nothing on the Amazon Prime enrollment.

    ReplyDelete
  9. To download epson printer drivers on your Windows 10, Windows 7, or 8, or Mac, you need to go to the Epson Connect Utility page and scroll down. After scrolling down, you will find the two options to download the drivers for different operating systems. Once you find the download option for your OS, click on the Download option present again it, and follow some easy prompts.

    epson connect printer setup utility enables you to enjoy remote printing on the go without the hurdles of connecting your printer with cables and then print.

    Learn the essential steps to epson printer not printing error. Follow the instructions carefully to avoid interruptions in the process to resolve the issue.

    To fix epson error code 0x97, you can reset your printer, clean the print-head, update the printer drivers, or re-install the latest Epson printer drivers.

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

    venmo login |
    quickbooks login |
    yahoo mail login |

    ReplyDelete
  11. mcafee activate: Go to mcafee.com/activate. Activate Your Subscription form on the www.mcafee.com/activate page. Type your product key activation code in the Enter your code field.

    ReplyDelete
  12. 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
  13. When will update your site? Im really looking forward for more articles from your site. Keep me posted. Thanks www.amazon.com/code | tubi.tv/activate

    ReplyDelete
  14. Looking for Cricket Shoes? Buy Online Cricket Shoes of All Sizes like Men, Youth, Boys, Kids and Junior Available at affordable price at NZ Cricket Store. We provide branded Cricket Shoes of best quality in New Zealand.

    ReplyDelete
  15. Cash App is the easiest way to send, spend, save, and invest your money. It's the SAFE, FAST, and FREE mobile banking app. First of all, you need to install Cash App on your mobile. Tap on the “Sign In” tab. Fill up your login details.
    Cash app login | Cash App Login

    ReplyDelete
  16. This is a good post. This post gives truly quality information. I’m definitely going to look into it. Really very useful tips are provided here.

    Hotmail Login | 1337x

    ReplyDelete
  17. Thanks for sharing your amazing thoughts. It's a well-explained and informative blog. Click here for more details
    Aol mail login |
    Outlook 365 Login |

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

    ReplyDelete
  19. Cash App is the easiest way to send, spend, save, and invest your money. It's the SAFE, FAST, and FREE mobile banking app. First of all, you need to install Cash App on your mobile. Tap on the “Sign In” tab. Fill up your login details.
    Cash app login | Cash App Login

    ReplyDelete
  20. Thanks for sharing your amazing thoughts. It's a well-explained and informative blog. Click here for more details
    Aol mail login |
    Outlook 365 Login |

    ReplyDelete
  21. Thankyou for this nice post. Stream live TV from ABC, CBS, FOX, NBC, ESPN & popular cable networks. Record without DVR storage space limits. Try it free.
    tv.youtube.com/start
    www.amazon.com/mytv

    ReplyDelete
  22. Thanks for sharing that information, this is great full to us. Please follow this link to know more about PayPal Account Login.
    PayPal Account Login is one of the best, user-friendly payment platforms. Moreover, it facilitates payments that take place via online transfers between different parties.

    ReplyDelete
  23. Pretty! This was an extremely wonderful post. Thanks for providing these details. amazon.com/code

    ReplyDelete
  24. I really like your post, I always like to read quality content having accurate information regarding the subject. Thanks for sharing. It is such a very amazing post.

    Tubi.tv/activate

    Facebook Login

    ReplyDelete
  25. I like your informational views. Such a pleasant article. I even have some entertaining and informational topics like Nba streams reddit | www.amazon.com/mytv

    ReplyDelete
  26. Showtime Anytime is one of the online video streaming platforms Like Amazon prime video, which is exclusively available in the USA. To know more interesting details about Showtime Anytime you can visit us at showtimeanytime/activate
    Netflix is one of the most popular online video streaming platforms all over the world. which can be accessed just by paying for a monthly subscription account. To get more details about this feel free to visit Netflix login whenever you are free.

    ReplyDelete
  27. mcafee.com/activate - Find the McAfee antivirus download, install & activation steps. Enter McAfee activate code and get started at www.mcafee.com/activate.

    ReplyDelete
  28. 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
  29. 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
  30. quickbooks login makes online accounting easy. Log in to your QuickBooks Online account to keep track of the money you spend and to see how much money you are making.
    quickbooks unrecoverable error |
    quickbooks error 3371 |

    ReplyDelete
  31. looking for solutions? you can wait for a few minutes or hours and then log back in and you will be able to log in if there was a temporary connectivity issue.
    PayPal Login |
    MoonPay Login |
    Venmo Login |

    ReplyDelete
  32. looking for solutions? you can wait for a few minutes or hours and then log back in and you will be able to log in if there was a temporary connectivity issue.
    Hulu Activate |
    www.hulu.com/activate |

    ReplyDelete
  33. 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
  34. This is really interesting do check Paypal Login

    ReplyDelete
  35. Tubi tv is one of well known online video streaming platforms in the United States of America. Which provides free tv for its users. if you want the Tubi Tv subscription for yourself as well then feel free to visit our website at Tubi.tv/activate
    Are you having trouble while logging into your Hotmail account? then you need to visit our website at Hotmail Login
    Youtube is one of the best online streaming platforms, to watch free videos online. But nowadays youtube started offering a premium subscription for its users so that they can enjoy premium content on youtube ads free. If you want to dig more information about his feel free to visit us at YouTube.com/activate.

    ReplyDelete
  36. It read your article every thing is clear , Thanks for sharing.
    Do check
    Paypal Login
    gemini login

    ReplyDelete
  37. For accessing your walmart login account or managing your Credit Card/Money Card, you need to go to #walmartcom, tap on the "Account" tab, and choose "Sign In."
    bank logins:
    bank of america login |
    wells fargo login |

    ReplyDelete
  38. I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much.
    Do check
    Telstra email login

    ReplyDelete