Electronic – How to read audio from a 3.5mm jack

adcamplifieraudio

A seemingly simple question that has a myriad of answers all over the web.

Goal: I am trying to design a device that is able to read analog audio and extract frequency distribution. I do not care about absolute amplitude, only relative amplitude, i.e. I am only trying to compare the intensity of certain frequencies in a given audio signal.

Why the other answers don't cut it: All the answers that I have found don't seem to address the issue of differing peak to peak voltage device to device and volume setting to volume setting. My device is going to sit between source and speaker, so it needs to be able to recalibrate when volume is changed. It will also be used with at least three different devices: my desktop, laptop, and phone. The P2P voltage at max volume on the headphone outputs of these 3 devices varies from hundreds of mV to 4V. My understanding is that there exist other devices with P2P voltages as high as 12V. I would like to design with those devices in mind as well.

I intend to use the ADC on my MCU with range 0-3V3.

If it wasn't clear already, I am by no means an electrical engineer and my understanding is fairly limited and I have not been able to devise a way to make this work. The issue the way I see it is that I need a circuit that will adjust gain and dc offset appropriately based on the source.

My thoughts so far: My current solution is to use two opamps as a peak detector and use that to add a dc offset to the signal using another opamp as an inverting amplifier. The gain of this amplifier will be adjusted using a digital potentiometer that is being controlled by the MCU. The amplifier starts at max gain and keeps stepping down until the peak of the signal is less than 3V3. The solution has the benefit that with a push of a button, I can reset the peak detector and instruct the MCU to begin recalibration. I am not at all married to this solution (I am asking how to best solve my goal, not how to fix the solution).

My Solution

However, I'm unsure how to protect my MCU from being damaged by input voltages greater than 3V3 (since the calibration method relies on starting above 3V3 and coming down).

Best Answer

You are on the right track. It is very unlikely that over-voltage audio signals will cause any kind of "damage" to the CPU or the ADC. The worst that can happen is that the signal will be "clipped" or "flat-topped" which will cause distortion. So you can write the firmware for your application to look for an extended sequence of minimum (zero) or maximum (your did you reveal your digital resolution?) and reduce the gain of the input stage. Or conversely detect an average audio level that is too low, and increase the gain, etc. You may be anticipating "problems" that aren't really "problems".