views:

301

answers:

6

Is there an algorithm or some heuristic to decide whether digital audio data is clipping?

+6  A: 

If you ever receive values at the maximum or minimum, then you are, by definition, clipping. Those values represent their particular value as well as all values beyond, and so they are best used as outside bounds detectors.

Adam Davis
-1: Slightly inaccurate: not by definition; the maximum and mkinimum can happen to be the maxima and minima of the waves of the underlying signal.
Charles Stewart
+2  A: 

What Adam said. You could also add some logic to detect maximum amplitude values over a period of time and only flag those, but the essence is to determine if/when the signal hits the maximum amplitude.

MSN

Mat Noguchi
A: 

http://www.dspguide.com/

superjoe30
-1: The page linked to lacks directly relevant content.
Charles Stewart
+2  A: 

For digital audio data, the term "clipping" doesn't really carry a lot of meaning other than "max amplitude". In the analog world, audio data comes from some hardware which usually contains a "clipping register", which allows you the possibility of a maximum amplitude that isn't clipped.

What might be better suited to digital audio is to set some threshold based on the limitations of your output D/A. If you're doing VOIP, then choose some threshold typical of handsets or cell phones, and call it "clipping" if your digital audio gets above that. If you're outputting to high-end home theater systems, then you probably won't have any "clipping".

Ben Collins
+2  A: 

I just noticed that there even are some nice implementations.

For example in Audacity:
AnalyzeFind Clipping…

bene
+3  A: 

The simple answer is that if any sample has the maximum or minimum value (-32768 and +32767 respectively for 16 bit samples), you can consider it clipping. This isn't stricly true, since that value may actually be the correct value, but there is no way to tell whether +32767 really should have been +33000.

For a more complicated answer: There is such a thing as sample counting clipping detectors that require x consecutive samples to be at the max/min value for them to be considered clipping (where x may be as high as 7). The theory here is that clipping in just a few samples is not audible.

That said, there is audio equipment that clips quite audible even at values below the maximum (and above the minimum). Typical advice is to master music to peak at -0.3 dB instead of 0.0 dB for this reason. You might want to consider any sample above that level to be clipping. It all depends on what you need it for.

Martin Vilcans
This is currently the best answer.
Charles Stewart
mastering at -0.3 dB isn't practical - you want your production to be as loud as possible without distorting the source.
superjoe30