I have been trying to create a virtual device to record the internal audio of my sound card using pure ALSA. After googling a lot, I found a .asoundrc
file¹ that is very near of what I am looking for:
pcm.mycard {
type hw
card 0
}
ctl.mycard {
type hw
card 0
}
pcm.myconvert {
type plug
slave {
pcm "myrecord"
format S16_LE
}
}
pcm.myrecord {
type file
format "raw"
slave.pcm "mycard"
file "| oggenc -Q -q6 -r -B %b -C %c -R %r -o /tmp/record-$(date +%%Y-%%m-%%d_%%H%%M%%S).ogg -"
}
pcm.!default{
type asym
playback.pcm "myconvert"
capture.pcm "mycard"
}
This configuration makes possible to record a ogg
file with all audio played in my computer. What I would like to do now, is to modify the pcm.myrecord
part of the configuration, so that the audio is "streamed" in a virtual card that I could capture later with let's say, arecord
. I would be glad if someone could help me with this.
I tried this: How do I create virtual ALSA device from which I can record everything that is played? but that did not work for me. Below, the output from arecord -L
:
muammar@zarathustra /tmp
% arecord -L !10015
null
Discard all samples (playback) or generate zero samples (capture)
default:CARD=PCH
HDA Intel PCH, CS4208 Analog
Default Audio Device
sysdefault:CARD=PCH
HDA Intel PCH, CS4208 Analog
Default Audio Device
front:CARD=PCH,DEV=0
HDA Intel PCH, CS4208 Analog
Front speakers
dmix:CARD=PCH,DEV=0
HDA Intel PCH, CS4208 Analog
Direct sample mixing device
dsnoop:CARD=PCH,DEV=0
HDA Intel PCH, CS4208 Analog
Direct sample snooping device
hw:CARD=PCH,DEV=0
HDA Intel PCH, CS4208 Analog
Direct hardware device without any conversions
plughw:CARD=PCH,DEV=0
HDA Intel PCH, CS4208 Analog
Hardware device with all software conversions
default:CARD=Loopback
Loopback, Loopback PCM
Default Audio Device
sysdefault:CARD=Loopback
Loopback, Loopback PCM
Default Audio Device
front:CARD=Loopback,DEV=0
Loopback, Loopback PCM
Front speakers
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
dsnoop:CARD=Loopback,DEV=0
Loopback, Loopback PCM
Direct sample snooping device
dsnoop:CARD=Loopback,DEV=1
Loopback, Loopback PCM
Direct sample snooping device
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
Thanks.
Best Answer
I solved this issue as follows:
First, load the
snd-aloop
module:This will create a new device called
Loopback
:From the information shown above we have to create two
hw
devices:hw:0,0
(PCH is my main sound card).hw:2,1
(TheLoopback
virtual device).Normally,
hw
devices have the form:hw:X,Y
. For our purposes, it seems thatY
for the main card is always0
while for theLoopback
we haveY
equals1
.Now, in order to make all of this work, we need a
~/.asoundrc
file with the following:Modify
hw:X1,Y1
with the values for your main card (in my casehw:0,0
).You can test that this configuration works by playing something in your computer. If you hear it, so it is fine. Now let's play something in the computer, and record it from this virtual device with
ffmpeg
:Where
hw:X2,Y2
has to be replaced by theLoopback
device, in this casehw:2,1
.I suppose that using
arecord
should work too.