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.

61 lines
1.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. namespace dsp
  16. {
  17. /**
  18. Represents an increasing phase value between 0 and 2*pi.
  19. This represents a value which can be incremented, and which wraps back to 0 when it
  20. goes past 2 * pi.
  21. @tags{DSP}
  22. */
  23. template <typename Type>
  24. struct Phase
  25. {
  26. /** Resets the phase to 0. */
  27. void reset() noexcept { phase = 0; }
  28. /** Returns the current value, and increments the phase by the given increment.
  29. The increment must be a positive value, it can't go backwards!
  30. The new value of the phase after calling this function will be (phase + increment) % (2 * pi).
  31. */
  32. Type advance (Type increment) noexcept
  33. {
  34. jassert (increment >= 0); // cannot run this value backwards!
  35. auto last = phase;
  36. auto next = last + increment;
  37. while (next >= MathConstants<Type>::twoPi)
  38. next -= MathConstants<Type>::twoPi;
  39. phase = next;
  40. return last;
  41. }
  42. Type phase = 0;
  43. };
  44. } // namespace dsp
  45. } // namespace juce