Has it really been over a year? Well, progress has been made. Without any useful help I came back to this and tried to see what I could do. I achieved creating a virtual device which mixes the mic with my USB capture device.
Here's what I wrote into .asoundrc; recall that 0,0 refers to the mic and 2,0 is the USB device.
Code: Select all
pcm.castsrc {
type multi;
slaves.a.pcm "hw:0,0";
slaves.a.channels 2;
slaves.b.pcm "hw:2,0";
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;
}
ctl.castsrc {
type hw;
card 0;
}
pcm.ttable {
type route;
slave.pcm "castsrc";
slave.channels 4;
ttable.0.0 1;
ttable.1.1 1;
ttable.2.2 1;
ttable.3.3 1;
}
ctl.ttable {
type hw;
card 0;
}
Basically a duplicate of the example definition for a multi type device for ALSA. I thought the mic would be 1 channel but arecord was not happy until I set it as a 2-channel device but it's working fine. Did a sample recording for 15 seconds and got the expected result.
Next I want to expand this to 6-channels. I would like to add a loopback device of the system audio output.
My problem is when I try to arecord the loopback, I get silence. (For my experiment I have audio playing from Clementine during the recording.)
I've seen two or three example configurations for it. (I've already loaded the snd-aloop module and confirmed I have loopback devices with aplay -l).
Code: Select all
# output device
pcm.loopout {
type dmix
ipc_key 328211
slave.pcm "hw:Loopback,0,0"
}
# input device
pcm.loopin {
type dsnoop
ipc_key 686592
slave.pcm "hw:Loopback,1,0"
}
# duplex plug device
pcm.loop {
type plug
slave {
pcm {
type asym
playback.pcm "loopout"
capture.pcm "loopin"
}
}
}
pcm.mout {
type plug
slave.pcm mdev
route_policy "duplicate"
}
pcm.mdev {
type multi
slaves.a.pcm "hw:Loopback,0,0"
slaves.a.channels 2
slaves.b.pcm "hw:0,0"
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
}
That configuration is from someone over at the Arch Linux forum.
(Here.)
arecord is happy with recording, but I get silence. What's missing? Oh yes. Audio has to be specifically directed at this new multi device. With mplayer I used -ao alsa:device=mout to redirect audio output to the device. Since mout is routing the audio both to the default output (speakers) and the loopback at the same time, I could use arecord to capture from the loop device. Perfect. Setting Clementine to use the ALSA engine of GStreamer and passing mout as the device achieved what I did with mplayer on the command line.
Lastly I must now add in loop to my original 4-channel multi which needs to become 6-channel, I hope this works!
Full .asoundrc, 6-channel virtual device
Code: Select all
pcm.castsrc {
type multi;
slaves.a.pcm "hw:0,0";
slaves.a.channels 2;
slaves.b.pcm "hw:2,0";
slaves.b.channels 2;
slaves.c.pcm "loop";
slaves.c.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;
bindings.4.slave c;
bindings.4.channel 0;
bindings.5.slave c;
bindings.5.channel 1;
}
ctl.castsrc {
type hw;
card 0;
}
pcm.ttable {
type route;
slave.pcm "castsrc";
slave.channels 6;
ttable.0.0 1;
ttable.1.1 1;
ttable.2.2 1;
ttable.3.3 1;
ttable.4.4 1;
ttable.5.5 1;
}
ctl.ttable {
type hw;
card 0;
}
# output device
pcm.loopout {
type dmix
ipc_key 328211
slave.pcm "hw:Loopback,0,0"
}
# input device
pcm.loopin {
type dsnoop
ipc_key 686592
slave.pcm "hw:Loopback,1,0"
}
# duplex plug device
pcm.loop {
type plug
slave {
pcm {
type asym
playback.pcm "loopout"
capture.pcm "loopin"
}
}
}
pcm.mout {
type plug
slave.pcm mdev
route_policy "duplicate"
}
pcm.mdev {
type multi
slaves.a.pcm "hw:Loopback,0,0"
slaves.a.channels 2
slaves.b.pcm "hw:0,0"
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
}
Yes, it is working! All that remains is testing using "castsrc" with VLC.
...And I'm stuck. VLC won't read the 4-channel ALSA device. I tried downmixing within .asoundrc by mapping both left and right sources to the same left and right channels and that doesn't work. Now I've tried to use ffmpeg and the -ac 2 option to suggest it needs to downmix and it bails with an I/O error immediately. With 4-channel vorbis and x264 I can write a video file with ffmpeg, but the goal is to stream, and the required format is 2-channel mp3 with x264 video...
I need to do what was the original intent of this whole project. To mix multiple sources together and still have 2 channels. There's just no way to work with more audio channels. Both ffmpeg and VLC won't permit it. I suspect the only options are to attempt to learn to use JACK (which I don't know if it will truly mix audio, or just create a huge multi-channel audio device like I did manually with ALSA) or just give up with no options left. Even if they did permit it, it wouldn't matter, it seems. For streaming the required format for audio is 2-channel MP3. I tried to ignore this when testing with ffmpeg and I received RTMP errors telling me that it's not going to happen.
