mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added method AudioData::Pointer::findMinAndMax
This commit is contained in:
parent
f5175b3c2d
commit
a802f5d081
1 changed files with 50 additions and 2 deletions
|
|
@ -422,8 +422,7 @@ public:
|
|||
{
|
||||
static_jassert (Constness::isConst == 0); // trying to write to a const pointer! For a writeable one, use AudioData::NonConst instead!
|
||||
|
||||
Pointer dest (*this);
|
||||
while (--numSamples >= 0)
|
||||
for (Pointer dest (*this); --numSamples >= 0;)
|
||||
{
|
||||
dest.data.copyFromSameType (source.data);
|
||||
dest.advance();
|
||||
|
|
@ -467,6 +466,55 @@ public:
|
|||
dest.clear (dest.data, numSamples);
|
||||
}
|
||||
|
||||
/** Scans a block of data, returning the lowest and highest levels as floats */
|
||||
void findMinAndMax (size_t numSamples, float& minValue, float& maxValue) const noexcept
|
||||
{
|
||||
if (numSamples == 0)
|
||||
{
|
||||
minValue = maxValue = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
Pointer dest (*this);
|
||||
|
||||
if (isFloatingPoint())
|
||||
{
|
||||
float mn = dest.getAsFloat();
|
||||
dest.advance();
|
||||
float mx = mn;
|
||||
|
||||
while (--numSamples > 0)
|
||||
{
|
||||
const float v = dest.getAsFloat();
|
||||
dest.advance();
|
||||
|
||||
if (mx < v) mx = v;
|
||||
if (v < mn) mn = v;
|
||||
}
|
||||
|
||||
minValue = mn;
|
||||
maxValue = mx;
|
||||
}
|
||||
else
|
||||
{
|
||||
int32 mn = dest.getAsInt32();
|
||||
dest.advance();
|
||||
int32 mx = mn;
|
||||
|
||||
while (--numSamples > 0)
|
||||
{
|
||||
const int v = dest.getAsInt32();
|
||||
dest.advance();
|
||||
|
||||
if (mx < v) mx = v;
|
||||
if (v < mn) mn = v;
|
||||
}
|
||||
|
||||
minValue = mn * (float) (1.0 / (1.0 + Int32::maxValue));
|
||||
maxValue = mx * (float) (1.0 / (1.0 + Int32::maxValue));
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns true if the pointer is using a floating-point format. */
|
||||
static bool isFloatingPoint() noexcept { return (bool) SampleFormat::isFloat; }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue