View previous topic :: View next topic |
Author |
Message |
jiaxi n00b
Joined: 25 Sep 2012 Posts: 30
|
Posted: Tue Nov 27, 2012 12:38 pm Post subject: ALSA:How to switch to usb audio when usb audio plugin |
|
|
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 |
|
|
audiodef Watchman
Joined: 06 Jul 2005 Posts: 6639 Location: The soundosphere
|
|
Back to top |
|
|
jiaxi n00b
Joined: 25 Sep 2012 Posts: 30
|
Posted: Wed Nov 28, 2012 3:26 am Post subject: |
|
|
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 |
|
|
Logicien Veteran
Joined: 16 Sep 2005 Posts: 1555 Location: Montréal
|
Posted: Wed Nov 28, 2012 4:45 am Post subject: |
|
|
Hi,
you have the choice to tell every audio application which sound card to use, according to the output of the command
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 |
|
|
jiaxi n00b
Joined: 25 Sep 2012 Posts: 30
|
Posted: Wed Nov 28, 2012 6:27 am Post subject: |
|
|
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 |
|
|
Logicien Veteran
Joined: 16 Sep 2005 Posts: 1555 Location: Montréal
|
Posted: Wed Nov 28, 2012 1:04 pm Post subject: |
|
|
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 |
|
|
PaulBredbury Watchman
Joined: 14 Jul 2005 Posts: 7310
|
Posted: Wed Nov 28, 2012 5:47 pm Post subject: |
|
|
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 |
|
|
jiaxi n00b
Joined: 25 Sep 2012 Posts: 30
|
Posted: Fri Nov 30, 2012 1:09 am Post subject: |
|
|
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 |
|
|
Logicien Veteran
Joined: 16 Sep 2005 Posts: 1555 Location: Montréal
|
Posted: Sun Dec 02, 2012 2:28 am Post subject: |
|
|
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 |
|
|
jiaxi n00b
Joined: 25 Sep 2012 Posts: 30
|
Posted: Tue Dec 18, 2012 9:13 am Post subject: |
|
|
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 |
|
|
LiquidAcid Apprentice
Joined: 11 Sep 2006 Posts: 171
|
Posted: Sun Dec 30, 2012 12:15 am Post subject: |
|
|
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 |
|
|
jiaxi n00b
Joined: 25 Sep 2012 Posts: 30
|
Posted: Tue Jan 08, 2013 2:12 pm Post subject: |
|
|
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 |
|
|
jiaxi n00b
Joined: 25 Sep 2012 Posts: 30
|
Posted: Tue Jan 08, 2013 2:13 pm Post subject: |
|
|
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 |
|
|
|