mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
AudioBlock: Fixed an issue preventing usage with SIMDRegister
This commit is contained in:
parent
1237b8c831
commit
85f76d2546
5 changed files with 391 additions and 217 deletions
|
|
@ -1075,8 +1075,17 @@ private:
|
|||
|
||||
void allocateData()
|
||||
{
|
||||
static_assert (std::alignment_of<Type>::value <= std::alignment_of<std::max_align_t>::value,
|
||||
"AudioBuffer cannot hold types with alignment requirements larger than that guaranteed by malloc");
|
||||
jassert (size >= 0);
|
||||
|
||||
auto channelListSize = (size_t) (numChannels + 1) * sizeof (Type*);
|
||||
auto requiredSampleAlignment = std::alignment_of<Type>::value;
|
||||
size_t alignmentOverflow = channelListSize % requiredSampleAlignment;
|
||||
|
||||
if (alignmentOverflow != 0)
|
||||
channelListSize += requiredSampleAlignment - alignmentOverflow;
|
||||
|
||||
allocatedBytes = (size_t) numChannels * (size_t) size * sizeof (Type) + channelListSize + 32;
|
||||
allocatedData.malloc (allocatedBytes);
|
||||
channels = reinterpret_cast<Type**> (allocatedData.get());
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@
|
|||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <map>
|
||||
#include <cstddef>
|
||||
|
||||
//==============================================================================
|
||||
#include "juce_CompilerSupport.h"
|
||||
|
|
|
|||
|
|
@ -288,8 +288,8 @@ public:
|
|||
const AudioBlock& clear() const noexcept { clearInternal(); return *this; }
|
||||
|
||||
/** Fills the memory referenced by this AudioBlock with value. */
|
||||
AudioBlock& JUCE_VECTOR_CALLTYPE fill (SampleType value) noexcept { fillInternal (value); return *this; }
|
||||
const AudioBlock& JUCE_VECTOR_CALLTYPE fill (SampleType value) const noexcept { fillInternal (value); return *this; }
|
||||
AudioBlock& JUCE_VECTOR_CALLTYPE fill (NumericType value) noexcept { fillInternal (value); return *this; }
|
||||
const AudioBlock& JUCE_VECTOR_CALLTYPE fill (NumericType value) const noexcept { fillInternal (value); return *this; }
|
||||
|
||||
/** Copies the values in src to this block. */
|
||||
template <typename OtherSampleType>
|
||||
|
|
@ -297,25 +297,25 @@ public:
|
|||
template <typename OtherSampleType>
|
||||
const AudioBlock& copyFrom (const AudioBlock<OtherSampleType>& src) const noexcept { copyFromInternal (src); return *this; }
|
||||
|
||||
/** Copy the values from a JUCE's AudioBuffer to this block.
|
||||
/** Copy the values from an AudioBuffer to this block.
|
||||
|
||||
All indices and sizes are in the receiver's units, i.e. if SampleType is a
|
||||
All indices and sizes are in this AudioBlock's units, i.e. if SampleType is a
|
||||
SIMDRegister then incrementing srcPos by one will increase the sample position
|
||||
in the AudioBuffer's units by a factor of SIMDRegister<SampleType>::SIMDNumElements.
|
||||
*/
|
||||
template <typename OtherSampleType>
|
||||
AudioBlock& copyFrom (const AudioBuffer<OtherSampleType>& src,
|
||||
template <typename OtherNumericType>
|
||||
AudioBlock& copyFrom (const AudioBuffer<OtherNumericType>& src,
|
||||
size_t srcPos = 0, size_t dstPos = 0,
|
||||
size_t numElements = std::numeric_limits<size_t>::max()) { copyFromInternal (src, srcPos, dstPos, numElements); return *this; }
|
||||
template <typename OtherSampleType>
|
||||
const AudioBlock& copyFrom (const AudioBuffer<OtherSampleType>& src,
|
||||
template <typename OtherNumericType>
|
||||
const AudioBlock& copyFrom (const AudioBuffer<OtherNumericType>& src,
|
||||
size_t srcPos = 0, size_t dstPos = 0,
|
||||
size_t numElements = std::numeric_limits<size_t>::max()) const { copyFromInternal (src, srcPos, dstPos, numElements); return *this; }
|
||||
|
||||
|
||||
/** Copies the values from this block to an AudioBuffer.
|
||||
|
||||
All indices and sizes are in the receiver's units, i.e. if SampleType is a
|
||||
All indices and sizes are in this AudioBlock's units, i.e. if SampleType is a
|
||||
SIMDRegister then incrementing dstPos by one will increase the sample position
|
||||
in the AudioBuffer's units by a factor of SIMDRegister<SampleType>::SIMDNumElements.
|
||||
*/
|
||||
|
|
@ -329,7 +329,8 @@ public:
|
|||
for (size_t ch = 0; ch < maxChannels; ++ch)
|
||||
FloatVectorOperations::copy (dst.getWritePointer (static_cast<int> (ch),
|
||||
static_cast<int> (dstPos * sizeFactor)),
|
||||
getChannelPointer (ch) + srcPos, n);
|
||||
getDataPointer (ch) + (srcPos * sizeFactor),
|
||||
n);
|
||||
}
|
||||
|
||||
/** Move memory within this block from the position srcPos to the position dstPos.
|
||||
|
|
@ -375,8 +376,8 @@ public:
|
|||
|
||||
//==============================================================================
|
||||
/** Adds a fixed value to the elements in this block. */
|
||||
AudioBlock& JUCE_VECTOR_CALLTYPE add (SampleType value) noexcept { addInternal (value); return *this; }
|
||||
const AudioBlock& JUCE_VECTOR_CALLTYPE add (SampleType value) const noexcept { addInternal (value); return *this; }
|
||||
AudioBlock& JUCE_VECTOR_CALLTYPE add (NumericType value) noexcept { addInternal (value); return *this; }
|
||||
const AudioBlock& JUCE_VECTOR_CALLTYPE add (NumericType value) const noexcept { addInternal (value); return *this; }
|
||||
|
||||
/** Adds the elements in the src block to the elements in this block. */
|
||||
template <typename OtherSampleType>
|
||||
|
|
@ -386,9 +387,9 @@ public:
|
|||
|
||||
/** Adds a fixed value to each source value and replaces the contents of this block. */
|
||||
template <typename OtherSampleType>
|
||||
AudioBlock& JUCE_VECTOR_CALLTYPE replaceWithSumOf (AudioBlock<OtherSampleType> src, SampleType value) noexcept { replaceWithSumOfInternal (src, value); return *this; }
|
||||
AudioBlock& JUCE_VECTOR_CALLTYPE replaceWithSumOf (AudioBlock<OtherSampleType> src, NumericType value) noexcept { replaceWithSumOfInternal (src, value); return *this; }
|
||||
template <typename OtherSampleType>
|
||||
const AudioBlock& JUCE_VECTOR_CALLTYPE replaceWithSumOf (AudioBlock<OtherSampleType> src, SampleType value) const noexcept { replaceWithSumOfInternal (src, value); return *this; }
|
||||
const AudioBlock& JUCE_VECTOR_CALLTYPE replaceWithSumOf (AudioBlock<OtherSampleType> src, NumericType value) const noexcept { replaceWithSumOfInternal (src, value); return *this; }
|
||||
|
||||
/** Adds each source1 value to the corresponding source2 value and replaces the contents of this block. */
|
||||
template <typename Src1SampleType, typename Src2SampleType>
|
||||
|
|
@ -398,8 +399,8 @@ public:
|
|||
|
||||
//==============================================================================
|
||||
/** Subtracts a fixed value from the elements in this block. */
|
||||
AudioBlock& JUCE_VECTOR_CALLTYPE subtract (SampleType value) noexcept { subtractInternal (value); return *this; }
|
||||
const AudioBlock& JUCE_VECTOR_CALLTYPE subtract (SampleType value) const noexcept { subtractInternal (value); return *this; }
|
||||
AudioBlock& JUCE_VECTOR_CALLTYPE subtract (NumericType value) noexcept { subtractInternal (value); return *this; }
|
||||
const AudioBlock& JUCE_VECTOR_CALLTYPE subtract (NumericType value) const noexcept { subtractInternal (value); return *this; }
|
||||
|
||||
/** Subtracts the source values from the elements in this block. */
|
||||
template <typename OtherSampleType>
|
||||
|
|
@ -409,9 +410,9 @@ public:
|
|||
|
||||
/** Subtracts a fixed value from each source value and replaces the contents of this block. */
|
||||
template <typename OtherSampleType>
|
||||
AudioBlock& JUCE_VECTOR_CALLTYPE replaceWithDifferenceOf (AudioBlock<OtherSampleType> src, SampleType value) noexcept { replaceWithDifferenceOfInternal (src, value); return *this; }
|
||||
AudioBlock& JUCE_VECTOR_CALLTYPE replaceWithDifferenceOf (AudioBlock<OtherSampleType> src, NumericType value) noexcept { replaceWithDifferenceOfInternal (src, value); return *this; }
|
||||
template <typename OtherSampleType>
|
||||
const AudioBlock& JUCE_VECTOR_CALLTYPE replaceWithDifferenceOf (AudioBlock<OtherSampleType> src, SampleType value) const noexcept { replaceWithDifferenceOfInternal (src, value); return *this; }
|
||||
const AudioBlock& JUCE_VECTOR_CALLTYPE replaceWithDifferenceOf (AudioBlock<OtherSampleType> src, NumericType value) const noexcept { replaceWithDifferenceOfInternal (src, value); return *this; }
|
||||
|
||||
/** Subtracts each source2 value from the corresponding source1 value and replaces the contents of this block. */
|
||||
template <typename Src1SampleType, typename Src2SampleType>
|
||||
|
|
@ -421,8 +422,8 @@ public:
|
|||
|
||||
//==============================================================================
|
||||
/** Multiplies the elements in this block by a fixed value. */
|
||||
AudioBlock& JUCE_VECTOR_CALLTYPE multiplyBy (SampleType value) noexcept { multiplyByInternal (value); return *this; }
|
||||
const AudioBlock& JUCE_VECTOR_CALLTYPE multiplyBy (SampleType value) const noexcept { multiplyByInternal (value); return *this; }
|
||||
AudioBlock& JUCE_VECTOR_CALLTYPE multiplyBy (NumericType value) noexcept { multiplyByInternal (value); return *this; }
|
||||
const AudioBlock& JUCE_VECTOR_CALLTYPE multiplyBy (NumericType value) const noexcept { multiplyByInternal (value); return *this; }
|
||||
|
||||
/** Multiplies the elements in this block by the elements in the src block */
|
||||
template <typename OtherSampleType>
|
||||
|
|
@ -432,9 +433,9 @@ public:
|
|||
|
||||
/** Replaces the elements in this block with the product of the elements in the source src block and a fixed value. */
|
||||
template <typename OtherSampleType>
|
||||
AudioBlock& JUCE_VECTOR_CALLTYPE replaceWithProductOf (AudioBlock<OtherSampleType> src, SampleType value) noexcept { replaceWithProductOfInternal (src, value); return *this; }
|
||||
AudioBlock& JUCE_VECTOR_CALLTYPE replaceWithProductOf (AudioBlock<OtherSampleType> src, NumericType value) noexcept { replaceWithProductOfInternal (src, value); return *this; }
|
||||
template <typename OtherSampleType>
|
||||
const AudioBlock& JUCE_VECTOR_CALLTYPE replaceWithProductOf (AudioBlock<OtherSampleType> src, SampleType value) const noexcept { replaceWithProductOfInternal (src, value); return *this; }
|
||||
const AudioBlock& JUCE_VECTOR_CALLTYPE replaceWithProductOf (AudioBlock<OtherSampleType> src, NumericType value) const noexcept { replaceWithProductOfInternal (src, value); return *this; }
|
||||
|
||||
/** Replaces the elements in this block with the product of the elements in the src1 and scr2 blocks. */
|
||||
template <typename Src1SampleType, typename Src2SampleType>
|
||||
|
|
@ -458,9 +459,9 @@ public:
|
|||
//==============================================================================
|
||||
/** Multiplies each value in src by a fixed value and adds the result to this block. */
|
||||
template <typename OtherSampleType>
|
||||
AudioBlock& JUCE_VECTOR_CALLTYPE addProductOf (AudioBlock<OtherSampleType> src, SampleType factor) noexcept { addProductOfInternal (src, factor); return *this; }
|
||||
AudioBlock& JUCE_VECTOR_CALLTYPE addProductOf (AudioBlock<OtherSampleType> src, NumericType factor) noexcept { addProductOfInternal (src, factor); return *this; }
|
||||
template <typename OtherSampleType>
|
||||
const AudioBlock& JUCE_VECTOR_CALLTYPE addProductOf (AudioBlock<OtherSampleType> src, SampleType factor) const noexcept { addProductOfInternal (src, factor); return *this; }
|
||||
const AudioBlock& JUCE_VECTOR_CALLTYPE addProductOf (AudioBlock<OtherSampleType> src, NumericType factor) const noexcept { addProductOfInternal (src, factor); return *this; }
|
||||
|
||||
/** Multiplies each value in srcA with the corresponding value in srcB and adds the result to this block. */
|
||||
template <typename Src1SampleType, typename Src2SampleType>
|
||||
|
|
@ -506,30 +507,30 @@ public:
|
|||
return {};
|
||||
|
||||
auto n = static_cast<int> (numSamples * sizeFactor);
|
||||
auto minmax = FloatVectorOperations::findMinAndMax (getChannelPointer (0), n);
|
||||
auto minmax = FloatVectorOperations::findMinAndMax (getDataPointer (0), n);
|
||||
|
||||
for (size_t ch = 1; ch < numChannels; ++ch)
|
||||
minmax = minmax.getUnionWith (FloatVectorOperations::findMinAndMax (getChannelPointer (ch), n));
|
||||
minmax = minmax.getUnionWith (FloatVectorOperations::findMinAndMax (getDataPointer (ch), n));
|
||||
|
||||
return minmax;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
// Convenient operator wrappers.
|
||||
AudioBlock& JUCE_VECTOR_CALLTYPE operator+= (SampleType value) noexcept { return add (value); }
|
||||
const AudioBlock& JUCE_VECTOR_CALLTYPE operator+= (SampleType value) const noexcept { return add (value); }
|
||||
AudioBlock& JUCE_VECTOR_CALLTYPE operator+= (NumericType value) noexcept { return add (value); }
|
||||
const AudioBlock& JUCE_VECTOR_CALLTYPE operator+= (NumericType value) const noexcept { return add (value); }
|
||||
|
||||
AudioBlock& operator+= (AudioBlock src) noexcept { return add (src); }
|
||||
const AudioBlock& operator+= (AudioBlock src) const noexcept { return add (src); }
|
||||
|
||||
AudioBlock& JUCE_VECTOR_CALLTYPE operator-= (SampleType value) noexcept { return subtract (value); }
|
||||
const AudioBlock& JUCE_VECTOR_CALLTYPE operator-= (SampleType value) const noexcept { return subtract (value); }
|
||||
AudioBlock& JUCE_VECTOR_CALLTYPE operator-= (NumericType value) noexcept { return subtract (value); }
|
||||
const AudioBlock& JUCE_VECTOR_CALLTYPE operator-= (NumericType value) const noexcept { return subtract (value); }
|
||||
|
||||
AudioBlock& operator-= (AudioBlock src) noexcept { return subtract (src); }
|
||||
const AudioBlock& operator-= (AudioBlock src) const noexcept { return subtract (src); }
|
||||
|
||||
AudioBlock& JUCE_VECTOR_CALLTYPE operator*= (SampleType value) noexcept { return multiplyBy (value); }
|
||||
const AudioBlock& JUCE_VECTOR_CALLTYPE operator*= (SampleType value) const noexcept { return multiplyBy (value); }
|
||||
AudioBlock& JUCE_VECTOR_CALLTYPE operator*= (NumericType value) noexcept { return multiplyBy (value); }
|
||||
const AudioBlock& JUCE_VECTOR_CALLTYPE operator*= (NumericType value) const noexcept { return multiplyBy (value); }
|
||||
|
||||
AudioBlock& operator*= (AudioBlock src) noexcept { return multiplyBy (src); }
|
||||
const AudioBlock& operator*= (AudioBlock src) const noexcept { return multiplyBy (src); }
|
||||
|
|
@ -574,42 +575,48 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
NumericType* getDataPointer (size_t channel) const noexcept
|
||||
{
|
||||
return reinterpret_cast<NumericType*> (getChannelPointer (channel));
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void JUCE_VECTOR_CALLTYPE clearInternal() const noexcept
|
||||
{
|
||||
auto n = static_cast<int> (numSamples * sizeFactor);
|
||||
|
||||
for (size_t ch = 0; ch < numChannels; ++ch)
|
||||
FloatVectorOperations::clear (getChannelPointer (ch), n);
|
||||
FloatVectorOperations::clear (getDataPointer (ch), n);
|
||||
}
|
||||
|
||||
void JUCE_VECTOR_CALLTYPE fillInternal (SampleType value) const noexcept
|
||||
void JUCE_VECTOR_CALLTYPE fillInternal (NumericType value) const noexcept
|
||||
{
|
||||
auto n = static_cast<int> (numSamples * sizeFactor);
|
||||
|
||||
for (size_t ch = 0; ch < numChannels; ++ch)
|
||||
FloatVectorOperations::fill (getChannelPointer (ch), value, n);
|
||||
FloatVectorOperations::fill (getDataPointer (ch), value, n);
|
||||
}
|
||||
|
||||
template <typename OtherSampleType>
|
||||
void copyFromInternal (const AudioBlock<OtherSampleType>& src) const noexcept
|
||||
{
|
||||
auto maxChannels = jmin (src.numChannels, numChannels);
|
||||
auto n = static_cast<int> (jmin (src.numSamples, numSamples) * sizeFactor);
|
||||
auto n = static_cast<int> (jmin (src.numSamples * src.sizeFactor,
|
||||
numSamples * sizeFactor));
|
||||
|
||||
for (size_t ch = 0; ch < maxChannels; ++ch)
|
||||
FloatVectorOperations::copy (getChannelPointer (ch), src.getChannelPointer (ch), n);
|
||||
FloatVectorOperations::copy (getDataPointer (ch), src.getDataPointer (ch), n);
|
||||
}
|
||||
|
||||
template <typename OtherSampleType>
|
||||
void copyFromInternal (const AudioBuffer<OtherSampleType>& src, size_t srcPos, size_t dstPos, size_t numElements) const
|
||||
template <typename OtherNumericType>
|
||||
void copyFromInternal (const AudioBuffer<OtherNumericType>& src, size_t srcPos, size_t dstPos, size_t numElements) const
|
||||
{
|
||||
auto srclen = static_cast<size_t> (src.getNumSamples()) / sizeFactor;
|
||||
auto n = static_cast<int> (jmin (srclen - srcPos, numSamples - dstPos, numElements) * sizeFactor);
|
||||
auto maxChannels = jmin (static_cast<size_t> (src.getNumChannels()), static_cast<size_t> (numChannels));
|
||||
|
||||
for (size_t ch = 0; ch < maxChannels; ++ch)
|
||||
FloatVectorOperations::copy (getChannelPointer (ch) + dstPos,
|
||||
FloatVectorOperations::copy (getDataPointer (ch) + (dstPos * sizeFactor),
|
||||
src.getReadPointer (static_cast<int> (ch),
|
||||
static_cast<int> (srcPos * sizeFactor)),
|
||||
n);
|
||||
|
|
@ -628,12 +635,12 @@ private:
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
void JUCE_VECTOR_CALLTYPE addInternal (SampleType value) const noexcept
|
||||
void JUCE_VECTOR_CALLTYPE addInternal (NumericType value) const noexcept
|
||||
{
|
||||
auto n = static_cast<int> (numSamples * sizeFactor);
|
||||
|
||||
for (size_t ch = 0; ch < numChannels; ++ch)
|
||||
FloatVectorOperations::add (getChannelPointer (ch), value, n);
|
||||
FloatVectorOperations::add (getDataPointer (ch), value, n);
|
||||
}
|
||||
|
||||
template <typename OtherSampleType>
|
||||
|
|
@ -643,17 +650,17 @@ private:
|
|||
auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
|
||||
|
||||
for (size_t ch = 0; ch < numChannels; ++ch)
|
||||
FloatVectorOperations::add (getChannelPointer (ch), src.getChannelPointer (ch), n);
|
||||
FloatVectorOperations::add (getDataPointer (ch), src.getDataPointer (ch), n);
|
||||
}
|
||||
|
||||
template <typename OtherSampleType>
|
||||
void JUCE_VECTOR_CALLTYPE replaceWithSumOfInternal (AudioBlock<OtherSampleType> src, SampleType value) const noexcept
|
||||
void JUCE_VECTOR_CALLTYPE replaceWithSumOfInternal (AudioBlock<OtherSampleType> src, NumericType value) const noexcept
|
||||
{
|
||||
jassert (numChannels == src.numChannels);
|
||||
auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
|
||||
|
||||
for (size_t ch = 0; ch < numChannels; ++ch)
|
||||
FloatVectorOperations::add (getChannelPointer (ch), src.getChannelPointer (ch), value, n);
|
||||
FloatVectorOperations::add (getDataPointer (ch), src.getDataPointer (ch), value, n);
|
||||
}
|
||||
|
||||
template <typename Src1SampleType, typename Src2SampleType>
|
||||
|
|
@ -663,13 +670,13 @@ private:
|
|||
auto n = static_cast<int> (jmin (numSamples, src1.numSamples, src2.numSamples) * sizeFactor);
|
||||
|
||||
for (size_t ch = 0; ch < numChannels; ++ch)
|
||||
FloatVectorOperations::add (getChannelPointer (ch), src1.getChannelPointer (ch), src2.getChannelPointer (ch), n);
|
||||
FloatVectorOperations::add (getDataPointer (ch), src1.getDataPointer (ch), src2.getDataPointer (ch), n);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
constexpr void JUCE_VECTOR_CALLTYPE subtractInternal (SampleType value) const noexcept
|
||||
constexpr void JUCE_VECTOR_CALLTYPE subtractInternal (NumericType value) const noexcept
|
||||
{
|
||||
addInternal (value * static_cast<SampleType> (-1.0));
|
||||
addInternal (value * static_cast<NumericType> (-1.0));
|
||||
}
|
||||
|
||||
template <typename OtherSampleType>
|
||||
|
|
@ -679,13 +686,13 @@ private:
|
|||
auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
|
||||
|
||||
for (size_t ch = 0; ch < numChannels; ++ch)
|
||||
FloatVectorOperations::subtract (getChannelPointer (ch), src.getChannelPointer (ch), n);
|
||||
FloatVectorOperations::subtract (getDataPointer (ch), src.getDataPointer (ch), n);
|
||||
}
|
||||
|
||||
template <typename OtherSampleType>
|
||||
void JUCE_VECTOR_CALLTYPE replaceWithDifferenceOfInternal (AudioBlock<OtherSampleType> src, SampleType value) const noexcept
|
||||
void JUCE_VECTOR_CALLTYPE replaceWithDifferenceOfInternal (AudioBlock<OtherSampleType> src, NumericType value) const noexcept
|
||||
{
|
||||
replaceWithSumOfInternal (src, static_cast<SampleType> (-1.0) * value);
|
||||
replaceWithSumOfInternal (src, static_cast<NumericType> (-1.0) * value);
|
||||
}
|
||||
|
||||
template <typename Src1SampleType, typename Src2SampleType>
|
||||
|
|
@ -695,16 +702,16 @@ private:
|
|||
auto n = static_cast<int> (jmin (numSamples, src1.numSamples, src2.numSamples) * sizeFactor);
|
||||
|
||||
for (size_t ch = 0; ch < numChannels; ++ch)
|
||||
FloatVectorOperations::subtract (getChannelPointer (ch), src1.getChannelPointer (ch), src2.getChannelPointer (ch), n);
|
||||
FloatVectorOperations::subtract (getDataPointer (ch), src1.getDataPointer (ch), src2.getDataPointer (ch), n);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void JUCE_VECTOR_CALLTYPE multiplyByInternal (SampleType value) const noexcept
|
||||
void JUCE_VECTOR_CALLTYPE multiplyByInternal (NumericType value) const noexcept
|
||||
{
|
||||
auto n = static_cast<int> (numSamples * sizeFactor);
|
||||
|
||||
for (size_t ch = 0; ch < numChannels; ++ch)
|
||||
FloatVectorOperations::multiply (getChannelPointer (ch), value, n);
|
||||
FloatVectorOperations::multiply (getDataPointer (ch), value, n);
|
||||
}
|
||||
|
||||
template <typename OtherSampleType>
|
||||
|
|
@ -714,17 +721,17 @@ private:
|
|||
auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
|
||||
|
||||
for (size_t ch = 0; ch < numChannels; ++ch)
|
||||
FloatVectorOperations::multiply (getChannelPointer (ch), src.getChannelPointer (ch), n);
|
||||
FloatVectorOperations::multiply (getDataPointer (ch), src.getDataPointer (ch), n);
|
||||
}
|
||||
|
||||
template <typename OtherSampleType>
|
||||
void JUCE_VECTOR_CALLTYPE replaceWithProductOfInternal (AudioBlock<OtherSampleType> src, SampleType value) const noexcept
|
||||
void JUCE_VECTOR_CALLTYPE replaceWithProductOfInternal (AudioBlock<OtherSampleType> src, NumericType value) const noexcept
|
||||
{
|
||||
jassert (numChannels == src.numChannels);
|
||||
auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
|
||||
|
||||
for (size_t ch = 0; ch < numChannels; ++ch)
|
||||
FloatVectorOperations::multiply (getChannelPointer (ch), src.getChannelPointer (ch), value, n);
|
||||
FloatVectorOperations::multiply (getDataPointer (ch), src.getDataPointer (ch), value, n);
|
||||
}
|
||||
|
||||
template <typename Src1SampleType, typename Src2SampleType>
|
||||
|
|
@ -734,7 +741,7 @@ private:
|
|||
auto n = static_cast<int> (jmin (numSamples, src1.numSamples, src2.numSamples) * sizeFactor);
|
||||
|
||||
for (size_t ch = 0; ch < numChannels; ++ch)
|
||||
FloatVectorOperations::multiply (getChannelPointer (ch), src1.getChannelPointer (ch), src2.getChannelPointer (ch), n);
|
||||
FloatVectorOperations::multiply (getDataPointer (ch), src1.getDataPointer (ch), src2.getDataPointer (ch), n);
|
||||
}
|
||||
|
||||
template <typename SmoothingType>
|
||||
|
|
@ -751,7 +758,7 @@ private:
|
|||
const auto scaler = value.getNextValue();
|
||||
|
||||
for (size_t ch = 0; ch < numChannels; ++ch)
|
||||
getChannelPointer (ch)[i] *= scaler;
|
||||
getDataPointer (ch)[i] *= scaler;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -774,20 +781,20 @@ private:
|
|||
const auto scaler = value.getNextValue();
|
||||
|
||||
for (size_t ch = 0; ch < numChannels; ++ch)
|
||||
getChannelPointer (ch)[i] = scaler * src.getChannelPointer (ch)[i];
|
||||
getDataPointer (ch)[i] = scaler * src.getChannelPointer (ch)[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
template <typename OtherSampleType>
|
||||
void JUCE_VECTOR_CALLTYPE addProductOfInternal (AudioBlock<OtherSampleType> src, SampleType factor) const noexcept
|
||||
void JUCE_VECTOR_CALLTYPE addProductOfInternal (AudioBlock<OtherSampleType> src, NumericType factor) const noexcept
|
||||
{
|
||||
jassert (numChannels == src.numChannels);
|
||||
auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
|
||||
|
||||
for (size_t ch = 0; ch < numChannels; ++ch)
|
||||
FloatVectorOperations::addWithMultiply (getChannelPointer (ch), src.getChannelPointer (ch), factor, n);
|
||||
FloatVectorOperations::addWithMultiply (getDataPointer (ch), src.getDataPointer (ch), factor, n);
|
||||
}
|
||||
|
||||
template <typename Src1SampleType, typename Src2SampleType>
|
||||
|
|
@ -797,13 +804,13 @@ private:
|
|||
auto n = static_cast<int> (jmin (numSamples, src1.numSamples, src2.numSamples) * sizeFactor);
|
||||
|
||||
for (size_t ch = 0; ch < numChannels; ++ch)
|
||||
FloatVectorOperations::addWithMultiply (getChannelPointer (ch), src1.getChannelPointer (ch), src2.getChannelPointer (ch), n);
|
||||
FloatVectorOperations::addWithMultiply (getDataPointer (ch), src1.getDataPointer (ch), src2.getDataPointer (ch), n);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
constexpr void negateInternal() const noexcept
|
||||
{
|
||||
multiplyByInternal (static_cast<SampleType> (-1.0));
|
||||
multiplyByInternal (static_cast<NumericType> (-1.0));
|
||||
}
|
||||
|
||||
template <typename OtherSampleType>
|
||||
|
|
@ -813,7 +820,7 @@ private:
|
|||
auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
|
||||
|
||||
for (size_t ch = 0; ch < numChannels; ++ch)
|
||||
FloatVectorOperations::negate (getChannelPointer (ch), src.getChannelPointer (ch), n);
|
||||
FloatVectorOperations::negate (getDataPointer (ch), src.getDataPointer (ch), n);
|
||||
}
|
||||
|
||||
template <typename OtherSampleType>
|
||||
|
|
@ -823,7 +830,7 @@ private:
|
|||
auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
|
||||
|
||||
for (size_t ch = 0; ch < numChannels; ++ch)
|
||||
FloatVectorOperations::abs (getChannelPointer (ch), src.getChannelPointer (ch), n);
|
||||
FloatVectorOperations::abs (getDataPointer (ch), src.getDataPointer (ch), n);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -834,7 +841,7 @@ private:
|
|||
auto n = static_cast<int> (jmin (src1.numSamples, src2.numSamples, numSamples) * sizeFactor);
|
||||
|
||||
for (size_t ch = 0; ch < numChannels; ++ch)
|
||||
FloatVectorOperations::min (getChannelPointer (ch), src1.getChannelPointer (ch), src2.getChannelPointer (ch), n);
|
||||
FloatVectorOperations::min (getDataPointer (ch), src1.getDataPointer (ch), src2.getDataPointer (ch), n);
|
||||
}
|
||||
|
||||
template <typename Src1SampleType, typename Src2SampleType>
|
||||
|
|
@ -844,7 +851,7 @@ private:
|
|||
auto n = static_cast<int> (jmin (src1.numSamples, src2.numSamples, numSamples) * sizeFactor);
|
||||
|
||||
for (size_t ch = 0; ch < numChannels; ++ch)
|
||||
FloatVectorOperations::max (getChannelPointer (ch), src1.getChannelPointer (ch), src2.getChannelPointer (ch), n);
|
||||
FloatVectorOperations::max (getDataPointer (ch), src1.getDataPointer (ch), src2.getDataPointer (ch), n);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
|
|||
|
|
@ -29,12 +29,32 @@ namespace juce
|
|||
namespace dsp
|
||||
{
|
||||
|
||||
template <typename SampleType>
|
||||
class AudioBlockUnitTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
//==============================================================================
|
||||
using NumericType = typename SampleTypeHelpers::ElementType<SampleType>::Type;
|
||||
|
||||
AudioBlockUnitTests()
|
||||
: UnitTest ("AudioBlock", UnitTestCategories::dsp)
|
||||
{}
|
||||
{
|
||||
for (auto v : { &data, &otherData })
|
||||
for (auto& channel : *v)
|
||||
channel = allocateAlignedMemory (numSamples);
|
||||
|
||||
block = { data.data(), data.size(), (size_t) numSamples };
|
||||
otherBlock = { otherData.data(), otherData.size(), (size_t) numSamples };
|
||||
|
||||
resetBlocks();
|
||||
}
|
||||
|
||||
~AudioBlockUnitTests() override
|
||||
{
|
||||
for (auto v : { &data, &otherData })
|
||||
for (auto channel : *v)
|
||||
deallocateAlignedMemory (channel);
|
||||
}
|
||||
|
||||
void runTest() override
|
||||
{
|
||||
|
|
@ -46,13 +66,13 @@ public:
|
|||
|
||||
beginTest ("Constructors");
|
||||
{
|
||||
expect (block == AudioBlock<float> (data.getArrayOfWritePointers(), (size_t) data.getNumChannels(), (size_t) data.getNumSamples()));
|
||||
expect (block == AudioBlock<float> (data.getArrayOfWritePointers(), (size_t) data.getNumChannels(), (size_t) 0, (size_t) data.getNumSamples()));
|
||||
expect (block == AudioBlock<float> (block));
|
||||
expect (block == AudioBlock<SampleType> (data.data(), data.size(), numSamples));
|
||||
expect (block == AudioBlock<SampleType> (data.data(), data.size(), (size_t) 0, numSamples));
|
||||
expect (block == AudioBlock<SampleType> (block));
|
||||
|
||||
expect (block == AudioBlock<const float> (data.getArrayOfWritePointers(), (size_t) data.getNumChannels(), (size_t) data.getNumSamples()));
|
||||
expect (block == AudioBlock<const float> (data.getArrayOfWritePointers(), (size_t) data.getNumChannels(), (size_t) 0, (size_t) data.getNumSamples()));
|
||||
expect (block == AudioBlock<const float> (block));
|
||||
expect (block == AudioBlock<const SampleType> (data.data(), data.size(), numSamples));
|
||||
expect (block == AudioBlock<const SampleType> (data.data(), data.size(), (size_t) 0, numSamples));
|
||||
expect (block == AudioBlock<const SampleType> (block));
|
||||
}
|
||||
|
||||
beginTest ("Swap");
|
||||
|
|
@ -60,188 +80,159 @@ public:
|
|||
resetBlocks();
|
||||
|
||||
expect (block != otherBlock);
|
||||
expectEquals (block.getSample (0, 0), 1.0f);
|
||||
expectEquals (block.getSample (0, 4), 5.0f);
|
||||
expectEquals (otherBlock.getSample (0, 0), -1.0f);
|
||||
expectEquals (otherBlock.getSample (0, 3), -4.0f);
|
||||
expect (block.getSample (0, 0) == SampleType (1.0));
|
||||
expect (block.getSample (0, 4) == SampleType (5.0));
|
||||
expect (otherBlock.getSample (0, 0) == SampleType (-1.0));
|
||||
expect (otherBlock.getSample (0, 3) == SampleType (-4.0));
|
||||
|
||||
block.swap (otherBlock);
|
||||
|
||||
expect (block != otherBlock);
|
||||
expectEquals (otherBlock.getSample (0, 0), 1.0f);
|
||||
expectEquals (otherBlock.getSample (0, 4), 5.0f);
|
||||
expectEquals (block.getSample (0, 0), -1.0f);
|
||||
expectEquals (block.getSample (0, 3), -4.0f);
|
||||
expect (otherBlock.getSample (0, 0) == SampleType (1.0));
|
||||
expect (otherBlock.getSample (0, 4) == SampleType (5.0));
|
||||
expect (block.getSample (0, 0) == SampleType (-1.0));
|
||||
expect (block.getSample (0, 3) == SampleType (-4.0));
|
||||
|
||||
block.swap (otherBlock);
|
||||
|
||||
expect (block.getSample (0, 0) == SampleType (1.0));
|
||||
expect (block.getSample (0, 4) == SampleType (5.0));
|
||||
expect (otherBlock.getSample (0, 0) == SampleType (-1.0));
|
||||
expect (otherBlock.getSample (0, 3) == SampleType (-4.0));
|
||||
}
|
||||
|
||||
beginTest ("Getters and setters");
|
||||
{
|
||||
resetBlocks();
|
||||
|
||||
expectEquals ((int) block.getNumChannels(), data.getNumChannels());
|
||||
expectEquals ((int) block.getNumSamples(), data.getNumSamples());
|
||||
expectEquals ((int) block.getNumChannels(), (int) data.size());
|
||||
expectEquals ((int) block.getNumSamples(), numSamples);
|
||||
|
||||
expectEquals (block.getChannelPointer (0)[2], 3.0f);
|
||||
block.getChannelPointer (0)[2] = 999.0f;
|
||||
expectEquals (block.getChannelPointer (0)[2], 999.0f);
|
||||
expect (block.getChannelPointer (0)[2] == SampleType (3.0));
|
||||
block.getChannelPointer (0)[2] = SampleType (999.0);
|
||||
expect (block.getChannelPointer (0)[2] == SampleType (999.0));
|
||||
|
||||
expectEquals (block.getSample (0, 4), 5.0f);
|
||||
expectEquals (block.getSample (1, 4), 11.0f);
|
||||
expect (block.getSample (0, 4) == SampleType (5.0));
|
||||
expect (block.getSample (1, 4) == SampleType (11.0));
|
||||
|
||||
expectEquals (block.getSingleChannelBlock (1).getSample (0, 3), block.getSample (1, 3));
|
||||
expect (block.getSingleChannelBlock (1).getSample (0, 3) == block.getSample (1, 3));
|
||||
|
||||
expectEquals (block.getSubsetChannelBlock (0, 2).getSample (1, 3), block.getSample (1, 3));
|
||||
expectEquals (block.getSubsetChannelBlock (1, 1).getSample (0, 3), block.getSample (1, 3));
|
||||
expect (block.getSubsetChannelBlock (0, 2).getSample (1, 3) == block.getSample (1, 3));
|
||||
expect (block.getSubsetChannelBlock (1, 1).getSample (0, 3) == block.getSample (1, 3));
|
||||
|
||||
block.setSample (1, 1, 777.0f);
|
||||
expectEquals (block.getSample (1, 1), 777.0f);
|
||||
block.setSample (1, 1, SampleType (777.0));
|
||||
expect (block.getSample (1, 1) == SampleType (777.0));
|
||||
|
||||
block.addSample (1, 1, 1.0f);
|
||||
expectEquals (block.getSample (1, 1), 778.0f);
|
||||
block.addSample (1, 1, SampleType (1.0));
|
||||
expect (block.getSample (1, 1) == SampleType (778.0));
|
||||
}
|
||||
|
||||
beginTest ("Copying");
|
||||
beginTest ("Basic copying");
|
||||
{
|
||||
block.clear();
|
||||
expectEquals (block.getSample (0, 2), 0.0f);
|
||||
expectEquals (block.getSample (1, 4), 0.0f);
|
||||
expect (block.getSample (0, 2) == SampleType (0.0));
|
||||
expect (block.getSample (1, 4) == SampleType (0.0));
|
||||
|
||||
block.fill (456.0f);
|
||||
expectEquals (block.getSample (0, 2), 456.0f);
|
||||
expectEquals (block.getSample (1, 4), 456.0f);
|
||||
block.fill ((NumericType) 456.0);
|
||||
expect (block.getSample (0, 2) == SampleType (456.0));
|
||||
expect (block.getSample (1, 4) == SampleType (456.0));
|
||||
|
||||
block.copyFrom (otherBlock);
|
||||
expect (block != otherBlock);
|
||||
expectEquals (block.getSample (0, 2), otherBlock.getSample (0, 2));
|
||||
expectEquals (block.getSample (1, 4), otherBlock.getSample (1, 4));
|
||||
expect (block.getSample (0, 2) == otherBlock.getSample (0, 2));
|
||||
expect (block.getSample (1, 4) == otherBlock.getSample (1, 4));
|
||||
|
||||
resetBlocks();
|
||||
|
||||
AudioBuffer<float> otherBuffer ((int) block.getNumChannels(), (int) block.getNumSamples());
|
||||
otherBlock.copyTo (otherBuffer);
|
||||
expectEquals (otherBlock.getSample (0, 2), otherBuffer.getSample (0, 2));
|
||||
expectEquals (otherBlock.getSample (1, 4), otherBuffer.getSample (1, 4));
|
||||
|
||||
block.copyFrom (otherBuffer);
|
||||
expectEquals (block.getSample (0, 2), otherBlock.getSample (0, 2));
|
||||
expectEquals (block.getSample (1, 4), otherBlock.getSample (1, 4));
|
||||
|
||||
float testSample1 = block.getSample (0, 2);
|
||||
float testSample2 = block.getSample (1, 3);
|
||||
SampleType testSample1 = block.getSample (0, 2);
|
||||
SampleType testSample2 = block.getSample (1, 3);
|
||||
expect (testSample1 != block.getSample (0, 4));
|
||||
expect (testSample2 != block.getSample (1, 5));
|
||||
block.move (0, 2);
|
||||
expectEquals (block.getSample (0, 4), testSample1);
|
||||
expectEquals (block.getSample (1, 5), testSample2);
|
||||
expect (block.getSample (0, 4) == testSample1);
|
||||
expect (block.getSample (1, 5) == testSample2);
|
||||
}
|
||||
|
||||
beginTest ("Addition");
|
||||
{
|
||||
resetBlocks();
|
||||
|
||||
block.add (15.0f);
|
||||
expectEquals (block.getSample (0, 4), 20.0f);
|
||||
expectEquals (block.getSample (1, 4), 26.0f);
|
||||
block.add ((NumericType) 15.0);
|
||||
expect (block.getSample (0, 4) == SampleType (20.0));
|
||||
expect (block.getSample (1, 4) == SampleType (26.0));
|
||||
|
||||
block.add (otherBlock);
|
||||
expectEquals (block.getSample (0, 4), 15.0f);
|
||||
expectEquals (block.getSample (1, 4), 15.0f);
|
||||
expect (block.getSample (0, 4) == SampleType (15.0));
|
||||
expect (block.getSample (1, 4) == SampleType (15.0));
|
||||
|
||||
block.replaceWithSumOf (otherBlock, 9.0f);
|
||||
expectEquals (block.getSample (0, 4), 4.0f);
|
||||
expectEquals (block.getSample (1, 4), -2.0f);
|
||||
block.replaceWithSumOf (otherBlock, (NumericType) 9.0);
|
||||
expect (block.getSample (0, 4) == SampleType (4.0));
|
||||
expect (block.getSample (1, 4) == SampleType (-2.0));
|
||||
|
||||
resetBlocks();
|
||||
|
||||
block.replaceWithSumOf (block, otherBlock);
|
||||
expectEquals (block.getSample (0, 4), 0.0f);
|
||||
expectEquals (block.getSample (1, 4), 0.0f);
|
||||
expect (block.getSample (0, 4) == SampleType (0.0));
|
||||
expect (block.getSample (1, 4) == SampleType (0.0));
|
||||
}
|
||||
|
||||
beginTest ("Subtraction");
|
||||
{
|
||||
resetBlocks();
|
||||
|
||||
block.subtract (15.0f);
|
||||
expectEquals (block.getSample (0, 4), -10.0f);
|
||||
expectEquals (block.getSample (1, 4), -4.0f);
|
||||
block.subtract ((NumericType) 15.0);
|
||||
expect (block.getSample (0, 4) == SampleType (-10.0));
|
||||
expect (block.getSample (1, 4) == SampleType (-4.0));
|
||||
|
||||
block.subtract (otherBlock);
|
||||
expectEquals (block.getSample (0, 4), -5.0f);
|
||||
expectEquals (block.getSample (1, 4), 7.0f);
|
||||
expect (block.getSample (0, 4) == SampleType (-5.0));
|
||||
expect (block.getSample (1, 4) == SampleType (7.0));
|
||||
|
||||
block.replaceWithDifferenceOf (otherBlock, 9.0f);
|
||||
expectEquals (block.getSample (0, 4), -14.0f);
|
||||
expectEquals (block.getSample (1, 4), -20.0f);
|
||||
block.replaceWithDifferenceOf (otherBlock, (NumericType) 9.0);
|
||||
expect (block.getSample (0, 4) == SampleType (-14.0));
|
||||
expect (block.getSample (1, 4) == SampleType (-20.0));
|
||||
|
||||
resetBlocks();
|
||||
|
||||
block.replaceWithDifferenceOf (block, otherBlock);
|
||||
expectEquals (block.getSample (0, 4), 10.0f);
|
||||
expectEquals (block.getSample (1, 4), 22.0f);
|
||||
expect (block.getSample (0, 4) == SampleType (10.0));
|
||||
expect (block.getSample (1, 4) == SampleType (22.0));
|
||||
}
|
||||
|
||||
beginTest ("Multiplication");
|
||||
{
|
||||
resetBlocks();
|
||||
|
||||
block.multiplyBy (10.0f);
|
||||
expectEquals (block.getSample (0, 4), 50.0f);
|
||||
expectEquals (block.getSample (1, 4), 110.0f);
|
||||
block.multiplyBy ((NumericType) 10.0);
|
||||
expect (block.getSample (0, 4) == SampleType (50.0));
|
||||
expect (block.getSample (1, 4) == SampleType (110.0));
|
||||
|
||||
block.multiplyBy (otherBlock);
|
||||
expectEquals (block.getSample (0, 4), -250.0f);
|
||||
expectEquals (block.getSample (1, 4), -1210.0f);
|
||||
expect (block.getSample (0, 4) == SampleType (-250.0));
|
||||
expect (block.getSample (1, 4) == SampleType (-1210.0));
|
||||
|
||||
block.replaceWithProductOf (otherBlock, 3.0f);
|
||||
expectEquals (block.getSample (0, 4), -15.0f);
|
||||
expectEquals (block.getSample (1, 4), -33.0f);
|
||||
block.replaceWithProductOf (otherBlock, (NumericType) 3.0);
|
||||
expect (block.getSample (0, 4) == SampleType (-15.0));
|
||||
expect (block.getSample (1, 4) == SampleType (-33.0));
|
||||
|
||||
resetBlocks();
|
||||
|
||||
block.replaceWithProductOf (block, otherBlock);
|
||||
expectEquals (block.getSample (0, 4), -25.0f);
|
||||
expectEquals (block.getSample (1, 4), -121.0f);
|
||||
}
|
||||
|
||||
beginTest ("Smoothing");
|
||||
{
|
||||
block.fill (1.0f);
|
||||
SmoothedValue<float> sv { 1.0f };
|
||||
sv.reset (1, 4);
|
||||
sv.setTargetValue (0.0f);
|
||||
|
||||
block.multiplyBy (sv);
|
||||
expect (block.getSample (0, 2) < 1.0f);
|
||||
expect (block.getSample (1, 2) < 1.0f);
|
||||
expect (block.getSample (0, 2) > 0.0f);
|
||||
expect (block.getSample (1, 2) > 0.0f);
|
||||
expectEquals (block.getSample (0, 5), 0.0f);
|
||||
expectEquals (block.getSample (1, 5), 0.0f);
|
||||
|
||||
sv.setCurrentAndTargetValue (-1.0f);
|
||||
sv.setTargetValue (0.0f);
|
||||
otherBlock.fill (-1.0f);
|
||||
block.replaceWithProductOf (otherBlock, sv);
|
||||
expect (block.getSample (0, 2) < 1.0f);
|
||||
expect (block.getSample (1, 2) < 1.0f);
|
||||
expect (block.getSample (0, 2) > 0.0f);
|
||||
expect (block.getSample (1, 2) > 0.0f);
|
||||
expectEquals (block.getSample (0, 5), 0.0f);
|
||||
expectEquals (block.getSample (1, 5), 0.0f);
|
||||
expect (block.getSample (0, 4) == SampleType (-25.0));
|
||||
expect (block.getSample (1, 4) == SampleType (-121.0));
|
||||
}
|
||||
|
||||
beginTest ("Multiply add");
|
||||
{
|
||||
resetBlocks();
|
||||
|
||||
block.addProductOf (otherBlock, -1.0f);
|
||||
expectEquals (block.getSample (0, 4), 10.0f);
|
||||
expectEquals (block.getSample (1, 4), 22.0f);
|
||||
block.addProductOf (otherBlock, (NumericType) -1.0);
|
||||
expect (block.getSample (0, 4) == SampleType (10.0));
|
||||
expect (block.getSample (1, 4) == SampleType (22.0));
|
||||
|
||||
block.addProductOf (otherBlock, otherBlock);
|
||||
expectEquals (block.getSample (0, 4), 35.0f);
|
||||
expectEquals (block.getSample (1, 4), 143.0f);
|
||||
expect (block.getSample (0, 4) == SampleType (35.0));
|
||||
expect (block.getSample (1, 4) == SampleType (143.0));
|
||||
}
|
||||
|
||||
beginTest ("Negative abs min max");
|
||||
|
|
@ -250,93 +241,259 @@ public:
|
|||
otherBlock.negate();
|
||||
|
||||
block.add (otherBlock);
|
||||
expectEquals (block.getSample (0, 4), 10.0f);
|
||||
expectEquals (block.getSample (1, 4), 22.0f);
|
||||
expect (block.getSample (0, 4) == SampleType (10.0));
|
||||
expect (block.getSample (1, 4) == SampleType (22.0));
|
||||
|
||||
block.replaceWithNegativeOf (otherBlock);
|
||||
expectEquals (block.getSample (0, 4), -5.0f);
|
||||
expectEquals (block.getSample (1, 4), -11.0f);
|
||||
expect (block.getSample (0, 4) == SampleType (-5.0));
|
||||
expect (block.getSample (1, 4) == SampleType (-11.0));
|
||||
|
||||
block.clear();
|
||||
otherBlock.negate();
|
||||
block.replaceWithAbsoluteValueOf (otherBlock);
|
||||
expectEquals (block.getSample (0, 4), 5.0f);
|
||||
expectEquals (block.getSample (1, 4), 11.0f);
|
||||
expect (block.getSample (0, 4) == SampleType (5.0));
|
||||
expect (block.getSample (1, 4) == SampleType (11.0));
|
||||
|
||||
resetBlocks();
|
||||
block.replaceWithMinOf (block, otherBlock);
|
||||
expectEquals (block.getSample (0, 4), -5.0f);
|
||||
expectEquals (block.getSample (1, 4), -11.0f);
|
||||
expect (block.getSample (0, 4) == SampleType (-5.0));
|
||||
expect (block.getSample (1, 4) == SampleType (-11.0));
|
||||
|
||||
resetBlocks();
|
||||
block.replaceWithMaxOf (block, otherBlock);
|
||||
expectEquals (block.getSample (0, 4), 5.0f);
|
||||
expectEquals (block.getSample (1, 4), 11.0f);
|
||||
expect (block.getSample (0, 4) == SampleType (5.0));
|
||||
expect (block.getSample (1, 4) == SampleType (11.0));
|
||||
|
||||
resetBlocks();
|
||||
auto range = block.findMinAndMax();
|
||||
expectEquals (range.getStart(), 1.0f);
|
||||
expectEquals (range.getEnd(), 12.0f);
|
||||
expect (SampleType (range.getStart()) == SampleType (1.0));
|
||||
expect (SampleType (range.getEnd()) == SampleType (12.0));
|
||||
}
|
||||
|
||||
beginTest ("Operators");
|
||||
{
|
||||
resetBlocks();
|
||||
block += 10.0f;
|
||||
expectEquals (block.getSample (0, 4), 15.0f);
|
||||
expectEquals (block.getSample (1, 4), 21.0f);
|
||||
block += (NumericType) 10.0;
|
||||
expect (block.getSample (0, 4) == SampleType (15.0));
|
||||
expect (block.getSample (1, 4) == SampleType (21.0));
|
||||
block += otherBlock;
|
||||
expectEquals (block.getSample (0, 4), 10.0f);
|
||||
expectEquals (block.getSample (1, 4), 10.0f);
|
||||
expect (block.getSample (0, 4) == SampleType (10.0));
|
||||
expect (block.getSample (1, 4) == SampleType (10.0));
|
||||
|
||||
resetBlocks();
|
||||
block -= 10.0f;
|
||||
expectEquals (block.getSample (0, 4), -5.0f);
|
||||
expectEquals (block.getSample (1, 4), 1.0f);
|
||||
block -= (NumericType) 10.0;
|
||||
expect (block.getSample (0, 4) == SampleType (-5.0));
|
||||
expect (block.getSample (1, 4) == SampleType (1.0));
|
||||
block -= otherBlock;
|
||||
expectEquals (block.getSample (0, 4), 0.0f);
|
||||
expectEquals (block.getSample (1, 4), 12.0f);
|
||||
expect (block.getSample (0, 4) == SampleType (0.0));
|
||||
expect (block.getSample (1, 4) == SampleType (12.0));
|
||||
|
||||
resetBlocks();
|
||||
block *= 10.0f;
|
||||
expectEquals (block.getSample (0, 4), 50.0f);
|
||||
expectEquals (block.getSample (1, 4), 110.0f);
|
||||
block *= (NumericType) 10.0;
|
||||
expect (block.getSample (0, 4) == SampleType (50.0));
|
||||
expect (block.getSample (1, 4) == SampleType (110.0));
|
||||
block *= otherBlock;
|
||||
expectEquals (block.getSample (0, 4), -250.0f);
|
||||
expectEquals (block.getSample (1, 4), -1210.0f);
|
||||
expect (block.getSample (0, 4) == SampleType (-250.0));
|
||||
expect (block.getSample (1, 4) == SampleType (-1210.0));
|
||||
}
|
||||
|
||||
beginTest ("Process");
|
||||
{
|
||||
resetBlocks();
|
||||
AudioBlock<float>::process (block, otherBlock, [](float x) { return x + 1.0f; });
|
||||
expectEquals (otherBlock.getSample (0, 4), 6.0f);
|
||||
expectEquals (otherBlock.getSample (1, 4), 12.0f);
|
||||
AudioBlock<SampleType>::process (block, otherBlock, [](SampleType x) { return x + (NumericType) 1.0; });
|
||||
expect (otherBlock.getSample (0, 4) == SampleType (6.0));
|
||||
expect (otherBlock.getSample (1, 4) == SampleType (12.0));
|
||||
}
|
||||
|
||||
beginTest ("Copying");
|
||||
{
|
||||
resetBlocks();
|
||||
copyingTests();
|
||||
}
|
||||
|
||||
beginTest ("Smoothing");
|
||||
{
|
||||
resetBlocks();
|
||||
smoothedValueTests();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
AudioBuffer<float> data { 2, 6 }, otherData { 2, 6 };
|
||||
AudioBlock<float> block { data }, otherBlock { otherData };
|
||||
//==============================================================================
|
||||
template <typename T>
|
||||
using ScalarVoid = typename std::enable_if_t < std::is_scalar <T>::value, void>;
|
||||
|
||||
template <typename T>
|
||||
using SIMDVoid = typename std::enable_if_t <! std::is_scalar <T>::value, void>;
|
||||
|
||||
//==============================================================================
|
||||
template <typename T = SampleType>
|
||||
ScalarVoid<T> copyingTests()
|
||||
{
|
||||
auto unchangedElement1 = block.getSample (0, 4);
|
||||
auto unchangedElement2 = block.getSample (1, 1);
|
||||
|
||||
AudioBuffer<SampleType> otherBuffer (otherData.data(), (int) otherData.size(), numSamples);
|
||||
|
||||
block.copyFrom (otherBuffer, 1, 2, 2);
|
||||
|
||||
expectEquals (block.getSample (0, 4), unchangedElement1);
|
||||
expectEquals (block.getSample (1, 1), unchangedElement2);
|
||||
expectEquals (block.getSample (0, 2), otherBuffer.getSample (0, 1));
|
||||
expectEquals (block.getSample (1, 3), otherBuffer.getSample (1, 2));
|
||||
|
||||
resetBlocks();
|
||||
|
||||
unchangedElement1 = otherBuffer.getSample (0, 4);
|
||||
unchangedElement2 = otherBuffer.getSample (1, 3);
|
||||
|
||||
block.copyTo (otherBuffer, 2, 1, 2);
|
||||
|
||||
expectEquals (otherBuffer.getSample (0, 4), unchangedElement1);
|
||||
expectEquals (otherBuffer.getSample (1, 3), unchangedElement2);
|
||||
expectEquals (otherBuffer.getSample (0, 1), block.getSample (0, 2));
|
||||
expectEquals (otherBuffer.getSample (1, 2), block.getSample (1, 3));
|
||||
}
|
||||
|
||||
template <typename T = SampleType>
|
||||
SIMDVoid<T> copyingTests()
|
||||
{
|
||||
auto numSIMDElements = SIMDRegister<NumericType>::SIMDNumElements;
|
||||
AudioBuffer<NumericType> numericData ((int) block.getNumChannels(),
|
||||
(int) (block.getNumSamples() * numSIMDElements));
|
||||
|
||||
for (int c = 0; c < numericData.getNumChannels(); ++c)
|
||||
std::fill_n (numericData.getWritePointer (c), numericData.getNumSamples(), (NumericType) 1.0);
|
||||
|
||||
numericData.applyGainRamp (0, numericData.getNumSamples(), (NumericType) 0.127, (NumericType) 17.3);
|
||||
|
||||
auto lastUnchangedIndexBeforeCopiedRange = (int) ((numSIMDElements * 2) - 1);
|
||||
auto firstUnchangedIndexAfterCopiedRange = (int) ((numSIMDElements * 4) + 1);
|
||||
auto unchangedElement1 = numericData.getSample (0, lastUnchangedIndexBeforeCopiedRange);
|
||||
auto unchangedElement2 = numericData.getSample (1, firstUnchangedIndexAfterCopiedRange);
|
||||
|
||||
block.copyTo (numericData, 1, 2, 2);
|
||||
|
||||
expectEquals (numericData.getSample (0, lastUnchangedIndexBeforeCopiedRange), unchangedElement1);
|
||||
expectEquals (numericData.getSample (1, firstUnchangedIndexAfterCopiedRange), unchangedElement2);
|
||||
expect (SampleType (numericData.getSample (0, 2 * (int) numSIMDElements)) == block.getSample (0, 1));
|
||||
expect (SampleType (numericData.getSample (1, 3 * (int) numSIMDElements)) == block.getSample (1, 2));
|
||||
|
||||
numericData.applyGainRamp (0, numericData.getNumSamples(), (NumericType) 15.1, (NumericType) 0.7);
|
||||
|
||||
auto unchangedSIMDElement1 = block.getSample (0, 1);
|
||||
auto unchangedSIMDElement2 = block.getSample (1, 4);
|
||||
|
||||
block.copyFrom (numericData, 1, 2, 2);
|
||||
|
||||
expect (block.getSample (0, 1) == unchangedSIMDElement1);
|
||||
expect (block.getSample (1, 4) == unchangedSIMDElement2);
|
||||
expectEquals (block.getSample (0, 2).get (0), numericData.getSample (0, (int) numSIMDElements));
|
||||
expectEquals (block.getSample (1, 3).get (0), numericData.getSample (1, (int) (numSIMDElements * 2)));
|
||||
|
||||
if (numSIMDElements > 1)
|
||||
{
|
||||
expectEquals (block.getSample (0, 2).get (1), numericData.getSample (0, (int) (numSIMDElements + 1)));
|
||||
expectEquals (block.getSample (1, 3).get (1), numericData.getSample (1, (int) ((numSIMDElements * 2) + 1)));
|
||||
}
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
template <typename T = SampleType>
|
||||
ScalarVoid<T> smoothedValueTests()
|
||||
{
|
||||
block.fill ((SampleType) 1.0);
|
||||
SmoothedValue<SampleType> sv { (SampleType) 1.0 };
|
||||
sv.reset (1, 4);
|
||||
sv.setTargetValue ((SampleType) 0.0);
|
||||
|
||||
block.multiplyBy (sv);
|
||||
expect (block.getSample (0, 2) < (SampleType) 1.0);
|
||||
expect (block.getSample (1, 2) < (SampleType) 1.0);
|
||||
expect (block.getSample (0, 2) > (SampleType) 0.0);
|
||||
expect (block.getSample (1, 2) > (SampleType) 0.0);
|
||||
expectEquals (block.getSample (0, 5), (SampleType) 0.0);
|
||||
expectEquals (block.getSample (1, 5), (SampleType) 0.0);
|
||||
|
||||
sv.setCurrentAndTargetValue (-1.0f);
|
||||
sv.setTargetValue (0.0f);
|
||||
otherBlock.fill (-1.0f);
|
||||
block.replaceWithProductOf (otherBlock, sv);
|
||||
expect (block.getSample (0, 2) < (SampleType) 1.0);
|
||||
expect (block.getSample (1, 2) < (SampleType) 1.0);
|
||||
expect (block.getSample (0, 2) > (SampleType) 0.0);
|
||||
expect (block.getSample (1, 2) > (SampleType) 0.0);
|
||||
expectEquals (block.getSample (0, 5), (SampleType) 0.0);
|
||||
expectEquals (block.getSample (1, 5), (SampleType) 0.0);
|
||||
}
|
||||
|
||||
template <typename T = SampleType>
|
||||
SIMDVoid<T> smoothedValueTests() {}
|
||||
|
||||
//==============================================================================
|
||||
void resetBlocks()
|
||||
{
|
||||
auto value = 1.0f;
|
||||
auto value = SampleType (1.0);
|
||||
|
||||
for (size_t c = 0; c < block.getNumChannels(); ++c)
|
||||
{
|
||||
for (size_t i = 0; i < block.getNumSamples(); ++i)
|
||||
{
|
||||
block.setSample ((int) c, (int) i, value);
|
||||
value += 1.0f;
|
||||
value += SampleType (1.0);
|
||||
}
|
||||
}
|
||||
|
||||
otherBlock.replaceWithNegativeOf (block);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
static SampleType* allocateAlignedMemory (int numSamplesToAllocate)
|
||||
{
|
||||
auto alignmentLowerBound = std::alignment_of<SampleType>::value;
|
||||
#if ! JUCE_WINDOWS
|
||||
alignmentLowerBound = jmax (sizeof (void*), alignmentLowerBound);
|
||||
#endif
|
||||
auto alignmentOrder = std::ceil (std::log2 (alignmentLowerBound));
|
||||
auto requiredAlignment = (size_t) std::pow (2, alignmentOrder);
|
||||
|
||||
auto size = (size_t) numSamplesToAllocate * sizeof (SampleType);
|
||||
|
||||
#if JUCE_WINDOWS
|
||||
auto* memory = _aligned_malloc (size, requiredAlignment);
|
||||
#else
|
||||
void* memory;
|
||||
auto result = posix_memalign (&memory, requiredAlignment, size);
|
||||
|
||||
if (result != 0)
|
||||
{
|
||||
jassertfalse;
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return static_cast<SampleType*> (memory);
|
||||
}
|
||||
|
||||
void deallocateAlignedMemory (void* address)
|
||||
{
|
||||
#if JUCE_WINDOWS
|
||||
_aligned_free (address);
|
||||
#else
|
||||
free (address);
|
||||
#endif
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
static constexpr int numChannels = 2, numSamples = 6;
|
||||
std::array<SampleType*, numChannels> data, otherData;
|
||||
AudioBlock<SampleType> block, otherBlock;
|
||||
};
|
||||
|
||||
static AudioBlockUnitTests audioBlockUnitTests;
|
||||
static AudioBlockUnitTests<float> audioBlockFloatUnitTests;
|
||||
static AudioBlockUnitTests<double> audioBlockDoubleUnitTests;
|
||||
static AudioBlockUnitTests<SIMDRegister<float>> audioBlockSIMDFloatUnitTests;
|
||||
static AudioBlockUnitTests<SIMDRegister<double>> audioBlockSIMDDoubleUnitTests;
|
||||
|
||||
} // namespace dsp
|
||||
} // namespace juce
|
||||
|
|
|
|||
|
|
@ -267,10 +267,10 @@ struct SIMDRegister
|
|||
inline SIMDRegister JUCE_VECTOR_CALLTYPE operator^ (MaskType s) const noexcept { return { NativeOps::bit_xor (value, toVecType (s)) }; }
|
||||
|
||||
//==============================================================================
|
||||
/** Returns true if all elements-wise comparisons return true. */
|
||||
/** Returns true if all element-wise comparisons return true. */
|
||||
inline bool JUCE_VECTOR_CALLTYPE operator== (SIMDRegister other) const noexcept { return NativeOps::allEqual (value, other.value); }
|
||||
|
||||
/** Returns true if any elements-wise comparisons return false. */
|
||||
/** Returns true if any element-wise comparisons return false. */
|
||||
inline bool JUCE_VECTOR_CALLTYPE operator!= (SIMDRegister other) const noexcept { return ! (*this == other); }
|
||||
|
||||
/** Returns true if all elements are equal to the scalar. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue