aicodix___dsp/phasor.hh
2019-02-04 12:29:40 +01:00

38 lines
605 B
C++

/*
Numerically controlled oscillator
Copyright 2019 Ahmet Inan <inan@aicodix.de>
*/
#include "unit_circle.hh"
#pragma once
namespace DSP {
template <typename TYPE>
class Phasor
{
typedef TYPE complex_type;
typedef typename complex_type::value_type value_type;
complex_type prev, delta;
public:
constexpr Phasor() : prev(1, 0), delta(1, 0)
{
}
void omega(int n, int N)
{
delta = complex_type(
UnitCircle<value_type>::cos(n, N),
UnitCircle<value_type>::sin(n, N));
}
complex_type operator()()
{
complex_type tmp = prev;
prev *= delta;
prev /= abs(prev);
return tmp;
}
};
}