Thread Tools
This thread is privately moderated by Jack Crossfire, who may elect to delete unwanted replies.
Jul 22, 2014, 04:56 AM
Registered User
Jack Crossfire's Avatar
Thread OP
Discussion

Audio loopback in ALSA


20 years after it began, someone finally figured out how to route the audio output in ALSA back to an audio input. The sequence for recording from a Firefox player is:

modprobe snd_aloop
FLASH_ALSA_DEVICE=hw:1 firefox
Make Cinelerra record Loopback #1

The problem is the recording samplerate has to be the same as the playback samplerate. It has to be determined by trial & error or by playing the source in another player besides Firefox. If the player doesn't have a way to send audio to another device besides hw:0, you're screwed.

There is theoretically a way to do it with a line like pcm.!hw in the /etc/asound.conf file, but this never worked. pcm.!hw is supposed to replace any device called hw with what's described in the file.

Some time in 2012, someone wrote the snd_aloop module. The last ALSA release which could be easily compiled without upgrading the entire kernel was 1.0.25 & it has the snd_aloop module.

It creates a virtual soundcard for playback which really routes the audio to the recording handle of another virtual soundcard. aplay -l lists the virtual soundcard as

card 1: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]
card 1: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]

which translates to hw:1 for Firefox. They never quite figured out a naming convention, back in their dorm rooms in 1997, so there's a hodge podge of hw:1, Loopback #0, hw:1,0 naming conventions. Playing audio to Loopback #0 makes it appear on Loopback #1 for recording.

There's still no way to copy the output of a physical soundcard. There are ways to create routes. The application has to be able to specifically send audio to a route, which Cinelerra can't do. There's no way to hear the audio being recorded by the loopback device. Adding the following to the /etc/asound.conf file is supposed to split the output of a route to both a physical soundcard & the loopback device.

pcm.!default plug:both



pcm.both {
type route;
slave.pcm {
type multi;
slaves.a.pcm "intel";
slaves.b.pcm "cinelerra";
slaves.a.channels 2;
slaves.b.channels 2;
bindings.0.slave a;
bindings.0.channel 0;
bindings.1.slave a;
bindings.1.channel 1;

bindings.2.slave b;
bindings.2.channel 0;
bindings.3.slave b;
bindings.3.channel 1;
}

pcm.intel {
type dmix
ipc_key 1024
slave {
pcm "hw:0"
rate 44100
channels 2
}
bindings {
0 0
1 1
}
}

pcm.cinelerra {
type dmix
ipc_key 2048
slave {
pcm "hw:1"
rate 44100
channels 2
}
bindings {
0 0
1 1
}
}

The samplerate has to be perfect. It still doesn't work in Firefox. There is lot less interest in multimedia on Linux than there was 20 years ago. The Goog can only find fragments of information.
Sign up now
to remove ads between posts


Quick Reply
Message:
Thread Tools