Page 1 of 1

ALSA - downmix to mono via .asoundrc.

Posted: Tue Feb 12, 2013 3:50 pm
by JanHolstJensen
Hi,

I am trying to downmix stereo to mono when I play internet radio. I have edited /home/pi/.asoundrc to this so I get a 'monocard' device that I can play to.

Code: Select all

pcm.card0 {
  type hw
  card 0
}

ctl.card0 {
  type hw
  card 0
}

pcm.monocard {
  slave.pcm card0
  slave.channels 2
  type plug
}

ctl.monocard {
  type hw
  card 0
}

pcm.!default monocard
This works nicely; I can play stuff with 'aplay' like this

Code: Select all

aplay -D monocard Front_Left_And_Right.wav
and just like when I listen to radio, I can't hear what's in the right channel because I only have one speaker which is connected to the left output.

So I try to downmix to mono. Based on a number of ALSA pages on the net this should do it (change pcm.monocard's type to "route" and adding a "ttable" definition for it):

Code: Select all

pcm.card0 {
  type hw
  card 0
}

ctl.card0 {
  type hw
  card 0
}

pcm.monocard {
  slave.pcm card0
  slave.channels 2
#  type plug
  type route
  ttable {
    # Copy both input channels to output channel 0 (Left).
    0.0 1
    1.0 1
    # Send nothing to output channel 1 (Right).
    0.1 0
    1.1 0
  }
}

ctl.monocard {
  type hw
  card 0
}

pcm.!default monocard
But then I get this error:

[email protected] ~ $ aplay -D monocard Front_Left_And_Right.wav
Playing WAVE 'Front_Left_And_Right.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
aplay: set_params:1059: Broken configuration for this PCM: no configurations available
[email protected] ~ $

I have looked left and right (pun intended) but I can't figure out what's wrong. Any help appreciated.

Kind regards
-- Jan Holst Jensen

Re: ALSA - downmix to mono via .asoundrc.

Posted: Wed Feb 13, 2013 11:12 am
by JanHolstJensen
Update: If I try the above .asoundrc examples on a Debian 7 x64 virtual machine they work just fine. The mono downmix works perfectly, putting everything into the left channel. So the problem is Raspberry- or soundcard- specific. Can anyone shed some light on how to debug this so I can figure out how the .asoundrc should be written on Raspberry ?

Re: ALSA - downmix to mono via .asoundrc.

Posted: Wed Feb 20, 2013 9:05 pm
by Alec

Re: ALSA - downmix to mono via .asoundrc.

Posted: Mon Feb 25, 2013 12:38 pm
by JanHolstJensen
Hi Alec,

Thanks for the pointers. Unfortunately they don't really give me anything new to go on.

I have also tried making vlc (which I use for playing radio streams) play the stream in mono, but it won't accept the "--mono" command line parameter and just ignores "--audio-filter mono". I have now spent several hours in vain, so I will just wire up my own hardware stereo-to-mono converter jack. Much easier than mucking around with weird software options that don't work.

Cheers
-- Jan

Re: ALSA - downmix to mono via .asoundrc.

Posted: Mon Feb 25, 2013 3:33 pm
by KenT
Don't know whether it helps but using mplayer you can use the -af channels command to convert stereo to mono and direct it to one of the two speakers.

Re: ALSA - downmix to mono via .asoundrc.

Posted: Sun Apr 21, 2013 7:56 pm
by Alec
If the original issue is still a problem, its been suggested to me that a post to uk.comp.os.linux or uk.rec.audio might elicit helpful info.

HTH

Re: ALSA - downmix to mono via .asoundrc.

Posted: Mon Apr 22, 2013 1:38 am
by sdjf
Have you considered using sox, the classic linux sound editor? I think you could use it to combine the sound files. And you can either use it as a player or save the output.

I realize you want to stream radio, but I would imagine you can pipe the radio stream as input to sox.

[SOLVED] Re: ALSA - downmix to mono via .asoundrc.

Posted: Fri Aug 09, 2013 4:00 pm
by JanHolstJensen
I have just updated to the 2013-07-26 Wheezy image and the .asoundrc file now works, putting all my sound into the Left channel only. Hooray :D !

Re: ALSA - downmix to mono via .asoundrc.

Posted: Fri Mar 07, 2014 9:11 am
by ripop
This was really helpful, btw, thanks!

Re: ALSA - downmix to mono via .asoundrc.

Posted: Mon Apr 06, 2015 10:49 am
by kokarn
Just for anybody else that stumbles onto this, this still works with modifications.

The setup I did for was Shairplay/AirPi

The file I had to edit to get this to work is /etc/asound.conf

I also had to reboot to get the changes to work.

The guide i found said you had to restart ALSA by doing

Code: Select all

/etc/init.d/alsa-utils restart
so this might be enough for you, it was not for me however.

Thank you so much for the config!

Re: ALSA - downmix to mono via .asoundrc.

Posted: Wed Jul 20, 2016 2:09 pm
by audio-badger
@JanHolstJensen - Great work. This helped me too (turning a stereo input into a mono input needed for Amazon Alexa!)

@ kokarn - Thanks for your update too. BTW,

Code: Select all

/etc/init.d/alsa-utils restart
works with

Code: Select all

sudo

Re: ALSA - downmix to mono via .asoundrc.

Posted: Sat Nov 05, 2016 4:55 pm
by geertvdijk
Maybe somewhat resurrecting an old thread, but I used this and got mono sound, albeit quite distorted. At first I blamed my soundcard and all other possible causes, but in the end I found the culprit in this piece:

Code: Select all

    # Copy both input channels to output channel 0 (Left).
    0.0 1
    1.0 1
    # Send nothing to output channel 1 (Right).
    0.1 0
    1.1 0
Which combines left and right on the left channel (good), but on full volume for each channel (bad). To fix this, and prevent the signal from being sent out at 200%, the simple fix is this:

Code: Select all

    # Copy both input channels to output channel 0 (Left).
    0.0 0.5
    1.0 0.5
    # Send nothing to output channel 1 (Right).
    0.1 0
    1.1 0
Which worked, at least for me. For easy copy and paste (assuming your usb sound card is configured as card 1), here's the full file once more.

Code: Select all

pcm.card1 {
  type hw
  card 1
}

ctl.card1 {
  type hw
  card 1
}

pcm.monocard {
  slave.pcm card1
  slave.channels 2
#  type plug
  type route
  ttable {
    # Copy both input channels to output channel 0 (Left).
    0.0 0.5
    1.0 0.5
    # Send nothing to output channel 1 (Right).
    0.1 0
    1.1 0
  }
}

ctl.monocard {
  type hw
  card 1
}

pcm.!default monocard
Hopefully this helps someone :)