Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] asound.conf for onboard & usb audio simultaneously
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Multimedia
View previous topic :: View next topic  
Author Message
Faustov
Tux's lil' helper
Tux's lil' helper


Joined: 31 Oct 2004
Posts: 111
Location: Warsaw

PostPosted: Sat Nov 14, 2015 7:12 pm    Post subject: [SOLVED] asound.conf for onboard & usb audio simultaneou Reply with quote

Hello,

I have 2 sound cards, onboard and external connected via USB. The goal is to have sound via both of them.

System now detects each card but I can't get them both to play (just one at a time). Could anyone please have a look at my /etc/asound.conf file and advise what I am missing?

Code:

fst@ryba ~ % cat /etc/modprobe.d/alsa.conf
alias char-major-116 snd
alias char-major-14 soundcore

# Card 1
alias snd-card-0 snd-hda-intel
alias sound-slot-0 snd-hda-intel
alias sound-service-0-0 snd-mixer-oss
alias sound-service-0-3 snd-pcm-oss
alias sound-service-0-12 snd-pcm-oss
options snd-hda-intel index=0
options snd-hda-intel model=auto
alias /dev/dsp snd-pcm-oss


# Card 2
alias snd-card-1 snd_usb_audio
alias sound-slot-1 snd_usb_audio
alias sound-service-1-0 snd-mixer-oss
alias sound-service-1-1 snd-seq-oss
alias sound-service-1-3 snd-pcm-oss
alias sound-service-1-8 snd-seq-oss
alias sound-service-1-12 snd-pcm-oss
options snd-usb-audio index=1 vid=0x20b1 pid=0x3008
alias /dev/dsp1 snd-pcm-oss

options snd cards_limit=2


Code:

root@ryba ~ # cat asound.conf

pcm.!default plug:both

ctl.!default {
  type hw
  card 0
}

pcm.both {
  type route;
  slave.pcm {
      type multi;
      slaves.a.pcm "usb";
      slaves.b.pcm "onboard";
      slaves.a.channels 2;
      slaves.b.channels 4;
      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 b;
      bindings.4.channel 2;
      bindings.5.slave b;
      bindings.5.channel 3;
  }

  ttable.0.0 1;
  ttable.1.1 1;

  ttable.0.2 1; # front left
  ttable.1.3 1; # front right
  ttable.0.4 1; # copy front left to rear left
  ttable.1.5 1; # copy front right to rear right
}

ctl.both {
  type hw
  card 0
}

pcm.onboard {
   type dmix
   ipc_key 11024
   slave {
   pcm "hw:0,0"
   }
}

pcm.usb {
   type dmix
   ipc_key 22048
   slave {
   pcm "hw:1,0"
   }
}

ctl.onboard {
   type hw
   card 0
}

ctl.usb{
   type hw
   card 1
}


Last edited by Faustov on Sat Nov 21, 2015 8:12 pm; edited 1 time in total
Back to top
View user's profile Send private message
audiodef
Watchman
Watchman


Joined: 06 Jul 2005
Posts: 6639
Location: The soundosphere

PostPosted: Tue Nov 17, 2015 4:28 pm    Post subject: Reply with quote

I know you may be looking only for an ALSA answer, but could I persuade you to use JACK to control your sound card output? It's much more flexible, and you'd be able to use a GUI to switch to your preferred output at any time.
_________________
decibel Linux: https://decibellinux.org
Github: https://github.com/Gentoo-Music-and-Audio-Technology
Facebook: https://www.facebook.com/decibellinux
Discord: https://discord.gg/73XV24dNPN
Back to top
View user's profile Send private message
Faustov
Tux's lil' helper
Tux's lil' helper


Joined: 31 Oct 2004
Posts: 111
Location: Warsaw

PostPosted: Wed Nov 18, 2015 4:12 pm    Post subject: Reply with quote

Thanks! I was hoping for an alsa-only solution because I don't really need a GUI for something I modify once per 4-5 years... But at least the suggestion is not to use pulseaudio so I give you that ;)

I'll try JACK and let you know...
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3136

PostPosted: Wed Nov 18, 2015 4:33 pm    Post subject: Reply with quote

Definitely let us know, I've been thinking about a similar setup, but never really had enough time/pressure to actually do that.
A good post on this matter may stand a valid point for me, and perhaps quite a few others.
Back to top
View user's profile Send private message
depontius
Advocate
Advocate


Joined: 05 May 2004
Posts: 3509

PostPosted: Wed Nov 18, 2015 11:19 pm    Post subject: Reply with quote

I've recently been wanting this - with a slight twist. I'd like to have two headsets working completely in parallel - both microphones sourcing audio and audio going to both headphones. My wife and I use Skype with our daughter and her husband, and we have echo problems. I presume headsets would take care of that.
_________________
.sigs waste space and bandwidth
Back to top
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Thu Nov 19, 2015 9:58 am    Post subject: Reply with quote

Faustov wrote:
I'll try JACK and let you know...

As szatox and depontius said, please do.

One query, displaying my ignorance: you have !default in your asound.conf; what happens to default?
I'm wondering if that shouldn't be default, since anything else is directed at a specific card/destination already.

Sorry if that's a newb question.
Back to top
View user's profile Send private message
Faustov
Tux's lil' helper
Tux's lil' helper


Joined: 31 Oct 2004
Posts: 111
Location: Warsaw

PostPosted: Thu Nov 19, 2015 6:32 pm    Post subject: Reply with quote

Actually that might be something for me to check - I never changed that because it was in the examples, so I auto-assumed it is just the syntax.

I had a quick read last night about JACK and JACK2 and shrugged a bit about the overhead I'd be adding to my system (and I don't really have much time anymore to dig into things when they break). But I have a few other ideas to try with and without JACK{2}, just need to wait till Saturday ;)
Back to top
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Fri Nov 20, 2015 3:49 pm    Post subject: Reply with quote

Faustov wrote:
I had a quick read last night about JACK and JACK2 and shrugged a bit about the overhead I'd be adding to my system (and I don't really have much time anymore to dig into things when they break).

Seriously, don't worry about the "overhead": that's pulsefail's department.

JACK is about low-latency, essential for pro-audio work, which means less delay, not more.

Main thing I recall, is setting up RT stuff in-kernel, but not using an RT-kernel sources package. Most of the options have been integrated into mainline.
Michel Dominique wrote this up well, but I think the docs are on the site. Here's a useful post about it (from my bookmarks.) See also the alsa-jack bridge howto, but you want zita-ajbridge from pro-audio overlay.
Hmm media-libs/zita-alsa-pcmi is in-tree now. New one on me.

Anyhow there's plenty of help here; if you're stuck on a particular thing, you're in the right forum; or ask in #gentoo on IRC: chat.freenode.net or .org
#gentoo-desktop is about the closest wrt multimedia, but main channel is where you should get help on snafus; can also try #gentoo-chat but only if you're not getting anywhere in say half-an-hour in main-room, and mention that. (bear in mind no-one in #-chat has to help, nor even be on any sort of topic.)

I mention IRC, as it really is the bees-knees once you're used to it, and comfortable.

audiodef and Dominique (usernames) are two very knowledgeable users on the forums, wrt pro-audio.
audiodef provides the loverly GentooStudio.
Michel maintains fvwm-crystal, essentially as a way of being sure of his audio-workstation.

Though it's a shame there's no article on the Wiki about JACK, that I can see.
Volunteers to wrestle with wiki-format are ofc very welcome. (I found GuideXML much cleaner.)

Apologies if anything is old-hat to you.
Back to top
View user's profile Send private message
Faustov
Tux's lil' helper
Tux's lil' helper


Joined: 31 Oct 2004
Posts: 111
Location: Warsaw

PostPosted: Sat Nov 21, 2015 8:03 pm    Post subject: Reply with quote

As promised. So, I tried a few tricks with /etc/asound.conf but whatever I did, I just could not get sound from both cards. The below howto is based on JACK. On the 4.3 kernel (no -rt stuff, as written above most of the good stuff is long in the mainline kernel), it works well.

I rebuild @world to USE jack, which pulled in the daemon itself. Now, for some reason it is a daemon that does not have a startup script, so you'll need to figure out how you want to start it - for me it ended up in the xfce session controller (so it starts with my user ID when I log in) - but you can write a script too, just ensure it depends on alsasound.

There is a gotcha here - for running the jackd without root privileges, you need to edit limtis.conf to give the audio group rt permissions:
Code:

root@ryba ~ # grep audio /etc/security/limits.conf
@audio          -       rtprio          99
@audio      -   memlock      unlimited
@audio      -   nice      -10

And of course, have your user in the audio group. As always with groups - for them to take effect, all sessions must die.

Now, trick is you still need alsasound daemon running and a proper /etc/asound.conf which mixes multiple devices. Basically the following config works for the first two sound cards, because it uses the indexes instead of the device names (you get those from aplay -l. An exception is with the last config section, because it is apparently a dummy control, alsa needs it):

Code:

root@ryba ~ # cat /etc/asound.conf
pcm.both {
   type route;
        slave.pcm {
                type multi;
                slaves.a.pcm "plughw:0,0"
                slaves.b.pcm "plughw:1,0"
                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;
        }
   ttable.0.0 1;
        ttable.1.1 1;
        ttable.0.2 1;
        ttable.1.3 1;
}

pcm.jack {
   type jack
        playback_ports {
                0 system:playback_1
                1 system:playback_2
        }
   capture_ports {
                0 system:capture_1
                1 system:capture_2
        }
}

pcm.!default {
   type plug;
        slave.pcm "jack";
}

ctl.!default {
   type hw;
        card 0;
}


Next, I need to tell jack to start WITH this config too, so my line that starts it under xfce session starter is as follows:
Code:

/usr/bin/jackd -d alsa -P both

Explanation: run jackd using -Device alsa and -Playback both - because that's how my device is named in /etc/asound.conf: pcm.both

Final step is to tell your software, such as mplayer, moc music on console, or whatever else you use, to switch from alsa to jack - that's fairly easy, just rtfm.
Needed: alsa-plugins, jack-audio-connection-kit
Not needed: alsa_out, qjackctl (the gui thing), gst-plugins-alsa, pulseaudio

EDIT: I've modified the above asound.conf (or if you like, use .asoundrc - I prefer one cfg system wide) to get Firefox + HTML5 or adobe flash to work too (since you can't tell FF to use jack, it tries pulse by default and falls back to the default device of ALSA - which is why I modified that section.

Hope this helps!


Last edited by Faustov on Sun Nov 22, 2015 6:15 pm; edited 1 time in total
Back to top
View user's profile Send private message
Faustov
Tux's lil' helper
Tux's lil' helper


Joined: 31 Oct 2004
Posts: 111
Location: Warsaw

PostPosted: Sat Nov 21, 2015 8:11 pm    Post subject: Reply with quote

depontius wrote:
I've recently been wanting this - with a slight twist. I'd like to have two headsets working completely in parallel - both microphones sourcing audio and audio going to both headphones. My wife and I use Skype with our daughter and her husband, and we have echo problems. I presume headsets would take care of that.


I nearly forgot to anser this - basically this is doable, but to the jackd -d alsa -P whatever (you need to add) -C whatever-in
and have equally well defined "whatever-in" in asound.conf, but there are plenty of examples google knows about.
Back to top
View user's profile Send private message
audiodef
Watchman
Watchman


Joined: 06 Jul 2005
Posts: 6639
Location: The soundosphere

PostPosted: Sat Nov 21, 2015 9:37 pm    Post subject: Reply with quote

I'm glad you got it solved. Someone around here has a badass knowledge of ALSA setups, but I couldn't remember who. I need to track that down and put it on Gentoostudio.org somewhere.
_________________
decibel Linux: https://decibellinux.org
Github: https://github.com/Gentoo-Music-and-Audio-Technology
Facebook: https://www.facebook.com/decibellinux
Discord: https://discord.gg/73XV24dNPN
Back to top
View user's profile Send private message
Faustov
Tux's lil' helper
Tux's lil' helper


Joined: 31 Oct 2004
Posts: 111
Location: Warsaw

PostPosted: Sun Nov 22, 2015 6:17 pm    Post subject: Reply with quote

I have just edited the solution post to provide an updated config - basically I had to make modifications to get Firefox and HTML5/Flash to work. Hey, let me know if anything needs commenting!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Multimedia All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum