You are not logged in.

#1 2012-01-17 21:36:36

Sotanaht
Member
Registered: 2012-01-14
Posts: 29

A few questions regarding ALSA and keyboard volume control

After much struggle, I've finally gotten my ASUS Xonar Essence ST to work under ALSA, but now I have a couple quirks to work out and a command I need to figure out.

I'm running LXDE and OpenBox, and I added the Volume Control applet to my panel, but it's not showing up.  Also, I have a Logitech G11 keyboard with a wheel for volume control, but the wheel currently does nothing.  How would I get it to function properly?

Also, I'd like to add two applets to the panel that switch between headphone output and speaker output, or if possible, one applet that detects the current state and switches to the other.  I can't seem to find anything in the amixer documentation regarding how to change the output, and only know how to do it using alsamixer.  What commands would I have to use to change the output, and to detect the current output?

Thanks smile

Offline

#2 2012-01-17 22:12:28

brebs
Member
Registered: 2007-04-03
Posts: 3,406

Re: A few questions regarding ALSA and keyboard volume control

Use xbindkeys. Run "xev" to hopefully detect the keycodes.

In ~/.xbindkeysrc I have:

"/usr/bin/amixer -q sset Master 2+ && /home/brebs/bin/notifyvolume"
    Control+Shift + Up
"/usr/bin/amixer -q sset Master 2- && /home/brebs/bin/notifyvolume"
    Control+Shift + Down

"/usr/bin/amixer -q sset Master 2+ && /home/brebs/bin/notifyvolume"
    KP_Multiply
"/usr/bin/amixer -q sset Master 2- && /home/brebs/bin/notifyvolume"
    KP_Subtract
"/usr/bin/amixer -q sset Master 0% && /home/brebs/bin/notifyvolume"
    KP_Divide


"/home/brebs/bin/speakers-headphones"
    Control+Shift + h
"/home/brebs/bin/speakers-surround"
    Control+Shift + s

notifyvolume is:

#!/bin/bash

exec /usr/bin/notify-send -t 1000 -i volume-knob "Volume $(amixer -q | grep -A5 Master | grep '%' | cut -d'[' -f2 | cut -d']' -f1)"

Also see speakers-* scripts.

A possible dirty trick to detect whether headphones are connected, is to do a diff of:

cat /proc/asound/card0/codec#0

E.g. I got:

-  Amp-Out vals:  [0x00 0x00]
+  Amp-Out vals:  [0x80 0x80]

Last edited by brebs (2012-01-17 22:13:18)

Offline

#3 2012-01-17 22:48:31

Sotanaht
Member
Registered: 2012-01-14
Posts: 29

Re: A few questions regarding ALSA and keyboard volume control

I'm having a problem with using amixer.  To run amixer or alsamixer, I need to add the argument "-c 0" or else I get a "no such file or directory" error.  This only works when the command is a simple "amixer -c 0", not when the rest of the arguments you provided are including.  Adding "-c 0" before or after "-q" gives me the error "-q: command not found".  How would I include the "-c 0"?

Also, I'm not trying to detect if headphones are connected.  I have an extension cable, so they're always connected as far as my sound card is concerned.  I want to check whether alsa is using speakers or headphones, so that I can make an applet on my panel that toggles between the two.

Offline

#4 2012-01-17 23:37:36

brebs
Member
Registered: 2007-04-03
Posts: 3,406

Re: A few questions regarding ALSA and keyboard volume control

Sotanaht wrote:

How would I include the "-c 0"?

I assume you're running pulseaudio, to need it.

man amixer gives an example:

amixer -c 1 -- sset Master playback -20dB

So maybe those 2 dashes are helpful.

I want to check whether alsa is using speakers or headphones, so that I can make an applet on my panel that toggles between the two.

Dunno. In my experience, ALSA automatically switches, when it detects a change in the headphone jack.

Looking in /usr/src/linux/sound/pci/oxygen/, maybe you have an amixer control for it. Try:

amixer | grep -i headph

Offline

#5 2012-01-17 23:45:05

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: A few questions regarding ALSA and keyboard volume control

@brebs: amixer already returns the current state when setting levels, so it would be cleaner to parse the results instead of doing a separate query in notifyvolume. I'm doing this (DWM):

button/volumeup)
        OUTPUT=$(/usr/bin/amixer set Master 5%+ | egrep 'Playback.*?\[o' | egrep -o '\[.+%\]');
        DISPLAY="0:0" /usr/bin/xsetroot -name "Volume: $OUTPUT";
;;

(there's probably a better way than doing two egrep's though, i'm waiting for karol to chime in)


ᶘ ᵒᴥᵒᶅ

Offline

Board footer

Powered by FluxBB