Question

I'm happily drawing waveforms to screen from pcm data. I have a problem where occassionally the waveforms height will exceed the height of the display area height.

How can I ensure that the waveform plotting data will never exceed a determined height without having to rip through the entire set of pcm data and normalizing from the maximum value found?

Was it helpful?

Solution

using a normalized representation is exactly what you would do.

you could cheat and pre-calculate max values for a given range, if that's a constraint offered by the implementation.

OTHER TIPS

Unfortunately, there is no good way to discover the actual maximum of a signal without going through sample by sample and finding it.

If you know the number of bits in the PCM samples, you can assume the scaling will be bounded by [-2^(bits-1), 2^(bits-1)-1]. That will be the absolute highest and lowest the signal can go. However, this is the most pessimistic scaling - if you have a 16-bit signal that never goes outside the range [-1024,1024], for instance, you're giving up a lot of display area (as well as ADC dynamic range, but that's another story).

If you are willing to dynamically scale the signal, you can simply make the graph scale bigger each time your signal would get clipped. A more sophisticated approach would be to upscale as necessary, but then slowly relax the max scale downwards over time. A good way to relax the max scale is exponential decay, like multiply the max scale by .98 (or some other number < 1) on each iteration.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top