Browse Source

AudioBuffer: Add equality operators

v7.0.9
Anthony Nicholls 2 years ago
parent
commit
92aa3cf330
3 changed files with 25 additions and 40 deletions
  1. +25
    -0
      modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h
  2. +0
    -20
      modules/juce_audio_basics/sources/juce_MemoryAudioSource.cpp
  3. +0
    -20
      modules/juce_audio_formats/format/juce_BufferingAudioFormatReader.cpp

+ 25
- 0
modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h View File

@@ -1280,6 +1280,31 @@ private:
JUCE_LEAK_DETECTOR (AudioBuffer) 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. A multi-channel buffer of 32-bit floating point audio samples.


+ 0
- 20
modules/juce_audio_basics/sources/juce_MemoryAudioSource.cpp View File

@@ -108,26 +108,6 @@ void MemoryAudioSource::setLooping (bool shouldLoop)
//============================================================================== //==============================================================================
#if JUCE_UNIT_TESTS #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 struct MemoryAudioSourceTests : public UnitTest
{ {
MemoryAudioSourceTests() : UnitTest ("MemoryAudioSource", UnitTestCategories::audio) {} MemoryAudioSourceTests() : UnitTest ("MemoryAudioSource", UnitTestCategories::audio) {}


+ 0
- 20
modules/juce_audio_formats/format/juce_BufferingAudioFormatReader.cpp View File

@@ -176,26 +176,6 @@ bool BufferingAudioReader::readNextBufferChunk()
//============================================================================== //==============================================================================
#if JUCE_UNIT_TESTS #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) static bool isSilent (const AudioBuffer<float>& b)
{ {
for (int channel = 0; channel < b.getNumChannels(); ++channel) for (int channel = 0; channel < b.getNumChannels(); ++channel)


Loading…
Cancel
Save