OpenShot Library | OpenShotAudio 0.2.2
juce_Phase.h
1
2/** @weakgroup juce_dsp-maths
3 * @{
4 */
5/*
6 ==============================================================================
7
8 This file is part of the JUCE library.
9 Copyright (c) 2017 - ROLI Ltd.
10
11 JUCE is an open source library subject to commercial or open-source
12 licensing.
13
14 By using JUCE, you agree to the terms of both the JUCE 5 End-User License
15 Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
16 27th April 2017).
17
18 End User License Agreement: www.juce.com/juce-5-licence
19 Privacy Policy: www.juce.com/juce-5-privacy-policy
20
21 Or: You may also use this code under the terms of the GPL v3 (see
22 www.gnu.org/licenses).
23
24 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
25 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
26 DISCLAIMED.
27
28 ==============================================================================
29*/
30
31namespace juce
32{
33namespace dsp
34{
35
36/**
37 Represents an increasing phase value between 0 and 2*pi.
38
39 This represents a value which can be incremented, and which wraps back to 0 when it
40 goes past 2 * pi.
41
42 @tags{DSP}
43*/
44template <typename Type>
45struct Phase
46{
47 /** Resets the phase to 0. */
48 void reset() noexcept { phase = 0; }
49
50 /** Returns the current value, and increments the phase by the given increment.
51 The increment must be a positive value, it can't go backwards!
52 The new value of the phase after calling this function will be (phase + increment) % (2 * pi).
53 */
54 Type advance (Type increment) noexcept
55 {
56 jassert (increment >= 0); // cannot run this value backwards!
57
58 auto last = phase;
59 auto next = last + increment;
60
61 while (next >= MathConstants<Type>::twoPi)
63
64 phase = next;
65 return last;
66 }
67
68 Type phase = 0;
69};
70
71} // namespace dsp
72} // namespace juce
73
74/** @}*/
Commonly used mathematical constants.
Represents an increasing phase value between 0 and 2*pi.
Definition: juce_Phase.h:46
void reset() noexcept
Resets the phase to 0.
Definition: juce_Phase.h:48
Type advance(Type increment) noexcept
Returns the current value, and increments the phase by the given increment.
Definition: juce_Phase.h:54