Detecting audio clipping

Hello there great coders!

I’m building an audio analyzer, FFT, and stereo goniometer/vectorscope.
Is going to be used as a tool for mastering on our home-studio.
The Raspberry v3 is going to run the code with the Logic Cirrus Audio Card inputting the sound.

I’m now working on the Peak, and RMS signals faders on both left and right channels.

Here is the thing:
When I’m sending a signal to the master on my DAW (Logic 9), I can see if this one is clipping, it marks from 0 to 6 dB’s (being that area when the RED light turns on).

Now, after the sound is send throw my soundcard (Motu Ultralite) and received on the Raspberry Pi Logic Cirrus soundcard, there’s NO way to see if the signal is clipped, or not, at least not with the dB’s markers…

This makes sense, as the maximum signal in digital is 0 dB’s.
How could I detect those extra “of-limits” 6 dB’s to turn the red light on?

How do analog to digital converters to detect clipping?

Any help, or ideas will be really appreciated!

Thanks a lot

there is a big problem here, as the signal is clipped by the DA converter of the first soundcard, then the gain is changed by the audio input preamp of the second soundcard.
If the input gain is not carefully calibrated you will get clipping in the second card input when there isn’t in the first, and if it is too low you won’t know if something is clipping.
Ideally if you calibrate the input gain in the way that 0dB of the Motu output is registered as 0dB in the rPi input then you could test clipping as a value of -1.0f or 1.0f in the samples buffer, but i don’t think you can get that really precise calibration.

Thanks npisanti!

Right now, everything seems to be really well calibrated…
0 dB’s on the output of the motu are really o dB’s on the input of the Raspberry, the same with other values, so one thing is good!

Yes, I think you could be right, I should look for values that are -1.0 or 1.0, sum them, and depending on the quantity of values that are “peaked”, I could do the math and see how much it peaked.

I’ll try that!

that seems a good idea =)
you could also set a “peaking threshold” in dB, this function for dB to linear conversion could be useful:

float dB(float value){
    return pow(10.0f, value*0.05f);


I plan to use RPI2 and RPI3 for sound input analysis and I want to find out if the Logic Cirrus Audio Card works (is recognized, ) smoothly and properly within the openframeworks… before I buy one. May be you have any advices what should I consider while using this Logic Cirrus Audio Card?

thx in advance.

It works perfectly!
You have to do some things to get it working, but after a couple of hours, it will be working smooth