For working with audio input (AC) - from a laptop's or smartphone's headphone output (TRS jack) or a PC's soundcard output (RCA jack) and using a 5V microcontroller with 10-bit ADC - what is the preferred way? It seems like after 2,5V baseline shifting (DC), output from a PC's soundcard yields a much better range of 580 peak-to-peak, compared to a mere 183 peak-to-peak from a headphone output. Is this a good way to think about it? If one were forced to use a headphone output, is the only viable option to use 3.3V AREF, so the baseline would sit at 1.65V? Thanks for some clarifications!
The 5V reference is probably OK, depending on how much resolution you need and what you are doing.
Assuming you are adjusting the volume control you can get wide range of audio signals.
I've got some sound activated lighting effects and I switch automatically between the 5V and 1.1V references on an Uno depending on the signal I'm getting. I also adjust the software references.
But I'm using an op-amp peak detector and just reading the "loudness" so there is no negative and I don't have to bias the input.
With multiple analog inputs, you can have multiple inputs connected with different biases and select the most appropriate one in software..
Isn't a higher resolution obtained with a line input instead of a headphone input better, more "room to work with"? Wouldn't using an AREF of 3.3V be the preferred option for headphone inputs in case one must use those? A maximum resolution of 183 values from a headphone output seems rather poor, if the standard 5V reference voltage is used.
For a 32 ohm headphone that would be only 131uW output power
Most headphone outputs can supply 50mW to 100mW
You are doing something wrong somewhere
I took the nominal levels shown here.
An Apple MacBook Pro's headphone output provides 1.08V and a DELL XPS' headphone output provides 0.94V, a Huawei P30 smartphone 0.77V. So 0.894V is quite close to that nominal level. How many volts do headphone outputs provide in your experience; what voltage should I use to compare to line level? In any case, 3.3V AREF seems better for both headphone and line inputs.
With a 10 bit ADC the LSB size with a 3.3V ref will be 3.3/1024 = 3.22mV
The LSB size with a 5.0V ref will be 5.0/1024 = 4.88mV
So it's more "granular" with the 5V reference
Thanks, 4.8V and 3.2mV is what I had. So, around 588 possible values (5V) is better than around 884 possible values (3.3V AREF)? I read before that it would be just the other way around; higher precision, higher resolution.
What about the headphone output voltages you have seen in your experience? You mentioned that something was wrong.
No 844 is better than 588
What about the headphone output voltages you have seen in your experience?
It depends. At full volume I've seen as high as 5V p-p from some computers and laptops.
There is no standard output level.
All right, so then using 3.3V AREF is better for laptop/smartphone headphone level below 1.5V maximum, and soundcard level is better than using laptop/smartphone headphone output.
Yes but you can go as high 1.65V peak but 1.5V is a good safety margin
I see, thanks.
Last question: To capture the full "loudness" of the sounds I'm intending to measure, the negative half of the former AC signal below the 2.5V or 1.65V baseline needs to be mirrored to the positive half like so?
int audioIn; // Input from headphone level or line level
int levelShift = 512;
audioIn = abs(analogRead(A0) - levelShift);
In case of 3.3V AREF and 279 peak-to-peak from the headphone level, I would obtain a final value range of 0 - 139 to work with, and a range of 0 - 442 from the line level, so a PC's soundcard's line level output "beats" a laptop's headphone level output. Smartphone level output is probably the worst of the three, real Hi-Fi amplifier output and then 5V AREF probably the best of them all?
The negative half will be below 0V.
It's AC, so the signal will go Plus and Minus.
You can't connec an AC signal directly to an Arduino
Or are you shifting it up by 2.5V, 1.65V before it goes to the ADC?
In any case you would not take the absolute value of the signal.
Correct. And I've done that.
But if all you're after is loudness, the positive & negative peaks are about the same so you probably don't need both.
If you are calculating an average (or moving average) finding the absolute value is helpful because the true-average is zero (positive half the time and negative half the time).
If you are using FFT to get the frequency information you need to keep the negative & positive halves of the waveform intact.
...I mentioned above that I've used a Peak Detector which charges a capacitor up to the peak, and then it discharges depending on the resistor & capacitor values. (Sometimes this is called an "envelope follower".) I use one similar to the link which is half-wave and it ignores the negative half of the waveform.
With a peak detector I can sample more slowly (maybe 10 times per second) instead of sampling the audio waveform thousands of times per second. That frees-up the processor to do other things.
Yep, see #1, and the images; it's shifted 2.5V or 1.65V respectively. What I mean is negative in relation to the baseline. There's a capacitor behind the output, then a voltage divider for the level shifting, then comes the microcontroller's analog pin.
It's about "loudness" of sounds, which are noise recordings that were done with a Zoom H6 field recorder; I only have the WAV files, unfortunately not the recorder (which has a line level output). I will have to try playback from maybe two or three different laptops and PCs to see what actually comes out of their TRS/RCA jacks.
Why would you think I won't need both? What's the explanation for that? There's no FFT involved.
Here's positive, negative, and peak-to-peak of an example.
What I mean is negative in relation to the baseline.
Ok that is fine but why do you think you need to take the absolute value?
Are you trying to find the peak voltage, average voltage or RMS voltage?
I'm after the peak amplitude.
OK then take the abs() and compare your first sample to the next sample and save the bigger one
Then compare that one to the next sample and so on.
Do that for however long you think is necessary for the signal you are are analyzing.
However, I think that the RMS value would be a better measure of "loudness"
All right, I will look up RMS in relation to "loudness". I don't have an acoustics background.
I found this here regarding RMS quite good for the layperson to understand.


