Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Alsa: How to detect if headphones plugged?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Multimedia
View previous topic :: View next topic  
Author Message
musv
Advocate
Advocate


Joined: 01 Dec 2002
Posts: 2696
Location: de

PostPosted: Sun Nov 11, 2012 9:18 pm    Post subject: Alsa: How to detect if headphones plugged? Reply with quote

Hi there,

Currently I'm switching back from OSS4 to Alsa for several reasons. For OSS I wrote a script to change the volume by pressing some key combinations. This I want to adopt to the amixer settings.

amixer ALC269:
Simple mixer control 'Master',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined
  Playback channels: Mono
  Limits: Playback 0 - 64
  Mono: Playback 48 [75%] [-16.00dB] [on]
Simple mixer control 'Headphone',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 64
  Mono:
  Front Left: Playback 54 [84%] [-9.00dB] [on]
  Front Right: Playback 54 [84%] [-9.00dB] [on]
Simple mixer control 'Speaker',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 64
  Mono:
  Front Left: Playback 53 [83%] [-10.00dB] [on]
  Front Right: Playback 53 [83%] [-10.00dB] [on]
Simple mixer control 'PCM',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 255
  Mono:
  Front Left: Playback 255 [100%] [0.00dB]
  Front Right: Playback 255 [100%] [0.00dB]
Simple mixer control 'Mic',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Mono:
  Front Left: Playback 0 [0%] [-34.50dB] [off]
  Front Right: Playback 0 [0%] [-34.50dB] [off]
Simple mixer control 'Mic Boost',0
  Capabilities: volume
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 3
  Front Left: 0 [0%] [0.00dB]
  Front Right: 0 [0%] [0.00dB]
Simple mixer control 'Capture',0
  Capabilities: cvolume cswitch
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 46
  Front Left: Capture 29 [63%] [12.00dB] [on]
  Front Right: Capture 29 [63%] [12.00dB] [on]
Simple mixer control 'Auto-Mute Mode',0
  Capabilities: enum
  Items: 'Disabled' 'Enabled'
  Item0: 'Enabled'
Simple mixer control 'Internal Mic',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Mono:
  Front Left: Playback 0 [0%] [-34.50dB] [off]
  Front Right: Playback 0 [0%] [-34.50dB] [off]
Simple mixer control 'Internal Mic Boost',0
  Capabilities: volume
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 3
  Front Left: 0 [0%] [0.00dB]
  Front Right: 0 [0%] [0.00dB]


Relevant for me are the following mixers:
  • Speaker
  • Headphone


Idea:
  • When no headphones are plugged, my script should change the Speaker volume.
  • If headphones are plugged, the script should change Headphone volume.


Problem:
I didn't find a state information, if the headphones are plugged or not. Neither in amixer settings nor in /proc/asound.

Is there a chance to find out the plugged-state?
Back to top
View user's profile Send private message
audiodef
Watchman
Watchman


Joined: 06 Jul 2005
Posts: 5282

PostPosted: Mon Nov 12, 2012 2:09 pm    Post subject: Reply with quote

That's possible only if it's supported by hardware. Normally, stereo and mini-stereo jacks simply transmit audio and do nothing else. I've never played around with this, but if you can determine that your hardware has a sensor for plugged states for your audio connections, then the short answer is yes, you can do that. Otherwise, there's no way to.
_________________
Gentoo Studio: http://gentoostudio.org
Facebook: http://www.facebook.com/gentoostudio
G+: https://plus.google.com/113947758237122861689/posts
Pappy's Kernel Seeds: http://kernel-seeds.org
Back to top
View user's profile Send private message
Clad in Sky
l33t
l33t


Joined: 04 May 2007
Posts: 778
Location: Germany

PostPosted: Mon Nov 12, 2012 4:40 pm    Post subject: Reply with quote

There's this in the kernel for SND_HDA_INTEL. So if you have an intel chip, this might work. Dunno how to actually get the information via the input layer, though.
# CONFIG_SND_HDA_INPUT_JACK is not set
_________________
Kali Ma
Now it's autumn of the aeons
Dance with your sword
Now it's time for the harvest
Back to top
View user's profile Send private message
audiodef
Watchman
Watchman


Joined: 06 Jul 2005
Posts: 5282

PostPosted: Mon Nov 12, 2012 7:40 pm    Post subject: Reply with quote

I would imagine that if the hardware supports it, there should be a corresponding device in /dev. So an easy test would be to diff the contents of /dev before and after plugging into the headphone jack.
_________________
Gentoo Studio: http://gentoostudio.org
Facebook: http://www.facebook.com/gentoostudio
G+: https://plus.google.com/113947758237122861689/posts
Pappy's Kernel Seeds: http://kernel-seeds.org
Back to top
View user's profile Send private message
PaulBredbury
Watchman
Watchman


Joined: 14 Jul 2005
Posts: 7310

PostPosted: Mon Nov 12, 2012 7:50 pm    Post subject: Reply with quote

audiodef wrote:
diff the contents of /dev

Also hda-verb.
Back to top
View user's profile Send private message
musv
Advocate
Advocate


Joined: 01 Dec 2002
Posts: 2696
Location: de

PostPosted: Mon Nov 12, 2012 9:00 pm    Post subject: Reply with quote

audiodef wrote:
That's possible only if it's supported by hardware.

That's not the problem. If the headphones are plugged, the speakers are mute and the sound is played via the headphones and viceversa.

PaulBredbury wrote:
Also hda-verb.

Thanks, that looks like what I was looking for. I'll study that later.
Back to top
View user's profile Send private message
audiodef
Watchman
Watchman


Joined: 06 Jul 2005
Posts: 5282

PostPosted: Tue Nov 13, 2012 3:43 pm    Post subject: Reply with quote

musv wrote:
audiodef wrote:
That's possible only if it's supported by hardware.

That's not the problem. If the headphones are plugged, the speakers are mute and the sound is played via the headphones and viceversa.


Ergo, the hardware does detect the change, so you should be able to write a script to take action based on that change. :)
_________________
Gentoo Studio: http://gentoostudio.org
Facebook: http://www.facebook.com/gentoostudio
G+: https://plus.google.com/113947758237122861689/posts
Pappy's Kernel Seeds: http://kernel-seeds.org
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Multimedia All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum