Browse Source

Deprecated some old functions roundDoubleToInt and roundFloatToInt - these can both be trivially replaced by roundToInt, and should have been deprecated long ago!

tags/2021-05-28
jules 7 years ago
parent
commit
f9313c8338
11 changed files with 48 additions and 77 deletions
  1. +4
    -4
      examples/DSP module plugin demo/Source/PluginProcessor.cpp
  2. +1
    -1
      examples/DSPDemo/Source/Demos/ConvolutionDemo.cpp
  3. +1
    -1
      extras/Projucer/Source/ComponentEditor/PaintElements/jucer_PaintElementPath.cpp
  4. +4
    -4
      extras/Projucer/Source/ComponentEditor/jucer_ComponentLayout.cpp
  5. +1
    -1
      modules/juce_audio_formats/format/juce_AudioFormatReader.cpp
  6. +1
    -1
      modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp
  7. +4
    -5
      modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp
  8. +11
    -38
      modules/juce_core/maths/juce_MathsFunctions.h
  9. +6
    -4
      modules/juce_core/system/juce_PlatformDefs.h
  10. +7
    -7
      modules/juce_dsp/filter_design/juce_FilterDesign.cpp
  11. +8
    -11
      modules/juce_dsp/frequency/juce_Convolution.cpp

+ 4
- 4
examples/DSP module plugin demo/Source/PluginProcessor.cpp View File

@@ -109,7 +109,6 @@ void DspModulePluginDemoAudioProcessor::reset()
void DspModulePluginDemoAudioProcessor::releaseResources()
{
}
void DspModulePluginDemoAudioProcessor::process (dsp::ProcessContextReplacing<float> context) noexcept
@@ -126,12 +125,13 @@ void DspModulePluginDemoAudioProcessor::process (dsp::ProcessContextReplacing<fl
// Upsampling
dsp::AudioBlock<float> oversampledBlock;
setLatencySamples (audioCurrentlyOversampled ? roundFloatToInt (oversampling->getLatencyInSamples()) : 0);
setLatencySamples (audioCurrentlyOversampled ? roundToInt (oversampling->getLatencyInSamples()) : 0);
if (audioCurrentlyOversampled)
oversampledBlock = oversampling->processSamplesUp (context.getInputBlock());
dsp::ProcessContextReplacing<float> waveshaperContext = audioCurrentlyOversampled ? dsp::ProcessContextReplacing<float> (oversampledBlock) : context;
auto waveshaperContext = audioCurrentlyOversampled ? dsp::ProcessContextReplacing<float> (oversampledBlock)
: context;
// Waveshaper processing, for distortion generation, thanks to the input gain
// The fast tanh can be used instead of std::tanh to reduce the CPU load
@@ -266,7 +266,7 @@ void DspModulePluginDemoAudioProcessor::updateParameters()
{
cabinetType.set(type);
auto maxSize = static_cast<size_t> (roundDoubleToInt (8192 * getSampleRate() / 44100));
auto maxSize = static_cast<size_t> (roundToInt (getSampleRate() * (8192.0 / 44100.0)));
if (type == 0)
convolution.loadImpulseResponse (BinaryData::Impulse1_wav, BinaryData::Impulse1_wavSize, false, true, maxSize);


+ 1
- 1
examples/DSPDemo/Source/Demos/ConvolutionDemo.cpp View File

@@ -60,7 +60,7 @@ struct ConvolutionDemo
{
bypass = false;
auto maxSize = static_cast<size_t> (roundDoubleToInt (8192.0 * sampleRate / 44100.0));
auto maxSize = static_cast<size_t> (roundToInt (sampleRate * (8192.0 / 44100.0)));
if (cabinetTypeParameter->getCurrentSelectedID() == 2)
convolution.loadImpulseResponse (BinaryData::guitar_amp_wav,


+ 1
- 1
extras/Projucer/Source/ComponentEditor/PaintElements/jucer_PaintElementPath.cpp View File

@@ -161,7 +161,7 @@ void PaintElementPath::setInitialBounds (int w, int h)
//==============================================================================
int PaintElementPath::getBorderSize() const
{
return isStrokePresent ? 1 + roundFloatToInt (strokeType.stroke.getStrokeThickness())
return isStrokePresent ? 1 + roundToInt (strokeType.stroke.getStrokeThickness())
: 0;
}


+ 4
- 4
extras/Projucer/Source/ComponentEditor/jucer_ComponentLayout.cpp View File

@@ -971,7 +971,7 @@ void positionToCode (const RelativePositionedRectangle& position,
if (position.rect.getWidthMode() == PositionedRectangle::proportionalSize)
{
if (wrw.isNotEmpty())
w << "roundFloatToInt (" << bracketIfNeeded (wrw) << " * " << CodeHelpers::floatLiteral (position.rect.getWidth(), 4) << ")";
w << "roundToInt (" << bracketIfNeeded (wrw) << " * " << CodeHelpers::floatLiteral (position.rect.getWidth(), 4) << ")";
else
w << "proportionOfWidth (" << CodeHelpers::floatLiteral (position.rect.getWidth(), 4) << ")";
}
@@ -994,7 +994,7 @@ void positionToCode (const RelativePositionedRectangle& position,
if (position.rect.getHeightMode() == PositionedRectangle::proportionalSize)
{
if (hrh.isNotEmpty())
h << "roundFloatToInt (" << bracketIfNeeded (hrh) << " * " << CodeHelpers::floatLiteral (position.rect.getHeight(), 4) << ")";
h << "roundToInt (" << bracketIfNeeded (hrh) << " * " << CodeHelpers::floatLiteral (position.rect.getHeight(), 4) << ")";
else
h << "proportionOfHeight (" << CodeHelpers::floatLiteral (position.rect.getHeight(), 4) << ")";
}
@@ -1017,7 +1017,7 @@ void positionToCode (const RelativePositionedRectangle& position,
if (position.rect.getPositionModeX() == PositionedRectangle::proportionOfParentSize)
{
if (xrx.isNotEmpty() && xrw.isNotEmpty())
x << bracketIfNeeded (xrx) << " + roundFloatToInt (" << bracketIfNeeded (xrw) << " * " << CodeHelpers::floatLiteral (position.rect.getX(), 4) << ")";
x << bracketIfNeeded (xrx) << " + roundToInt (" << bracketIfNeeded (xrw) << " * " << CodeHelpers::floatLiteral (position.rect.getX(), 4) << ")";
else
x << "proportionOfWidth (" << CodeHelpers::floatLiteral (position.rect.getX(), 4) << ")";
}
@@ -1063,7 +1063,7 @@ void positionToCode (const RelativePositionedRectangle& position,
if (position.rect.getPositionModeY() == PositionedRectangle::proportionOfParentSize)
{
if (yry.isNotEmpty() && yrh.isNotEmpty())
y << bracketIfNeeded (yry) << " + roundFloatToInt (" << bracketIfNeeded (yrh) << " * " << CodeHelpers::floatLiteral (position.rect.getY(), 4) << ")";
y << bracketIfNeeded (yry) << " + roundToInt (" << bracketIfNeeded (yrh) << " * " << CodeHelpers::floatLiteral (position.rect.getY(), 4) << ")";
else
y << "proportionOfHeight (" << CodeHelpers::floatLiteral (position.rect.getY(), 4) << ")";
}


+ 1
- 1
modules/juce_audio_formats/format/juce_AudioFormatReader.cpp View File

@@ -274,7 +274,7 @@ int64 AudioFormatReader::searchForLevel (int64 startSample,
while (numSamplesToSearch != 0)
{
auto numThisTime = (int) jmin (abs64 (numSamplesToSearch), (int64) bufferSize);
auto numThisTime = (int) jmin (std::abs (numSamplesToSearch), (int64) bufferSize);
int64 bufferStart = startSample;
if (numSamplesToSearch < 0)


+ 1
- 1
modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp View File

@@ -62,7 +62,7 @@ struct SimpleDeviceManagerInputLevelMeter : public Component,
void paint (Graphics& g) override
{
getLookAndFeel().drawLevelMeter (g, getWidth(), getHeight(),
(float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
(float) std::exp (std::log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
}
AudioDeviceManager& manager;


+ 4
- 5
modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp View File

@@ -53,8 +53,8 @@ struct AudioThumbnail::MinMaxValue
values[0] = (int8) (limitedRange.getStart() * 127.0f);
values[1] = (int8) (limitedRange.getEnd() * 127.0f);
#else
values[0] = (int8) jlimit (-128, 127, roundFloatToInt (newRange.getStart() * 127.0f));
values[1] = (int8) jlimit (-128, 127, roundFloatToInt (newRange.getEnd() * 127.0f));
values[0] = (int8) jlimit (-128, 127, roundToInt (newRange.getStart() * 127.0f));
values[1] = (int8) jlimit (-128, 127, roundToInt (newRange.getEnd() * 127.0f));
#endif
if (values[0] == values[1])
@@ -274,8 +274,7 @@ private:
class AudioThumbnail::ThumbData
{
public:
ThumbData (const int numThumbSamples)
: peakLevel (-1)
ThumbData (int numThumbSamples)
{
ensureSize (numThumbSamples);
}
@@ -356,7 +355,7 @@ public:
private:
Array<MinMaxValue> data;
int peakLevel;
int peakLevel = -1;
void ensureSize (int thumbSamples)
{


+ 11
- 38
modules/juce_core/maths/juce_MathsFunctions.h View File

@@ -313,12 +313,6 @@ inline float juce_hypot (float a, float b) noexcept
}
#endif
/** 64-bit abs function. */
inline int64 abs64 (const int64 n) noexcept
{
return (n >= 0) ? n : -n;
}
#if JUCE_MSVC && ! defined (DOXYGEN) // The MSVC libraries omit these functions for some reason...
template<typename Type> Type asinh (Type x) { return std::log (x + std::sqrt (x * x + (Type) 1)); }
template<typename Type> Type acosh (Type x) { return std::log (x + std::sqrt (x * x - (Type) 1)); }
@@ -491,7 +485,7 @@ inline int roundToInt (int value) noexcept
/** Fast floating-point-to-integer conversion.
This is a slightly slower and slightly more accurate version of roundDoubleToInt(). It works
This is a slightly slower and slightly more accurate version of roundToInt(). It works
fine for values above zero, but negative numbers are rounded the wrong way.
*/
inline int roundToIntAccurate (double value) noexcept
@@ -503,37 +497,6 @@ inline int roundToIntAccurate (double value) noexcept
return roundToInt (value + 1.5e-8);
}
/** Fast floating-point-to-integer conversion.
This is faster than using the normal c++ cast to convert a double to an int, and
it will round the value to the nearest integer, rather than rounding it down
like the normal cast does.
Note that this routine gets its speed at the expense of some accuracy, and when
rounding values whose floating point component is exactly 0.5, odd numbers and
even numbers will be rounded up or down differently. For a more accurate conversion,
see roundDoubleToIntAccurate().
*/
inline int roundDoubleToInt (double value) noexcept
{
return roundToInt (value);
}
/** Fast floating-point-to-integer conversion.
This is faster than using the normal c++ cast to convert a float to an int, and
it will round the value to the nearest integer, rather than rounding it down
like the normal cast does.
Note that this routine gets its speed at the expense of some accuracy, and when
rounding values whose floating point component is exactly 0.5, odd numbers and
even numbers will be rounded up or down differently.
*/
inline int roundFloatToInt (float value) noexcept
{
return roundToInt (value);
}
//==============================================================================
/** Truncates a positive floating-point number to an unsigned int.
@@ -693,4 +656,14 @@ namespace TypeHelpers
template <> struct UnsignedTypeWithSize<8> { typedef uint64 type; };
}
//==============================================================================
#if ! DOXYGEN
// These old functions are deprecated: Just use roundToInt instead.
JUCE_DEPRECATED_ATTRIBUTE inline int roundDoubleToInt (double value) noexcept { return roundToInt (value); }
JUCE_DEPRECATED_ATTRIBUTE inline int roundFloatToInt (float value) noexcept { return roundToInt (value); }
// This old function isn't needed - just use std::abs() instead
JUCE_DEPRECATED_ATTRIBUTE inline int64 abs64 (int64 n) noexcept { return std::abs (n); }
#endif
} // namespace juce

+ 6
- 4
modules/juce_core/system/juce_PlatformDefs.h View File

@@ -260,11 +260,13 @@ namespace juce
#define JUCE_DEPRECATED(functionDef)
#define JUCE_DEPRECATED_WITH_BODY(functionDef, body)
#elif JUCE_MSVC && ! JUCE_NO_DEPRECATION_WARNINGS
#define JUCE_DEPRECATED(functionDef) __declspec(deprecated) functionDef
#define JUCE_DEPRECATED_WITH_BODY(functionDef, body) __declspec(deprecated) functionDef body
#define JUCE_DEPRECATED_ATTRIBUTE __declspec(deprecated)
#define JUCE_DEPRECATED(functionDef) JUCE_DEPRECATED_ATTRIBUTE functionDef
#define JUCE_DEPRECATED_WITH_BODY(functionDef, body) JUCE_DEPRECATED_ATTRIBUTE functionDef body
#elif (JUCE_GCC || JUCE_CLANG) && ! JUCE_NO_DEPRECATION_WARNINGS
#define JUCE_DEPRECATED(functionDef) functionDef __attribute__ ((deprecated))
#define JUCE_DEPRECATED_WITH_BODY(functionDef, body) functionDef __attribute__ ((deprecated)) body
#define JUCE_DEPRECATED_ATTRIBUTE __attribute__ ((deprecated))
#define JUCE_DEPRECATED(functionDef) functionDef JUCE_DEPRECATED_ATTRIBUTE
#define JUCE_DEPRECATED_WITH_BODY(functionDef, body) functionDef JUCE_DEPRECATED_ATTRIBUTE body
#else
#define JUCE_DEPRECATED(functionDef) functionDef
#define JUCE_DEPRECATED_WITH_BODY(functionDef, body) functionDef body


+ 7
- 7
modules/juce_dsp/filter_design/juce_FilterDesign.cpp View File

@@ -81,8 +81,8 @@ typename FIR::Coefficients<FloatType>::Ptr
else if (attenuationdB <= 21)
beta = static_cast<FloatType> (0.5842 * std::pow (-attenuationdB - 21, 0.4) + 0.07886 * (-attenuationdB - 21));
int order = attenuationdB < -21 ? roundDoubleToInt (ceil ((-attenuationdB - 7.95) / (2.285 * normalizedTransitionWidth * MathConstants<double>::twoPi)))
: roundDoubleToInt (ceil (5.79 / (normalizedTransitionWidth * MathConstants<double>::twoPi)));
int order = attenuationdB < -21 ? roundToInt (std::ceil ((-attenuationdB - 7.95) / (2.285 * normalizedTransitionWidth * MathConstants<double>::twoPi)))
: roundToInt (std::ceil (5.79 / (normalizedTransitionWidth * MathConstants<double>::twoPi)));
jassert (order >= 0);
@@ -244,7 +244,7 @@ typename FIR::Coefficients<FloatType>::Ptr
auto wpT = (0.5 - normalizedTransitionWidth) * MathConstants<double>::pi;
auto n = roundDoubleToInt (ceil ((attenuationdB - 18.18840664 * wpT + 33.64775300) / (18.54155181 * wpT - 29.13196871)));
auto n = roundToInt (std::ceil ((attenuationdB - 18.18840664 * wpT + 33.64775300) / (18.54155181 * wpT - 29.13196871)));
auto kp = (n * wpT - 1.57111377 * n + 0.00665857) / (-1.01927560 * n + 0.37221484);
auto A = (0.01525753 * n + 0.03682344 + 9.24760314 / (double) n) * kp + 1.01701407 + 0.73512298 / (double) n;
auto B = (0.00233667 * n - 1.35418408 + 5.75145813 / (double) n) * kp + 1.02999650 - 0.72759508 / (double) n;
@@ -416,11 +416,11 @@ Array<IIR::Coefficients<FloatType>>
if (type == 0)
{
N = roundDoubleToInt (ceil (log (1.0 / k1) / log (1.0 / k)));
N = roundToInt (std::ceil (std::log (1.0 / k1) / std::log (1.0 / k)));
}
else if (type == 1 || type == 2)
{
N = roundDoubleToInt (ceil (std::acosh (1.0 / k1) / std::acosh (1.0 / k)));
N = roundToInt (std::ceil (std::acosh (1.0 / k1) / std::acosh (1.0 / k)));
}
else
{
@@ -429,7 +429,7 @@ Array<IIR::Coefficients<FloatType>>
SpecialFunctions::ellipticIntegralK (k, K, Kp);
SpecialFunctions::ellipticIntegralK (k1, K1, K1p);
N = roundDoubleToInt (ceil ((K1p * K) / (K1 * Kp)));
N = roundToInt (std::ceil ((K1p * K) / (K1 * Kp)));
}
const int r = N % 2;
@@ -625,7 +625,7 @@ typename FilterDesign<FloatType>::IIRPolyphaseAllpassStructure
auto q = e + 2 * std::pow (e, 5.0) + 15 * std::pow (e, 9.0) + 150 * std::pow (e, 13.0);
auto k1 = ds * ds / (1 - ds * ds);
int n = roundDoubleToInt (ceil (log (k1 * k1 / 16) / log (q)));
int n = roundToInt (std::ceil (std::log (k1 * k1 / 16) / std::log (q)));
if (n % 2 == 0)
++n;


+ 8
- 11
modules/juce_dsp/frequency/juce_Convolution.cpp View File

@@ -90,7 +90,7 @@ struct ConvolutionEngine
numInputSegments = (blockSize > 128 ? numSegments : 3 * numSegments);
FFTobject = new FFT (roundDoubleToInt (log2 (FFTSize)));
FFTobject = new FFT (roundToInt (std::log2 (FFTSize)));
bufferInput.setSize (1, static_cast<int> (FFTSize));
bufferOutput.setSize (1, static_cast<int> (FFTSize * 2));
@@ -114,7 +114,7 @@ struct ConvolutionEngine
buffersImpulseSegments.add (newImpulseSegment);
}
ScopedPointer<FFT> FFTTempObject = new FFT (roundDoubleToInt (log2 (FFTSize)));
ScopedPointer<FFT> FFTTempObject = new FFT (roundToInt (std::log2 (FFTSize)));
auto numChannels = (info.wantsStereo && info.buffer->getNumChannels() >= 2 ? 2 : 1);
if (channel < numChannels)
@@ -149,7 +149,7 @@ struct ConvolutionEngine
{
if (FFTSize != other.FFTSize)
{
FFTobject = new FFT (roundDoubleToInt (log2 (other.FFTSize)));
FFTobject = new FFT (roundToInt (std::log2 (other.FFTSize)));
FFTSize = other.FFTSize;
}
@@ -334,7 +334,6 @@ struct ConvolutionEngine
*/
struct Convolution::Pimpl : private Thread
{
public:
enum class ChangeRequest
{
changeEngine = 0,
@@ -357,7 +356,7 @@ public:
requestsType.resize (fifoSize);
requestsParameter.resize (fifoSize);
for (auto i = 0u; i < 4; ++i)
for (int i = 0; i < 4; ++i)
engines.add (new ConvolutionEngine());
currentInfo.maximumBufferSize = 0;
@@ -764,7 +763,6 @@ private:
void processImpulseResponse()
{
if (currentInfo.sourceType == SourceType::sourceBinaryData)
{
copyAudioStreamInAudioBuffer (new MemoryInputStream (currentInfo.sourceData, currentInfo.sourceDataSize, false));
@@ -794,7 +792,6 @@ private:
normalizeImpulseResponse (currentInfo.buffer->getWritePointer (0), currentInfo.buffer->getNumSamples(), 1.0);
}
}
}
/** Converts the data from an audio file into a stereo audio buffer of floats, and
@@ -808,7 +805,7 @@ private:
if (ScopedPointer<AudioFormatReader> formatReader = manager.createReaderFor (stream))
{
auto maximumTimeInSeconds = 10.0;
int64 maximumLength = static_cast<int64> (roundDoubleToInt (maximumTimeInSeconds * formatReader->sampleRate));
auto maximumLength = static_cast<int64> (roundToInt (maximumTimeInSeconds * formatReader->sampleRate));
auto numChannels = formatReader->numChannels > 1 ? 2 : 1;
impulseResponseOriginal.setSize (2, static_cast<int> (jmin (maximumLength, formatReader->lengthInSamples)), false, false, true);
@@ -817,8 +814,8 @@ private:
return trimAndResampleImpulseResponse (numChannels, formatReader->sampleRate, currentInfo.wantsTrimming);
}
else
return 0.0;
return 0.0;
}
double trimAndResampleImpulseResponse (int numChannels, double bufferSampleRate, bool mustTrim)
@@ -886,7 +883,7 @@ private:
{
// Resampling
factorReading = bufferSampleRate / currentInfo.sampleRate;
auto impulseSize = jmin (static_cast<int> (currentInfo.impulseResponseSize), roundDoubleToInt ((indexEnd - indexStart + 1) / factorReading));
auto impulseSize = jmin (static_cast<int> (currentInfo.impulseResponseSize), roundToInt ((indexEnd - indexStart + 1) / factorReading));
impulseResponse.setSize (2, impulseSize);
impulseResponse.clear();


Loading…
Cancel
Save