반응형

출처 : https://unix.stackexchange.com/questions/62818/how-can-i-switch-between-different-audio-output-hardware-using-the-shell

$ pacmd list-sinks

2 sink(s) available.

    index: 0

name: <alsa_output.pci-0000_01_00.1.hdmi-stereo>

driver: <module-alsa-card.c>

flags: HARDWARE DECIBEL_VOLUME LATENCY 

state: IDLE

suspend cause: 

priority: 9050

volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB

        balance 0.00

base volume: 65536 / 100% / 0.00 dB

volume steps: 65537

muted: no

current latency: 100.14 ms

max request: 17 KiB

max rewind: 17 KiB

monitor source: 0

sample spec: s16le 2ch 44100Hz

channel map: front-left,front-right

             스테레오

used by: 0

linked by: 1

fixed latency: 100.14 ms

card: 0 <alsa_card.pci-0000_01_00.1>

module: 6

properties:

alsa.resolution_bits = "16"

device.api = "alsa"

device.class = "sound"

alsa.class = "generic"

alsa.subclass = "generic-mix"

alsa.name = "HDMI 0"

alsa.id = "HDMI 0"

alsa.subdevice = "0"

alsa.subdevice_name = "subdevice #0"

alsa.device = "3"

alsa.card = "1"

alsa.card_name = "HDA NVidia"

alsa.long_card_name = "HDA NVidia at 0xf6080000 irq 17"

alsa.driver_name = "snd_hda_intel"

device.bus_path = "pci-0000:01:00.1"

sysfs.path = "/devices/pci0000:00/0000:00:01.0/0000:01:00.1/sound/card1"

device.bus = "pci"

device.vendor.id = "10de"

device.vendor.name = "NVIDIA Corporation"

device.product.id = "0be9"

device.product.name = "GF106 High Definition Audio Controller"

device.string = "hdmi:1"

device.buffering.buffer_size = "17664"

device.buffering.fragment_size = "2944"

device.access_mode = "mmap"

device.profile.name = "hdmi-stereo"

device.profile.description = "Digital Stereo (HDMI)"

device.description = "GF106 High Definition Audio Controller Digital Stereo (HDMI)"

alsa.mixer_name = "Nvidia GPU 11 HDMI/DP"

alsa.components = "HDA:10de0011,10de0101,00100100"

module-udev-detect.discovered = "1"

device.icon_name = "audio-card-pci"

ports:

hdmi-output-0: HDMI / DisplayPort (priority 5900, latency offset 0 usec, available: yes)

properties:

device.icon_name = "video-display"

device.product.name = "DELL U2717D

 "

active port: <hdmi-output-0>

  * index: 1

name: <alsa_output.pci-0000_00_1b.0.analog-stereo>

driver: <module-alsa-card.c>

flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY 

state: IDLE

suspend cause: 

priority: 9959

volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB

        balance 0.00

base volume: 65536 / 100% / 0.00 dB

volume steps: 65537

muted: no

current latency: 101.03 ms

max request: 17 KiB

max rewind: 17 KiB

monitor source: 1

sample spec: s16le 2ch 44100Hz

channel map: front-left,front-right

             스테레오

used by: 0

linked by: 1

fixed latency: 99.95 ms

card: 1 <alsa_card.pci-0000_00_1b.0>

module: 7

properties:

alsa.resolution_bits = "16"

device.api = "alsa"

device.class = "sound"

alsa.class = "generic"

alsa.subclass = "generic-mix"

alsa.name = "ALC887-VD Analog"

alsa.id = "ALC887-VD Analog"

alsa.subdevice = "0"

alsa.subdevice_name = "subdevice #0"

alsa.device = "0"

alsa.card = "0"

alsa.card_name = "HDA Intel PCH"

alsa.long_card_name = "HDA Intel PCH at 0xf6100000 irq 30"

alsa.driver_name = "snd_hda_intel"

device.bus_path = "pci-0000:00:1b.0"

sysfs.path = "/devices/pci0000:00/0000:00:1b.0/sound/card0"

device.bus = "pci"

device.vendor.id = "8086"

device.vendor.name = "Intel Corporation"

device.product.id = "1c20"

device.product.name = "6 Series/C200 Series Chipset Family High Definition Audio Controller"

device.form_factor = "internal"

device.string = "front:0"

device.buffering.buffer_size = "17632"

device.buffering.fragment_size = "4408"

device.access_mode = "mmap"

device.profile.name = "analog-stereo"

device.profile.description = "아날로그 스테레오"

device.description = "내장 오디오 아날로그 스테레오"

alsa.mixer_name = "Realtek ALC887-VD"

alsa.components = "HDA:10ec0887,1458a002,00100302"

module-udev-detect.discovered = "1"

device.icon_name = "audio-card-pci"

ports:

analog-output-lineout: 라인 출력 (priority 9900, latency offset 0 usec, available: no)

properties:

analog-output-headphones: 헤드폰 (priority 9000, latency offset 0 usec, available: unknown)

properties:

device.icon_name = "audio-headphones"

active port: <analog-output-headphones>


$ pacmd 

Welcome to PulseAudio 8.0! Use "help" for usage information.

>>> help

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|name)

    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)

    set-port-latency-offset   Change the latency of a port (args: card-index|card-name, port-name, latency-offset)

    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-target            Change the log target (args: null|auto|syslog|stderr|file:PATH|newfile:PATH)

    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


You can use pactl, read its man page for more information.

In this case the card is always the same. What is changing between a switch and another is the "card-profile".


So the solution which actually worked is:


pacmd set-card-profile <cardindex> <profilename>

In my case I found all the card profiles with:


pacmd list-cards

And after I can switch between monitor and laptop speakers with:


pacmd set-card-profile 0 output:hdmi-stereo

And:


pacmd set-card-profile 0 output:analog-stereo+input:analog-stereo

Where 0 is the index of the card:


pacmd list-cards

Welcome to PulseAudio! Use "help" for usage information.

>>> 1 card(s) available.

    index: 0

    name: <alsa_card.pci-0000_00_1b.0>

And finally, in order to make the switch faster, I set up two alias in my .bashrc file:


alias audio-hdmi='pacmd set-card-profile 0 output:hdmi-stereo+input:analog-stereo'

alias audio-laptop='pacmd set-card-profile 0 output:analog-stereo+input:analog-stereo'

This way I can switch between audio from the monitor or from the laptop (headphones) typing in the shell: audio-hdmi or audio-laptop

반응형

'Linux > Linux 일반' 카테고리의 다른 글

dbus로 MPRIS 날려서 VLC 제어해보기  (0) 2019.02.25
udev / hidraw  (0) 2019.01.31
How use PulseAudio and JACK?  (0) 2019.01.07
Posted by Real_G