Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
ALSA:How to switch to usb audio when usb audio plugin
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
jiaxi
n00b
n00b


Joined: 25 Sep 2012
Posts: 30

PostPosted: Tue Nov 27, 2012 12:38 pm    Post subject: ALSA:How to switch to usb audio when usb audio plugin Reply with quote

Hi,
There are two sound card. card0 is built-in.card1 is USB audio.

The sound can output from card0 when playing music,and now the sound how to switch to usb audio when plugin in usb audio ?
Back to top
View user's profile Send private message
audiodef
Watchman
Watchman


Joined: 06 Jul 2005
Posts: 5246

PostPosted: Tue Nov 27, 2012 2:19 pm    Post subject: Reply with quote

It's not clear whether you're trying to get your USB sound card to work at all or if you want to start playing audio with your built-in and then switch to the USB card.

Assuming you're just trying to get your USB sound card working, you generally want snd_usb_audio under ALSA. If that doesn't help, let me know and we'll see what we can figure out.
_________________
Gentoo Studio: http://gentoostudio.org
Facebook: http://www.facebook.com/gentoostudio
G+: https://plus.google.com/113947758237122861689/posts
Pappy's Kernel Seeds: http://kernel-seeds.gentoostudio.org
Back to top
View user's profile Send private message
jiaxi
n00b
n00b


Joined: 25 Sep 2012
Posts: 30

PostPosted: Wed Nov 28, 2012 3:26 am    Post subject: Reply with quote

audiodef wrote:
It's not clear whether you're trying to get your USB sound card to work at all or if you want to start playing audio with your built-in and then switch to the USB card.

Assuming you're just trying to get your USB sound card working, you generally want snd_usb_audio under ALSA. If that doesn't help, let me know and we'll see what we can figure out.


Thanks for your replay.

My usb sound card work fine in my system.

and now i want to start playing audio with my built-in and then switch to the USB card when usb audio plugin.

Can you give me some help?
Back to top
View user's profile Send private message
Logicien
l33t
l33t


Joined: 16 Sep 2005
Posts: 788
Location: Montréal

PostPosted: Wed Nov 28, 2012 4:45 am    Post subject: Reply with quote

Hi,
you have the choice to tell every audio application which sound card to use, according to the output of the command
Code:
aplay -l

It tell you the audio outputs you have and their respective number. For example, with Mplayer using Alsa drivers you will specify
Code:
mplayer -ao alsa:device=hw=0,0 audio-file

or
Code:
mplayer -ao alsa:device=hw=1,0 audio-file


That's a bit painfull to do that every time you want to change audio card. You can modify the file /etc/asound.conf or ~/.asoundrc to tell Alsa drivers which audio card to use by default:
Code:
pcm.!default {
        type  hw
        card 0
}

ctl.!default {
        type hw   
        card 0
}


You can change the zeros for any number you want according to aplay -l, than every program who use Alsa drivers should use the card number specify unless you change it in the Preferences of the program itself.

Every audio driver you want to use need to know which sound card you want to use. With Pulseaudio sound mixer set has the default Alsa output, you can use a graphical interface, Pulse Volume Control, to choose in the Configuration tab the sound card Pulse will use. In this way, /etc/asound.conf or ~/.asoundrc can look like this:
Code:
# Use PulseAudio by default
pcm.!default {
  type pulse
  fallback "sysdefault"
  hint {
    show on
    description "Default ALSA Output (currently PulseAudio Sound Server)"
  }
}

ctl.!default {
  type pulse
  fallback "sysdefault"
}


Every application set to use Alsa drivers or Pulseaudio has output should use the sound card you have specified for Pulse.
_________________
Paul
Back to top
View user's profile Send private message
jiaxi
n00b
n00b


Joined: 25 Sep 2012
Posts: 30

PostPosted: Wed Nov 28, 2012 6:27 am    Post subject: Reply with quote

Thank you for your replay.
In fact i want to start playing audio with my built-in card and then switch to the USB card when usb audio plugin automatically.

can ALSA or PulseAudio do it ?
Back to top
View user's profile Send private message
Logicien
l33t
l33t


Joined: 16 Sep 2005
Posts: 788
Location: Montréal

PostPosted: Wed Nov 28, 2012 1:04 pm    Post subject: Reply with quote

I do not think Alsa and Pulseaudio can switch automacically from a sound card to an other without any indication by the user.

Something have to be done to change the default sound card to use when you plug and unglug the Usb sound card. The change will not be reflected during audio activity but, if I am right, only between it. That's mean you can have to restart the audio programs in use.

Maybe someone else have an HOWTO. Udev and Dbus could do it. You can have informations from the Web.
_________________
Paul
Back to top
View user's profile Send private message
PaulBredbury
Watchman
Watchman


Joined: 14 Jul 2005
Posts: 7310

PostPosted: Wed Nov 28, 2012 5:47 pm    Post subject: Reply with quote

jiaxi wrote:
switch to the USB card when usb audio plugin automatically.

I can tell you what ALSA can do:

You could write a UDEV rule to alter or replace your ~/.asoundrc when the USB soundcard is added/removed. That would not affect any sound which is already being played, though.
_________________
Improve your font rendering and ALSA sound
Back to top
View user's profile Send private message
jiaxi
n00b
n00b


Joined: 25 Sep 2012
Posts: 30

PostPosted: Fri Nov 30, 2012 1:09 am    Post subject: Reply with quote

PulseAudio Feture:

Ability to change which output device an application plays sound through while the application is playing sound (without the application needing to support this, and indeed without even being aware that this happened)

That means Pulseaudio can do it ? Do you think so?
Back to top
View user's profile Send private message
Logicien
l33t
l33t


Joined: 16 Sep 2005
Posts: 788
Location: Montréal

PostPosted: Sun Dec 02, 2012 2:28 am    Post subject: Reply with quote

In Lxde menu, Preferences/PulseAudio Preferences/Simultaneous Output tab, there's an option that allow to create a virtual audio device that can be use to synchronise audio output with all sounds cards.
_________________
Paul
Back to top
View user's profile Send private message
jiaxi
n00b
n00b


Joined: 25 Sep 2012
Posts: 30

PostPosted: Tue Dec 18, 2012 9:13 am    Post subject: Reply with quote

Logicien wrote:
In Lxde menu, Preferences/PulseAudio Preferences/Simultaneous Output tab, there's an option that allow to create a virtual audio device that can be use to synchronise audio output with all sounds cards.


Thanks for your information.
Back to top
View user's profile Send private message
LiquidAcid
Apprentice
Apprentice


Joined: 11 Sep 2006
Posts: 171

PostPosted: Sun Dec 30, 2012 12:15 am    Post subject: Reply with quote

PulseAudio is fully scriptable via pactl. You just need to write something that moves all currently playing streams from the default device to the USB device. Then you let udev exec this (with a delay) upon plugin of the USB device. The removal should automatically be handled by PA, if you've loaded the right PA modules (should move the streams back to the fallback device when the current device disappears).
Back to top
View user's profile Send private message
jiaxi
n00b
n00b


Joined: 25 Sep 2012
Posts: 30

PostPosted: Tue Jan 08, 2013 2:12 pm    Post subject: Reply with quote

LiquidAcid wrote:
PulseAudio is fully scriptable via pactl. You just need to write something that moves all currently playing streams from the default device to the USB device. Then you let udev exec this (with a delay) upon plugin of the USB device. The removal should automatically be handled by PA, if you've loaded the right PA modules (should move the streams back to the fallback device when the current device disappears).

Thanks for your repaly. I donot have knowledge about PA.
Back to top
View user's profile Send private message
jiaxi
n00b
n00b


Joined: 25 Sep 2012
Posts: 30

PostPosted: Tue Jan 08, 2013 2:13 pm    Post subject: Reply with quote

LiquidAcid wrote:
PulseAudio is fully scriptable via pactl. You just need to write something that moves all currently playing streams from the default device to the USB device. Then you let udev exec this (with a delay) upon plugin of the USB device. The removal should automatically be handled by PA, if you've loaded the right PA modules (should move the streams back to the fallback device when the current device disappears).

Thanks for your repaly. I donot have knowledge about PA.
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