From 3ef1ab02c6ed6fa6c8c21028836ef8fc7d3f04b2 Mon Sep 17 00:00:00 2001 From: jules Date: Wed, 11 Sep 2013 11:40:59 +0100 Subject: [PATCH] Added AudioSampleBuffer::reverse() method. --- .../buffers/juce_AudioSampleBuffer.cpp | 36 ++++++++++--------- .../buffers/juce_AudioSampleBuffer.h | 18 +++++----- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.cpp b/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.cpp index 1dd3e3c28e..944140f71d 100644 --- a/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.cpp +++ b/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.cpp @@ -285,9 +285,7 @@ void AudioSampleBuffer::applyGainRamp (const int channel, } } -void AudioSampleBuffer::applyGain (const int startSample, - const int numSamples, - const float gain) noexcept +void AudioSampleBuffer::applyGain (int startSample, int numSamples, float gain) noexcept { for (int i = 0; i < numChannels; ++i) applyGain (i, startSample, numSamples, gain); @@ -298,10 +296,8 @@ void AudioSampleBuffer::applyGain (const float gain) noexcept applyGain (0, size, gain); } -void AudioSampleBuffer::applyGainRamp (const int startSample, - const int numSamples, - const float startGain, - const float endGain) noexcept +void AudioSampleBuffer::applyGainRamp (int startSample, int numSamples, + float startGain, float endGain) noexcept { for (int i = 0; i < numChannels; ++i) applyGainRamp (i, startSample, numSamples, startGain, endGain); @@ -399,11 +395,9 @@ void AudioSampleBuffer::copyFrom (const int destChannel, jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size); if (numSamples > 0) - { FloatVectorOperations::copy (channels [destChannel] + destStartSample, source.channels [sourceChannel] + sourceStartSample, numSamples); - } } void AudioSampleBuffer::copyFrom (const int destChannel, @@ -416,11 +410,7 @@ void AudioSampleBuffer::copyFrom (const int destChannel, jassert (source != nullptr); if (numSamples > 0) - { - FloatVectorOperations::copy (channels [destChannel] + destStartSample, - source, - numSamples); - } + FloatVectorOperations::copy (channels [destChannel] + destStartSample, source, numSamples); } void AudioSampleBuffer::copyFrom (const int destChannel, @@ -482,6 +472,21 @@ void AudioSampleBuffer::copyFromWithRamp (const int destChannel, } } +void AudioSampleBuffer::reverse (int channel, int startSample, int numSamples) const noexcept +{ + jassert (isPositiveAndBelow (channel, numChannels)); + jassert (startSample >= 0 && startSample + numSamples <= size); + + std::reverse (channels[channel] + startSample, + channels[channel] + startSample + numSamples); +} + +void AudioSampleBuffer::reverse (int startSample, int numSamples) const noexcept +{ + for (int i = 0; i < numChannels; ++i) + reverse (i, startSample, numSamples); +} + void AudioSampleBuffer::findMinMax (const int channel, const int startSample, int numSamples, @@ -508,8 +513,7 @@ float AudioSampleBuffer::getMagnitude (const int channel, return jmax (mn, -mn, mx, -mx); } -float AudioSampleBuffer::getMagnitude (const int startSample, - const int numSamples) const noexcept +float AudioSampleBuffer::getMagnitude (int startSample, int numSamples) const noexcept { float mag = 0.0f; diff --git a/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h b/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h index bff2a0a7ce..cd71c3da2e 100644 --- a/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h +++ b/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h @@ -107,19 +107,16 @@ public: //============================================================================== /** Returns the number of channels of audio data that this buffer contains. - @see getSampleData */ int getNumChannels() const noexcept { return numChannels; } /** Returns the number of samples allocated in each of the buffer's channels. - @see getSampleData */ int getNumSamples() const noexcept { return size; } /** Returns a pointer one of the buffer's channels. - For speed, this doesn't check whether the channel number is out of range, so be careful when using it! */ @@ -409,23 +406,26 @@ public: float& minVal, float& maxVal) const noexcept; - /** Finds the highest absolute sample value within a region of a channel. - */ + /** Finds the highest absolute sample value within a region of a channel. */ float getMagnitude (int channel, int startSample, int numSamples) const noexcept; - /** Finds the highest absolute sample value within a region on all channels. - */ + /** Finds the highest absolute sample value within a region on all channels. */ float getMagnitude (int startSample, int numSamples) const noexcept; - /** Returns the root mean squared level for a region of a channel. - */ + /** Returns the root mean squared level for a region of a channel. */ float getRMSLevel (int channel, int startSample, int numSamples) const noexcept; + /** Reverses a part of a channel. */ + void reverse (int channel, int startSample, int numSamples) const noexcept; + + /** Reverses a part of the buffer. */ + void reverse (int startSample, int numSamples) const noexcept; + private: //============================================================================== int numChannels, size;