Does JUCE have a function to read true peak?
You could use oversampling to generate the ‘missing’ samples which might give a more accurate peak value, of course that won’t necessarily give you the absolute highest peak but it will give you a closer estimate.
Might be a bit expensive to check every sample of an oversampled signal so maybe you could optimise by first checking a window of say 10-15 samples to see if it contains a peak and then just oversample that window using an interpolator to get a much larger window.
The AudioBuffer<> class has functions to determine min/max (i.e. peak) in a variety of formats.
Depending on what you mean by “peak”, I would say findMinMax() seems like a candidate. If you mean absolutely value, the getMagnitude () functions are possibly a better fit.
Range< Type > findMinMax (int channel, int startSample, int numSamples) const noexcept
Returns a Range indicating the lowest and highest sample values in a given section. More…
Type getMagnitude (int channel, int startSample, int numSamples) const noexcept
Finds the highest absolute sample value within a region of a channel. More…
Type getMagnitude (int startSample, int numSamples) const noexcept
Finds the highest absolute sample value within a region on all channels. More…
Type getRMSLevel (int channel, int startSample, int numSamples) const noexcept
That would return the maximum sample value but that’s not the same thing as ‘true peak’ which refers to the peak value after a signal has been converted back to analogue.
For example, you could have a sin wave sampled 4 times such that you have the values [0.0, 1.0, 1.0, 0.0]. The maximum sample value would be 1.0 but the actual true peak of the sin wave would be between those 2 samples and so would be something like 1.1 (not-so-educated guess).
Short answer is no, JUCE doesn’t have any methods to get such a value (AFAIK) but one could easily utilise a few other JUCE APIs to calculate it.
There’s a good and relatively simple writeup from Russell at iZotope on how true peak estimation works here. Juce doesn’t supply something to do all these steps together, but it should be pretty easy to piece together.