Browse Source

Added some get/set/addSample methods to AudioBlock

tags/2021-05-28
jules 7 years ago
parent
commit
c4342e684d
1 changed files with 39 additions and 2 deletions
  1. +39
    -2
      modules/juce_dsp/containers/juce_AudioBlock.h

+ 39
- 2
modules/juce_dsp/containers/juce_AudioBlock.h View File

@@ -158,7 +158,7 @@ public:
{
jassert (channel < numChannels);
jassert (numSamples > 0);
return *(channels + channel) + startSample;
return channels[channel] + startSample;
}
/** Returns a raw pointer into one of the channels in this block. */
@@ -166,7 +166,7 @@ public:
{
jassert (channel < numChannels);
jassert (numSamples > 0);
return *(channels + channel) + startSample;
return channels[channel] + startSample;
}
/** Returns an AudioBlock that represents one of the channels in this block. */
@@ -188,6 +188,42 @@ public:
return AudioBlock (channels + channelStart, numChannelsToUse, startSample, numSamples);
}
/** Returns a sample from the buffer.
The channel and index are not checked - they are expected to be in-range. If not,
an assertion will be thrown, but in a release build, you're into 'undefined behaviour'
territory.
*/
SampleType getSample (int channel, int sampleIndex) const noexcept
{
jassert (isPositiveAndBelow (channel, numChannels));
jassert (isPositiveAndBelow (sampleIndex, numSamples));
return channels[channel][startSample + sampleIndex];
}
/** Modifies a sample in the buffer.
The channel and index are not checked - they are expected to be in-range. If not,
an assertion will be thrown, but in a release build, you're into 'undefined behaviour'
territory.
*/
void setSample (int destChannel, int destSample, SampleType newValue) noexcept
{
jassert (isPositiveAndBelow (destChannel, numChannels));
jassert (isPositiveAndBelow (destSample, numSamples));
channels[destChannel][startSample + destSample] = newValue;
}
/** Adds a value to a sample in the buffer.
The channel and index are not checked - they are expected to be in-range. If not,
an assertion will be thrown, but in a release build, you're into 'undefined behaviour'
territory.
*/
void addSample (int destChannel, int destSample, SampleType valueToAdd) noexcept
{
jassert (isPositiveAndBelow (destChannel, numChannels));
jassert (isPositiveAndBelow (destSample, numSamples));
channels[destChannel][startSample + destSample] += valueToAdd;
}
//==============================================================================
/** Clear the memory described by this AudioBlock. */
forcedinline AudioBlock& clear() noexcept
@@ -400,6 +436,7 @@ public:
for (size_t ch = 0; ch < numChannels; ++ch)
FloatVectorOperations::multiply (channelPtr (ch), src1.channelPtr (ch), src2.channelPtr (ch), n);
return *this;
}


Loading…
Cancel
Save