How to detect input data through the audio jack?

前端 未结 4 1146
耶瑟儿~
耶瑟儿~ 2021-01-31 06:26

I know that some devices headphone ports (maybe all of them? any reference here would be good) have 3 channels, for stereo sound and microphone. So I was wondering if it\'s poss

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-31 06:52

    There are two potential paths of possibility here.

    • One would be to use the headset (or perhaps more specifically microphone) presence detection circuitry, and read that status via the appropriate API. This would be fairly simple (just have to figure out what property of a real headset is being measured). However, there is a good chance that the response may be fairly slow, as the phone is likely to go through some audio configuration changes and will not want to do that until it is "sure" that the headset has been connected or disconnected. Also the simplest non-microphone headset detection may be via a mechanical mechanism in the jack which could be difficult to electrically actuate across models.

    • A more complicated idea would be to couple some sound into the microphone input, and detect that in software. However, it will have to be an oscillating signal, as the microphone bandwidth typically does not range down to DC. If you just apply a steady voltage, you would get a "click" transient when it changes, but not otherwise. Injecting an audio frequency signal would require a power source - with careful design you may be able to steal enough power from the microphone bias supply to run a small oscillator. But perhaps simpler would be to have software output an audio tone on the speaker, and have your pedal switch couple this back into the microphone through a small capacitor.

提交回复
热议问题