mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Tidied up a few issues in AudioBlock
This commit is contained in:
parent
1c580123b3
commit
73c319d249
2 changed files with 38 additions and 30 deletions
|
|
@ -170,7 +170,7 @@ public:
|
|||
}
|
||||
|
||||
/** Returns an AudioBlock that represents one of the channels in this block. */
|
||||
forcedinline AudioBlock<SampleType> getSingleChannelBlock (size_t channel) const noexcept
|
||||
forcedinline AudioBlock getSingleChannelBlock (size_t channel) const noexcept
|
||||
{
|
||||
jassert (channel < numChannels);
|
||||
return AudioBlock (channels + channel, 1, startSample, numSamples);
|
||||
|
|
@ -180,7 +180,7 @@ public:
|
|||
@param channelStart First channel of the subset
|
||||
@param numChannelsToUse Count of channels in the subset
|
||||
*/
|
||||
forcedinline AudioBlock<SampleType> getSubsetChannelBlock (size_t channelStart, size_t numChannelsToUse) noexcept
|
||||
forcedinline AudioBlock getSubsetChannelBlock (size_t channelStart, size_t numChannelsToUse) noexcept
|
||||
{
|
||||
jassert (channelStart < numChannels);
|
||||
jassert ((channelStart + numChannelsToUse) <= numChannels);
|
||||
|
|
@ -212,7 +212,7 @@ public:
|
|||
}
|
||||
|
||||
/** Copy the values in src to the receiver. */
|
||||
forcedinline AudioBlock& copy (const AudioBlock& src) noexcept
|
||||
forcedinline AudioBlock& copy (AudioBlock src) noexcept
|
||||
{
|
||||
auto maxChannels = jmin (src.numChannels, numChannels);
|
||||
auto n = static_cast<int> (jmin (src.numSamples, numSamples) * sizeFactor);
|
||||
|
|
@ -286,7 +286,7 @@ public:
|
|||
}
|
||||
|
||||
/** Adds the source values to the receiver. */
|
||||
forcedinline AudioBlock& add (const AudioBlock& src) noexcept
|
||||
forcedinline AudioBlock& add (AudioBlock src) noexcept
|
||||
{
|
||||
jassert (numChannels == src.numChannels);
|
||||
auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
|
||||
|
|
@ -298,7 +298,7 @@ public:
|
|||
}
|
||||
|
||||
/** Adds a fixed value to each source value and stores it in the destination array of the receiver. */
|
||||
forcedinline AudioBlock& JUCE_VECTOR_CALLTYPE add (const AudioBlock& src, SampleType value) noexcept
|
||||
forcedinline AudioBlock& JUCE_VECTOR_CALLTYPE add (AudioBlock src, SampleType value) noexcept
|
||||
{
|
||||
jassert (numChannels == src.numChannels);
|
||||
auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
|
||||
|
|
@ -310,7 +310,7 @@ public:
|
|||
}
|
||||
|
||||
/** Adds each source1 value to the corresponding source2 value and stores it in the destination array of the receiver. */
|
||||
forcedinline AudioBlock& add (const AudioBlock& src1, const AudioBlock& src2) noexcept
|
||||
forcedinline AudioBlock& add (AudioBlock src1, AudioBlock src2) noexcept
|
||||
{
|
||||
jassert (numChannels == src1.numChannels && src1.numChannels == src2.numChannels);
|
||||
auto n = static_cast<int> (jmin (numSamples, src1.numSamples, src2.numSamples) * sizeFactor);
|
||||
|
|
@ -328,7 +328,7 @@ public:
|
|||
}
|
||||
|
||||
/** Subtracts the source values from the receiver. */
|
||||
forcedinline AudioBlock& subtract (const AudioBlock& src) noexcept
|
||||
forcedinline AudioBlock& subtract (AudioBlock src) noexcept
|
||||
{
|
||||
jassert (numChannels == src.numChannels);
|
||||
auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
|
||||
|
|
@ -340,19 +340,20 @@ public:
|
|||
}
|
||||
|
||||
/** Subtracts a fixed value from each source value and stores it in the destination array of the receiver. */
|
||||
forcedinline AudioBlock& JUCE_VECTOR_CALLTYPE subtract (const AudioBlock& src, SampleType value) noexcept
|
||||
forcedinline AudioBlock& JUCE_VECTOR_CALLTYPE subtract (AudioBlock src, SampleType value) noexcept
|
||||
{
|
||||
return add (src, static_cast<SampleType> (-1.0) * value);
|
||||
}
|
||||
|
||||
/** Subtracts each source2 value from the corresponding source1 value and stores it in the destination array of the receiver. */
|
||||
forcedinline AudioBlock& subtract (const AudioBlock& src1, const AudioBlock& src2) noexcept
|
||||
forcedinline AudioBlock& subtract (AudioBlock src1, AudioBlock src2) noexcept
|
||||
{
|
||||
jassert (numChannels == src1.numChannels && src1.numChannels == src2.numChannels);
|
||||
auto n = static_cast<int> (jmin (numSamples, src1.numSamples, src2.numSamples) * sizeFactor);
|
||||
|
||||
for (size_t ch = 0; ch < numChannels; ++ch)
|
||||
FloatVectorOperations::subtract (channelPtr (ch), src1.channelPtr (ch), src2.channelPtr (ch), n);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -368,7 +369,7 @@ public:
|
|||
}
|
||||
|
||||
/** Multiplies the source values to the receiver. */
|
||||
forcedinline AudioBlock& multiply (const AudioBlock& src) noexcept
|
||||
forcedinline AudioBlock& multiply (AudioBlock src) noexcept
|
||||
{
|
||||
jassert (numChannels == src.numChannels);
|
||||
auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
|
||||
|
|
@ -380,7 +381,7 @@ public:
|
|||
}
|
||||
|
||||
/** Multiplies a fixed value to each source value and stores it in the destination array of the receiver. */
|
||||
forcedinline AudioBlock& JUCE_VECTOR_CALLTYPE multiply (const AudioBlock& src, SampleType value) noexcept
|
||||
forcedinline AudioBlock& JUCE_VECTOR_CALLTYPE multiply (AudioBlock src, SampleType value) noexcept
|
||||
{
|
||||
jassert (numChannels == src.numChannels);
|
||||
auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
|
||||
|
|
@ -392,7 +393,7 @@ public:
|
|||
}
|
||||
|
||||
/** Multiplies each source1 value to the corresponding source2 value and stores it in the destination array of the receiver. */
|
||||
forcedinline AudioBlock& multiply (const AudioBlock& src1, const AudioBlock& src2) noexcept
|
||||
forcedinline AudioBlock& multiply (AudioBlock src1, AudioBlock src2) noexcept
|
||||
{
|
||||
jassert (numChannels == src1.numChannels && src1.numChannels == src2.numChannels);
|
||||
auto n = static_cast<int> (jmin (numSamples, src1.numSamples, src2.numSamples) * sizeFactor);
|
||||
|
|
@ -403,7 +404,7 @@ public:
|
|||
}
|
||||
|
||||
/** Multiplies each value in src with factor and adds the result to the receiver. */
|
||||
forcedinline AudioBlock& JUCE_VECTOR_CALLTYPE addWithMultiply (const AudioBlock& src, SampleType factor) noexcept
|
||||
forcedinline AudioBlock& JUCE_VECTOR_CALLTYPE addWithMultiply (AudioBlock src, SampleType factor) noexcept
|
||||
{
|
||||
jassert (numChannels == src.numChannels);
|
||||
auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
|
||||
|
|
@ -415,7 +416,7 @@ public:
|
|||
}
|
||||
|
||||
/** Multiplies each value in srcA with the corresponding value in srcB and adds the result to the receiver. */
|
||||
forcedinline AudioBlock& addWithMultiply (const AudioBlock& src1, const AudioBlock& src2) noexcept
|
||||
forcedinline AudioBlock& addWithMultiply (AudioBlock src1, AudioBlock src2) noexcept
|
||||
{
|
||||
jassert (numChannels == src1.numChannels && src1.numChannels == src2.numChannels);
|
||||
auto n = static_cast<int> (jmin (numSamples, src1.numSamples, src2.numSamples) * sizeFactor);
|
||||
|
|
@ -433,7 +434,7 @@ public:
|
|||
}
|
||||
|
||||
/** Negates each value of source and stores it in the receiver. */
|
||||
forcedinline AudioBlock& replaceWithNegativeOf (const AudioBlock& src) noexcept
|
||||
forcedinline AudioBlock& replaceWithNegativeOf (AudioBlock src) noexcept
|
||||
{
|
||||
jassert (numChannels == src.numChannels);
|
||||
auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
|
||||
|
|
@ -445,7 +446,7 @@ public:
|
|||
}
|
||||
|
||||
/** Takes the absolute value of each element of src and stores it inside the receiver. */
|
||||
forcedinline AudioBlock& replaceWithAbsoluteValueOf (const AudioBlock& src) noexcept
|
||||
forcedinline AudioBlock& replaceWithAbsoluteValueOf (AudioBlock src) noexcept
|
||||
{
|
||||
jassert (numChannels == src.numChannels);
|
||||
auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
|
||||
|
|
@ -457,7 +458,7 @@ public:
|
|||
}
|
||||
|
||||
/** Each element of receiver will be the minimum of the corresponding element of the source arrays. */
|
||||
forcedinline AudioBlock& min (const AudioBlock& src1, const AudioBlock& src2) noexcept
|
||||
forcedinline AudioBlock& min (AudioBlock src1, AudioBlock src2) noexcept
|
||||
{
|
||||
jassert (numChannels == src1.numChannels && src1.numChannels == src2.numChannels);
|
||||
auto n = static_cast<int> (jmin (src1.numSamples, src2.numSamples, numSamples) * sizeFactor);
|
||||
|
|
@ -483,10 +484,13 @@ public:
|
|||
/** Finds the minimum and maximum value of the buffer. */
|
||||
forcedinline Range<NumericType> findMinAndMax() const noexcept
|
||||
{
|
||||
Range<NumericType> minmax;
|
||||
auto n = static_cast<int> (numSamples * sizeFactor);
|
||||
if (numChannels == 0)
|
||||
return {};
|
||||
|
||||
for (size_t ch = 0; ch < numChannels; ++ch)
|
||||
auto n = static_cast<int> (numSamples * sizeFactor);
|
||||
auto minmax = FloatVectorOperations::findMinAndMax (channelPtr (0), n);
|
||||
|
||||
for (size_t ch = 1; ch < numChannels; ++ch)
|
||||
minmax = minmax.getUnionWith (FloatVectorOperations::findMinAndMax (channelPtr (ch), n));
|
||||
|
||||
return minmax;
|
||||
|
|
@ -503,25 +507,32 @@ public:
|
|||
|
||||
//==============================================================================
|
||||
// This class can only be used with floating point types
|
||||
static_assert (std::is_same<SampleType, float>::value || std::is_same<SampleType, double>::value
|
||||
static_assert (std::is_same<SampleType, float>::value
|
||||
|| std::is_same<SampleType, double>::value
|
||||
#if JUCE_USE_SIMD
|
||||
|| std::is_same<SampleType, SIMDRegister<float>>::value || std::is_same<SampleType, SIMDRegister<double>>::value
|
||||
|| std::is_same<SampleType, SIMDRegister<float>>::value
|
||||
|| std::is_same<SampleType, SIMDRegister<double>>::value
|
||||
#endif
|
||||
, "AudioBlock only supports single or double precision floating point types");
|
||||
|
||||
//==============================================================================
|
||||
/** Applies a function to each value in an input block, putting the result into an output block.
|
||||
The function supplied must take a SampleType as its parameter, and return a SampleType.
|
||||
The two blocks must have the same number of channels and samples.
|
||||
*/
|
||||
template <typename FunctionType>
|
||||
static void process (const AudioBlock<SampleType>& inBlock,
|
||||
AudioBlock<SampleType>& outBlock,
|
||||
const FunctionType& function)
|
||||
static void process (AudioBlock inBlock, AudioBlock outBlock, FunctionType&& function)
|
||||
{
|
||||
auto len = inBlock.getNumSamples();
|
||||
auto numChans = inBlock.getNumChannels();
|
||||
|
||||
jassert (len == outBlock.getNumSamples());
|
||||
jassert (numChans == outBlock.getNumChannels());
|
||||
|
||||
for (ChannelCountType c = 0; c < numChans; ++c)
|
||||
{
|
||||
auto* src = inBlock.getChannelPointer(c);
|
||||
auto* dst = outBlock.getChannelPointer(c);
|
||||
auto* src = inBlock.getChannelPointer (c);
|
||||
auto* dst = outBlock.getChannelPointer (c);
|
||||
|
||||
for (size_t i = 0; i < len; ++i)
|
||||
dst[i] = function (src[i]);
|
||||
|
|
|
|||
|
|
@ -53,9 +53,6 @@ struct WaveShaper
|
|||
template <typename ProcessContext>
|
||||
void process (const ProcessContext& context) const noexcept
|
||||
{
|
||||
jassert (context.getInputBlock().getNumChannels() == context.getOutputBlock().getNumChannels());
|
||||
jassert (context.getInputBlock().getNumSamples() == context.getOutputBlock().getNumSamples());
|
||||
|
||||
AudioBlock<FloatType>::process (context.getInputBlock(),
|
||||
context.getOutputBlock(),
|
||||
functionToUse);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue