kfr

Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
Log | Files | Refs | README

commit 5bd2b04b371186f35ae23ee176c4b8f3f07911e7
parent 9659c6d9e677113b74112e40012a8526122ce240
Author: [email protected] <[email protected]>
Date:   Sat, 27 Aug 2016 00:44:55 +0300

Add phasor function

Diffstat:
Minclude/kfr/dsp/oscillators.hpp | 12++++++++++++
Mtests/dsp_test.cpp | 8++++++++
2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/include/kfr/dsp/oscillators.hpp b/include/kfr/dsp/oscillators.hpp @@ -45,6 +45,18 @@ auto swept(identity<T> magn, size_t size) size); } +template <typename T = fbase> +auto phasor(identity<T> frequency) +{ + return fract(counter(T(0), frequency)); +} + +template <typename T = fbase> +auto phasor(identity<T> frequency, identity<T> sample_rate) +{ + return fract(counter(T(0), frequency / sample_rate)); +} + namespace intrinsics { template <typename T> diff --git a/tests/dsp_test.cpp b/tests/dsp_test.cpp @@ -72,4 +72,12 @@ TEST(mixdown_stereo) CHECK(side[20] == -120); } +TEST(phasor) +{ + constexpr fbase sr = 44100.0; + univector<fbase, 100> v1 = sinenorm(phasor(15000, sr)); + univector<fbase, 100> v2 = sin(c_pi<fbase, 2> * counter(0, 15000 / sr)); + CHECK(rms(v1 - v2) < 1.e-5); +} + int main(int argc, char** argv) { return testo::run_all("", true); }