Page 4 of 4 FirstFirst ... 234
Results 31 to 34 of 34

Thread: Audio device switch

  1. #31
    Join Date
    Dec 2008
    Beans
    3

    Re: Audio device switch

    I'm new to all of this as well, and only came up with my solution through testing, trial, and error (and of course the starting point that the previous posts provided). I have looked into your question a bit, but I only have one card, so I cannot test through this as I did for my issue.

    That said, I started up a pacmd session, than enter "help" (without the quotes). From this you will see an entire list of what is possible and I wonder whether the profile names are identical between your cards, and if not whether you could still use the profile switch that I used above. If not, there is a "set-card-profile" command that would be my next area of research.

    Sorry I'm not able to be more helpful.

  2. #32
    Join Date
    Dec 2012
    Beans
    1

    Re: Audio device switch

    Here is the code for switching audio INPUTS.

    Code:
    #!/bin/bash
    ## This code is for switching audio inputs.
    
    declare -i sources=(`pacmd list-sources | sed -n -e 's/\**[[:space:]]index:[[:space:]]\([[:digit:]]\)/\1/p'`)
    declare -i sources_count=${#sources[*]}
    declare -i active_source_index=`pacmd list-sources | sed -n -e 's/\*[[:space:]]index:[[:space:]]\([[:digit:]]\)/\1/p'`
    declare -i next_source_index=${sources[0]}
    
    
    #find the next source (not always the next index number)
    declare -i ord=0
    while [ $ord -lt $sources_count ];
    do
        echo ${sources[$ord]}
        if [ ${sources[$ord]} -gt $active_source_index ] ; then
            next_source_index=${sources[$ord]}
            break
        fi
        let ord++
    done
    
    
    #change the default source
    pacmd "set-default-source ${next_source_index}"
    
    
    #move all outputs to the new source
    for app in $(pacmd list-source-outputs | sed -n -e 's/index:[[:space:]]\([[:digit:]]\)/\1/p');
    do
        pacmd "move-source-output $app $next_source_index"
    done
    
    
    #display notification
    declare -i ndx=0
    pacmd list-sources | sed -n -e 's/device.description[[:space:]]=[[:space:]]"\(.*\)"/\1/p' | while read line;
    do
        if [ $(( $ord % $sources_count )) -eq $ndx ] ; then
            notify-send -i notification-audio-volume-high --hint=string:x-canonical-private-synchronous: "Sound input switched to" "$line"
            exit
        fi
        let ndx++
    done;
    Basically it's the same code as from the original, just using pacmd list-sources (for input devices) instead of pacmd list-sinks (for output devices).
    Last edited by alesr; April 23rd, 2013 at 01:52 PM.

  3. #33
    Join Date
    Jan 2007
    Beans
    1,634
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Audio device switch

    This is my output from
    Code:
    pacmd list-cards
    Code:
    2 card(s) available.
        index: 0
    	name: <alsa_card.pci-0000_01_05.1>
    	driver: <module-alsa-card.c>
    	owner module: 4
    	properties:
    		alsa.card = "1"
    		alsa.card_name = "HDA ATI HDMI"
    		alsa.long_card_name = "HDA ATI HDMI at 0xd0410000 irq 19"
    		alsa.driver_name = "snd_hda_intel"
    		device.bus_path = "pci-0000:01:05.1"
    		sysfs.path = "/devices/pci0000:00/0000:00:01.0/0000:01:05.1/sound/card1"
    		device.bus = "pci"
    		device.vendor.id = "1002"
    		device.vendor.name = "Advanced Micro Devices [AMD] nee ATI"
    		device.product.name = "RS880 HDMI Audio [Radeon HD 4200 Series]"
    		device.string = "1"
    		device.description = "RS880 HDMI Audio [Radeon HD 4200 Series]"
    		module-udev-detect.discovered = "1"
    		device.icon_name = "audio-card-pci"
    	profiles:
    		output:hdmi-stereo: Digital Stereo (HDMI) Output (priority 5400)
    		off: Off (priority 0)
    	active profile: <output:hdmi-stereo>
    	sinks:
    		alsa_output.pci-0000_01_05.1.hdmi-stereo/#0: RS880 HDMI Audio [Radeon HD 4200 Series] Digital Stereo (HDMI)
    	sources:
    		alsa_output.pci-0000_01_05.1.hdmi-stereo.monitor/#0: Monitor of RS880 HDMI Audio [Radeon HD 4200 Series] Digital Stereo (HDMI)
    	ports:
    		hdmi-output-0: HDMI / DisplayPort (priority 5900, available: unknown)
    			properties:
    				
        index: 1
    	name: <alsa_card.pci-0000_00_14.2>
    	driver: <module-alsa-card.c>
    	owner module: 5
    	properties:
    		alsa.card = "0"
    		alsa.card_name = "HDA ATI SB"
    		alsa.long_card_name = "HDA ATI SB at 0xd0a00000 irq 16"
    		alsa.driver_name = "snd_hda_intel"
    		device.bus_path = "pci-0000:00:14.2"
    		sysfs.path = "/devices/pci0000:00/0000:00:14.2/sound/card0"
    		device.bus = "pci"
    		device.vendor.id = "1002"
    		device.vendor.name = "Advanced Micro Devices [AMD] nee ATI"
    		device.product.name = "SBx00 Azalia (Intel HDA)"
    		device.form_factor = "internal"
    		device.string = "0"
    		device.description = "Built-in Audio"
    		module-udev-detect.discovered = "1"
    		device.icon_name = "audio-card-pci"
    	profiles:
    		output:analog-stereo: Analog Stereo Output (priority 6000)
    		output:analog-stereo+input:analog-stereo: Analog Stereo Duplex (priority 6060)
    		input:analog-stereo: Analog Stereo Input (priority 60)
    		off: Off (priority 0)
    	active profile: <output:analog-stereo+input:analog-stereo>
    	sinks:
    		alsa_output.pci-0000_00_14.2.analog-stereo/#1: Built-in Audio Analog Stereo
    	sources:
    		alsa_output.pci-0000_00_14.2.analog-stereo.monitor/#1: Monitor of Built-in Audio Analog Stereo
    		alsa_input.pci-0000_00_14.2.analog-stereo/#2: Built-in Audio Analog Stereo
    	ports:
    		analog-output-speaker: Speakers (priority 10000, available: unknown)
    			properties:
    				
    		analog-output-headphones: Headphones (priority 9000, available: no)
    			properties:
    				
    		analog-input-microphone: Microphone (priority 8700, available: no)
    			properties:
    I can't quite figure out how to work with this. The card at index 0 is my ATI graphics card (ugh), which is apparently responsible for sound via HDMI out. The card at index 1 is my actual sound card.
    Don't forget to give thanks and mark your thread as solved

  4. #34
    Join Date
    Oct 2008
    Beans
    2

    Re: Audio device switch

    I found this thread very helpful, but for my needs, I just set up this simple script that switches between my monitor+desktop audio and HDMI tv+HDMI audio.
    Since I mostly use my TV with XBMC, I included that in the script, and mapped [Super+Enter (keypad)] to run it.
    Now everything switches to my TV when I want to watch something, and switches back when I exit XBMC.

    Code:
    #!/bin/bash
    
    if xrandr | grep -q ', current 1440'
    
    	then
    		xrandr --output HDMI-0 --mode 1920x1080 --output DVI-0 --off
    		xbmc
    		pacmd set-default-sink 0
    
    	while pgrep -u root xbmc > /dev/null; do sleep 1; done
    		xrandr --output DVI-0 --mode 1440x900 --output HDMI-0 --off
    		pacmd set-default-sink 1
    
    	else
    		xrandr --output DVI-0 --mode 1440x900 --output HDMI-0 --off
    		pacmd set-default-sink 1
    
    fi
    Now if I could only get Igor Cesko's COM receiver to work with lirc...

Page 4 of 4 FirstFirst ... 234

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •