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 36e2c4c5a37c243dd23a4bad5aa540b5599f7031
parent 29e69c6ce91f7c12581893063e7c5954f719b157
Author: d.levin256@gmail.com <d.levin256@gmail.com>
Date:   Tue,  8 Nov 2016 08:13:39 +0300

Remove impulse.hpp, Add special.hpp

Diffstat:
Mexamples/biquads.cpp | 16++++++++--------
Minclude/kfr/dsp.hpp | 4++--
Dinclude/kfr/dsp/impulse.hpp | 46----------------------------------------------
Minclude/kfr/dsp/oscillators.hpp | 17+----------------
Ainclude/kfr/dsp/special.hpp | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msources.cmake | 2+-
6 files changed, 93 insertions(+), 73 deletions(-)

diff --git a/examples/biquads.cpp b/examples/biquads.cpp @@ -20,49 +20,49 @@ int main() { biquad_params<fbase> bq[] = { biquad_notch(0.1, 0.5), biquad_notch(0.2, 0.5), biquad_notch(0.3, 0.5), biquad_notch(0.4, 0.5) }; - output = biquad(bq, simpleimpulse()); + output = biquad(bq, unitimpulse()); } plot_save("biquad_notch", output, options + ", title='Four Biquad Notch filters'"); { biquad_params<fbase> bq[] = { biquad_lowpass(0.2, 0.9) }; - output = biquad(bq, simpleimpulse()); + output = biquad(bq, unitimpulse()); } plot_save("biquad_lowpass", output, options + ", title='Biquad Low pass filter (0.2, 0.9)'"); { biquad_params<fbase> bq[] = { biquad_highpass(0.3, 0.1) }; - output = biquad(bq, simpleimpulse()); + output = biquad(bq, unitimpulse()); } plot_save("biquad_highpass", output, options + ", title='Biquad High pass filter (0.3, 0.1)'"); { biquad_params<fbase> bq[] = { biquad_peak(0.3, 0.5, +9.0) }; - output = biquad(bq, simpleimpulse()); + output = biquad(bq, unitimpulse()); } plot_save("biquad_peak", output, options + ", title='Biquad Peak filter (0.2, 0.5, +9)'"); { biquad_params<fbase> bq[] = { biquad_peak(0.3, 3.0, -2.0) }; - output = biquad(bq, simpleimpulse()); + output = biquad(bq, unitimpulse()); } plot_save("biquad_peak2", output, options + ", title='Biquad Peak filter (0.3, 3, -2)'"); { biquad_params<fbase> bq[] = { biquad_lowshelf(0.3, -1.0) }; - output = biquad(bq, simpleimpulse()); + output = biquad(bq, unitimpulse()); } plot_save("biquad_lowshelf", output, options + ", title='Biquad low shelf filter (0.3, -1)'"); { biquad_params<fbase> bq[] = { biquad_highshelf(0.3, +9.0) }; - output = biquad(bq, simpleimpulse()); + output = biquad(bq, unitimpulse()); } plot_save("biquad_highshelf", output, options + ", title='Biquad high shelf filter (0.3, +9)'"); { biquad_params<fbase> bq[] = { biquad_bandpass(0.25, 0.2) }; - output = biquad(bq, simpleimpulse()); + output = biquad(bq, unitimpulse()); } plot_save("biquad_bandpass", output, options + ", title='Biquad band pass (0.25, 0.2)'"); diff --git a/include/kfr/dsp.hpp b/include/kfr/dsp.hpp @@ -32,12 +32,12 @@ #include "dsp/fir_design.hpp" #include "dsp/fracdelay.hpp" #include "dsp/goertzel.hpp" -#include "dsp/impulse.hpp" #include "dsp/interpolation.hpp" #include "dsp/mixdown.hpp" #include "dsp/oscillators.hpp" -#include "dsp/resample.hpp" +#include "dsp/sample_rate_conversion.hpp" #include "dsp/speaker.hpp" +#include "dsp/special.hpp" #include "dsp/units.hpp" #include "dsp/waveshaper.hpp" #include "dsp/weighting.hpp" diff --git a/include/kfr/dsp/impulse.hpp b/include/kfr/dsp/impulse.hpp @@ -1,46 +0,0 @@ -/** @addtogroup dsp - * @{ - */ -/* - Copyright (C) 2016 D Levin (https://www.kfrlib.com) - This file is part of KFR - - KFR is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - KFR is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with KFR. - - If GPL is not suitable for your project, you must purchase a commercial license to use KFR. - Buying a commercial license is mandatory as soon as you develop commercial activities without - disclosing the source code of your own applications. - See https://www.kfrlib.com for details. - */ -#pragma once - -#include "../base/basic_expressions.hpp" -#include "../base/vec.hpp" - -namespace kfr -{ -/** - * @brief Returns expression template that generates unit impulse - */ -template <typename T = int> -inline auto simpleimpulse() -{ - return lambda<T>([](cinput_t, size_t index, auto x) { - if (index == 0) - return onoff(x); - else - return zerovector(x); - }); -} -} diff --git a/include/kfr/dsp/oscillators.hpp b/include/kfr/dsp/oscillators.hpp @@ -32,22 +32,7 @@ namespace kfr { template <typename T = fbase> -KFR_FUNC auto jaehne(identity<T> magn, size_t size) -{ - return truncate(magn * sin(constants<T>::pi_s(1, 2) * sqr(linspace(T(0), T(size), size, false)) / size), - size); -} - -template <typename T = fbase> -KFR_FUNC auto swept(identity<T> magn, size_t size) -{ - return truncate( - magn * sin(c_pi<T, 1, 4> * sqr(sqr(linspace(T(0), T(size), size, false)) / sqr(T(size))) * T(size)), - size); -} - -template <typename T = fbase> -KFR_FUNC auto phasor(identity<T> frequency) +KFR_FUNC static auto phasor(identity<T> frequency) { return fract(counter(T(0), frequency)); } diff --git a/include/kfr/dsp/special.hpp b/include/kfr/dsp/special.hpp @@ -0,0 +1,81 @@ +/** @addtogroup dsp + * @{ + */ +/* + Copyright (C) 2016 D Levin (https://www.kfrlib.com) + This file is part of KFR + + KFR is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + KFR is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with KFR. + + If GPL is not suitable for your project, you must purchase a commercial license to use KFR. + Buying a commercial license is mandatory as soon as you develop commercial activities without + disclosing the source code of your own applications. + See https://www.kfrlib.com for details. + */ +#pragma once + +#include "../base/basic_expressions.hpp" +#include "../base/operators.hpp" +#include "../base/vec.hpp" + +namespace kfr +{ +/** + * @brief Returns expression template that generates a unit impulse + */ +template <typename T = int> +static auto unitimpulse() +{ + return lambda<T>([](cinput_t, size_t index, auto x) { + if (index == 0) + return onoff(x); + else + return zerovector(x); + }); +} + +template <typename T = fbase> +static auto jaehne_arg(size_t size) +{ + return truncate(constants<T>::pi_s(1, 2) * sqr(linspace(T(0), T(size), size, false)) / size, size); +} + +/** + * @brief Returns expression template that generates a jaehne vector + * Generates the sine with linearly increasing frequency from 0hz to nyquist frequency. + */ +template <typename T = fbase> +static auto jaehne(identity<T> magn, size_t size) +{ + return magn * sin(jaehne_arg<T>(size)); +} + +template <typename T = fbase> +static auto swept_arg(size_t size) +{ + return truncate(constants<T>::pi_s(1, 4) * sqr(sqr(linspace(T(0), T(size), size, false)) / sqr(T(size))) * + T(size), + size); +} + +/** + * @brief Returns expression template that generates a jaehne vector + * Generates the sine with logarithmically increasing frequency from 0hz to nyquist frequency. + */ +template <typename T = fbase> +static auto swept(identity<T> magn, size_t size) +{ + return magn * sin(swept_arg<T>(size)); +} +} diff --git a/sources.cmake b/sources.cmake @@ -83,13 +83,13 @@ set( ${PROJECT_SOURCE_DIR}/include/kfr/dsp/fir_design.hpp ${PROJECT_SOURCE_DIR}/include/kfr/dsp/fracdelay.hpp ${PROJECT_SOURCE_DIR}/include/kfr/dsp/goertzel.hpp - ${PROJECT_SOURCE_DIR}/include/kfr/dsp/impulse.hpp ${PROJECT_SOURCE_DIR}/include/kfr/dsp/interpolation.hpp ${PROJECT_SOURCE_DIR}/include/kfr/dsp/mixdown.hpp ${PROJECT_SOURCE_DIR}/include/kfr/dsp/oscillators.hpp ${PROJECT_SOURCE_DIR}/include/kfr/dsp/resample.hpp ${PROJECT_SOURCE_DIR}/include/kfr/dsp/sample_rate_conversion.hpp ${PROJECT_SOURCE_DIR}/include/kfr/dsp/speaker.hpp + ${PROJECT_SOURCE_DIR}/include/kfr/dsp/special.hpp ${PROJECT_SOURCE_DIR}/include/kfr/dsp/units.hpp ${PROJECT_SOURCE_DIR}/include/kfr/dsp/waveshaper.hpp ${PROJECT_SOURCE_DIR}/include/kfr/dsp/weighting.hpp