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.

93 lines
3.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. namespace juce
  18. {
  19. #if JUCE_UNIT_TESTS
  20. static CommonSmoothedValueTests <SmoothedValue<float, ValueSmoothingTypes::Linear>> commonLinearSmoothedValueTests;
  21. static CommonSmoothedValueTests <SmoothedValue<float, ValueSmoothingTypes::Multiplicative>> commonMultiplicativeSmoothedValueTests;
  22. class SmoothedValueTests : public UnitTest
  23. {
  24. public:
  25. SmoothedValueTests()
  26. : UnitTest ("SmoothedValueTests", UnitTestCategories::smoothedValues)
  27. {}
  28. void runTest() override
  29. {
  30. beginTest ("Linear moving target");
  31. {
  32. SmoothedValue<float, ValueSmoothingTypes::Linear> sv;
  33. sv.reset (12);
  34. float initialValue = 0.0f;
  35. sv.setCurrentAndTargetValue (initialValue);
  36. sv.setTargetValue (1.0f);
  37. auto delta = sv.getNextValue() - initialValue;
  38. sv.skip (6);
  39. auto newInitialValue = sv.getCurrentValue();
  40. sv.setTargetValue (newInitialValue + 2.0f);
  41. auto doubleDelta = sv.getNextValue() - newInitialValue;
  42. expectWithinAbsoluteError (doubleDelta, delta * 2.0f, 1.0e-7f);
  43. }
  44. beginTest ("Multiplicative curve");
  45. {
  46. SmoothedValue<double, ValueSmoothingTypes::Multiplicative> sv;
  47. auto numSamples = 12;
  48. AudioBuffer<double> values (2, numSamples + 1);
  49. sv.reset (numSamples);
  50. sv.setCurrentAndTargetValue (1.0);
  51. sv.setTargetValue (2.0f);
  52. values.setSample (0, 0, sv.getCurrentValue());
  53. for (int i = 1; i < values.getNumSamples(); ++i)
  54. values.setSample (0, i, sv.getNextValue());
  55. sv.setTargetValue (1.0f);
  56. values.setSample (1, values.getNumSamples() - 1, sv.getCurrentValue());
  57. for (int i = values.getNumSamples() - 2; i >= 0 ; --i)
  58. values.setSample (1, i, sv.getNextValue());
  59. for (int i = 0; i < values.getNumSamples(); ++i)
  60. expectWithinAbsoluteError (values.getSample (0, i), values.getSample (1, i), 1.0e-9);
  61. }
  62. }
  63. };
  64. static SmoothedValueTests smoothedValueTests;
  65. #endif
  66. } // namespace juce