Browse Source

Added 64-bit double methods to FloatVectorOperations. Refactored some of the min/max methods in FloatVectorOperations to return a Range instead of getting the results as parameters.

tags/2021-05-28
jules 11 years ago
parent
commit
d74bf3dca8
6 changed files with 563 additions and 384 deletions
  1. +6
    -10
      modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.cpp
  2. +4
    -8
      modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h
  3. +497
    -350
      modules/juce_audio_basics/buffers/juce_FloatVectorOperations.cpp
  4. +44
    -2
      modules/juce_audio_basics/buffers/juce_FloatVectorOperations.h
  5. +10
    -11
      modules/juce_audio_formats/format/juce_AudioFormatReader.cpp
  6. +2
    -3
      modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp

+ 6
- 10
modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.cpp View File

@@ -487,17 +487,14 @@ void AudioSampleBuffer::reverse (int startSample, int numSamples) const noexcept
reverse (i, startSample, numSamples);
}
void AudioSampleBuffer::findMinMax (const int channel,
const int startSample,
int numSamples,
float& minVal,
float& maxVal) const noexcept
Range<float> AudioSampleBuffer::findMinMax (const int channel,
const int startSample,
int numSamples) const noexcept
{
jassert (isPositiveAndBelow (channel, numChannels));
jassert (startSample >= 0 && startSample + numSamples <= size);
FloatVectorOperations::findMinAndMax (channels [channel] + startSample,
numSamples, minVal, maxVal);
return FloatVectorOperations::findMinAndMax (channels [channel] + startSample, numSamples);
}
float AudioSampleBuffer::getMagnitude (const int channel,
@@ -507,10 +504,9 @@ float AudioSampleBuffer::getMagnitude (const int channel,
jassert (isPositiveAndBelow (channel, numChannels));
jassert (startSample >= 0 && startSample + numSamples <= size);
float mn, mx;
findMinMax (channel, startSample, numSamples, mn, mx);
const Range<float> r (findMinMax (channel, startSample, numSamples));
return jmax (mn, -mn, mx, -mx);
return jmax (r.getStart(), -r.getStart(), r.getEnd(), -r.getEnd());
}
float AudioSampleBuffer::getMagnitude (int startSample, int numSamples) const noexcept


+ 4
- 8
modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h View File

@@ -392,19 +392,15 @@ public:
float endGain) noexcept;
/** Finds the highest and lowest sample values in a given range.
/** Returns a Range indicating the lowest and highest sample values in a given section.
@param channel the channel to read from
@param startSample the start sample within the channel
@param numSamples the number of samples to check
@param minVal on return, the lowest value that was found
@param maxVal on return, the highest value that was found
*/
void findMinMax (int channel,
int startSample,
int numSamples,
float& minVal,
float& maxVal) const noexcept;
Range<float> findMinMax (int channel,
int startSample,
int numSamples) const noexcept;
/** Finds the highest absolute sample value within a region of a channel. */
float getMagnitude (int channel,


+ 497
- 350
modules/juce_audio_basics/buffers/juce_FloatVectorOperations.cpp
File diff suppressed because it is too large
View File


+ 44
- 2
modules/juce_audio_basics/buffers/juce_FloatVectorOperations.h View File

@@ -38,48 +38,90 @@ public:
/** Clears a vector of floats. */
static void JUCE_CALLTYPE clear (float* dest, int numValues) noexcept;
/** Clears a vector of doubles. */
static void JUCE_CALLTYPE clear (double* dest, int numValues) noexcept;
/** Copies a repeated value into a vector of floats. */
static void JUCE_CALLTYPE fill (float* dest, float valueToFill, int numValues) noexcept;
/** Copies a repeated value into a vector of doubles. */
static void JUCE_CALLTYPE fill (double* dest, double valueToFill, int numValues) noexcept;
/** Copies a vector of floats. */
static void JUCE_CALLTYPE copy (float* dest, const float* src, int numValues) noexcept;
/** Copies a vector of doubles. */
static void JUCE_CALLTYPE copy (double* dest, const double* src, int numValues) noexcept;
/** Copies a vector of floats, multiplying each value by a given multiplier */
static void JUCE_CALLTYPE copyWithMultiply (float* dest, const float* src, float multiplier, int numValues) noexcept;
/** Copies a vector of doubles, multiplying each value by a given multiplier */
static void JUCE_CALLTYPE copyWithMultiply (double* dest, const double* src, double multiplier, int numValues) noexcept;
/** Adds a fixed value to the destination values. */
static void JUCE_CALLTYPE add (float* dest, float amountToAdd, int numValues) noexcept;
/** Adds a fixed value to the destination values. */
static void JUCE_CALLTYPE add (float* dest, float amount, int numValues) noexcept;
static void JUCE_CALLTYPE add (double* dest, double amountToAdd, int numValues) noexcept;
/** Adds the source values to the destination values. */
static void JUCE_CALLTYPE add (float* dest, const float* src, int numValues) noexcept;
/** Adds the source values to the destination values. */
static void JUCE_CALLTYPE add (double* dest, const double* src, int numValues) noexcept;
/** Subtracts the source values from the destination values. */
static void JUCE_CALLTYPE subtract (float* dest, const float* src, int numValues) noexcept;
/** Subtracts the source values from the destination values. */
static void JUCE_CALLTYPE subtract (double* dest, const double* src, int numValues) noexcept;
/** Multiplies each source value by the given multiplier, then adds it to the destination value. */
static void JUCE_CALLTYPE addWithMultiply (float* dest, const float* src, float multiplier, int numValues) noexcept;
/** Multiplies each source value by the given multiplier, then adds it to the destination value. */
static void JUCE_CALLTYPE addWithMultiply (double* dest, const double* src, double multiplier, int numValues) noexcept;
/** Multiplies the destination values by the source values. */
static void JUCE_CALLTYPE multiply (float* dest, const float* src, int numValues) noexcept;
/** Multiplies the destination values by the source values. */
static void JUCE_CALLTYPE multiply (double* dest, const double* src, int numValues) noexcept;
/** Multiplies each of the destination values by a fixed multiplier. */
static void JUCE_CALLTYPE multiply (float* dest, float multiplier, int numValues) noexcept;
/** Multiplies each of the destination values by a fixed multiplier. */
static void JUCE_CALLTYPE multiply (double* dest, double multiplier, int numValues) noexcept;
/** Copies a source vector to a destination, negating each value. */
static void JUCE_CALLTYPE negate (float* dest, const float* src, int numValues) noexcept;
/** Copies a source vector to a destination, negating each value. */
static void JUCE_CALLTYPE negate (double* dest, const double* src, int numValues) noexcept;
/** Converts a stream of integers to floats, multiplying each one by the given multiplier. */
static void JUCE_CALLTYPE convertFixedToFloat (float* dest, const int* src, float multiplier, int numValues) noexcept;
/** Finds the miniumum and maximum values in the given array. */
static void JUCE_CALLTYPE findMinAndMax (const float* src, int numValues, float& minResult, float& maxResult) noexcept;
static Range<float> JUCE_CALLTYPE findMinAndMax (const float* src, int numValues) noexcept;
/** Finds the miniumum and maximum values in the given array. */
static Range<double> JUCE_CALLTYPE findMinAndMax (const double* src, int numValues) noexcept;
/** Finds the miniumum value in the given array. */
static float JUCE_CALLTYPE findMinimum (const float* src, int numValues) noexcept;
/** Finds the miniumum value in the given array. */
static double JUCE_CALLTYPE findMinimum (const double* src, int numValues) noexcept;
/** Finds the maximum value in the given array. */
static float JUCE_CALLTYPE findMaximum (const float* src, int numValues) noexcept;
/** Finds the maximum value in the given array. */
static double JUCE_CALLTYPE findMaximum (const double* src, int numValues) noexcept;
/** On Intel CPUs, this method enables or disables the SSE flush-to-zero mode.
Effectively, this is a wrapper around a call to _MM_SET_FLUSH_ZERO_MODE
*/


+ 10
- 11
modules/juce_audio_formats/format/juce_AudioFormatReader.cpp View File

@@ -174,30 +174,29 @@ void AudioFormatReader::read (AudioSampleBuffer* buffer,
}
template <typename SampleType>
static inline void getChannelMinAndMax (SampleType* channel, const int numSamples, SampleType& mn, SampleType& mx)
static Range<SampleType> getChannelMinAndMax (SampleType* channel, int numSamples) noexcept
{
findMinAndMax (channel, numSamples, mn, mx);
return Range<SampleType>::findMinAndMax (channel, numSamples);
}
static inline void getChannelMinAndMax (float* channel, const int numSamples, float& mn, float& mx)
static Range<float> getChannelMinAndMax (float* channel, int numSamples) noexcept
{
FloatVectorOperations::findMinAndMax (channel, numSamples, mn, mx);
return FloatVectorOperations::findMinAndMax (channel, numSamples);
}
template <typename SampleType>
static void getStereoMinAndMax (SampleType* const* channels, const int numChannels, const int numSamples,
SampleType& lmin, SampleType& lmax, SampleType& rmin, SampleType& rmax)
{
SampleType bufMin, bufMax;
getChannelMinAndMax (channels[0], numSamples, bufMin, bufMax);
lmax = jmax (lmax, bufMax);
lmin = jmin (lmin, bufMin);
Range<SampleType> range (getChannelMinAndMax (channels[0], numSamples));
lmax = jmax (lmax, range.getEnd());
lmin = jmin (lmin, range.getStart());
if (numChannels > 1)
{
getChannelMinAndMax (channels[1], numSamples, bufMin, bufMax);
rmax = jmax (rmax, bufMax);
rmin = jmin (rmin, bufMin);
range = getChannelMinAndMax (channels[1], numSamples);
rmax = jmax (rmax, range.getEnd());
rmin = jmin (rmin, range.getStart());
}
else
{


+ 2
- 3
modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp View File

@@ -712,10 +712,9 @@ void AudioThumbnail::addBlock (const int64 startSample, const AudioSampleBuffer&
for (int i = 0; i < numToDo; ++i)
{
float low, high;
const int start = i * samplesPerThumbSample;
FloatVectorOperations::findMinAndMax (sourceData + start, jmin (samplesPerThumbSample, numSamples - start), low, high);
dest[i].setFloat (low, high);
Range<float> range (FloatVectorOperations::findMinAndMax (sourceData + start, jmin (samplesPerThumbSample, numSamples - start)));
dest[i].setFloat (range.getStart(), range.getEnd());
}
}


Loading…
Cancel
Save