Linux Audio

From S23Wiki
Revision as of 16:08, 27 September 2013 by DrOwl (Talk | contribs) (Added information about card profiles)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Linux Audio with Pulse Audio

Pulse Audio is a popular audio system for Linux.

Its basic command line app is "pacmd"


Sink: an audio output, typically an Analog audio output such as a sound card.

Source: an audio input, typically an Analog audio from a sound card such as a microphone. Can also can be a loop back / monitor of an audio output (Sink)

A very nice audio mixer with graphical options for setting up and choosing inputs / outputs (as below) is pavucontrol

List Default Devices

You can use `pactl info` to list the default devices / settings Pulse Audio is using.

# pactl info
Default Sink: alsa_output.pci-0000_00_1b.0.analog-stereo
Default Source: alsa_input.usb-Behringer_BCD3000-00-BCD3000.analog-4-channel-input


List available sound outouts

# pacmd list-sinks 
Welcome to PulseAudio! Use "help" for usage information.
>>> 2 sink(s) available.
  index: 0
	name: <alsa_output.pci-0000_00_1b.0.analog-stereo> 
	state: RUNNING
  * index: 14
	name: <alsa_output.usb-Behringer_BCD3000-00-BCD3000.analog-surround-40>
	driver: <module-alsa-card.c>
	state: RUNNING

Change Default Output Device

# pacmd "set-default-sink ${Device Index}"


# pacmd "set-default-sink ${Device Name}"


# pacmd "set-default-sink 14"
Welcome to PulseAudio! Use "help" for usage information.
>>> >>> 
# pacmd set-default-sink alsa_output.usb-Behringer_BCD3000-00-BCD3000.analog-surround-40
Welcome to PulseAudio! Use "help" for usage information.
>>> >>> 

List Apps using sound outputs

# pacmd list-sink-inputs
Welcome to PulseAudio! Use "help" for usage information.
>>> 2 sink input(s) available.
	index: 1994
		driver: <protocol-native.c>
		state: RUNNING
		sink: 0 <alsa_output.pci-0000_00_1b.0.analog-stereo>
... = "12170"
			application.process.binary = "java"
	index: 2106
		driver: <protocol-native.c>
		flags: START_CORKED 
		state: RUNNING
		sink: 14 <alsa_output.usb-Behringer_BCD3000-00-BCD3000.analog-surround-40>
... = "22083"
			application.icon_name = "media-player-banshee"

Move App to another output device

# pacmd "move-sink-input ${App Index}  ${Device Index}"

# pacmd "move-sink-input 1994 0"
Welcome to PulseAudio! Use "help" for usage information.
>>> >>> 


List available sound inputs

# pacmd list-sources

 # pacmd list-sources
Welcome to PulseAudio! Use "help" for usage information.
>>> 4 source(s) available.
    index: 0
	name: <alsa_output.pci-0000_00_1b.0.analog-stereo.monitor>
		device.description = "Monitor of Built-in Audio Analog Stereo"
		device.class = "monitor"
  * index: 1
	name: <alsa_input.pci-0000_00_1b.0.analog-stereo>
	used by: 0
	linked by: 0
	module: 4
	properties: = "VT1708S Analog" = "VT1708S Analog"
		alsa.card_name = "HDA Intel PCH" = "analog-stereo"
		device.profile.description = "Analog Stereo"
		device.description = "Built-in Audio Analog Stereo"
		analog-input-microphone-front: Front Microphone (priority 8500, available: unknown)
		analog-input-microphone-rear: Rear Microphone (priority 8200, available: unknown)
		analog-input-linein: Line In (priority 8100, available: unknown)
	active port: <analog-input-microphone-front>
    index: 28
	name: <alsa_output.usb-Behringer_BCD3000-00-BCD3000.analog-surround-40.monitor>
		device.description = "Monitor of BCD3000 Analog Surround 4.0"
		device.class = "monitor"
    index: 29
	name: <alsa_input.usb-Behringer_BCD3000-00-BCD3000.analog-4-channel-input>
	used by: 0
	linked by: 0 = "USB Audio" = "USB Audio"
		alsa.card_name = "BCD3000" = "analog-4-channel-input"
		device.profile.description = "Analog 4-channel Input"
		device.description = "BCD3000 Analog 4-channel Input"
		alsa.mixer_name = "USB Mixer"

Managing Card Profiles

Audio device will often have multiple usage Profiles. Profiles such as "Input", "output" or "Input and Output"

Having your card set in the "wrong" profile will prevent its sink or source showing up and there for pulseaudio will not show the device as you may expect.

Listing a Cards Profile

We can see what profile our sound card is currently running in by listing the cards current settings.

# pactl list cards
Card #1
	Name: alsa_card.usb-Behringer_BCD3000-00-BCD3000
	Driver: module-alsa-card.c
	Owner Module: 26
		alsa.card_name = "BCD3000"
		alsa.long_card_name = "Behringer BCD3000 at usb-0000:00:1d.0-1.7, full speed"
		alsa.driver_name = "snd_usb_audio"
... = "usb-Behringer_BCD3000-00-BCD3000"
		device.description = "BCD3000"
		module-udev-detect.discovered = "1"
		device.icon_name = "audio-card-usb"
		output:analog-surround-40: Analog Surround 4.0 Output (sinks: 1, sources: 0, priority. 700)
		output:analog-surround-40+input:analog-4-channel-input: Analog Surround 4.0 Output + Analog 4-channel Input Input (sinks: 1, sources: 1, priority. 701)
		input:analog-4-channel-input: Analog 4-channel Input Input (sinks: 0, sources: 1, priority. 1)
		off: Off (sinks: 0, sources: 0, priority. 0)
	Active Profile: output:analog-surround-40+input:analog-4-channel-input

Changing Profile

Changing the cards profile is simple we simple need the name of the card and profile we want to use. These names can be found in the output of the list command (above)

# pacmd set-card-profile ${Card Name} ${Profile Name}
# pacmd set-card-profile alsa_card.usb-Behringer_BCD3000-00-BCD3000 output:analog-surround-40+input:analog-4-channel-input
Welcome to PulseAudio! Use "help" for usage information.

pacmd help

#pacmd help
Welcome to PulseAudio! Use "help" for usage information.
>>> Available commands:
   help                      Show this help
   list-modules              List loaded modules
   list-cards                List cards
   list-sinks                List loaded sinks
   list-sources              List loaded sources
   list-clients              List loaded clients
   list-sink-inputs          List sink inputs
   list-source-outputs       List source outputs
   stat                      Show memory block statistics
   info                      Show comprehensive status
   load-module               Load a module (args: name, arguments)
   unload-module             Unload a module (args: index)
   describe-module           Describe a module (arg: name)
   set-sink-volume           Set the volume of a sink (args: index|name, volume)
   set-source-volume         Set the volume of a source (args: index|name, volume)
   set-sink-mute             Set the mute switch of a sink (args: index|name, bool)
   set-source-mute           Set the mute switch of a source (args: index|name, bool)
   set-sink-input-volume     Set the volume of a sink input (args: index, volume)
   set-source-output-volume  Set the volume of a source output (args: index, volume)
   set-sink-input-mute       Set the mute switch of a sink input (args: index, bool)
   set-source-output-mute    Set the mute switch of a source output (args: index, bool)
   set-default-sink          Set the default sink (args: index|name)
   set-default-source        Set the default source (args: index|name)
   set-card-profile          Change the profile of a card (args: index|name, profile-name)
   set-sink-port             Change the port of a sink (args: index|name, port-name)
   set-source-port           Change the port of a source (args: index|name, port-name)
   suspend-sink              Suspend sink (args: index|name, bool)
   suspend-source            Suspend source (args: index|name, bool)
   suspend                   Suspend all sinks and all sources (args: bool)
   move-sink-input           Move sink input to another sink (args: index, sink)
   move-source-output        Move source output to another source (args: index, source)
   update-sink-proplist      Update the properties of a sink (args: index|name, properties)
   update-source-proplist    Update the properties of a source (args: index|name, properties)
   update-sink-input-proplist Update the properties of a sink input (args: index, properties)
   update-source-output-proplist Update the properties of a source output (args: index, properties)
   list-samples              List all entries in the sample cache
   play-sample               Play a sample from the sample cache (args: name, sink|index)
   remove-sample             Remove a sample from the sample cache (args: name)
   load-sample               Load a sound file into the sample cache (args: name, filename)
   load-sample-lazy          Lazily load a sound file into the sample cache (args: name, filename)
   load-sample-dir-lazy      Lazily load all files in a directory into the sample cache (args: pathname)
   kill-client               Kill a client (args: index)
   kill-sink-input           Kill a sink input (args: index)
   kill-source-output        Kill a source output (args: index)
   set-log-level             Change the log level (args: numeric level)
   set-log-meta              Show source code location in log messages (args: bool)
   set-log-time              Show timestamps in log messages (args: bool)
   set-log-backtrace         Show backtrace in log messages (args: frames)
   play-file                 Play a sound file (args: filename, sink|index)
   dump                      Dump daemon configuration
   dump-volumes              Debug: Show the state of all volumes
   shared                    Debug: Show shared properties
   exit                      Terminate the daemon

pactl help

# pactl --help
pactl [options] stat [short]
pactl [options] info
pactl [options] list [short] [TYPE]
pactl [options] exit
pactl [options] upload-sample FILENAME [NAME]
pactl [options] play-sample  NAME [SINK]
pactl [options] remove-sample  NAME
pactl [options] load-module  NAME [ARGS ...]
pactl [options] unload-module  #N
pactl [options] move-(sink-input|source-output) #N SINK|SOURCE
pactl [options] suspend-(sink|source) NAME|#N 1|0
pactl [options] set-card-profile  CARD PROFILE
pactl [options] set-(sink|source)-port NAME|#N PORT
pactl [options] set-(sink|source)-volume NAME|#N VOLUME
pactl [options] set-(sink-input|source-output)-volume #N VOLUME
pactl [options] set-(sink|source)-mute NAME|#N 1|0
pactl [options] set-(sink-input|source-output)-mute #N 1|0
pactl [options] set-sink-formats #N FORMATS
pactl [options] subscribe

 -h, --help                            Show this help
      --version                         Show version

 -s, --server=SERVER                   The name of the server to connect to
 -n, --client-name=NAME                How to call this client on the server

Linux Pulseaudio USB Audio