# Switch One Jack From Headphones To Mic Or Line-in



## dmtr (Mar 1, 2016)

Good evening!

Notebook ASUS X555LJ on Intel(R) Core(TM) i3-4005U CPU @ 1.70GHz
Installed FreeBSD 10.2 RELEASE amd64 and then update to 11-CURRENT amd64.

There is a need to switch the single jack from Headphones mode to  Line-in mode or Mic. Need record sound from this jack.


```
cat /dev/sndstat
FreeBSD Audio Driver (64bit 2009061500/amd64)
Installed devices:
pcm0: <Intel Haswell (HDMI/DP 8ch)> on hdaa0  (1p:1v/0r:0v)
pcm1: <Realtek (0x0233) (Internal Analog)> on hdaa1  (1p:4v/2r:4v) default
pcm2: <Realtek (0x0233) (Right Analog Headphones)> on hdaa1  (1p:1v/0r:0v)
```
No devices installed from userspace.

after `sysctl hw.snd.verbose=1`


```
sysctl dev.hdac.1.pindump=1 && dmesg

hdaa1: Dumping AFG pins:
hdaa1: nid  0x  as seq device  conn  jack  loc  color  misc
hdaa1: 18 40000000 0  0  Line-out  None  Unknown 0x00  Unknown 0 DISA
hdaa1:  Caps: IN   
hdaa1: 20 90170110 1  0  Speaker  Fixed Analog  Internal  Unknown 1
hdaa1:  Caps:  OUT  EAPD  Sense: 0x00000000 (disconnected)
hdaa1: 23 411111f0 15 0  Speaker  None  1/8  Rear  Black  1 DISA
hdaa1:  Caps:  OUT   
hdaa1: 24 411111f0 15 0  Speaker  None  1/8  Rear  Black  1 DISA
hdaa1:  Caps: IN  VREF Sense: 0x00000000 (disconnected)
hdaa1: 25 411111f0 15 0  Speaker  None  1/8  Rear  Black  1 DISA
hdaa1:  Caps: IN  VREF Sense: 0x00000000 (disconnected)
hdaa1: 26 411111f0 15 0  Speaker  None  1/8  Rear  Black  1 DISA
hdaa1:  Caps: IN  VREF Sense: 0x00000000 (disconnected)
hdaa1: 27 90a70130 3  0  Mic  Fixed Analog  Internal  Unknown 1
hdaa1:  Caps: IN OUT HP EAPD VREF Sense: 0x00000000 (disconnected)
hdaa1: 30 411111f0 15 0  Speaker  None  1/8  Rear  Black  1 DISA
hdaa1:  Caps:  OUT  Sense: 0x00000000 (disconnected)
hdaa1: [B]33[/B] 04211020 2  0  [B]Headphones[/B]  Jack  1/8  Right  Black  0
hdaa1:  Caps:  OUT HP EAPD  Sense: 0x00000000 (disconnected)
hdaa1: NumGPIO=3 NumGPO=0 NumGPI=0 GPIWake=0 GPIUnsol=1
hdaa1:  GPIO0: disabled
hdaa1:  GPIO1: disabled
hdaa1:  GPIO2: disabled
```
Change mode made by /boot/device.hints:

```
hint.hdac.1.cad0.nid33.config="as=2 seq=1 device=Line-in conn=Jack loc=Right color=Blue"
```

But this not work and device pcm2 disappear

Also not working are the following options:

```
hint.hdac.1.cad0.nid33.config="as=2 seq=0 device=Line-in conn=Jack loc=Right color=Blue"
hint.hdac.1.cad0.nid33.config="as=2 seq=0 device=Mic"
hint.hdac.1.cad0.nid33.config="as=2 seq=0 device=Line-in conn=Jack loc=Rear color=Blue"
hint.hdac.1.cad0.nid33.config="as=2 seq=1 device=Line-in conn=Jack loc=Right color=Blue"
hint.hdac.1.cad0.nid33.config="as=3 seq=15 device=Line-in conn=Jack loc=Rear color=Blue"
hint.hdac.1.cad0.nid33.config="as=3 seq=1 device=Line-in"
hint.hdac.1.cad0.nid33.config="as=3 seq=1 device=Mic"
hint.hdac.1.cad0.nid33.config="as=4 seq=15 device=Line-in conn=Jack"
hint.hdac.1.cad0.nid33.config="as=4 seq=0 device=Line-in"
hint.hdac.1.cad0.nid33.config="as=5 seq=0 device=Line-in"
hint.hdac.1.cad0.nid33.config="as=6 seq=0 device=Line-in"
hint.hdac.1.cad0.nid33.config="as=7 seq=0 device=Line-in"
```
Work only one variant, but mode continue headphones:

```
hint.hdac.1.cad0.nid33.config="as=2 seq=15"
```
Detailed analysis of the snd_hda(4) did not give ready-made solutions.

It's all in as and seq, but how to choose correctly?


----------



## SirDice (Mar 1, 2016)

dmtr said:


> Installed FreeBSD 10.2 RELEASE amd64 and then update to 11-CURRENT amd64.



Topics about unsupported FreeBSD versions


----------



## dmtr (Mar 2, 2016)

Good day!
Well, if it's important, we will discuss only the version FreeBSD 10.2 RELEASE amd64.


----------



## Juha Nurmela (Mar 2, 2016)

There is no "Caps: IN" for the jack in question. Maybe it's just not possible?

Juha


----------



## dmtr (Mar 2, 2016)

Hmm.
We have to think.
However it is normal practice that one jack and it works as a headphone and as a microphone. Strange saving of course.
The choice is made by the user at the time of sticking the socket in another operating system such as MS WIN.
And I want to put jack in a state of constant.
I'll note that iron implies this, but how to switch programmatically - that is the question


----------



## Juha Nurmela (Mar 2, 2016)

There are two record channels in pcm1, you've probably checked where they come from.

Juha


----------



## dmtr (Mar 3, 2016)

Juha Nurmela said:


> There are two record channels in pcm1, you've probably checked where they come from.
> 
> Juha



I too have noticed it.


```
cat /dev/sndstat
FreeBSD Audio Driver (64bit 2009061500/amd64)
Installed devices:
pcm0: <Intel Haswell (HDMI/DP 8ch)> on hdaa0  (1p:1v/0r:0v)
pcm1: <Realtek (0x0233) (Internal Analog)> on hdaa1  (1p:4v/2r:4v) default
pcm2: <Realtek (0x0233) (Right Analog Headphones)> on hdaa1  (1p:1v/0r:0v)
```

and how do you know who is a two channel recording?


----------



## Juha Nurmela (Mar 3, 2016)

Peek at dsp1.r0 and dsp1.r1.

Juha


----------



## dmtr (Mar 3, 2016)

Juha Nurmela said:


> Peek at dsp1.r0 and dsp1.r1.
> 
> Juha



not sure what you mean  please explain.


----------



## Juha Nurmela (Mar 3, 2016)

Just wild guesses, record from those devices and hear what you get.

Juha


----------



## shepper (Mar 3, 2016)

One thing that has not been mentioned is that newer hardware combines headphones and mic into a single 4 pin jack.  Older systems use a headphone/line-out jack with 3 pins (right channel, left channel, common).  The older 3 pin jacks were usually green.  The mic would usually be a separate blue jack with 2 pins (input, common).  If you are using a 4 pin connector, the mic should just work.

Edit: remove redundant 3pins.


----------



## dmtr (Mar 3, 2016)

shepper said:


> One thing that has not been mentioned is that newer hardware combines headphones and mic into a single 4 pin jack.  Older systems use a 3 pin headphone/line-out jack with 3 pins (right channel, left channel, common).  The older 3 pin jacks were usually green.  The mic would usually be a separate blue jack with 2 pins (input, common).  If you are using a 4 pin connector, the mic should just work.


I understood and realized that a little wrong. Need an adapter. At the output of one plug with 4 bands and two connector - headphone and microphone.
I will try ..


----------



## dmtr (Mar 4, 2016)

Good day!
_Developing the idea further._
And how to automatically switch the sound from the speakers of the laptop on the headphones when the headphones are plugged in.
And back - switch to laptop speakers when headphones are disconnected?
Seen a lot of information about this, but I would like to consider this question for this configuration.

That is, only these three NID, with *as* > 0.
`sysctl dev.hdac.1.pindump=1 && dmesg`


```
hdaa1: Dumping AFG pins:
hdaa1: nid  0x  as seq device  conn  jack  loc  color  misc
hdaa1: 20 90170110 1  0  Speaker  Fixed Analog  Internal  Unknown 1
hdaa1:  Caps:  OUT  EAPD  Sense: 0x00000000 (disconnected)
...
hdaa1: 27 90a70130 3  0  Mic  Fixed Analog  Internal  Unknown 1
hdaa1:  Caps: IN OUT HP EAPD VREF Sense: 0x00000000 (disconnected)
...
hdaa1: 33 04211020 2  0  Headphones  Jack  1/8  Right  Black  0
hdaa1:  Caps:  OUT HP EAPD  Sense: 0x00000000 (disconnected)
```

In General, for the future, I would like to examine the issue of the driver architecture, and to understand how that is formed.


----------



## Deleted member 9563 (Mar 4, 2016)

dmtr said:


> switch the single jack from Headphones mode to Line-in mode


One is an analogue input and the other is an output. To change them around you need to physically switch electrical connections. Think two ends of an OpAmp. Software can only do this if there is a way to electrically insulate one from the other. This could theoretically be done by an actual switching circuit but the jack is a physical item, not a digital one.


----------



## Juha Nurmela (Mar 4, 2016)

Sometimes one pin can be two without any active switches. Low-impedance driver, 1000 ohm resistance, line-out-and-in pin, high-impedance input stage. 

Juha


----------



## dmtr (Mar 4, 2016)

I will try this scheme, it complies with the CTIA 2012.
let's see what happens with immutable configurations from the point of view of the driver.


----------



## shepper (Mar 4, 2016)

dmtr said:


> Good day!
> _Developing the idea further._
> And how to automatically switch the sound from the speakers of the laptop on the headphones when the headphones are plugged in.
> And back - switch to laptop speakers when headphones are disconnected?



This was the subject of a prior Thread 54229


----------



## dmtr (Mar 10, 2016)

shepper said:


> This was the subject of a prior Thread 54229


Yes, thank you, it works.


----------



## dmtr (Mar 10, 2016)

dmtr said:


> I will try this scheme, it complies with the CTIA 2012.
> let's see what happens with immutable configurations from the point of view of the driver.


Complete nonsense. Does not work.
Did splitter 3.5 Jack pin 4 -> two 3.5 Jack to 3 pins one microphone and one headphone.
Headphones work.
The microphone does not wish to work.
It seems that physically the circuit is such that an external MIC cannot be used. I'll check with support ASUS.

I'm tired of all this pandemonium.
Bought an external sound card on the CM108 chip to work with the microphone.


----------



## shepper (Mar 10, 2016)

OJ said:


> One is an analogue input and the other is an output. To change them around you need to physically switch electrical connections. Think two ends of an OpAmp. Software can only do this if there is a way to electrically insulate one from the other. This could theoretically be done by an actual switching circuit but the jack is a physical item, not a digital one.



The manual page for snd_hda(4) indicates that pins can be configure as either "in" or "out"


> *EXAMPLES*
> Taking HP Compaq DX2300 with Realtek ALC888 HDA codec for example.     This
> system has    two audio connectors on    a front    side, three audio connectors
> on    a rear side and    one internal speaker.  According to verbose driver
> ...



Doing this is beyond my experience but in theory should be doable.  If you are able to accomplish this, you would become the forums resident expert on sound configuration.


----------



## Deleted member 9563 (Mar 10, 2016)

shepper said:


> The manual page for snd_hda(4) indicates that pins can be configure as either "in" or "out"


Could this be digital? That can go both ways on one physical line, but I'm still sceptical about running analogue signals in "both directions".


----------



## chrbr (Mar 10, 2016)

I think there are switches inside the chip to provide the flexibility, comparable to the good old http://www.ti.com/product/cd4066b. It is then of course either "in" or "out" per port.


----------



## shepper (Mar 10, 2016)

OJ said:


> Could this be digital? That can go both ways on one physical line, but I'm still sceptical about running analogue signals in "both directions".



Could the direction change occur at the level of the AnalogDigitalConverter?


----------



## chrbr (Mar 10, 2016)

The AnalogDigitalConverter is analog input to digital output. For analog signals it is an input. For the DigitalAnalogConverter it is opposite. The configuration should be as below.

```
---------------------------------------------
                 |
                 |         / o----------------->---ADC
socket ------------------o                                        Sound circuit
                 |           o-----------------<----DAC
                 |    switch
                 |    configurable by software
                  -----------------------------------------------
```
Of course the socket is usually stereo.


----------



## dmtr (Mar 12, 2016)

I switch Headphones To mode in /boot/device.hints:
hint.hdac.1.cad0.nid33.config="as=1 seq=15"
This work, nice work. But pcm2 disappeared.
In such a situation it is hardly possible to use jack as a microphone.

`cat /dev/sndstat`
FreeBSD Audio Driver (64bit 2009061500/amd64)
Installed devices:
pcm0: <Intel Haswell (HDMI/DP 8ch)> on hdaa0  (1p:1v/0r:0v)
pcm1: <Realtek (0x0233) (Analog 2.0+HP/2.0)> on hdaa1  (*1p*:4v/*2r*:4v) default

The combination of (*1p*:4v/*2r*:4v) leaves a lot of questions.
Why *2r*? Where the second recording source?
Even if splitter file audio through the microphone Jack, earphone Jack, his barely audible - i.e. the connection inside the device.


----------



## mav@ (Mar 31, 2016)

*2r* means that as result of your tunable there appeared extra unused ADC and driver plugged it for the same input signal to be able record same input two times, for example with different rate.


----------

