I want a flash application that wants to record my microphone (something like https://online-voice-recorder.com/) to record a Pulse Audio source.
I figured, that flash uses ALSA. So I installed the Alsa loop device sudo modprobe snd-aloop
, which neatly appeared both in pavucontrol
and in alplay -l
(at the end of the listing):
adam@adam-g551jm:~ 130 $ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: HDMI [HDA Intel HDMI], device 3: HDMI 0 [HDMI 0]
Subdevices: 0/1
Subdevice #0: subdevice #0
card 0: HDMI [HDA Intel HDMI], device 7: HDMI 1 [HDMI 1]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: HDMI [HDA Intel HDMI], device 8: HDMI 2 [HDMI 2]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 0: ALC668 Analog [ALC668 Analog]
Subdevices: 0/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
Then I confirmed, that the sound is routed to the loopback device:
Unfortunately, the flash plugin doesn't see the sound at all - as if I was recording zeroes.
The flash plugin sees all ALSA-facing sound sources:
- Why there is no sound visible to the flash plugin?
- What to do, to route a Pulse Audio's output into ALSA input?
The simple answer is at the end. But to help understand the solution, I will try to be as intelligible as possible. My assumption: "Loopback device" is card #2, device #0 and #1, so in all examples this holds true (e.g.
/dev/snd/pcmC2D0p
means "card 2, device 0, playback"). Your installation may vary, so modify the respective values.First, I created/modified
/etc/modprobe.d/alsa-aloop.conf
to have only one card with only one substream (just for simplicity):After
sudo modprobe snd_aloop
,aplay -l
andarecord -l
showNow, there is one problem: Both devices of the loopback card are playback as well as record devices. But the function of
snd_aloop
is to route input in device 0 to output at device 1 and vice versa (see e.g.https://www.alsa-project.org/main/index.php/Matrix:Module-aloop). You can see these in/proc/asound
directory:where "pcm0c" is capture device 0, "pcm0p" is playback device 0 etc.
So
pavucontrol
shows (and selects) two loop devices, one playback (hw:2,0) and one record (hw:2,1):You cannot select the playback device in
pavucontrol
, so it selects device 0:You will see this when loking at the playback device file:
So this means the capturing of this audio stream has to be done via
/dev/snd/pcmC2D1c
; if you selectloopback
as the input device for flash, it will use/dev/snd/pcmC2D0c
instead (plugin-co
means the plugin container flash is running in):You may check when explicitly playing sound through
/dev/snd/pcmC2D1p
, e.g. withNow the flash plugin records sound, and you can see the difference:
So, the task now is: How to have pulseaudio select the device #1 of the loopback card for playback?
Assuming the values from above, you may modify
/etc/pulse/default.pa
to readBe sure to define the statically driver(s) before the dynamic ones. Now after restart of PA (
pulseaudio -k
), theloopback
output of PA goes to card2, device 1 (device=hw:2,1
). To verify:Thus, your flash recorder is able to record from the output of pulseaudio.
Remark: If you do not want to edit
/etc/pulse/default.pa
, you can load the module interactively withpacmd load-module module-alsa-sink device=hw:2,1
. This will give you a secondloopback
device inpavucontrol
. And if you only want one loopback device, first unload the respective module:Look for the index where
device-id=2
(here:7), then unload the module (pacmd unload-module 7
) and after that load the sink for the loopback (pacmd load-module module-alsa-sink device=hw:2,1
).