Audio plugin host https://kx.studio/carla
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.

97 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
  19. {
  20. namespace dsp
  21. {
  22. static CommonSmoothedValueTests <LogRampedValue <float>> commonLogRampedValueTests;
  23. class LogRampedValueTests : public UnitTest
  24. {
  25. public:
  26. LogRampedValueTests()
  27. : UnitTest ("LogRampedValueTests", UnitTestCategories::dsp)
  28. {}
  29. void runTest() override
  30. {
  31. beginTest ("Curve");
  32. {
  33. Array<double> levels = { -0.12243, -1.21245, -12.2342, -22.4683, -30.0, -61.18753 };
  34. for (auto level : levels)
  35. {
  36. Array<Range<double>> ranges = { Range<double> (0.0, 1.0),
  37. Range<double> (-2.345, 0.0),
  38. Range<double> (-2.63, 3.56),
  39. Range<double> (3.3, -0.2) };
  40. for (auto range : ranges)
  41. {
  42. LogRampedValue<double> slowStart { range.getStart() } , fastStart { range.getEnd() };
  43. auto numSamples = 12;
  44. slowStart.reset (numSamples);
  45. fastStart.reset (numSamples);
  46. slowStart.setLogParameters (level, true);
  47. fastStart.setLogParameters (level, false);
  48. slowStart.setTargetValue (range.getEnd());
  49. fastStart.setTargetValue (range.getStart());
  50. AudioBuffer<double> results (2, numSamples + 1);
  51. results.setSample (0, 0, slowStart.getCurrentValue());
  52. results.setSample (1, 0, fastStart.getCurrentValue());
  53. for (int i = 1; i < results.getNumSamples(); ++i)
  54. {
  55. results.setSample (0, i, slowStart.getNextValue());
  56. results.setSample (1, i, fastStart.getNextValue());
  57. }
  58. for (int i = 0; i < results.getNumSamples(); ++i)
  59. expectWithinAbsoluteError (results.getSample (0, i),
  60. results.getSample (1, results.getNumSamples() - (i + 1)),
  61. 1.0e-7);
  62. auto expectedMidpoint = range.getStart() + (range.getLength() * Decibels::decibelsToGain (level));
  63. expectWithinAbsoluteError (results.getSample (0, numSamples / 2),
  64. expectedMidpoint,
  65. 1.0e-7);
  66. }
  67. }
  68. }
  69. }
  70. };
  71. static LogRampedValueTests LogRampedValueTests;
  72. } // namespace dsp
  73. } // namespace juce