The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. namespace dsp
  22. {
  23. static CommonSmoothedValueTests <LogRampedValue <float>> commonLogRampedValueTests;
  24. class LogRampedValueTests : public UnitTest
  25. {
  26. public:
  27. LogRampedValueTests()
  28. : UnitTest ("LogRampedValueTests", "DSP")
  29. {}
  30. void runTest() override
  31. {
  32. beginTest ("Curve");
  33. {
  34. Array<double> levels = { -0.12243, -1.21245, -12.2342, -22.4683, -30.0, -61.18753 };
  35. for (auto level : levels)
  36. {
  37. Array<Range<double>> ranges = { Range<double> (0.0, 1.0),
  38. Range<double> (-2.345, 0.0),
  39. Range<double> (-2.63, 3.56),
  40. Range<double> (3.3, -0.2) };
  41. for (auto range : ranges)
  42. {
  43. LogRampedValue<double> slowStart { range.getStart() } , fastStart { range.getEnd() };
  44. auto numSamples = 12;
  45. slowStart.reset (numSamples);
  46. fastStart.reset (numSamples);
  47. slowStart.setLogParameters (level, true);
  48. fastStart.setLogParameters (level, false);
  49. slowStart.setTargetValue (range.getEnd());
  50. fastStart.setTargetValue (range.getStart());
  51. AudioBuffer<double> results (2, numSamples + 1);
  52. results.setSample (0, 0, slowStart.getCurrentValue());
  53. results.setSample (1, 0, fastStart.getCurrentValue());
  54. for (int i = 1; i < results.getNumSamples(); ++i)
  55. {
  56. results.setSample (0, i, slowStart.getNextValue());
  57. results.setSample (1, i, fastStart.getNextValue());
  58. }
  59. for (int i = 0; i < results.getNumSamples(); ++i)
  60. expectWithinAbsoluteError (results.getSample (0, i),
  61. results.getSample (1, results.getNumSamples() - (i + 1)),
  62. 1.0e-7);
  63. auto expectedMidpoint = range.getStart() + (range.getLength() * Decibels::decibelsToGain (level));
  64. expectWithinAbsoluteError (results.getSample (0, numSamples / 2),
  65. expectedMidpoint,
  66. 1.0e-7);
  67. }
  68. }
  69. }
  70. }
  71. };
  72. static LogRampedValueTests LogRampedValueTests;
  73. } // namespace dsp
  74. } // namespace juce