2008-11-01

Pulseaudio and speakers+headphones remapping

Just thought I should share my pulseaudio configuration. It allows me to move audio streams between my speakers and my headphones. The drawback is that I had to connect my headphones to the rear-speaker output, effectively stopping any surround usage. The perfect setup would have been if I could instead have used the audio output on the front of my computer (I know this should work as the Realtek utilitiy in Windows is able to do it).

For sanity I just share the relevant parts of my system.pa

#### I do this by hand for the remaps
# ### Automatically load driver modules depending on the hardware available
# .ifexists module-hal-detect.so
# load-module module-hal-detect
# .else
# ### Alternatively use the static hardware detection module (for systems that
# ### lack HAL support)
# load-module module-detect
#.endif

### Automatically suspend sinks/sources that become idle for too long
#load-module module-suspend-on-idle
#bug: http://pulseaudio.org/ticket/326


# Set the speakers as the default device
set-default-sink speakers

# Map device 0 to sound_card (this is my sound card) and use 4 channels
load-module module-alsa-sink sink_name=sound_card device_id=0 channels=4 channel_map=front-left,front-right,rear-left,rear-right

# Map the front channels to the speakers sink
load-module module-remap-sink sink_name=speakers master=sound_card channels=2 master_channel_map=front-left,front-right channel_map=front-left,front-right

# Map the rear channels to the headphones sink
load-module module-remap-sink sink_name=headphones master=sound_card channels=2 master_channel_map=rear-left,rear-right channel_map=front-left,front-right


And here's what I changed in daemon.conf:

;make channel-splitting work (may destroy mono to stereo on mono files)
disable-remixing = yes

default-sample-channels = 4



Unfortunately the sink names are not shown in PulseAudio Volume Control but some trial and error (choosing 1 out of to 2 :P) will tell you which sink is the speakers and which is the headphones.

15 comments:

Gergő said...

I always wanted to use skype without plugging/unplugging the headset, and now I finally can, thanks to your post!

I did a few things differently, however (as the post is old - this applies to Ubuntu 9.10, pulse 0.9.19).

Manual module loading (load-module module-alsa...) is not needed, I used the automatic module-hal, and 0 for master sink name:

load-module module-remap-sink sink_name=speakers master=0 channels=2...

Also, whenever I set enable-remixing=no (it's now called enable instead of disable), the microphone ceased to work (and when set to 'yes', the stream was remixed on all channels).

Fortunately it is possible to disable remixing only for the remapped channels, so they look like this:

# Map the front channels to the speakers sink
load-module module-remap-sink sink_name=speakers master=0 channels=2 master_channel_map=front-left,front-right channel_map=front-left,front-right remix=no

# Map the rear channels to the headphones sink
load-module module-remap-sink sink_name=headphones master=0 channels=2 master_channel_map=rear-left,rear-right channel_map=front-left,front-right remix=no

After that I used pavucontrol to choose the headphone sink for skype. So skype uses the headset, and music plays on the speakers. And I can choose which stream goes where any time without plugging... very cool :)

Thomas A said...

I'm glad to hear it worked for someone else!

To hear when someone is calling I also told skype to run aplay with a sound-file on the receiving call event.

Unknown said...
This comment has been removed by a blog administrator.
Unknown said...
This comment has been removed by a blog administrator.
Anonymous said...

yay!!!!! thanx man. I did what I wanted long time... skype redirects to headphones and amarok to speakers at the same time

Unknown said...

Thanks a lot - can't get this to work atm though. I want to use it not for skype but mainly for dividing stuff up between my desktop speakers and my stereo.

I first tried the original post, then Gergö's adaption. the errors at trying to restart pulse told me module-detect was deprecated so i used module-udev-detect (which as I had overseen has been loaded in the original default.pa already so i scratched it).

Anyway - no matter what I try - I keep getting the following:

E: module-alsa-card.c: Failed to find a working profile.
E: module.c: Failed to load module "module-alsa-card" (argument: "device_id="1" name="1" card_name="alsa_card.1" tsched=yes ignore_dB=no card_properties="module-udev-detect.discovered=1""): initialization failed.
E: module-remap-sink.c: Failed to parse module arguments.
E: module.c: Failed to load module "module-remap-sink" (argument: "sink_name=0 device_id=0 channels=4 channel_map=front-left,front-right,rear-left,rear-right"): initialization failed.
E: main.c: Sink speakers does not exist.
E: main.c: Module load failed.
E: main.c: Konnte Daemon nicht initialisieren.


I've been looking for weeks for something like that - I tried alsa without pa but hardly anything can choose a specific alsa output so that was pretty much useless. So I'd be really grateful if someone could tell me what I'm doing wrong.

thanks in advance

Unknown said...

nevermind - I'm just too stupid to read :)

works like a charm

spi said...

I had to change it a bit for Ubuntu 11.04 as the pulse server is run now in the user's environment. So the right file tho put in the changes is /etc/pulse/default.pa instead of system.pa.

The first sink speakers works like a charm - but the second one named headphones doesn't. Have to dig into it once more.

spi said...

Got it - had to update modprobe to get the right soundcard drivers loaded.

I can route audio to different sinks now but Skype audio quality is pretty poor now...

Anonymous said...

Hurrah, that’s what I was trying to get for, just what a stuff Presented at this blog!! Thanks admin of the site. ear buds

Anonymous said...

I’m trampled by your contents carry on the wonderful work.dental implants south bay

Anonymous said...

The blog and data is excellent and informative as well. Medical Negligence Solicitors

dsds said...

Great post. I think it is good for visitors. I like this kind of website where has a lot of real information, It proved to be very helpful. Thanks for admin, His creativity, Presentation, Information and all is good.
audio speakers

Unknown said...

I can't get it to work properly and I'm using Ubuntu 15.10. I have followed updates people have posted and experimented some without success.

I have two remapped streams showing up in Pulse Audio, only one seems to work. It's the one for the front-jacks that work, yet it plays in speakers... Please help me.

I don't understand the first part:

#### I do this by hand for the remaps
# ### Automatically load driver modules depending on the hardware available
# .ifexists module-hal-detect.so
# load-module module-hal-detect
# .else
# ### Alternatively use the static hardware detection module (for systems that
# ### lack HAL support)
# load-module module-detect
#.endif

### Automatically suspend sinks/sources that become idle for too long
#load-module module-suspend-on-idle
#bug: http://pulseaudio.org/ticket/326

What do you mean "do this by hand"?

Pinky said...

M-Audio BX8D3 Speakers in UAE, Professional Multimedia Speakers in UAE, Speakers in UAE
https://gccgamers.com/m-audio-bx8d3.html
M-Audio BX8D3 Speakers in UAE, Safe Shopping Multiple Payment Options Express Delivery GCC Gamers Moneyback Guarantee.
1633414665826-8