From f9313c8338715cc1e578a406cd86a69a920b96ac Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 9 Jan 2018 16:05:00 +0000 Subject: [PATCH] Deprecated some old functions roundDoubleToInt and roundFloatToInt - these can both be trivially replaced by roundToInt, and should have been deprecated long ago! --- .../Source/PluginProcessor.cpp | 8 +-- .../DSPDemo/Source/Demos/ConvolutionDemo.cpp | 2 +- .../PaintElements/jucer_PaintElementPath.cpp | 2 +- .../ComponentEditor/jucer_ComponentLayout.cpp | 8 +-- .../format/juce_AudioFormatReader.cpp | 2 +- .../gui/juce_AudioDeviceSelectorComponent.cpp | 2 +- .../gui/juce_AudioThumbnail.cpp | 9 ++-- modules/juce_core/maths/juce_MathsFunctions.h | 49 +++++-------------- modules/juce_core/system/juce_PlatformDefs.h | 10 ++-- .../filter_design/juce_FilterDesign.cpp | 14 +++--- .../juce_dsp/frequency/juce_Convolution.cpp | 19 +++---- 11 files changed, 48 insertions(+), 77 deletions(-) diff --git a/examples/DSP module plugin demo/Source/PluginProcessor.cpp b/examples/DSP module plugin demo/Source/PluginProcessor.cpp index 34dee8ad87..3a8d6f3eb9 100644 --- a/examples/DSP module plugin demo/Source/PluginProcessor.cpp +++ b/examples/DSP module plugin demo/Source/PluginProcessor.cpp @@ -109,7 +109,6 @@ void DspModulePluginDemoAudioProcessor::reset() void DspModulePluginDemoAudioProcessor::releaseResources() { - } void DspModulePluginDemoAudioProcessor::process (dsp::ProcessContextReplacing context) noexcept @@ -126,12 +125,13 @@ void DspModulePluginDemoAudioProcessor::process (dsp::ProcessContextReplacing oversampledBlock; - setLatencySamples (audioCurrentlyOversampled ? roundFloatToInt (oversampling->getLatencyInSamples()) : 0); + setLatencySamples (audioCurrentlyOversampled ? roundToInt (oversampling->getLatencyInSamples()) : 0); if (audioCurrentlyOversampled) oversampledBlock = oversampling->processSamplesUp (context.getInputBlock()); - dsp::ProcessContextReplacing waveshaperContext = audioCurrentlyOversampled ? dsp::ProcessContextReplacing (oversampledBlock) : context; + auto waveshaperContext = audioCurrentlyOversampled ? dsp::ProcessContextReplacing (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 (roundDoubleToInt (8192 * getSampleRate() / 44100)); + auto maxSize = static_cast (roundToInt (getSampleRate() * (8192.0 / 44100.0))); if (type == 0) convolution.loadImpulseResponse (BinaryData::Impulse1_wav, BinaryData::Impulse1_wavSize, false, true, maxSize); diff --git a/examples/DSPDemo/Source/Demos/ConvolutionDemo.cpp b/examples/DSPDemo/Source/Demos/ConvolutionDemo.cpp index 36aa11b4ad..0b28560212 100644 --- a/examples/DSPDemo/Source/Demos/ConvolutionDemo.cpp +++ b/examples/DSPDemo/Source/Demos/ConvolutionDemo.cpp @@ -60,7 +60,7 @@ struct ConvolutionDemo { bypass = false; - auto maxSize = static_cast (roundDoubleToInt (8192.0 * sampleRate / 44100.0)); + auto maxSize = static_cast (roundToInt (sampleRate * (8192.0 / 44100.0))); if (cabinetTypeParameter->getCurrentSelectedID() == 2) convolution.loadImpulseResponse (BinaryData::guitar_amp_wav, diff --git a/extras/Projucer/Source/ComponentEditor/PaintElements/jucer_PaintElementPath.cpp b/extras/Projucer/Source/ComponentEditor/PaintElements/jucer_PaintElementPath.cpp index f6adf7fcd9..6df7cae2b8 100644 --- a/extras/Projucer/Source/ComponentEditor/PaintElements/jucer_PaintElementPath.cpp +++ b/extras/Projucer/Source/ComponentEditor/PaintElements/jucer_PaintElementPath.cpp @@ -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; } diff --git a/extras/Projucer/Source/ComponentEditor/jucer_ComponentLayout.cpp b/extras/Projucer/Source/ComponentEditor/jucer_ComponentLayout.cpp index de312f564b..136599af3b 100644 --- a/extras/Projucer/Source/ComponentEditor/jucer_ComponentLayout.cpp +++ b/extras/Projucer/Source/ComponentEditor/jucer_ComponentLayout.cpp @@ -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) << ")"; } diff --git a/modules/juce_audio_formats/format/juce_AudioFormatReader.cpp b/modules/juce_audio_formats/format/juce_AudioFormatReader.cpp index af46b3c36e..f40f46571f 100644 --- a/modules/juce_audio_formats/format/juce_AudioFormatReader.cpp +++ b/modules/juce_audio_formats/format/juce_AudioFormatReader.cpp @@ -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) diff --git a/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp b/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp index e12d9bf9b3..300d45d40f 100644 --- a/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp +++ b/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp @@ -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; diff --git a/modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp b/modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp index 89bcfc7091..fe495c670e 100644 --- a/modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp +++ b/modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp @@ -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 data; - int peakLevel; + int peakLevel = -1; void ensureSize (int thumbSamples) { diff --git a/modules/juce_core/maths/juce_MathsFunctions.h b/modules/juce_core/maths/juce_MathsFunctions.h index bd8f324b99..c107d6fafa 100644 --- a/modules/juce_core/maths/juce_MathsFunctions.h +++ b/modules/juce_core/maths/juce_MathsFunctions.h @@ -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 Type asinh (Type x) { return std::log (x + std::sqrt (x * x + (Type) 1)); } template 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 diff --git a/modules/juce_core/system/juce_PlatformDefs.h b/modules/juce_core/system/juce_PlatformDefs.h index 8531f1652f..56cb7d625e 100644 --- a/modules/juce_core/system/juce_PlatformDefs.h +++ b/modules/juce_core/system/juce_PlatformDefs.h @@ -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 diff --git a/modules/juce_dsp/filter_design/juce_FilterDesign.cpp b/modules/juce_dsp/filter_design/juce_FilterDesign.cpp index d72f7dbf8d..19d5fcbf5b 100644 --- a/modules/juce_dsp/filter_design/juce_FilterDesign.cpp +++ b/modules/juce_dsp/filter_design/juce_FilterDesign.cpp @@ -81,8 +81,8 @@ typename FIR::Coefficients::Ptr else if (attenuationdB <= 21) beta = static_cast (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::twoPi))) - : roundDoubleToInt (ceil (5.79 / (normalizedTransitionWidth * MathConstants::twoPi))); + int order = attenuationdB < -21 ? roundToInt (std::ceil ((-attenuationdB - 7.95) / (2.285 * normalizedTransitionWidth * MathConstants::twoPi))) + : roundToInt (std::ceil (5.79 / (normalizedTransitionWidth * MathConstants::twoPi))); jassert (order >= 0); @@ -244,7 +244,7 @@ typename FIR::Coefficients::Ptr auto wpT = (0.5 - normalizedTransitionWidth) * MathConstants::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> 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> 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::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; diff --git a/modules/juce_dsp/frequency/juce_Convolution.cpp b/modules/juce_dsp/frequency/juce_Convolution.cpp index 3854f6d47d..c9de260b96 100644 --- a/modules/juce_dsp/frequency/juce_Convolution.cpp +++ b/modules/juce_dsp/frequency/juce_Convolution.cpp @@ -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 (FFTSize)); bufferOutput.setSize (1, static_cast (FFTSize * 2)); @@ -114,7 +114,7 @@ struct ConvolutionEngine buffersImpulseSegments.add (newImpulseSegment); } - ScopedPointer FFTTempObject = new FFT (roundDoubleToInt (log2 (FFTSize))); + ScopedPointer 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 formatReader = manager.createReaderFor (stream)) { auto maximumTimeInSeconds = 10.0; - int64 maximumLength = static_cast (roundDoubleToInt (maximumTimeInSeconds * formatReader->sampleRate)); + auto maximumLength = static_cast (roundToInt (maximumTimeInSeconds * formatReader->sampleRate)); auto numChannels = formatReader->numChannels > 1 ? 2 : 1; impulseResponseOriginal.setSize (2, static_cast (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 (currentInfo.impulseResponseSize), roundDoubleToInt ((indexEnd - indexStart + 1) / factorReading)); + auto impulseSize = jmin (static_cast (currentInfo.impulseResponseSize), roundToInt ((indexEnd - indexStart + 1) / factorReading)); impulseResponse.setSize (2, impulseSize); impulseResponse.clear();