mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
AudioBuffer: Prefer early returns to nested if statements
This commit is contained in:
parent
04188c0e09
commit
a50292f50d
1 changed files with 114 additions and 103 deletions
|
|
@ -569,8 +569,9 @@ public:
|
|||
*/
|
||||
void clear() noexcept
|
||||
{
|
||||
if (! isClear)
|
||||
{
|
||||
if (isClear)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < numChannels; ++i)
|
||||
{
|
||||
JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4661)
|
||||
|
|
@ -580,7 +581,6 @@ public:
|
|||
|
||||
isClear = true;
|
||||
}
|
||||
}
|
||||
|
||||
/** Clears a specified region of all the channels.
|
||||
|
||||
|
|
@ -598,14 +598,14 @@ public:
|
|||
{
|
||||
jassert (startSample >= 0 && numSamples >= 0 && startSample + numSamples <= size);
|
||||
|
||||
if (! isClear)
|
||||
{
|
||||
if (isClear)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < numChannels; ++i)
|
||||
FloatVectorOperations::clear (channels[i] + startSample, numSamples);
|
||||
|
||||
isClear = (startSample == 0 && numSamples == size);
|
||||
}
|
||||
}
|
||||
|
||||
/** Clears a specified region of just one channel.
|
||||
|
||||
|
|
@ -700,12 +700,12 @@ public:
|
|||
jassert (isPositiveAndBelow (channel, numChannels));
|
||||
jassert (startSample >= 0 && numSamples >= 0 && startSample + numSamples <= size);
|
||||
|
||||
if (! isClear)
|
||||
{
|
||||
if (isClear)
|
||||
return;
|
||||
|
||||
auto* d = channels[channel] + startSample;
|
||||
FloatVectorOperations::multiply (d, gain, numSamples);
|
||||
}
|
||||
}
|
||||
|
||||
/** Applies a gain multiple to a region of all the channels.
|
||||
|
||||
|
|
@ -735,12 +735,13 @@ public:
|
|||
*/
|
||||
void applyGainRamp (int channel, int startSample, int numSamples,
|
||||
Type startGain, Type endGain) noexcept
|
||||
{
|
||||
if (! isClear)
|
||||
{
|
||||
jassert (isPositiveAndBelow (channel, numChannels));
|
||||
jassert (startSample >= 0 && numSamples >= 0 && startSample + numSamples <= size);
|
||||
|
||||
if (isClear)
|
||||
return;
|
||||
|
||||
const auto increment = (endGain - startGain) / (float) numSamples;
|
||||
auto* d = channels[channel] + startSample;
|
||||
|
||||
|
|
@ -750,7 +751,6 @@ public:
|
|||
startGain += increment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Applies a range of gains to a region of all channels.
|
||||
|
||||
|
|
@ -801,8 +801,9 @@ public:
|
|||
jassert (isPositiveAndBelow (sourceChannel, source.numChannels));
|
||||
jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
|
||||
|
||||
if (numSamples > 0 && ! source.isClear)
|
||||
{
|
||||
if (numSamples <= 0 || source.isClear)
|
||||
return;
|
||||
|
||||
auto* d = channels[destChannel] + destStartSample;
|
||||
auto* s = source.channels[sourceChannel] + sourceStartSample;
|
||||
|
||||
|
|
@ -820,7 +821,6 @@ public:
|
|||
|
||||
JUCE_END_IGNORE_WARNINGS_MSVC
|
||||
}
|
||||
}
|
||||
|
||||
/** Adds samples from an array of floats to one of the channels.
|
||||
|
||||
|
|
@ -846,6 +846,9 @@ public:
|
|||
jassert (destStartSample >= 0 && numSamples >= 0 && destStartSample + numSamples <= size);
|
||||
jassert (source != nullptr);
|
||||
|
||||
if (numSamples <= 0)
|
||||
return;
|
||||
|
||||
auto* d = channels[destChannel] + destStartSample;
|
||||
|
||||
if (isClear)
|
||||
|
|
@ -889,8 +892,9 @@ public:
|
|||
jassert (destStartSample >= 0 && numSamples >= 0 && destStartSample + numSamples <= size);
|
||||
jassert (source != nullptr);
|
||||
|
||||
if (numSamples > 0)
|
||||
{
|
||||
if (numSamples <= 0)
|
||||
return;
|
||||
|
||||
isClear = false;
|
||||
const auto increment = (endGain - startGain) / (Type) numSamples;
|
||||
auto* d = channels[destChannel] + destStartSample;
|
||||
|
|
@ -900,8 +904,7 @@ public:
|
|||
*d++ += startGain * *source++;
|
||||
startGain += increment;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Copies samples from another buffer to this one.
|
||||
|
||||
|
|
@ -930,8 +933,9 @@ public:
|
|||
jassert (isPositiveAndBelow (sourceChannel, source.numChannels));
|
||||
jassert (sourceStartSample >= 0 && numSamples >= 0 && sourceStartSample + numSamples <= source.size);
|
||||
|
||||
if (numSamples > 0)
|
||||
{
|
||||
if (numSamples <= 0)
|
||||
return;
|
||||
|
||||
if (source.isClear)
|
||||
{
|
||||
if (! isClear)
|
||||
|
|
@ -945,7 +949,6 @@ public:
|
|||
numSamples);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Copies samples from an array of floats into one of the channels.
|
||||
|
||||
|
|
@ -968,12 +971,12 @@ public:
|
|||
jassert (destStartSample >= 0 && numSamples >= 0 && destStartSample + numSamples <= size);
|
||||
jassert (source != nullptr);
|
||||
|
||||
if (numSamples > 0)
|
||||
{
|
||||
if (numSamples <= 0)
|
||||
return;
|
||||
|
||||
isClear = false;
|
||||
FloatVectorOperations::copy (channels[destChannel] + destStartSample, source, numSamples);
|
||||
}
|
||||
}
|
||||
|
||||
/** Copies samples from an array of floats into one of the channels, applying a gain to it.
|
||||
|
||||
|
|
@ -998,13 +1001,13 @@ public:
|
|||
jassert (destStartSample >= 0 && numSamples >= 0 && destStartSample + numSamples <= size);
|
||||
jassert (source != nullptr);
|
||||
|
||||
if (numSamples > 0)
|
||||
{
|
||||
if (numSamples <= 0)
|
||||
return;
|
||||
|
||||
auto* d = channels[destChannel] + destStartSample;
|
||||
isClear = false;
|
||||
FloatVectorOperations::copyWithMultiply (d, source, gain, numSamples);
|
||||
}
|
||||
}
|
||||
|
||||
/** Copies samples from an array of floats into one of the channels, applying a gain ramp.
|
||||
|
||||
|
|
@ -1037,8 +1040,9 @@ public:
|
|||
jassert (destStartSample >= 0 && numSamples >= 0 && destStartSample + numSamples <= size);
|
||||
jassert (source != nullptr);
|
||||
|
||||
if (numSamples > 0)
|
||||
{
|
||||
if (numSamples <= 0)
|
||||
return;
|
||||
|
||||
isClear = false;
|
||||
const auto increment = (endGain - startGain) / (Type) numSamples;
|
||||
auto* d = channels[destChannel] + destStartSample;
|
||||
|
|
@ -1049,7 +1053,6 @@ public:
|
|||
startGain += increment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns a Range indicating the lowest and highest sample values in a given section.
|
||||
|
||||
|
|
@ -1077,8 +1080,7 @@ public:
|
|||
if (isClear)
|
||||
return Type (0);
|
||||
|
||||
auto r = findMinMax (channel, startSample, numSamples);
|
||||
|
||||
const auto r = findMinMax (channel, startSample, numSamples);
|
||||
return jmax (r.getStart(), -r.getStart(), r.getEnd(), -r.getEnd());
|
||||
}
|
||||
|
||||
|
|
@ -1087,7 +1089,9 @@ public:
|
|||
{
|
||||
Type mag (0);
|
||||
|
||||
if (! isClear)
|
||||
if (isClear)
|
||||
return mag;
|
||||
|
||||
for (int i = 0; i < numChannels; ++i)
|
||||
mag = jmax (mag, getMagnitude (i, startSample, numSamples));
|
||||
|
||||
|
|
@ -1100,7 +1104,7 @@ public:
|
|||
jassert (isPositiveAndBelow (channel, numChannels));
|
||||
jassert (startSample >= 0 && numSamples >= 0 && startSample + numSamples <= size);
|
||||
|
||||
if (numSamples <= 0 || channel < 0 || channel >= numChannels || isClear)
|
||||
if (numSamples <= 0 || isClear || ! isPositiveAndBelow (channel, numChannels))
|
||||
return Type (0);
|
||||
|
||||
auto* data = channels[channel] + startSample;
|
||||
|
|
@ -1121,7 +1125,9 @@ public:
|
|||
jassert (isPositiveAndBelow (channel, numChannels));
|
||||
jassert (startSample >= 0 && numSamples >= 0 && startSample + numSamples <= size);
|
||||
|
||||
if (! isClear)
|
||||
if (isClear)
|
||||
return;
|
||||
|
||||
std::reverse (channels[channel] + startSample,
|
||||
channels[channel] + startSample + numSamples);
|
||||
}
|
||||
|
|
@ -1129,6 +1135,11 @@ public:
|
|||
/** Reverses a part of the buffer. */
|
||||
void reverse (int startSample, int numSamples) const noexcept
|
||||
{
|
||||
jassert (startSample >= 0 && numSamples >= 0 && startSample + numSamples <= size);
|
||||
|
||||
if (isClear)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < numChannels; ++i)
|
||||
reverse (i, startSample, numSamples);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue