mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
AudioBuffer: Add equality operators
This commit is contained in:
parent
eda1921961
commit
92aa3cf330
3 changed files with 25 additions and 40 deletions
|
|
@ -1280,6 +1280,31 @@ private:
|
|||
JUCE_LEAK_DETECTOR (AudioBuffer)
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
template <typename Type>
|
||||
bool operator== (const AudioBuffer<Type>& a, const AudioBuffer<Type>& b)
|
||||
{
|
||||
if (a.getNumChannels() != b.getNumChannels())
|
||||
return false;
|
||||
|
||||
for (auto c = 0; c < a.getNumChannels(); ++c)
|
||||
{
|
||||
const auto begin = [c] (auto& x) { return x.getReadPointer (c); };
|
||||
const auto end = [c] (auto& x) { return x.getReadPointer (c) + x.getNumSamples(); };
|
||||
|
||||
if (! std::equal (begin (a), end (a), begin (b), end (b)))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
bool operator!= (const AudioBuffer<Type>& a, const AudioBuffer<Type>& b)
|
||||
{
|
||||
return ! (a == b);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
A multi-channel buffer of 32-bit floating point audio samples.
|
||||
|
|
|
|||
|
|
@ -108,26 +108,6 @@ void MemoryAudioSource::setLooping (bool shouldLoop)
|
|||
//==============================================================================
|
||||
#if JUCE_UNIT_TESTS
|
||||
|
||||
static bool operator== (const AudioBuffer<float>& a, const AudioBuffer<float>& b)
|
||||
{
|
||||
if (a.getNumChannels() != b.getNumChannels())
|
||||
return false;
|
||||
|
||||
for (int channel = 0; channel < a.getNumChannels(); ++channel)
|
||||
{
|
||||
auto* aPtr = a.getReadPointer (channel);
|
||||
auto* bPtr = b.getReadPointer (channel);
|
||||
|
||||
if (std::vector<float> (aPtr, aPtr + a.getNumSamples())
|
||||
!= std::vector<float> (bPtr, bPtr + b.getNumSamples()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
struct MemoryAudioSourceTests : public UnitTest
|
||||
{
|
||||
MemoryAudioSourceTests() : UnitTest ("MemoryAudioSource", UnitTestCategories::audio) {}
|
||||
|
|
|
|||
|
|
@ -176,26 +176,6 @@ bool BufferingAudioReader::readNextBufferChunk()
|
|||
//==============================================================================
|
||||
#if JUCE_UNIT_TESTS
|
||||
|
||||
static bool operator== (const AudioBuffer<float>& a, const AudioBuffer<float>& b)
|
||||
{
|
||||
if (a.getNumChannels() != b.getNumChannels() || a.getNumSamples() != b.getNumSamples())
|
||||
return false;
|
||||
|
||||
for (int channel = 0; channel < a.getNumChannels(); ++channel)
|
||||
{
|
||||
auto* aPtr = a.getReadPointer (channel);
|
||||
auto* bPtr = b.getReadPointer (channel);
|
||||
|
||||
if (std::vector<float> (aPtr, aPtr + a.getNumSamples())
|
||||
!= std::vector<float> (bPtr, bPtr + b.getNumSamples()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool isSilent (const AudioBuffer<float>& b)
|
||||
{
|
||||
for (int channel = 0; channel < b.getNumChannels(); ++channel)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue