phase_iterator
Overview
Read phase first for prerequisite information. |
phase_iterator
is a class that iterates over the phase
with an iteration step size specified by the given frequency and sampling rate. phase_iterator
holds two phase
members, the phase accumulator and the phase step size.
The phase
accumulator, keeps track of the current phase value for the waveform. Initially, the accumulator is set to an arbitrary starting phase, usually 0. For each sample of the waveform, the phase
step size value is added to the current phase accumulator, which inherently rewraps the value when the next phase exceeds 2π.
Declaration
struct phase_iterator
{
constexpr phase_iterator();
constexpr phase_iterator(frequency freq, float sps);
constexpr phase_iterator operator++(int);
constexpr phase_iterator& operator++();
constexpr phase_iterator operator--(int);
constexpr phase_iterator& operator--();
constexpr phase_iterator& operator=(phase rhs);
constexpr phase_iterator& operator=(phase_iterator const& rhs) = default;
constexpr void set(frequency freq, float sps);
constexpr bool first() const;
constexpr bool last() const;
constexpr phase_iterator begin() const;
constexpr phase_iterator end() const;
constexpr phase_iterator middle() const;
phase _phase, _step;
};
Expressions
Notation
freq
-
Object of type
frequency
sps
-
Floating point value representing samples per second
i
,a
,b
-
Objects of type
phase_iterator
p
-
Objects of type
phase
Constructors and Assignments
Expression | Semantics |
---|---|
|
Default construct a |
|
Construct a |
|
Copy construct from |
|
Assign |
|
Assign |
C++ brace initialization may also be used. |
Iteration
Expression | Semantics | Return Type |
---|---|---|
|
Post increment. Returns a copy of the iterator made prior to increment. |
|
|
Pre increment. Increment and return a reference to the iterator. |
|
|
Post decrement. Returns a copy of the iterator made prior to decrement. |
|
|
Pre decrement. Decrement and return a reference to the iterator. |
|
Mutator
Expression | Semantics | Return Type |
---|---|---|
|
Modify a |
|
Modifying The State
When modifying a phase_iterator
with a new frequency, freq
, and sampling rate, sps
, only the phase step size will be changed. To prevent discontinuities, the phase accumulator will not be touched. This means that the phase accumulator will continue to count up from its previous value, while the updated phase step size will determine the new frequency.
Accessors
Expression | Semantics | Return Type |
---|---|---|
|
Returns |
bool |
|
Returns |
bool |
|
Return a new |
|
|
Return a new |
|
|
Return a new |
|
|
Direct access to the phase accumulator. |
|
|
Direct access to the phase step size. |
|