| @@ -78,7 +78,7 @@ public: | |||
| channelData[i] = amplitude * std::sin (phase); | |||
| // increment the phase step for the next sample | |||
| phase = std::fmod (phase + phaseDelta, float_Pi * 2.0f); | |||
| phase = std::fmod (phase + phaseDelta, MathConstants<float>::twoPi); | |||
| } | |||
| } | |||
| } | |||
| @@ -130,7 +130,7 @@ public: | |||
| frequency = (getHeight() - e.y) * 10.0f; | |||
| amplitude = jmin (0.9f, 0.2f * e.position.x / getWidth()); | |||
| phaseDelta = (float) (2.0 * double_Pi * frequency / sampleRate); | |||
| phaseDelta = (float) (MathConstants<double>::twoPi * frequency / sampleRate); | |||
| repaint(); | |||
| } | |||
| @@ -166,7 +166,7 @@ public: | |||
| blockComponent->block->getHeight() * blockUnitInPixels); | |||
| if (blockComponent->rotation != 0) | |||
| blockComponent->setTransform (AffineTransform::rotation (blockComponent->rotation * (static_cast<float> (double_Pi) / 180.0f), | |||
| blockComponent->setTransform (AffineTransform::rotation (degreesToRadians (blockComponent->rotation), | |||
| static_cast<float> (blockComponent->getX()), | |||
| static_cast<float> (blockComponent->getY()))); | |||
| } | |||
| @@ -43,7 +43,7 @@ public: | |||
| void startNote (int midiNoteNumber, float velocity, SynthesiserSound*, int) override | |||
| { | |||
| frequency = MidiMessage::getMidiNoteInHertz (midiNoteNumber); | |||
| phaseIncrement.setValue (((2.0 * double_Pi) * frequency) / sampleRate); | |||
| phaseIncrement.setValue (((MathConstants<double>::twoPi) * frequency) / sampleRate); | |||
| amplitude.setValue (velocity); | |||
| // Store the initial note and work out the maximum frequency deviations for pitch bend | |||
| @@ -62,7 +62,7 @@ public: | |||
| { | |||
| // Change the phase increment based on pitch bend amount | |||
| auto frequencyOffset = ((newValue > 0 ? maxFreq : minFreq) * (newValue / 127.0)); | |||
| phaseIncrement.setValue (((2.0 * double_Pi) * (frequency + frequencyOffset)) / sampleRate); | |||
| phaseIncrement.setValue (((MathConstants<double>::twoPi) * (frequency + frequencyOffset)) / sampleRate); | |||
| } | |||
| void controllerMoved (int, int) override | |||
| @@ -95,8 +95,8 @@ public: | |||
| phasePos += phaseIncrement.getNextValue(); | |||
| if (phasePos > (2.0 * double_Pi)) | |||
| phasePos -= (2.0 * double_Pi); | |||
| if (phasePos > MathConstants<double>::twoPi) | |||
| phasePos -= MathConstants<double>::twoPi; | |||
| return output; | |||
| } | |||
| @@ -177,7 +177,7 @@ struct SquareVoice : public Oscillator | |||
| bool canPlaySound (SynthesiserSound* sound) override { return dynamic_cast<SquareSound*> (sound) != nullptr; } | |||
| double renderWaveShape (const double currentPhase) override { return (currentPhase < double_Pi ? 0.0 : 1.0); } | |||
| double renderWaveShape (const double currentPhase) override { return (currentPhase < MathConstants<double>::pi ? 0.0 : 1.0); } | |||
| //============================================================================== | |||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SquareVoice) | |||
| @@ -208,7 +208,7 @@ struct SawVoice : public Oscillator | |||
| bool canPlaySound (SynthesiserSound* sound) override { return dynamic_cast<SawSound*> (sound) != nullptr; } | |||
| double renderWaveShape (const double currentPhase) override { return (1.0 / double_Pi) * currentPhase - 1.0; } | |||
| double renderWaveShape (const double currentPhase) override { return (1.0 / MathConstants<double>::pi) * currentPhase - 1.0; } | |||
| //============================================================================== | |||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SawVoice) | |||
| @@ -241,8 +241,8 @@ struct TriangleVoice : public Oscillator | |||
| double renderWaveShape (const double currentPhase) override | |||
| { | |||
| return (currentPhase < double_Pi ? -1.0 + (2.0 / double_Pi) * currentPhase | |||
| : 3.0 - (2.0 / double_Pi) * currentPhase); | |||
| return currentPhase < MathConstants<double>::pi ? -1.0 + (2.0 / MathConstants<double>::pi) * currentPhase | |||
| : 3.0 - (2.0 / MathConstants<double>::pi) * currentPhase; | |||
| } | |||
| //============================================================================== | |||
| @@ -51,7 +51,7 @@ public: | |||
| // Set current phase position to 0 and work out the required phase increment for one cycle | |||
| auto currentPhase = 0.0; | |||
| auto phaseInc = (1.0 / 30.0) * (2.0 * double_Pi); | |||
| auto phaseInc = (1.0 / 30.0) * MathConstants<double>::twoPi; | |||
| for (auto x = 0; x < 30; ++x) | |||
| { | |||
| @@ -60,7 +60,7 @@ public: | |||
| sineWaveY[x] = static_cast<uint8> (roundToInt ((sineOutput * 6.5) + 7.0)); | |||
| // Square wave output, set flags for when vertical line should be drawn | |||
| if (currentPhase < double_Pi) | |||
| if (currentPhase < MathConstants<double>::pi) | |||
| { | |||
| if (x == 0) | |||
| squareWaveY[x] = 255; | |||
| @@ -83,13 +83,13 @@ struct OscillatorDemo | |||
| { | |||
| // No Approximation | |||
| {[] (float x) { return std::sin (x); }}, // sine | |||
| {[] (float x) { return x / float_Pi; }}, // saw | |||
| {[] (float x) { return x / MathConstants<float>::pi; }}, // saw | |||
| {[] (float x) { return x < 0.0f ? -1.0f : 1.0f; }}, // square | |||
| // Approximated by a wave-table | |||
| {[] (float x) { return std::sin (x); }, 100}, // sine | |||
| {[] (float x) { return x / float_Pi; }, 100}, // saw | |||
| {[] (float x) { return x < 0.0f ? -1.0f : 1.0f; }, 100} // square | |||
| {[] (float x) { return std::sin (x); }, 100}, // sine | |||
| {[] (float x) { return x / MathConstants<float>::pi; }, 100}, // saw | |||
| {[] (float x) { return x < 0.0f ? -1.0f : 1.0f; }, 100} // square | |||
| }; | |||
| int currentOscillatorIdx = 0; | |||
| @@ -149,7 +149,7 @@ public: | |||
| for (int i = 0; i < componentsToAnimate.size(); ++i) | |||
| { | |||
| const int newIndex = (i + 3) % componentsToAnimate.size(); | |||
| const float angle = newIndex * 2.0f * float_Pi / componentsToAnimate.size(); | |||
| const float angle = newIndex * MathConstants<float>::twoPi / componentsToAnimate.size(); | |||
| const float radius = getWidth() * 0.35f; | |||
| Rectangle<int> r (getWidth() / 2 + (int) (radius * std::sin (angle)) - 50, | |||
| @@ -258,7 +258,7 @@ private: | |||
| for (int i = 0; i < componentsToAnimate.size(); ++i) | |||
| { | |||
| const int newIndex = (i + 3 * cycleCount) % componentsToAnimate.size(); | |||
| const float angle = newIndex * 2.0f * float_Pi / componentsToAnimate.size(); | |||
| const float angle = newIndex * MathConstants<float>::twoPi / componentsToAnimate.size(); | |||
| const float radius = getWidth() * 0.35f; | |||
| Rectangle<int> r (getWidth() / 2 + (int) (radius * std::sin (angle)) - 50, | |||
| @@ -59,7 +59,7 @@ struct SineWaveVoice : public SynthesiserVoice | |||
| double cyclesPerSecond = MidiMessage::getMidiNoteInHertz (midiNoteNumber); | |||
| double cyclesPerSample = cyclesPerSecond / getSampleRate(); | |||
| angleDelta = cyclesPerSample * 2.0 * double_Pi; | |||
| angleDelta = cyclesPerSample * MathConstants<double>::twoPi; | |||
| } | |||
| void stopNote (float /*velocity*/, bool allowTailOff) override | |||
| @@ -110,7 +110,7 @@ public: | |||
| AffineTransform t; | |||
| if (controls.animateRotation.getToggleState()) | |||
| t = t.rotated (rotation.getValue() * float_Pi * 2.0f); | |||
| t = t.rotated (rotation.getValue() * MathConstants<float>::twoPi); | |||
| if (controls.animateSize.getToggleState()) | |||
| t = t.scaled (0.3f + size.getValue() * 2.0f); | |||
| @@ -220,7 +220,7 @@ public: | |||
| AffineTransform transform (AffineTransform::translation (clipImage.getWidth() / -2.0f, | |||
| clipImage.getHeight() / -2.0f) | |||
| .rotated (clipImageAngle.getValue() * float_Pi * 2.0f) | |||
| .rotated (clipImageAngle.getValue() * MathConstants<float>::twoPi) | |||
| .scaled (2.0f + clipImageSize.getValue() * 3.0f) | |||
| .translated (getWidth() * 0.5f, | |||
| getHeight() * 0.5f)); | |||
| @@ -374,7 +374,7 @@ struct SquareLookAndFeel : public CustomLookAndFeel | |||
| float rotaryStartAngle, float rotaryEndAngle, Slider& slider) override | |||
| { | |||
| auto diameter = jmin (width, height) - 4.0f; | |||
| auto radius = (diameter / 2.0f) * std::cos (float_Pi / 4.0f); | |||
| auto radius = (diameter / 2.0f) * std::cos (MathConstants<float>::pi / 4.0f); | |||
| auto centreX = x + width * 0.5f; | |||
| auto centreY = y + height * 0.5f; | |||
| auto rx = centreX - radius; | |||
| @@ -44,7 +44,8 @@ public: | |||
| const float speed = 5.0f; // give each ball a fixed speed so we can | |||
| // see the effects of thread priority on how fast | |||
| // they actually go. | |||
| const float angle = Random::getSystemRandom().nextFloat() * float_Pi * 2.0f; | |||
| auto angle = Random::getSystemRandom().nextFloat() * MathConstants<float>::twoPi; | |||
| dx = std::sin (angle) * speed; | |||
| dy = std::cos (angle) * speed; | |||
| @@ -155,7 +155,7 @@ struct SlidersPage : public Component | |||
| s = createSlider (false); | |||
| s->setSliderStyle (Slider::Rotary); | |||
| s->setRotaryParameters (float_Pi * 1.2f, float_Pi * 2.8f, false); | |||
| s->setRotaryParameters (MathConstants<float>::pi * 1.2f, MathConstants<float>::pi * 2.8f, false); | |||
| s->setTextBoxStyle (Slider::TextBoxRight, false, 70, 20); | |||
| horizonalSliderArea.removeFromTop (15); | |||
| s->setBounds (horizonalSliderArea.removeFromTop (70)); | |||
| @@ -50,7 +50,7 @@ public: | |||
| phase = 0.0; | |||
| const double cyclesPerSample = frequency.getNextValue() / currentSampleRate; | |||
| phaseDelta = 2.0 * double_Pi * cyclesPerSample; | |||
| phaseDelta = MathConstants<double>::twoPi * cyclesPerSample; | |||
| tailOff = 0.0; | |||
| } | |||
| @@ -168,8 +168,8 @@ private: | |||
| const float nextSample = float (amplitude * ((a1 * f1) + (a2 * f2))); | |||
| const double cyclesPerSample = frequency.getNextValue() / currentSampleRate; | |||
| phaseDelta = 2.0 * double_Pi * cyclesPerSample; | |||
| phase = std::fmod (phase + phaseDelta, 2.0 * double_Pi); | |||
| phaseDelta = MathConstants<double>::twoPi * cyclesPerSample; | |||
| phase = std::fmod (phase + phaseDelta, MathConstants<double>::twoPi); | |||
| return nextSample; | |||
| } | |||
| @@ -299,7 +299,7 @@ struct FlockDemo : public BackgroundLogo | |||
| { | |||
| const float regionSize = high - low; | |||
| const float adjustedProportion = (proportion - low) / regionSize; | |||
| const float F = (0.5f - std::cos (adjustedProportion * float_Pi * 2.0f) * 0.5f + 0.5f) * strength; | |||
| const float F = (0.5f - std::cos (adjustedProportion * MathConstants<float>::twoPi) * 0.5f + 0.5f) * strength; | |||
| b1.accelerate (getVectorWithLength (b2.velocity, F)); | |||
| b2.accelerate (getVectorWithLength (b1.velocity, F)); | |||
| @@ -308,7 +308,7 @@ struct FlockDemo : public BackgroundLogo | |||
| { | |||
| const float regionSize = 1.0f - high; | |||
| const float adjustedProportion = (proportion - high) / regionSize; | |||
| const float F = (0.5f - std::cos (adjustedProportion * float_Pi * 2.0f) * 0.5f + 0.5f) * strength; | |||
| const float F = (0.5f - std::cos (adjustedProportion * MathConstants<float>::twoPi) * 0.5f + 0.5f) * strength; | |||
| delta = getVectorWithLength (delta, F); | |||
| b1.accelerate (-delta); | |||
| @@ -44,8 +44,8 @@ public: | |||
| //============================================================================== | |||
| void stringPlucked (float pluckPositionRelative) | |||
| { | |||
| amplitude = maxAmplitude * std::sin (pluckPositionRelative * float_Pi); | |||
| phase = float_Pi; | |||
| amplitude = maxAmplitude * std::sin (pluckPositionRelative * MathConstants<float>::pi); | |||
| phase = MathConstants<float>::pi; | |||
| } | |||
| //============================================================================== | |||
| @@ -57,7 +57,7 @@ public: | |||
| Path generateStringPath() const | |||
| { | |||
| const float y = height / 2.0f; | |||
| auto y = height / 2.0f; | |||
| Path stringPath; | |||
| stringPath.startNewSubPath (0, y); | |||
| @@ -87,8 +87,8 @@ public: | |||
| phase += phaseStep; | |||
| if (phase > float_Pi) | |||
| phase -= 2.0f * float_Pi; | |||
| if (phase >= MathConstants<float>::twoPi) | |||
| phase -= MathConstants<float>::twoPi; | |||
| } | |||
| private: | |||
| @@ -64,7 +64,7 @@ public: | |||
| { | |||
| // plucking in the middle gives the largest amplitude; | |||
| // plucking at the very ends will do nothing. | |||
| amplitude = std::sin (float_Pi * pluckPosition); | |||
| amplitude = std::sin (MathConstants<float>::pi * pluckPosition); | |||
| } | |||
| } | |||
| @@ -88,7 +88,7 @@ public: | |||
| const float freq = (float) (440.0 / getSampleRate()); | |||
| for (int i = 0; i < fillSamples; ++i) | |||
| channelBuffer[i] += std::sin (2.0f * float_Pi * freq * static_cast<float> (sampleOffset++)); | |||
| channelBuffer[i] += std::sin (MathConstants<float>::twoPi * freq * static_cast<float> (sampleOffset++)); | |||
| } | |||
| } | |||
| @@ -61,7 +61,7 @@ public: | |||
| double cyclesPerSecond = MidiMessage::getMidiNoteInHertz (midiNoteNumber); | |||
| double cyclesPerSample = cyclesPerSecond / getSampleRate(); | |||
| angleDelta = cyclesPerSample * 2.0 * double_Pi; | |||
| angleDelta = cyclesPerSample * MathConstants<double>::twoPi; | |||
| } | |||
| void stopNote (float /*velocity*/, bool allowTailOff) override | |||
| @@ -509,7 +509,7 @@ struct GraphEditorPanel::ConnectorComponent : public Component, | |||
| arrowL, 0.0f); | |||
| arrow.applyTransform (AffineTransform() | |||
| .rotated (float_Pi * 0.5f - (float) atan2 (p2.x - p1.x, p2.y - p1.y)) | |||
| .rotated (MathConstants<float>::pi * 0.5f - (float) atan2 (p2.x - p1.x, p2.y - p1.y)) | |||
| .translated ((p1 + p2) * 0.5f)); | |||
| linePath.addPath (arrow); | |||
| @@ -400,7 +400,7 @@ void ProjucerLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar | |||
| barBounds.getWidth() * 0.5f, | |||
| barBounds.getHeight() * 0.5f, 0.0f, | |||
| 0.0f, | |||
| 2.0f * float_Pi, | |||
| MathConstants<float>::twoPi, | |||
| true); | |||
| g.strokePath (arcPath2, PathStrokeType (2.0f)); | |||
| @@ -415,7 +415,8 @@ void ProjucerLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar | |||
| degreesToRadians (endInDegrees), | |||
| true); | |||
| arcPath.applyTransform (AffineTransform::rotation (normalisedRotation * float_Pi * 2.25f, barBounds.getCentreX(), barBounds.getCentreY())); | |||
| arcPath.applyTransform (AffineTransform::rotation (normalisedRotation * MathConstants<float>::pi * 2.25f, | |||
| barBounds.getCentreX(), barBounds.getCentreY())); | |||
| g.strokePath (arcPath, PathStrokeType (2.0f)); | |||
| if (textToShow.isNotEmpty()) | |||
| @@ -460,7 +461,8 @@ Path ProjucerLookAndFeel::getArrowPath (Rectangle<float> arrowZone, const int di | |||
| if (filled) | |||
| path.closeSubPath(); | |||
| path.applyTransform (AffineTransform::rotation (direction * (float_Pi / 2.0f), arrowZone.getCentreX(), arrowZone.getCentreY())); | |||
| path.applyTransform (AffineTransform::rotation (direction * (MathConstants<float>::pi / 2.0f), | |||
| arrowZone.getCentreX(), arrowZone.getCentreY())); | |||
| return path; | |||
| } | |||
| @@ -44,7 +44,7 @@ IIRCoefficients& IIRCoefficients::operator= (const IIRCoefficients& other) noexc | |||
| IIRCoefficients::IIRCoefficients (double c1, double c2, double c3, | |||
| double c4, double c5, double c6) noexcept | |||
| { | |||
| const double a = 1.0 / c4; | |||
| auto a = 1.0 / c4; | |||
| coefficients[0] = (float) (c1 * a); | |||
| coefficients[1] = (float) (c2 * a); | |||
| @@ -53,23 +53,23 @@ IIRCoefficients::IIRCoefficients (double c1, double c2, double c3, | |||
| coefficients[4] = (float) (c6 * a); | |||
| } | |||
| IIRCoefficients IIRCoefficients::makeLowPass (const double sampleRate, | |||
| const double frequency) noexcept | |||
| IIRCoefficients IIRCoefficients::makeLowPass (double sampleRate, | |||
| double frequency) noexcept | |||
| { | |||
| return makeLowPass (sampleRate, frequency, 1.0 / std::sqrt (2.0)); | |||
| } | |||
| IIRCoefficients IIRCoefficients::makeLowPass (const double sampleRate, | |||
| const double frequency, | |||
| const double Q) noexcept | |||
| IIRCoefficients IIRCoefficients::makeLowPass (double sampleRate, | |||
| double frequency, | |||
| double Q) noexcept | |||
| { | |||
| jassert (sampleRate > 0.0); | |||
| jassert (frequency > 0.0 && frequency <= sampleRate * 0.5); | |||
| jassert (Q > 0.0); | |||
| const double n = 1.0 / std::tan (double_Pi * frequency / sampleRate); | |||
| const double nSquared = n * n; | |||
| const double c1 = 1.0 / (1.0 + 1.0 / Q * n + nSquared); | |||
| auto n = 1.0 / std::tan (MathConstants<double>::pi * frequency / sampleRate); | |||
| auto nSquared = n * n; | |||
| auto c1 = 1.0 / (1.0 + 1.0 / Q * n + nSquared); | |||
| return IIRCoefficients (c1, | |||
| c1 * 2.0, | |||
| @@ -79,23 +79,23 @@ IIRCoefficients IIRCoefficients::makeLowPass (const double sampleRate, | |||
| c1 * (1.0 - 1.0 / Q * n + nSquared)); | |||
| } | |||
| IIRCoefficients IIRCoefficients::makeHighPass (const double sampleRate, | |||
| const double frequency) noexcept | |||
| IIRCoefficients IIRCoefficients::makeHighPass (double sampleRate, | |||
| double frequency) noexcept | |||
| { | |||
| return makeHighPass (sampleRate, frequency, 1.0 / std::sqrt(2.0)); | |||
| } | |||
| IIRCoefficients IIRCoefficients::makeHighPass (const double sampleRate, | |||
| const double frequency, | |||
| const double Q) noexcept | |||
| IIRCoefficients IIRCoefficients::makeHighPass (double sampleRate, | |||
| double frequency, | |||
| double Q) noexcept | |||
| { | |||
| jassert (sampleRate > 0.0); | |||
| jassert (frequency > 0.0 && frequency <= sampleRate * 0.5); | |||
| jassert (Q > 0.0); | |||
| const double n = std::tan (double_Pi * frequency / sampleRate); | |||
| const double nSquared = n * n; | |||
| const double c1 = 1.0 / (1.0 + 1.0 / Q * n + nSquared); | |||
| auto n = std::tan (MathConstants<double>::pi * frequency / sampleRate); | |||
| auto nSquared = n * n; | |||
| auto c1 = 1.0 / (1.0 + 1.0 / Q * n + nSquared); | |||
| return IIRCoefficients (c1, | |||
| c1 * -2.0, | |||
| @@ -105,23 +105,23 @@ IIRCoefficients IIRCoefficients::makeHighPass (const double sampleRate, | |||
| c1 * (1.0 - 1.0 / Q * n + nSquared)); | |||
| } | |||
| IIRCoefficients IIRCoefficients::makeBandPass (const double sampleRate, | |||
| const double frequency) noexcept | |||
| IIRCoefficients IIRCoefficients::makeBandPass (double sampleRate, | |||
| double frequency) noexcept | |||
| { | |||
| return makeBandPass (sampleRate, frequency, 1.0 / std::sqrt (2.0)); | |||
| } | |||
| IIRCoefficients IIRCoefficients::makeBandPass (const double sampleRate, | |||
| const double frequency, | |||
| const double Q) noexcept | |||
| IIRCoefficients IIRCoefficients::makeBandPass (double sampleRate, | |||
| double frequency, | |||
| double Q) noexcept | |||
| { | |||
| jassert (sampleRate > 0.0); | |||
| jassert (frequency > 0.0 && frequency <= sampleRate * 0.5); | |||
| jassert (Q > 0.0); | |||
| const double n = 1.0 / std::tan (double_Pi * frequency / sampleRate); | |||
| const double nSquared = n * n; | |||
| const double c1 = 1.0 / (1.0 + 1.0 / Q * n + nSquared); | |||
| auto n = 1.0 / std::tan (MathConstants<double>::pi * frequency / sampleRate); | |||
| auto nSquared = n * n; | |||
| auto c1 = 1.0 / (1.0 + 1.0 / Q * n + nSquared); | |||
| return IIRCoefficients (c1 * n / Q, | |||
| 0.0, | |||
| @@ -131,23 +131,23 @@ IIRCoefficients IIRCoefficients::makeBandPass (const double sampleRate, | |||
| c1 * (1.0 - 1.0 / Q * n + nSquared)); | |||
| } | |||
| IIRCoefficients IIRCoefficients::makeNotchFilter (const double sampleRate, | |||
| const double frequency) noexcept | |||
| IIRCoefficients IIRCoefficients::makeNotchFilter (double sampleRate, | |||
| double frequency) noexcept | |||
| { | |||
| return makeNotchFilter (sampleRate, frequency, 1.0 / std::sqrt (2.0)); | |||
| } | |||
| IIRCoefficients IIRCoefficients::makeNotchFilter (const double sampleRate, | |||
| const double frequency, | |||
| const double Q) noexcept | |||
| IIRCoefficients IIRCoefficients::makeNotchFilter (double sampleRate, | |||
| double frequency, | |||
| double Q) noexcept | |||
| { | |||
| jassert (sampleRate > 0.0); | |||
| jassert (frequency > 0.0 && frequency <= sampleRate * 0.5); | |||
| jassert (Q > 0.0); | |||
| const double n = 1.0 / std::tan (double_Pi * frequency / sampleRate); | |||
| const double nSquared = n * n; | |||
| const double c1 = 1.0 / (1.0 + n / Q + nSquared); | |||
| auto n = 1.0 / std::tan (MathConstants<double>::pi * frequency / sampleRate); | |||
| auto nSquared = n * n; | |||
| auto c1 = 1.0 / (1.0 + n / Q + nSquared); | |||
| return IIRCoefficients (c1 * (1.0 + nSquared), | |||
| 2.0 * c1 * (1.0 - nSquared), | |||
| @@ -157,23 +157,23 @@ IIRCoefficients IIRCoefficients::makeNotchFilter (const double sampleRate, | |||
| c1 * (1.0 - n / Q + nSquared)); | |||
| } | |||
| IIRCoefficients IIRCoefficients::makeAllPass (const double sampleRate, | |||
| const double frequency) noexcept | |||
| IIRCoefficients IIRCoefficients::makeAllPass (double sampleRate, | |||
| double frequency) noexcept | |||
| { | |||
| return makeAllPass (sampleRate, frequency, 1.0 / std::sqrt (2.0)); | |||
| } | |||
| IIRCoefficients IIRCoefficients::makeAllPass (const double sampleRate, | |||
| const double frequency, | |||
| const double Q) noexcept | |||
| IIRCoefficients IIRCoefficients::makeAllPass (double sampleRate, | |||
| double frequency, | |||
| double Q) noexcept | |||
| { | |||
| jassert (sampleRate > 0.0); | |||
| jassert (frequency > 0.0 && frequency <= sampleRate * 0.5); | |||
| jassert (Q > 0.0); | |||
| const double n = 1.0 / std::tan (double_Pi * frequency / sampleRate); | |||
| const double nSquared = n * n; | |||
| const double c1 = 1.0 / (1.0 + 1.0 / Q * n + nSquared); | |||
| auto n = 1.0 / std::tan (MathConstants<double>::pi * frequency / sampleRate); | |||
| auto nSquared = n * n; | |||
| auto c1 = 1.0 / (1.0 + 1.0 / Q * n + nSquared); | |||
| return IIRCoefficients (c1 * (1.0 - n / Q + nSquared), | |||
| c1 * 2.0 * (1.0 - nSquared), | |||
| @@ -183,22 +183,22 @@ IIRCoefficients IIRCoefficients::makeAllPass (const double sampleRate, | |||
| c1 * (1.0 - n / Q + nSquared)); | |||
| } | |||
| IIRCoefficients IIRCoefficients::makeLowShelf (const double sampleRate, | |||
| const double cutOffFrequency, | |||
| const double Q, | |||
| const float gainFactor) noexcept | |||
| IIRCoefficients IIRCoefficients::makeLowShelf (double sampleRate, | |||
| double cutOffFrequency, | |||
| double Q, | |||
| float gainFactor) noexcept | |||
| { | |||
| jassert (sampleRate > 0.0); | |||
| jassert (cutOffFrequency > 0.0 && cutOffFrequency <= sampleRate * 0.5); | |||
| jassert (Q > 0.0); | |||
| const double A = jmax (0.0f, std::sqrt (gainFactor)); | |||
| const double aminus1 = A - 1.0; | |||
| const double aplus1 = A + 1.0; | |||
| const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate; | |||
| const double coso = std::cos (omega); | |||
| const double beta = std::sin (omega) * std::sqrt (A) / Q; | |||
| const double aminus1TimesCoso = aminus1 * coso; | |||
| auto A = jmax (0.0f, std::sqrt (gainFactor)); | |||
| auto aminus1 = A - 1.0; | |||
| auto aplus1 = A + 1.0; | |||
| auto omega = (MathConstants<double>::twoPi * jmax (cutOffFrequency, 2.0)) / sampleRate; | |||
| auto coso = std::cos (omega); | |||
| auto beta = std::sin (omega) * std::sqrt (A) / Q; | |||
| auto aminus1TimesCoso = aminus1 * coso; | |||
| return IIRCoefficients (A * (aplus1 - aminus1TimesCoso + beta), | |||
| A * 2.0 * (aminus1 - aplus1 * coso), | |||
| @@ -208,22 +208,22 @@ IIRCoefficients IIRCoefficients::makeLowShelf (const double sampleRate, | |||
| aplus1 + aminus1TimesCoso - beta); | |||
| } | |||
| IIRCoefficients IIRCoefficients::makeHighShelf (const double sampleRate, | |||
| const double cutOffFrequency, | |||
| const double Q, | |||
| const float gainFactor) noexcept | |||
| IIRCoefficients IIRCoefficients::makeHighShelf (double sampleRate, | |||
| double cutOffFrequency, | |||
| double Q, | |||
| float gainFactor) noexcept | |||
| { | |||
| jassert (sampleRate > 0.0); | |||
| jassert (cutOffFrequency > 0.0 && cutOffFrequency <= sampleRate * 0.5); | |||
| jassert (Q > 0.0); | |||
| const double A = jmax (0.0f, std::sqrt (gainFactor)); | |||
| const double aminus1 = A - 1.0; | |||
| const double aplus1 = A + 1.0; | |||
| const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate; | |||
| const double coso = std::cos (omega); | |||
| const double beta = std::sin (omega) * std::sqrt (A) / Q; | |||
| const double aminus1TimesCoso = aminus1 * coso; | |||
| auto A = jmax (0.0f, std::sqrt (gainFactor)); | |||
| auto aminus1 = A - 1.0; | |||
| auto aplus1 = A + 1.0; | |||
| auto omega = (MathConstants<double>::twoPi * jmax (cutOffFrequency, 2.0)) / sampleRate; | |||
| auto coso = std::cos (omega); | |||
| auto beta = std::sin (omega) * std::sqrt (A) / Q; | |||
| auto aminus1TimesCoso = aminus1 * coso; | |||
| return IIRCoefficients (A * (aplus1 + aminus1TimesCoso + beta), | |||
| A * -2.0 * (aminus1 + aplus1 * coso), | |||
| @@ -233,21 +233,21 @@ IIRCoefficients IIRCoefficients::makeHighShelf (const double sampleRate, | |||
| aplus1 - aminus1TimesCoso - beta); | |||
| } | |||
| IIRCoefficients IIRCoefficients::makePeakFilter (const double sampleRate, | |||
| const double frequency, | |||
| const double Q, | |||
| const float gainFactor) noexcept | |||
| IIRCoefficients IIRCoefficients::makePeakFilter (double sampleRate, | |||
| double frequency, | |||
| double Q, | |||
| float gainFactor) noexcept | |||
| { | |||
| jassert (sampleRate > 0.0); | |||
| jassert (frequency > 0.0 && frequency <= sampleRate * 0.5); | |||
| jassert (Q > 0.0); | |||
| const double A = jmax (0.0f, std::sqrt (gainFactor)); | |||
| const double omega = (double_Pi * 2.0 * jmax (frequency, 2.0)) / sampleRate; | |||
| const double alpha = 0.5 * std::sin (omega) / Q; | |||
| const double c2 = -2.0 * std::cos (omega); | |||
| const double alphaTimesA = alpha * A; | |||
| const double alphaOverA = alpha / A; | |||
| auto A = jmax (0.0f, std::sqrt (gainFactor)); | |||
| auto omega = (MathConstants<double>::twoPi * jmax (frequency, 2.0)) / sampleRate; | |||
| auto alpha = 0.5 * std::sin (omega) / Q; | |||
| auto c2 = -2.0 * std::cos (omega); | |||
| auto alphaTimesA = alpha * A; | |||
| auto alphaOverA = alpha / A; | |||
| return IIRCoefficients (1.0 + alphaTimesA, | |||
| c2, | |||
| @@ -259,12 +259,10 @@ IIRCoefficients IIRCoefficients::makePeakFilter (const double sampleRate, | |||
| //============================================================================== | |||
| IIRFilter::IIRFilter() noexcept | |||
| : v1 (0.0), v2 (0.0), active (false) | |||
| { | |||
| } | |||
| IIRFilter::IIRFilter (const IIRFilter& other) noexcept | |||
| : v1 (0.0), v2 (0.0), active (other.active) | |||
| IIRFilter::IIRFilter (const IIRFilter& other) noexcept : active (other.active) | |||
| { | |||
| const SpinLock::ScopedLockType sl (other.processLock); | |||
| coefficients = other.coefficients; | |||
| @@ -284,7 +282,6 @@ void IIRFilter::makeInactive() noexcept | |||
| void IIRFilter::setCoefficients (const IIRCoefficients& newCoefficients) noexcept | |||
| { | |||
| const SpinLock::ScopedLockType sl (processLock); | |||
| coefficients = newCoefficients; | |||
| active = true; | |||
| } | |||
| @@ -296,9 +293,9 @@ void IIRFilter::reset() noexcept | |||
| v1 = v2 = 0.0; | |||
| } | |||
| float IIRFilter::processSingleSampleRaw (const float in) noexcept | |||
| float IIRFilter::processSingleSampleRaw (float in) noexcept | |||
| { | |||
| float out = coefficients.coefficients[0] * in + v1; | |||
| auto out = coefficients.coefficients[0] * in + v1; | |||
| JUCE_SNAP_TO_ZERO (out); | |||
| @@ -314,17 +311,17 @@ void IIRFilter::processSamples (float* const samples, const int numSamples) noex | |||
| if (active) | |||
| { | |||
| const float c0 = coefficients.coefficients[0]; | |||
| const float c1 = coefficients.coefficients[1]; | |||
| const float c2 = coefficients.coefficients[2]; | |||
| const float c3 = coefficients.coefficients[3]; | |||
| const float c4 = coefficients.coefficients[4]; | |||
| float lv1 = v1, lv2 = v2; | |||
| auto c0 = coefficients.coefficients[0]; | |||
| auto c1 = coefficients.coefficients[1]; | |||
| auto c2 = coefficients.coefficients[2]; | |||
| auto c3 = coefficients.coefficients[3]; | |||
| auto c4 = coefficients.coefficients[4]; | |||
| auto lv1 = v1, lv2 = v2; | |||
| for (int i = 0; i < numSamples; ++i) | |||
| { | |||
| const float in = samples[i]; | |||
| const float out = c0 * in + lv1; | |||
| auto in = samples[i]; | |||
| auto out = c0 * in + lv1; | |||
| samples[i] = out; | |||
| lv1 = c1 * in - c3 * out + lv2; | |||
| @@ -200,8 +200,8 @@ protected: | |||
| //============================================================================== | |||
| SpinLock processLock; | |||
| IIRCoefficients coefficients; | |||
| float v1, v2; | |||
| bool active; | |||
| float v1 = 0, v2 = 0; | |||
| bool active = false; | |||
| IIRFilter& operator= (const IIRFilter&); | |||
| JUCE_LEAK_DETECTOR (IIRFilter) | |||
| @@ -201,7 +201,7 @@ void ResamplingAudioSource::createLowPass (const double frequencyRatio) | |||
| const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio | |||
| : 0.5 * frequencyRatio; | |||
| const double n = 1.0 / std::tan (double_Pi * jmax (0.001, proportionalRate)); | |||
| const double n = 1.0 / std::tan (MathConstants<double>::pi * jmax (0.001, proportionalRate)); | |||
| const double nSquared = n * n; | |||
| const double c1 = 1.0 / (1.0 + std::sqrt (2.0) * n + nSquared); | |||
| @@ -63,7 +63,7 @@ void ToneGeneratorAudioSource::releaseResources() | |||
| void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info) | |||
| { | |||
| if (phasePerSample == 0.0) | |||
| phasePerSample = double_Pi * 2.0 / (sampleRate / frequency); | |||
| phasePerSample = MathConstants<double>::twoPi / (sampleRate / frequency); | |||
| for (int i = 0; i < info.numSamples; ++i) | |||
| { | |||
| @@ -986,13 +986,13 @@ void AudioDeviceManager::playTestSound() | |||
| if (currentAudioDevice != nullptr) | |||
| { | |||
| const double sampleRate = currentAudioDevice->getCurrentSampleRate(); | |||
| const int soundLength = (int) sampleRate; | |||
| auto sampleRate = currentAudioDevice->getCurrentSampleRate(); | |||
| auto soundLength = (int) sampleRate; | |||
| const double frequency = 440.0; | |||
| const float amplitude = 0.5f; | |||
| double frequency = 440.0; | |||
| float amplitude = 0.5f; | |||
| const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency); | |||
| auto phasePerSample = MathConstants<double>::twoPi / (sampleRate / frequency); | |||
| auto* newSound = new AudioBuffer<float> (1, soundLength); | |||
| @@ -611,7 +611,7 @@ private: | |||
| float* costab = cosTables[i]; | |||
| for (int k = 0; k < kr; ++k) | |||
| costab[k] = (float) (1.0 / (2.0 * std::cos (double_Pi * (k * 2 + 1) / divv))); | |||
| costab[k] = (float) (1.0 / (2.0 * std::cos (MathConstants<double>::pi * (k * 2 + 1) / divv))); | |||
| } | |||
| for (i = 0, j = 0; i < 256; ++i, ++j, table += 32) | |||
| @@ -696,23 +696,23 @@ private: | |||
| for (i = 0; i < 18; ++i) | |||
| { | |||
| win[0][i] = win[1][i] = (float) (0.5 * std::sin (double_Pi / 72.0 * (2 * i + 1)) / std::cos (double_Pi * (2 * i + 19) / 72.0)); | |||
| win[0][i + 18] = win[3][i + 18] = (float) (0.5 * std::sin (double_Pi / 72.0 * (2 * (i + 18) + 1)) / std::cos (double_Pi * (2 * (i + 18) + 19) / 72.0)); | |||
| win[0][i] = win[1][i] = (float) (0.5 * std::sin (MathConstants<double>::pi / 72.0 * (2 * i + 1)) / std::cos (MathConstants<double>::pi * (2 * i + 19) / 72.0)); | |||
| win[0][i + 18] = win[3][i + 18] = (float) (0.5 * std::sin (MathConstants<double>::pi / 72.0 * (2 * (i + 18) + 1)) / std::cos (MathConstants<double>::pi * (2 * (i + 18) + 19) / 72.0)); | |||
| } | |||
| const double piOver72 = double_Pi / 72.0; | |||
| const double piOver72 = MathConstants<double>::pi / 72.0; | |||
| for (i = 0; i < 6; ++i) | |||
| { | |||
| win[1][i + 18] = (float) (0.5 / std::cos (piOver72 * (2 * (i + 18) + 19))); | |||
| win[3][i + 12] = (float) (0.5 / std::cos (piOver72 * (2 * (i + 12) + 19))); | |||
| win[1][i + 24] = (float) (0.5 * std::sin (double_Pi / 24.0 * (2 * i + 13)) / std::cos (piOver72 * (2 * (i + 24) + 19))); | |||
| win[1][i + 24] = (float) (0.5 * std::sin (MathConstants<double>::pi / 24.0 * (2 * i + 13)) / std::cos (piOver72 * (2 * (i + 24) + 19))); | |||
| win[1][i + 30] = win[3][i] = 0; | |||
| win[3][i + 6] = (float) (0.5 * std::sin (double_Pi / 24.0 * (2 * i + 1)) / std::cos (piOver72 * (2 * (i + 6) + 19))); | |||
| win[3][i + 6] = (float) (0.5 * std::sin (MathConstants<double>::pi / 24.0 * (2 * i + 1)) / std::cos (piOver72 * (2 * (i + 6) + 19))); | |||
| } | |||
| for (i = 0; i < 12; ++i) | |||
| win[2][i] = (float) (0.5 * std::sin (double_Pi / 24.0 * (2 * i + 1)) / std::cos (double_Pi * (2 * i + 7) / 24.0)); | |||
| win[2][i] = (float) (0.5 * std::sin (MathConstants<double>::pi / 24.0 * (2 * i + 1)) / std::cos (MathConstants<double>::pi * (2 * i + 7) / 24.0)); | |||
| for (j = 0; j < 4; ++j) | |||
| { | |||
| @@ -725,7 +725,7 @@ private: | |||
| for (i = 0; i < 16; ++i) | |||
| { | |||
| const double t = std::tan (i * double_Pi / 12.0); | |||
| const double t = std::tan (i * MathConstants<double>::pi / 12.0); | |||
| tan1_1[i] = (float) (t / (1.0 + t)); | |||
| tan2_1[i] = (float) (1.0 / (1.0 + t)); | |||
| tan1_2[i] = (float) (sqrt2 * t / (1.0 + t)); | |||
| @@ -541,7 +541,7 @@ void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h, | |||
| Path path; | |||
| path.addTriangle (0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.5f); | |||
| path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * angle, 0.5f, 0.5f)); | |||
| path.applyTransform (AffineTransform::rotation (MathConstants<float>::twoPi * angle, 0.5f, 0.5f)); | |||
| g.setColour (findColour (upDownButtonArrowColourId) | |||
| .withAlpha (buttonDown ? 1.0f : (mouseOver ? 0.6f : 0.4f))); | |||
| @@ -225,12 +225,11 @@ void SoundPlayer::play (PositionableAudioSource* audioSource, bool deleteWhenFin | |||
| void SoundPlayer::playTestSound() | |||
| { | |||
| const int soundLength = (int) sampleRate; | |||
| auto soundLength = (int) sampleRate; | |||
| double frequency = 440.0; | |||
| float amplitude = 0.5f; | |||
| const double frequency = 440.0; | |||
| const float amplitude = 0.5f; | |||
| const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency); | |||
| auto phasePerSample = MathConstants<double>::twoPi / (sampleRate / frequency); | |||
| auto* newSound = new AudioBuffer<float> (1, soundLength); | |||
| @@ -1700,7 +1700,7 @@ struct JavascriptEngine::RootObject : public DynamicObject | |||
| setMethod ("sqr", Math_sqr); setMethod ("sqrt", Math_sqrt); | |||
| setMethod ("ceil", Math_ceil); setMethod ("floor", Math_floor); | |||
| setProperty ("PI", double_Pi); | |||
| setProperty ("PI", MathConstants<double>::pi); | |||
| setProperty ("E", exp (1.0)); | |||
| } | |||
| @@ -336,6 +336,9 @@ struct MathConstants | |||
| /** A predefined value for Pi */ | |||
| static constexpr FloatType pi = static_cast<FloatType> (3.141592653589793238L); | |||
| /** A predefined value for 2 * Pi */ | |||
| static constexpr FloatType twoPi = static_cast<FloatType> (2 * 3.141592653589793238L); | |||
| /** A predfined value for Euler's number */ | |||
| static constexpr FloatType euler = static_cast<FloatType> (2.71828182845904523536L); | |||
| }; | |||
| @@ -349,6 +352,9 @@ struct MathConstants | |||
| /** A predefined value for Pi */ | |||
| static const FloatType pi; | |||
| /** A predefined value for 2 * Pi */ | |||
| static const FloatType twoPi; | |||
| /** A predfined value for Euler's number */ | |||
| static const FloatType euler; | |||
| }; | |||
| @@ -356,34 +362,37 @@ struct MathConstants | |||
| template <typename FloatType> | |||
| const FloatType MathConstants<FloatType>::pi = static_cast<FloatType> (3.141592653589793238L); | |||
| template <typename FloatType> | |||
| const FloatType MathConstants<FloatType>::twoPi = static_cast<FloatType> (2 * 3.141592653589793238L); | |||
| template <typename FloatType> | |||
| const FloatType MathConstants<FloatType>::euler = static_cast<FloatType> (2.71828182845904523536L); | |||
| #endif | |||
| /** A predefined value for Pi, at double-precision. | |||
| @see float_Pi | |||
| /** A double-precision constant for pi. | |||
| @deprecated This is deprecated in favour of MathConstants<double>::pi. | |||
| The reason is that "double_Pi" was a confusing name, and many people misused it, | |||
| wrongly thinking it meant 2 * pi ! | |||
| */ | |||
| const JUCE_CONSTEXPR double double_Pi = MathConstants<double>::pi; | |||
| /** A predefined value for Pi, at single-precision. | |||
| @see double_Pi | |||
| /** A single-precision constant for pi. | |||
| @deprecated This is deprecated in favour of MathConstants<float>::pi. | |||
| The reason is that "double_Pi" was a confusing name, and many people misused it, | |||
| wrongly thinking it meant 2 * pi ! | |||
| */ | |||
| const JUCE_CONSTEXPR float float_Pi = MathConstants<float>::pi; | |||
| /** Converts an angle in degrees to radians. */ | |||
| inline JUCE_CONSTEXPR float degreesToRadians (float degrees) noexcept { return degrees * (float_Pi / 180.0f); } | |||
| /** Converts an angle in degrees to radians. */ | |||
| inline JUCE_CONSTEXPR double degreesToRadians (double degrees) noexcept { return degrees * (double_Pi / 180.0); } | |||
| /** Converts an angle in radians to degrees. */ | |||
| inline JUCE_CONSTEXPR float radiansToDegrees (float radians) noexcept { return radians * (180.0f / float_Pi); } | |||
| template <typename FloatType> | |||
| JUCE_CONSTEXPR FloatType degreesToRadians (FloatType degrees) noexcept { return degrees * (MathConstants<FloatType>::pi / FloatType (180)); } | |||
| /** Converts an angle in radians to degrees. */ | |||
| inline JUCE_CONSTEXPR double radiansToDegrees (double radians) noexcept { return radians * (180.0 / double_Pi); } | |||
| template <typename FloatType> | |||
| JUCE_CONSTEXPR FloatType radiansToDegrees (FloatType radians) noexcept { return radians * (FloatType (180) / MathConstants<FloatType>::pi); } | |||
| //============================================================================== | |||
| @@ -52,7 +52,7 @@ typename FIR::Coefficients<FloatType>::Ptr | |||
| } | |||
| else | |||
| { | |||
| auto indice = double_Pi * (static_cast<double> (i) - 0.5 * static_cast<double> (order)); | |||
| auto indice = MathConstants<double>::pi * (static_cast<double> (i) - 0.5 * static_cast<double> (order)); | |||
| c[i] = static_cast<FloatType> (std::sin (2.0 * indice * normalizedFrequency) / indice); | |||
| } | |||
| } | |||
| @@ -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 * 2.0 * double_Pi))) | |||
| : roundDoubleToInt (ceil (5.79 / (normalizedTransitionWidth * 2.0 * double_Pi))); | |||
| int order = attenuationdB < -21 ? roundDoubleToInt (ceil ((-attenuationdB - 7.95) / (2.285 * normalizedTransitionWidth * MathConstants<double>::twoPi))) | |||
| : roundDoubleToInt (ceil (5.79 / (normalizedTransitionWidth * MathConstants<double>::twoPi))); | |||
| jassert (order >= 0); | |||
| @@ -114,8 +114,8 @@ typename FIR::Coefficients<FloatType>::Ptr | |||
| } | |||
| else | |||
| { | |||
| auto indice = double_Pi * (i - 0.5 * order); | |||
| auto indice2 = double_Pi * normalizedTransitionWidth * (i - 0.5 * order) / spline; | |||
| auto indice = MathConstants<double>::pi * (i - 0.5 * order); | |||
| auto indice2 = MathConstants<double>::pi * normalizedTransitionWidth * (i - 0.5 * order) / spline; | |||
| c[i] = static_cast<FloatType> (std::sin (2 * indice * normalizedFrequency) | |||
| / indice * std::pow (std::sin (indice2) / indice2, spline)); | |||
| } | |||
| @@ -138,8 +138,8 @@ typename FIR::Coefficients<FloatType>::Ptr | |||
| auto normalizedFrequency = static_cast<double> (frequency) / sampleRate; | |||
| auto wp = 2.0 * double_Pi * (static_cast<double> (normalizedFrequency - normalizedTransitionWidth / 2.0)); | |||
| auto ws = 2.0 * double_Pi * (static_cast<double> (normalizedFrequency + normalizedTransitionWidth / 2.0)); | |||
| auto wp = MathConstants<double>::twoPi * (static_cast<double> (normalizedFrequency - normalizedTransitionWidth / 2.0)); | |||
| auto ws = MathConstants<double>::twoPi * (static_cast<double> (normalizedFrequency + normalizedTransitionWidth / 2.0)); | |||
| auto N = order + 1; | |||
| @@ -154,10 +154,11 @@ typename FIR::Coefficients<FloatType>::Ptr | |||
| Matrix<double> b (M + 1, 1), | |||
| q (2 * M + 1, 1); | |||
| auto sinc = [](double x) { return x == 0 ? 1 : std::sin (x * double_Pi) / (double_Pi * x); }; | |||
| auto sinc = [](double x) { return x == 0 ? 1 : std::sin (x * MathConstants<double>::pi) | |||
| / (MathConstants<double>::pi * x); }; | |||
| auto factorp = wp / double_Pi; | |||
| auto factors = ws / double_Pi; | |||
| auto factorp = wp / MathConstants<double>::pi; | |||
| auto factors = ws / MathConstants<double>::pi; | |||
| for (size_t i = 0; i <= M; ++i) | |||
| b (i, 0) = factorp * sinc (factorp * i); | |||
| @@ -191,10 +192,11 @@ typename FIR::Coefficients<FloatType>::Ptr | |||
| Matrix<double> qp (2 * M, 1); | |||
| Matrix<double> qs (2 * M, 1); | |||
| auto sinc = [](double x) { return x == 0 ? 1 : std::sin (x * double_Pi) / (double_Pi * x); }; | |||
| auto sinc = [](double x) { return x == 0 ? 1 : std::sin (x * MathConstants<double>::pi) | |||
| / (MathConstants<double>::pi * x); }; | |||
| auto factorp = wp / double_Pi; | |||
| auto factors = ws / double_Pi; | |||
| auto factorp = wp / MathConstants<double>::pi; | |||
| auto factors = ws / MathConstants<double>::pi; | |||
| for (size_t i = 0; i < M; ++i) | |||
| b (i, 0) = factorp * sinc (factorp * (i + 0.5)); | |||
| @@ -240,7 +242,7 @@ typename FIR::Coefficients<FloatType>::Ptr | |||
| jassert (normalizedTransitionWidth > 0 && normalizedTransitionWidth <= 0.5); | |||
| jassert (attenuationdB >= -300 && attenuationdB <= -10); | |||
| auto wpT = (0.5 - normalizedTransitionWidth) * double_Pi; | |||
| auto wpT = (0.5 - normalizedTransitionWidth) * MathConstants<double>::pi; | |||
| auto n = roundDoubleToInt (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); | |||
| @@ -277,10 +279,10 @@ typename FIR::Coefficients<FloatType>::Ptr | |||
| } | |||
| else | |||
| { | |||
| auto w01 = std::sqrt (kp * kp + (1 - kp * kp) * std::pow (std::cos (double_Pi / (2.0 * n + 1.0)), 2.0)); | |||
| auto w01 = std::sqrt (kp * kp + (1 - kp * kp) * std::pow (std::cos (MathConstants<double>::pi / (2.0 * n + 1.0)), 2.0)); | |||
| auto om01 = std::acos (-w01); | |||
| NN = -2.0 * result->getMagnitudeForFrequency (om01 / (2 * double_Pi), 1.0); | |||
| NN = -2.0 * result->getMagnitudeForFrequency (om01 / MathConstants<double>::twoPi, 1.0); | |||
| } | |||
| for (int i = 0; i < hh.size(); ++i) | |||
| @@ -403,8 +405,8 @@ Array<IIR::Coefficients<FloatType>> | |||
| auto epsp = std::sqrt (1.0 / (Gp * Gp) - 1.0); | |||
| auto epss = std::sqrt (1.0 / (Gs * Gs) - 1.0); | |||
| auto omegap = std::tan (double_Pi * fp); | |||
| auto omegas = std::tan (double_Pi * fs); | |||
| auto omegap = std::tan (MathConstants<double>::pi * fp); | |||
| auto omegas = std::tan (MathConstants<double>::pi * fs); | |||
| auto k = omegap / omegas; | |||
| auto k1 = epsp / epss; | |||
| @@ -444,35 +446,35 @@ Array<IIR::Coefficients<FloatType>> | |||
| for (int i = 1; i <= L; ++i) | |||
| { | |||
| auto ui = (2 * i - 1.0) / (double) N; | |||
| pa.add (omegap * std::pow (epsp, -1.0 / (double) N) * j * exp (ui * 0.5 * double_Pi * j)); | |||
| pa.add (omegap * std::pow (epsp, -1.0 / (double) N) * j * exp (ui * 0.5 * MathConstants<double>::pi * j)); | |||
| } | |||
| } | |||
| else if (type == 1) | |||
| { | |||
| auto v0 = std::asinh (1.0 / epsp) / (0.5 * N * double_Pi); | |||
| auto v0 = std::asinh (1.0 / epsp) / (0.5 * N * MathConstants<double>::pi); | |||
| if (r == 1) | |||
| pa.add (-omegap * std::sinh (v0 * 0.5 * double_Pi)); | |||
| pa.add (-omegap * std::sinh (v0 * 0.5 * MathConstants<double>::pi)); | |||
| for (int i = 1; i <= L; ++i) | |||
| { | |||
| auto ui = (2 * i - 1.0) / (double) N; | |||
| pa.add (omegap * j * std::cos ((ui - j * v0) * 0.5 * double_Pi)); | |||
| pa.add (omegap * j * std::cos ((ui - j * v0) * 0.5 * MathConstants<double>::pi)); | |||
| } | |||
| } | |||
| else if (type == 2) | |||
| { | |||
| auto v0 = std::asinh (epss) / (N * 0.5 * double_Pi); | |||
| auto v0 = std::asinh (epss) / (N * 0.5 * MathConstants<double>::pi); | |||
| if (r == 1) | |||
| pa.add(-1.0 / (k / omegap * std::sinh (v0 * 0.5 * double_Pi))); | |||
| pa.add(-1.0 / (k / omegap * std::sinh (v0 * 0.5 * MathConstants<double>::pi))); | |||
| for (int i = 1; i <= L; ++i) | |||
| { | |||
| auto ui = (2 * i - 1.0) / (double) N; | |||
| pa.add (1.0 / (k / omegap * j * std::cos ((ui - j * v0) * 0.5 * double_Pi))); | |||
| za.add (1.0 / (k / omegap * j * std::cos (ui * 0.5 * double_Pi))); | |||
| pa.add (1.0 / (k / omegap * j * std::cos ((ui - j * v0) * 0.5 * MathConstants<double>::pi))); | |||
| za.add (1.0 / (k / omegap * j * std::cos (ui * 0.5 * MathConstants<double>::pi))); | |||
| } | |||
| } | |||
| else | |||
| @@ -543,10 +545,10 @@ typename FilterDesign<FloatType>::IIRPolyphaseAllpassStructure | |||
| jassert (normalizedTransitionWidth > 0 && normalizedTransitionWidth <= 0.5); | |||
| jassert (stopbandAttenuationdB > -300 && stopbandAttenuationdB < -10); | |||
| const double wt = 2 * double_Pi * normalizedTransitionWidth; | |||
| const double wt = MathConstants<double>::twoPi * normalizedTransitionWidth; | |||
| const double ds = Decibels::decibelsToGain (stopbandAttenuationdB, static_cast<FloatType> (-300.0)); | |||
| auto k = std::pow (std::tan ((double_Pi - wt) / 4), 2.0); | |||
| auto k = std::pow (std::tan ((MathConstants<double>::pi - wt) / 4), 2.0); | |||
| auto kp = std::sqrt (1.0 - k * k); | |||
| auto e = (1 - std::sqrt (kp)) / (1 + std::sqrt (kp)) * 0.5; | |||
| auto q = e + 2 * std::pow (e, 5.0) + 15 * std::pow (e, 9.0) + 150 * std::pow (e, 13.0); | |||
| @@ -575,7 +577,7 @@ typename FilterDesign<FloatType>::IIRPolyphaseAllpassStructure | |||
| while (std::abs (delta) > 1e-100) | |||
| { | |||
| delta = std::pow (-1, m) * std::pow (q, m * (m + 1)) | |||
| * std::sin ((2 * m + 1) * double_Pi * i / (double) n); | |||
| * std::sin ((2 * m + 1) * MathConstants<double>::pi * i / (double) n); | |||
| num += delta; | |||
| m++; | |||
| } | |||
| @@ -589,7 +591,7 @@ typename FilterDesign<FloatType>::IIRPolyphaseAllpassStructure | |||
| while (std::abs (delta) > 1e-100) | |||
| { | |||
| delta = std::pow (-1, m) * std::pow (q, m * m) | |||
| * std::cos (2 * m * double_Pi * i / (double) n); | |||
| * std::cos (2 * m * MathConstants<double>::pi * i / (double) n); | |||
| den += delta; | |||
| ++m; | |||
| } | |||
| @@ -196,13 +196,13 @@ struct FFTFallback : public FFT::Instance | |||
| FFTConfig (int sizeOfFFT, bool isInverse) | |||
| : fftSize (sizeOfFFT), inverse (isInverse), twiddleTable ((size_t) sizeOfFFT) | |||
| { | |||
| const double inverseFactor = (inverse ? 2.0 : -2.0) * double_Pi / (double) fftSize; | |||
| auto inverseFactor = (inverse ? 2.0 : -2.0) * MathConstants<double>::pi / (double) fftSize; | |||
| if (fftSize <= 4) | |||
| { | |||
| for (int i = 0; i < fftSize; ++i) | |||
| { | |||
| const double phase = i * inverseFactor; | |||
| auto phase = i * inverseFactor; | |||
| twiddleTable[i].real ((float) std::cos (phase)); | |||
| twiddleTable[i].imag ((float) std::sin (phase)); | |||
| @@ -212,7 +212,7 @@ struct FFTFallback : public FFT::Instance | |||
| { | |||
| for (int i = 0; i < fftSize / 4; ++i) | |||
| { | |||
| const double phase = i * inverseFactor; | |||
| auto phase = i * inverseFactor; | |||
| twiddleTable[i].real ((float) std::cos (phase)); | |||
| twiddleTable[i].imag ((float) std::sin (phase)); | |||
| @@ -220,7 +220,7 @@ struct FFTFallback : public FFT::Instance | |||
| for (int i = fftSize / 4; i < fftSize / 2; ++i) | |||
| { | |||
| const int index = i - fftSize / 4; | |||
| auto index = i - fftSize / 4; | |||
| twiddleTable[i].real (inverse ? -twiddleTable[index].imag() : twiddleTable[index].imag()); | |||
| twiddleTable[i].imag (inverse ? twiddleTable[index].real() : -twiddleTable[index].real()); | |||
| @@ -231,12 +231,12 @@ struct FFTFallback : public FFT::Instance | |||
| for (int i = fftSize / 2; i < fftSize; ++i) | |||
| { | |||
| const int index = fftSize / 2 - (i - fftSize / 2); | |||
| auto index = fftSize / 2 - (i - fftSize / 2); | |||
| twiddleTable[i] = conj(twiddleTable[index]); | |||
| } | |||
| } | |||
| const int root = (int) std::sqrt ((double) fftSize); | |||
| auto root = (int) std::sqrt ((double) fftSize); | |||
| int divisor = 4, n = fftSize; | |||
| for (int i = 0; i < numElementsInArray (factors); ++i) | |||
| @@ -56,25 +56,25 @@ struct FFTUnitTest : public UnitTest | |||
| } | |||
| static void performReferenceFourier (const Complex<float>* in, Complex<float>* out, | |||
| size_t n, bool reverve) | |||
| size_t n, bool reverse) | |||
| { | |||
| float base_freq = static_cast<float>(((reverve ? 1.0 : -1.0) * 2.0 * double_Pi) | |||
| / static_cast<float> (n)); | |||
| auto base_freq = static_cast<float> (((reverse ? 1.0 : -1.0) * MathConstants<double>::twoPi) | |||
| / static_cast<float> (n)); | |||
| for (size_t i = 0; i < n; ++i) | |||
| out[i] = freqConvolution (in, static_cast<float>(i) * base_freq, n); | |||
| } | |||
| static void performReferenceFourier (const float* in, Complex<float>* out, | |||
| size_t n, bool reverve) | |||
| size_t n, bool reverse) | |||
| { | |||
| HeapBlock<Complex<float>> buffer (n); | |||
| for (size_t i = 0; i < n; ++i) | |||
| buffer.getData()[i] = Complex<float> (in[i], 0.0f); | |||
| float base_freq = static_cast<float>(((reverve ? 1.0 : -1.0) * 2.0 * double_Pi) | |||
| / static_cast<float> (n)); | |||
| float base_freq = static_cast<float> (((reverse ? 1.0 : -1.0) * MathConstants<double>::twoPi) | |||
| / static_cast<float> (n)); | |||
| for (size_t i = 0; i < n; ++i) | |||
| out[i] = freqConvolution (buffer.getData(), static_cast<float>(i) * base_freq, n); | |||
| @@ -53,7 +53,7 @@ void SpecialFunctions::ellipticIntegralK (double k, double& K, double& Kp) noexc | |||
| { | |||
| constexpr int M = 4; | |||
| K = double_Pi * 0.5; | |||
| K = MathConstants<double>::pi * 0.5; | |||
| auto lastK = k; | |||
| for (int i = 0; i < M; ++i) | |||
| @@ -62,7 +62,7 @@ void SpecialFunctions::ellipticIntegralK (double k, double& K, double& Kp) noexc | |||
| K *= 1 + lastK; | |||
| } | |||
| Kp = double_Pi * 0.5; | |||
| Kp = MathConstants<double>::pi * 0.5; | |||
| auto last = std::sqrt (1 - k * k); | |||
| for (int i = 0; i < M; ++i) | |||
| @@ -86,7 +86,7 @@ Complex<double> SpecialFunctions::cde (Complex<double> u, double k) noexcept | |||
| *++kei = next; | |||
| } | |||
| std::complex<double> last = std::cos (0.5 * u * double_Pi); | |||
| std::complex<double> last = std::cos (0.5 * u * MathConstants<double>::pi); | |||
| for (int i = M - 1; i >= 0; --i) | |||
| last = (1.0 + ke[i + 1]) / (1.0 / last + ke[i + 1] * last); | |||
| @@ -108,7 +108,7 @@ Complex<double> SpecialFunctions::sne (Complex<double> u, double k) noexcept | |||
| *++kei = next; | |||
| } | |||
| std::complex<double> last = std::sin (0.5 * u * double_Pi); | |||
| std::complex<double> last = std::sin (0.5 * u * MathConstants<double>::pi); | |||
| for (int i = M - 1; i >= 0; --i) | |||
| last = (1.0 + ke[i + 1]) / (1.0 / last + ke[i + 1] * last); | |||
| @@ -135,7 +135,7 @@ Complex<double> SpecialFunctions::asne (Complex<double> w, double k) noexcept | |||
| for (int i = 1; i <= M; ++i) | |||
| last = 2.0 * last / ((1.0 + ke[i]) * (1.0 + std::sqrt (1.0 - std::pow (ke[i - 1] * last, 2.0)))); | |||
| return 2.0 / double_Pi * std::asin (last); | |||
| return 2.0 / MathConstants<double>::pi * std::asin (last); | |||
| } | |||
| } // namespace dsp | |||
| @@ -39,7 +39,7 @@ double FIR::Coefficients<NumericType>::Coefficients::getMagnitudeForFrequency (d | |||
| auto order = getFilterOrder(); | |||
| Complex<double> numerator = 0.0, factor = 1.0; | |||
| Complex<double> jw = std::exp (-2.0 * double_Pi * frequency * j / theSampleRate); | |||
| Complex<double> jw = std::exp (-MathConstants<double>::twoPi * frequency * j / theSampleRate); | |||
| const auto* coefs = coefficients.begin(); | |||
| @@ -69,7 +69,7 @@ void FIR::Coefficients<NumericType>::Coefficients::getMagnitudeForFrequencyArray | |||
| Complex<double> numerator = 0.0; | |||
| Complex<double> factor = 1.0; | |||
| Complex<double> jw = std::exp (-2.0 * double_Pi * frequencies[i] * j / theSampleRate); | |||
| Complex<double> jw = std::exp (-MathConstants<double>::twoPi * frequencies[i] * j / theSampleRate); | |||
| for (size_t n = 0; n <= order; ++n) | |||
| { | |||
| @@ -92,7 +92,7 @@ double FIR::Coefficients<NumericType>::Coefficients::getPhaseForFrequency (doubl | |||
| Complex<double> numerator = 0.0; | |||
| Complex<double> factor = 1.0; | |||
| Complex<double> jw = std::exp (-2.0 * double_Pi * frequency * j / theSampleRate); | |||
| Complex<double> jw = std::exp (-MathConstants<double>::twoPi * frequency * j / theSampleRate); | |||
| const auto* coefs = coefficients.begin(); | |||
| auto order = getFilterOrder(); | |||
| @@ -122,7 +122,7 @@ void FIR::Coefficients<NumericType>::Coefficients::getPhaseForFrequencyArray (do | |||
| jassert (frequencies[i] >= 0.0 && frequencies[i] <= theSampleRate * 0.5); | |||
| Complex<double> numerator = 0.0, factor = 1.0; | |||
| Complex<double> jw = std::exp (-2.0 * double_Pi * frequencies[i] * j / theSampleRate); | |||
| Complex<double> jw = std::exp (-MathConstants<double>::twoPi * frequencies[i] * j / theSampleRate); | |||
| for (size_t n = 0; n <= order; ++n) | |||
| { | |||
| @@ -349,7 +349,7 @@ double IIR::Coefficients<NumericType>::getMagnitudeForFrequency (double frequenc | |||
| jassert (frequency >= 0 && frequency <= sampleRate * 0.5); | |||
| Complex<double> numerator = 0.0, denominator = 0.0, factor = 1.0; | |||
| Complex<double> jw = std::exp (-2.0 * double_Pi * frequency * j / sampleRate); | |||
| Complex<double> jw = std::exp (-MathConstants<double>::twoPi * frequency * j / sampleRate); | |||
| for (size_t n = 0; n <= order; ++n) | |||
| { | |||
| @@ -384,7 +384,7 @@ void IIR::Coefficients<NumericType>::getMagnitudeForFrequencyArray (const double | |||
| jassert (frequencies[i] >= 0 && frequencies[i] <= sampleRate * 0.5); | |||
| Complex<double> numerator = 0.0, denominator = 0.0, factor = 1.0; | |||
| Complex<double> jw = std::exp (-2.0 * double_Pi * frequencies[i] * j / sampleRate); | |||
| Complex<double> jw = std::exp (-MathConstants<double>::twoPi * frequencies[i] * j / sampleRate); | |||
| for (size_t n = 0; n <= order; ++n) | |||
| { | |||
| @@ -415,7 +415,7 @@ double IIR::Coefficients<NumericType>::getPhaseForFrequency (double frequency, d | |||
| jassert (frequency >= 0 && frequency <= sampleRate * 0.5); | |||
| Complex<double> numerator = 0.0, denominator = 0.0, factor = 1.0; | |||
| Complex<double> jw = std::exp (-2.0 * double_Pi * frequency * j / sampleRate); | |||
| Complex<double> jw = std::exp (-MathConstants<double>::twoPi * frequency * j / sampleRate); | |||
| for (size_t n = 0; n <= order; ++n) | |||
| { | |||
| @@ -453,7 +453,7 @@ void IIR::Coefficients<NumericType>::getPhaseForFrequencyArray (double* frequenc | |||
| jassert (frequencies[i] >= 0 && frequencies[i] <= sampleRate * 0.5); | |||
| Complex<double> numerator = 0.0, denominator = 0.0, factor = 1.0; | |||
| Complex<double> jw = std::exp (-2.0 * double_Pi * frequencies[i] * j * invSampleRate); | |||
| Complex<double> jw = std::exp (-MathConstants<double>::twoPi * frequencies[i] * j * invSampleRate); | |||
| for (size_t n = 0; n <= order; ++n) | |||
| { | |||
| @@ -153,9 +153,9 @@ template <typename Type> | |||
| void LadderFilter<Type>::setSampleRate (Type newValue) noexcept | |||
| { | |||
| jassert (newValue > Type (0)); | |||
| cutoffFreqScaler = Type (-2 * juce::double_Pi) / newValue; | |||
| cutoffFreqScaler = Type (-2.0 * juce::MathConstants<double>::pi) / newValue; | |||
| static constexpr auto smootherRampTimeSec = Type (5e-2); | |||
| static constexpr Type smootherRampTimeSec (0.05); | |||
| cutoffTransformSmoother.reset (newValue, smootherRampTimeSec); | |||
| scaledResonanceSmoother.reset (newValue, smootherRampTimeSec); | |||
| @@ -63,8 +63,10 @@ public: | |||
| { | |||
| if (lookupTableNumPoints != 0) | |||
| { | |||
| auto* table = new LookupTableTransform<NumericType> (function, static_cast <NumericType> (-1.0 * double_Pi), | |||
| static_cast<NumericType> (double_Pi), lookupTableNumPoints); | |||
| auto* table = new LookupTableTransform<NumericType> (function, | |||
| static_cast<NumericType> (-1.0 * MathConstants<double>::pi), | |||
| static_cast<NumericType> (MathConstants<double>::pi), | |||
| lookupTableNumPoints); | |||
| lookupTable = table; | |||
| generator = [table] (NumericType x) { return (*table) (x); }; | |||
| @@ -106,9 +108,9 @@ public: | |||
| SampleType JUCE_VECTOR_CALLTYPE processSample (SampleType) noexcept | |||
| { | |||
| jassert (isInitialised()); | |||
| auto increment = static_cast<NumericType> (2.0 * double_Pi) * frequency.getNextValue() / sampleRate; | |||
| auto value = generator (pos - static_cast<NumericType> (double_Pi)); | |||
| pos = std::fmod (pos + increment, static_cast<NumericType> (2.0 * double_Pi)); | |||
| auto increment = static_cast<NumericType> (MathConstants<double>::twoPi) * frequency.getNextValue() / sampleRate; | |||
| auto value = generator (pos - static_cast<NumericType> (MathConstants<double>::pi)); | |||
| pos = std::fmod (pos + increment, static_cast<NumericType> (MathConstants<double>::twoPi)); | |||
| return value; | |||
| } | |||
| @@ -126,7 +128,7 @@ public: | |||
| auto len = outBlock.getNumSamples(); | |||
| auto numChannels = outBlock.getNumChannels(); | |||
| auto baseIncrement = static_cast<NumericType> (2.0 * double_Pi) / sampleRate; | |||
| auto baseIncrement = static_cast<NumericType> (MathConstants<double>::twoPi) / sampleRate; | |||
| if (frequency.isSmoothing()) | |||
| { | |||
| @@ -134,9 +136,10 @@ public: | |||
| for (size_t i = 0; i < len; ++i) | |||
| { | |||
| buffer[i] = pos - static_cast<NumericType> (double_Pi); | |||
| buffer[i] = pos - static_cast<NumericType> (MathConstants<double>::pi); | |||
| pos = std::fmod (pos + (baseIncrement * frequency.getNextValue()), static_cast<NumericType> (2.0 * double_Pi)); | |||
| pos = std::fmod (pos + (baseIncrement * frequency.getNextValue()), | |||
| static_cast<NumericType> (MathConstants<double>::twoPi)); | |||
| } | |||
| for (size_t ch = 0; ch < numChannels; ++ch) | |||
| @@ -158,12 +161,13 @@ public: | |||
| for (size_t i = 0; i < len; ++i) | |||
| { | |||
| dst[i] = generator (p - static_cast<NumericType> (double_Pi)); | |||
| p = std::fmod (p + freq, static_cast<NumericType> (2.0 * double_Pi)); | |||
| dst[i] = generator (p - static_cast<NumericType> (MathConstants<double>::pi)); | |||
| p = std::fmod (p + freq, static_cast<NumericType> (MathConstants<double>::twoPi)); | |||
| } | |||
| } | |||
| pos = std::fmod (pos + freq * static_cast<NumericType> (len), static_cast<NumericType> (2.0 * double_Pi)); | |||
| pos = std::fmod (pos + freq * static_cast<NumericType> (len), | |||
| static_cast<NumericType> (MathConstants<double>::twoPi)); | |||
| } | |||
| } | |||
| @@ -286,11 +286,11 @@ public: | |||
| { | |||
| auto structureUp = dsp::FilterDesign<SampleType>::designIIRLowpassHalfBandPolyphaseAllpassMethod (normalizedTransitionWidthUp, stopbandAttenuationdBUp); | |||
| dsp::IIR::Coefficients<SampleType> coeffsUp = getCoefficients (structureUp); | |||
| latency = static_cast<SampleType> (-(coeffsUp.getPhaseForFrequency (0.0001, 1.0)) / (0.0001 * 2 * double_Pi)); | |||
| latency = static_cast<SampleType> (-(coeffsUp.getPhaseForFrequency (0.0001, 1.0)) / (0.0001 * MathConstants<double>::twoPi)); | |||
| auto structureDown = dsp::FilterDesign<SampleType>::designIIRLowpassHalfBandPolyphaseAllpassMethod (normalizedTransitionWidthDown, stopbandAttenuationdBDown); | |||
| dsp::IIR::Coefficients<SampleType> coeffsDown = getCoefficients (structureDown); | |||
| latency += static_cast<SampleType> (-(coeffsDown.getPhaseForFrequency (0.0001, 1.0)) / (0.0001 * 2 * double_Pi)); | |||
| latency += static_cast<SampleType> (-(coeffsDown.getPhaseForFrequency (0.0001, 1.0)) / (0.0001 * MathConstants<double>::twoPi)); | |||
| for (auto i = 0; i < structureUp.directPath.size(); i++) | |||
| coefficientsUp.add (structureUp.directPath[i].coefficients[0]); | |||
| @@ -187,7 +187,7 @@ namespace StateVariableFilter | |||
| void setCutOffFrequency (double sampleRate, NumericType frequency, | |||
| NumericType resonance = static_cast<NumericType> (1.0 / std::sqrt (2.0))) noexcept | |||
| { | |||
| g = static_cast<NumericType> (std::tan (double_Pi * frequency / sampleRate)); | |||
| g = static_cast<NumericType> (std::tan (MathConstants<double>::pi * frequency / sampleRate)); | |||
| R2 = static_cast<NumericType> (1.0 / resonance); | |||
| h = static_cast<NumericType> (1.0 / (1.0 + R2 * g + g * g)); | |||
| } | |||
| @@ -204,7 +204,7 @@ namespace StateVariableFilter | |||
| Parameters& operator= (const Parameters& o) noexcept { g = o.g; R2 = o.R2; h = o.h; return *this; } | |||
| //============================================================================== | |||
| NumericType g = static_cast<NumericType> (std::tan (double_Pi * 200.0 / 44100.0)); | |||
| NumericType g = static_cast<NumericType> (std::tan (MathConstants<double>::pi * 200.0 / 44100.0)); | |||
| NumericType R2 = static_cast<NumericType> (std::sqrt (2.0)); | |||
| NumericType h = static_cast<NumericType> (1.0 / (1.0 + R2 * g + g * g)); | |||
| }; | |||
| @@ -631,7 +631,7 @@ void Path::addPieSegment (const float x, const float y, | |||
| startNewSubPath (centre.getPointOnCircumference (radiusX, radiusY, fromRadians)); | |||
| addArc (x, y, width, height, fromRadians, toRadians); | |||
| if (std::abs (fromRadians - toRadians) > float_Pi * 1.999f) | |||
| if (std::abs (fromRadians - toRadians) > MathConstants<float>::pi * 1.999f) | |||
| { | |||
| closeSubPath(); | |||
| @@ -714,7 +714,7 @@ void Path::addPolygon (Point<float> centre, int numberOfSides, | |||
| if (numberOfSides > 1) | |||
| { | |||
| auto angleBetweenPoints = float_Pi * 2.0f / numberOfSides; | |||
| auto angleBetweenPoints = MathConstants<float>::twoPi / numberOfSides; | |||
| for (int i = 0; i < numberOfSides; ++i) | |||
| { | |||
| @@ -738,7 +738,7 @@ void Path::addStar (Point<float> centre, int numberOfPoints, float innerRadius, | |||
| if (numberOfPoints > 1) | |||
| { | |||
| auto angleBetweenPoints = float_Pi * 2.0f / numberOfPoints; | |||
| auto angleBetweenPoints = MathConstants<float>::twoPi / numberOfPoints; | |||
| for (int i = 0; i < numberOfPoints; ++i) | |||
| { | |||
| @@ -784,7 +784,7 @@ void Path::addBubble (Rectangle<float> bodyArea, | |||
| } | |||
| lineTo (bodyArea.getRight() - cornerSizeW, bodyArea.getY()); | |||
| addArc (bodyArea.getRight() - cornerSizeW2, bodyArea.getY(), cornerSizeW2, cornerSizeH2, 0, float_Pi * 0.5f); | |||
| addArc (bodyArea.getRight() - cornerSizeW2, bodyArea.getY(), cornerSizeW2, cornerSizeH2, 0, MathConstants<float>::pi * 0.5f); | |||
| if (Rectangle<float> (bodyArea.getRight(), targetLimit.getY(), | |||
| maximumArea.getRight() - bodyArea.getRight(), targetLimit.getHeight()).contains (arrowTip)) | |||
| @@ -795,7 +795,7 @@ void Path::addBubble (Rectangle<float> bodyArea, | |||
| } | |||
| lineTo (bodyArea.getRight(), bodyArea.getBottom() - cornerSizeH); | |||
| addArc (bodyArea.getRight() - cornerSizeW2, bodyArea.getBottom() - cornerSizeH2, cornerSizeW2, cornerSizeH2, float_Pi * 0.5f, float_Pi); | |||
| addArc (bodyArea.getRight() - cornerSizeW2, bodyArea.getBottom() - cornerSizeH2, cornerSizeW2, cornerSizeH2, MathConstants<float>::pi * 0.5f, MathConstants<float>::pi); | |||
| if (Rectangle<float> (targetLimit.getX(), bodyArea.getBottom(), | |||
| targetLimit.getWidth(), maximumArea.getBottom() - bodyArea.getBottom()).contains (arrowTip)) | |||
| @@ -806,7 +806,7 @@ void Path::addBubble (Rectangle<float> bodyArea, | |||
| } | |||
| lineTo (bodyArea.getX() + cornerSizeW, bodyArea.getBottom()); | |||
| addArc (bodyArea.getX(), bodyArea.getBottom() - cornerSizeH2, cornerSizeW2, cornerSizeH2, float_Pi, float_Pi * 1.5f); | |||
| addArc (bodyArea.getX(), bodyArea.getBottom() - cornerSizeH2, cornerSizeW2, cornerSizeH2, MathConstants<float>::pi, MathConstants<float>::pi * 1.5f); | |||
| if (Rectangle<float> (maximumArea.getX(), targetLimit.getY(), | |||
| bodyArea.getX() - maximumArea.getX(), targetLimit.getHeight()).contains (arrowTip)) | |||
| @@ -817,7 +817,7 @@ void Path::addBubble (Rectangle<float> bodyArea, | |||
| } | |||
| lineTo (bodyArea.getX(), bodyArea.getY() + cornerSizeH); | |||
| addArc (bodyArea.getX(), bodyArea.getY(), cornerSizeW2, cornerSizeH2, float_Pi * 1.5f, float_Pi * 2.0f - 0.05f); | |||
| addArc (bodyArea.getX(), bodyArea.getY(), cornerSizeW2, cornerSizeH2, MathConstants<float>::pi * 1.5f, MathConstants<float>::twoPi - 0.05f); | |||
| closeSubPath(); | |||
| } | |||
| @@ -243,13 +243,13 @@ namespace PathStrokeHelpers | |||
| if (std::abs (angle1 - angle2) > angleIncrement) | |||
| { | |||
| if (angle2 > angle1 + float_Pi | |||
| || (angle2 < angle1 && angle2 >= angle1 - float_Pi)) | |||
| if (angle2 > angle1 + MathConstants<float>::pi | |||
| || (angle2 < angle1 && angle2 >= angle1 - MathConstants<float>::pi)) | |||
| { | |||
| if (angle2 > angle1) | |||
| angle2 -= float_Pi * 2.0f; | |||
| angle2 -= MathConstants<float>::twoPi; | |||
| jassert (angle1 <= angle2 + float_Pi); | |||
| jassert (angle1 <= angle2 + MathConstants<float>::pi); | |||
| angle1 -= angleIncrement; | |||
| while (angle1 > angle2) | |||
| @@ -263,9 +263,9 @@ namespace PathStrokeHelpers | |||
| else | |||
| { | |||
| if (angle1 > angle2) | |||
| angle1 -= float_Pi * 2.0f; | |||
| angle1 -= MathConstants<float>::twoPi; | |||
| jassert (angle1 >= angle2 - float_Pi); | |||
| jassert (angle1 >= angle2 - MathConstants<float>::pi); | |||
| angle1 += angleIncrement; | |||
| while (angle1 < angle2) | |||
| @@ -31,7 +31,7 @@ ArrowButton::ArrowButton (const String& name, float arrowDirectionInRadians, Col | |||
| : Button (name), colour (arrowColour) | |||
| { | |||
| path.addTriangle (0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.5f); | |||
| path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * arrowDirectionInRadians, 0.5f, 0.5f)); | |||
| path.applyTransform (AffineTransform::rotation (MathConstants<float>::twoPi * arrowDirectionInRadians, 0.5f, 0.5f)); | |||
| } | |||
| ArrowButton::~ArrowButton() {} | |||
| @@ -1611,10 +1611,10 @@ private: | |||
| return result; | |||
| } | |||
| static void endpointToCentreParameters (const double x1, const double y1, | |||
| const double x2, const double y2, | |||
| const double angle, | |||
| const bool largeArc, const bool sweep, | |||
| static void endpointToCentreParameters (double x1, double y1, | |||
| double x2, double y2, | |||
| double angle, | |||
| bool largeArc, bool sweep, | |||
| double& rx, double& ry, | |||
| double& centreX, double& centreY, | |||
| double& startAngle, double& deltaAngle) noexcept | |||
| @@ -1669,7 +1669,7 @@ private: | |||
| if (uy < 0) | |||
| startAngle = -startAngle; | |||
| startAngle += double_Pi * 0.5; | |||
| startAngle += MathConstants<double>::pi * 0.5; | |||
| deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy)) | |||
| / (length * juce_hypot (vx, vy)))); | |||
| @@ -1680,15 +1680,15 @@ private: | |||
| if (sweep) | |||
| { | |||
| if (deltaAngle < 0) | |||
| deltaAngle += double_Pi * 2.0; | |||
| deltaAngle += MathConstants<double>::twoPi; | |||
| } | |||
| else | |||
| { | |||
| if (deltaAngle > 0) | |||
| deltaAngle -= double_Pi * 2.0; | |||
| deltaAngle -= MathConstants<double>::twoPi; | |||
| } | |||
| deltaAngle = fmod (deltaAngle, double_Pi * 2.0); | |||
| deltaAngle = fmod (deltaAngle, MathConstants<double>::twoPi); | |||
| } | |||
| SVGState& operator= (const SVGState&) JUCE_DELETED_FUNCTION; | |||
| @@ -623,9 +623,9 @@ void LookAndFeel_V2::drawSpinningWaitAnimation (Graphics& g, const Colour& colou | |||
| for (uint32 i = 0; i < 12; ++i) | |||
| { | |||
| const uint32 n = (i + 12 - animationIndex) % 12; | |||
| g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f)); | |||
| g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f)) | |||
| g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f)); | |||
| g.fillPath (p, AffineTransform::rotation (i * (MathConstants<float>::pi / 6.0f)) | |||
| .translated (cx, cy)); | |||
| } | |||
| } | |||
| @@ -2024,16 +2024,16 @@ void LookAndFeel_V2::drawGroupComponentOutline (Graphics& g, int width, int heig | |||
| p.startNewSubPath (x + textX + textW, y); | |||
| p.lineTo (x + w - cs, y); | |||
| p.addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f); | |||
| p.addArc (x + w - cs2, y, cs2, cs2, 0, MathConstants<float>::pi * 0.5f); | |||
| p.lineTo (x + w, y + h - cs); | |||
| p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi); | |||
| p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, MathConstants<float>::pi * 0.5f, MathConstants<float>::pi); | |||
| p.lineTo (x + cs, y + h); | |||
| p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f); | |||
| p.addArc (x, y + h - cs2, cs2, cs2, MathConstants<float>::pi, MathConstants<float>::pi * 1.5f); | |||
| p.lineTo (x, y + cs); | |||
| p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f); | |||
| p.addArc (x, y, cs2, cs2, MathConstants<float>::pi * 1.5f, MathConstants<float>::twoPi); | |||
| p.lineTo (x + textX, y); | |||
| const float alpha = group.isEnabled() ? 1.0f : 0.5f; | |||
| @@ -2207,8 +2207,8 @@ void LookAndFeel_V2::drawTabButtonText (TabBarButton& button, Graphics& g, bool | |||
| switch (button.getTabbedButtonBar().getOrientation()) | |||
| { | |||
| case TabbedButtonBar::TabsAtLeft: t = t.rotated (float_Pi * -0.5f).translated (area.getX(), area.getBottom()); break; | |||
| case TabbedButtonBar::TabsAtRight: t = t.rotated (float_Pi * 0.5f).translated (area.getRight(), area.getY()); break; | |||
| case TabbedButtonBar::TabsAtLeft: t = t.rotated (MathConstants<float>::pi * -0.5f).translated (area.getX(), area.getBottom()); break; | |||
| case TabbedButtonBar::TabsAtRight: t = t.rotated (MathConstants<float>::pi * 0.5f).translated (area.getRight(), area.getY()); break; | |||
| case TabbedButtonBar::TabsAtTop: | |||
| case TabbedButtonBar::TabsAtBottom: t = t.translated (area.getX(), area.getY()); break; | |||
| default: jassertfalse; break; | |||
| @@ -2948,7 +2948,7 @@ void LookAndFeel_V2::drawGlassPointer (Graphics& g, | |||
| p.lineTo (x, y + diameter * 0.6f); | |||
| p.closeSubPath(); | |||
| p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f)); | |||
| p.applyTransform (AffineTransform::rotation (direction * (MathConstants<float>::pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f)); | |||
| { | |||
| ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y, | |||
| @@ -259,8 +259,8 @@ void LookAndFeel_V3::drawTabButton (TabBarButton& button, Graphics& g, bool isMo | |||
| switch (o) | |||
| { | |||
| case TabbedButtonBar::TabsAtLeft: t = t.rotated (float_Pi * -0.5f).translated (area.getX(), area.getBottom()); break; | |||
| case TabbedButtonBar::TabsAtRight: t = t.rotated (float_Pi * 0.5f).translated (area.getRight(), area.getY()); break; | |||
| case TabbedButtonBar::TabsAtLeft: t = t.rotated (MathConstants<float>::pi * -0.5f).translated (area.getX(), area.getBottom()); break; | |||
| case TabbedButtonBar::TabsAtRight: t = t.rotated (MathConstants<float>::pi * 0.5f).translated (area.getRight(), area.getY()); break; | |||
| case TabbedButtonBar::TabsAtTop: | |||
| case TabbedButtonBar::TabsAtBottom: t = t.translated (area.getX(), area.getY()); break; | |||
| default: jassertfalse; break; | |||
| @@ -569,7 +569,7 @@ void LookAndFeel_V4::drawCircularProgressBar (Graphics& g, ProgressBar& progress | |||
| barBounds.getWidth() * 0.5f, | |||
| barBounds.getHeight() * 0.5f, 0.0f, | |||
| 0.0f, | |||
| 2.0f * float_Pi, | |||
| MathConstants<float>::twoPi, | |||
| true); | |||
| g.strokePath (arcPath2, PathStrokeType (4.0f)); | |||
| @@ -584,7 +584,7 @@ void LookAndFeel_V4::drawCircularProgressBar (Graphics& g, ProgressBar& progress | |||
| degreesToRadians (endInDegrees), | |||
| true); | |||
| arcPath.applyTransform (AffineTransform::rotation (normalisedRotation * float_Pi * 2.25f, barBounds.getCentreX(), barBounds.getCentreY())); | |||
| arcPath.applyTransform (AffineTransform::rotation (normalisedRotation * MathConstants<float>::pi * 2.25f, barBounds.getCentreX(), barBounds.getCentreY())); | |||
| g.strokePath (arcPath, PathStrokeType (4.0f)); | |||
| if (progressText.isNotEmpty()) | |||
| @@ -1071,8 +1071,8 @@ void LookAndFeel_V4::drawRotarySlider (Graphics& g, int x, int y, int width, int | |||
| } | |||
| auto thumbWidth = lineW * 2.0f; | |||
| Point<float> thumbPoint (bounds.getCentreX() + arcRadius * std::cos (toAngle - float_Pi * 0.5f), | |||
| bounds.getCentreY() + arcRadius * std::sin (toAngle - float_Pi * 0.5f)); | |||
| Point<float> thumbPoint (bounds.getCentreX() + arcRadius * std::cos (toAngle - MathConstants<float>::pi * 0.5f), | |||
| bounds.getCentreY() + arcRadius * std::sin (toAngle - MathConstants<float>::pi * 0.5f)); | |||
| g.setColour (slider.findColour (Slider::thumbColourId)); | |||
| g.fillEllipse (Rectangle<float> (thumbWidth, thumbWidth).withCentre (thumbPoint)); | |||
| @@ -1089,7 +1089,7 @@ void LookAndFeel_V4::drawPointer (Graphics& g, const float x, const float y, con | |||
| p.lineTo (x, y + diameter * 0.6f); | |||
| p.closeSubPath(); | |||
| p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f)); | |||
| p.applyTransform (AffineTransform::rotation (direction * (MathConstants<float>::pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f)); | |||
| g.setColour (colour); | |||
| g.fillPath (p); | |||
| @@ -130,8 +130,8 @@ int MouseEvent::getMouseDownScreenX() const { return getMous | |||
| int MouseEvent::getMouseDownScreenY() const { return getMouseDownScreenPosition().y; } | |||
| bool MouseEvent::isPressureValid() const noexcept { return pressure > 0.0f && pressure < 1.0f; } | |||
| bool MouseEvent::isOrientationValid() const noexcept { return orientation >= 0.0f && orientation <= 2.0f * float_Pi; } | |||
| bool MouseEvent::isRotationValid() const noexcept { return rotation >= 0 && rotation <= 2.0f * float_Pi; } | |||
| bool MouseEvent::isOrientationValid() const noexcept { return orientation >= 0.0f && orientation <= MathConstants<float>::twoPi; } | |||
| bool MouseEvent::isRotationValid() const noexcept { return rotation >= 0 && rotation <= MathConstants<float>::twoPi; } | |||
| bool MouseEvent::isTiltValid (bool isX) const noexcept { return isX ? (tiltX >= -1.0f && tiltX <= 1.0f) : (tiltY >= -1.0f && tiltY <= 1.0f); } | |||
| //============================================================================== | |||
| @@ -106,8 +106,8 @@ public: | |||
| } | |||
| bool isPressureValid() const noexcept { return pressure >= 0.0f && pressure <= 1.0f; } | |||
| bool isOrientationValid() const noexcept { return orientation >= 0.0f && orientation <= 2.0f * float_Pi; } | |||
| bool isRotationValid() const noexcept { return rotation >= 0.0f && rotation <= 2.0f * float_Pi; } | |||
| bool isOrientationValid() const noexcept { return orientation >= 0.0f && orientation <= MathConstants<float>::twoPi; } | |||
| bool isRotationValid() const noexcept { return rotation >= 0.0f && rotation <= MathConstants<float>::twoPi; } | |||
| bool isTiltValid (bool isX) const noexcept { return isX ? (tiltX >= -1.0f && tiltX <= 1.0f) : (tiltY >= -1.0f && tiltY <= 1.0f); } | |||
| //============================================================================== | |||
| @@ -39,8 +39,8 @@ public: | |||
| style (sliderStyle), | |||
| textBoxPos (textBoxPosition) | |||
| { | |||
| rotaryParams.startAngleRadians = float_Pi * 1.2f; | |||
| rotaryParams.endAngleRadians = float_Pi * 2.8f; | |||
| rotaryParams.startAngleRadians = MathConstants<float>::pi * 1.2f; | |||
| rotaryParams.endAngleRadians = MathConstants<float>::pi * 2.8f; | |||
| rotaryParams.stopAtEnd = true; | |||
| } | |||
| @@ -676,16 +676,16 @@ public: | |||
| auto angle = std::atan2 ((double) dx, (double) -dy); | |||
| while (angle < 0.0) | |||
| angle += double_Pi * 2.0; | |||
| angle += MathConstants<double>::twoPi; | |||
| if (rotaryParams.stopAtEnd && e.mouseWasDraggedSinceMouseDown()) | |||
| { | |||
| if (std::abs (angle - lastAngle) > double_Pi) | |||
| if (std::abs (angle - lastAngle) > MathConstants<double>::pi) | |||
| { | |||
| if (angle >= lastAngle) | |||
| angle -= double_Pi * 2.0; | |||
| angle -= MathConstants<double>::twoPi; | |||
| else | |||
| angle += double_Pi * 2.0; | |||
| angle += MathConstants<double>::twoPi; | |||
| } | |||
| if (angle >= lastAngle) | |||
| @@ -696,7 +696,7 @@ public: | |||
| else | |||
| { | |||
| while (angle < rotaryParams.startAngleRadians) | |||
| angle += double_Pi * 2.0; | |||
| angle += MathConstants<double>::twoPi; | |||
| if (angle > rotaryParams.endAngleRadians) | |||
| { | |||
| @@ -777,9 +777,9 @@ public: | |||
| if (speed != 0.0) | |||
| { | |||
| speed = 0.2 * velocityModeSensitivity | |||
| * (1.0 + std::sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset | |||
| + jmax (0.0, (double) (speed - velocityModeThreshold)) | |||
| / maxSpeed)))); | |||
| * (1.0 + std::sin (MathConstants<double>::pi * (1.5 + jmin (0.5, velocityModeOffset | |||
| + jmax (0.0, (double) (speed - velocityModeThreshold)) | |||
| / maxSpeed)))); | |||
| if (mouseDiff < 0) | |||
| speed = -speed; | |||
| @@ -1321,8 +1321,8 @@ public: | |||
| static double smallestAngleBetween (double a1, double a2) noexcept | |||
| { | |||
| return jmin (std::abs (a1 - a2), | |||
| std::abs (a1 + double_Pi * 2.0 - a2), | |||
| std::abs (a2 + double_Pi * 2.0 - a1)); | |||
| std::abs (a1 + MathConstants<double>::twoPi - a2), | |||
| std::abs (a2 + MathConstants<double>::twoPi - a1)); | |||
| } | |||
| }; | |||
| @@ -1370,7 +1370,8 @@ void Slider::setRotaryParameters (RotaryParameters p) noexcept | |||
| { | |||
| // make sure the values are sensible.. | |||
| jassert (p.startAngleRadians >= 0 && p.endAngleRadians >= 0); | |||
| jassert (p.startAngleRadians < float_Pi * 4.0f && p.endAngleRadians < float_Pi * 4.0f); | |||
| jassert (p.startAngleRadians < MathConstants<float>::pi * 4.0f | |||
| && p.endAngleRadians < MathConstants<float>::pi * 4.0f); | |||
| pimpl->rotaryParams = p; | |||
| } | |||