Wednesday, November 2, 2011

Transform one multi-channel sound card into 2 virtual stereo ones

I love music!
I may say that the only period of time I don't listen to music is when I'm asleep.
And essentially while sitting at my desktop at work I cannot escape temptation to tune to Last.fm.

Another thing to mention is I cannot wear headphones for too long. Even my Sennheiser HD-555 which are "open-desing" ones and extremely comfortable. So I prefer to enjoy some sort of loudspeakers. And I do have them.

But sometimes I have to talk with colleagues through Skype. And well... it's not so nice to bother colleague/s sitting right next to me (in the same room) with these conversations... at the same time they're OK with my music.

So basically I needed to split audio output of Skype and all other applications.
The first idea was to get an extra PC (some old one from garbage) and use as a remote player. It's possible to install there MPD or some other stuff that has an ability to be controlled remotely through local network for example.

But it was not so elegant and basically I didn't manage to find "extra PC".

At this point I though what if I try to play with PulseAudio setting which is default audio server in Ubuntu for years now.

And so I did.

This wiki article covers everything I needed: https://wiki.archlinux.org/index.php/PulseAudio#Splitting_front.2Frear

Below is an extract from it.

Splitting front/rear

You may want connect speakers to front analog output and headphones to rear output. It would be usefull to split front/rear to separate sinks. Add to default.pa:
load-module module-remap-sink sink_name=speakers remix=no master=alsa_output.pci-0000_05_00.0.analog-surround-40 channels=2 master_channel_map=front-left,front-right channel_map=front-left,front-right

load-module module-remap-sink sink_name=headphones remix=no master=alsa_output.pci-0000_05_00.0.analog-surround-40 channels=2 master_channel_map=rear-left,rear-right   channel_map=front-left,front-right
(replace alsa_output.pci-0000_05_00.0.analog-surround-40 to your sound card name that you got from 'pacmd list-sinks')
After that you can switch player between speakers and headphones.

To restart PulseAudio execute: pulseaudio -k

This will kill PulseAudio server and then it will be restarted automatically with new settings applied.

The only thing that surprised me then - I couldn't find a way or tool to select desired virtual output for particular application.

And it turned out this tool is "PulseAudio Volume Control" (pavucontrol).

Here's a screenshot:

Unfortunately pavucontrol isn't installed by default in Ubuntu 11.10 so one needs to install it:
sudo apt-get install pavucontrol

Another issue is that application which uses direct access to ALSA won't appear in pavucontrol and so it's impossible to control which output they use.

But this is also could be solved quite simple:
In order for ALSA to use PulseAudio it needs a special /etc/asound.conf (system wide settings) (recommended) or ~/.asoundrc (settings on a per user basis):
File: /etc/asound.conf
pcm.pulse {
    type pulse
}
ctl.pulse {
    type pulse
}
pcm.!default {
    type pulse
}
ctl.!default {
    type pulse
}
If you omit the last two groups, Pulseaudio will not be used by default. You will then need to change the ALSA device to "pulse" in the applications that you use to make it work.
That's it. I finally got what I was looking for and it cost me an hour to google and experiment a bit.

2 comments:

  1. This is what I was looking for!
    Thanks, it worked great in Ubuntu 13.04.

    ReplyDelete
  2. Play slots online at Lucky Club
    The Lucky luckyclub Club online casino brings you the biggest and best online slots available to players worldwide! Join now and get up to €250 welcome bonus and  Rating: 2.8 · ‎32 votes · ‎Free · ‎Game

    ReplyDelete