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.

94 lines
3.5KB

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