commit 8f333155b3c108bc259b84872f47b6a86e19e4f4
parent 3a4ad10a33f0ff9be3fdcf3ed27eb4461960bbe5
Author: d.levin256@gmail.com <d.levin256@gmail.com>
Date: Wed, 20 Jul 2016 20:22:10 +0300
Waveshaper
Diffstat:
3 files changed, 44 insertions(+), 0 deletions(-)
diff --git a/include/kfr/all.hpp b/include/kfr/all.hpp
@@ -78,6 +78,7 @@
#include "dsp/resample.hpp"
#include "dsp/speaker.hpp"
#include "dsp/units.hpp"
+#include "dsp/waveshaper.hpp"
#include "dsp/weighting.hpp"
#include "dsp/window.hpp"
#include "io/audiofile.hpp"
diff --git a/include/kfr/dsp/waveshaper.hpp b/include/kfr/dsp/waveshaper.hpp
@@ -0,0 +1,42 @@
+/**
+ * Copyright (C) 2016 D Levin (http://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 http://www.kfrlib.com for details.
+ */
+#pragma once
+
+#include "../base/abs.hpp"
+#include "../base/hyperbolic.hpp"
+#include "../base/min_max.hpp"
+
+namespace kfr
+{
+template <typename E1>
+inline auto waveshaper_hardclip(E1&& input, double clip_level)
+{
+ return native::clamp(input, -clip_level, +clip_level);
+}
+
+template <typename E1>
+inline auto waveshaper_tanh(E1&& input, double saturation)
+{
+ return native::tanh(saturation * input) * (native::coth(saturation));
+}
+}
diff --git a/sources.cmake b/sources.cmake
@@ -65,6 +65,7 @@ set(
${PROJECT_SOURCE_DIR}/include/kfr/dsp/interpolation.hpp
${PROJECT_SOURCE_DIR}/include/kfr/dsp/resample.hpp
${PROJECT_SOURCE_DIR}/include/kfr/dsp/speaker.hpp
+ ${PROJECT_SOURCE_DIR}/include/kfr/dsp/waveshaper.hpp
${PROJECT_SOURCE_DIR}/include/kfr/dsp/weighting.hpp
${PROJECT_SOURCE_DIR}/include/kfr/dsp/window.hpp
${PROJECT_SOURCE_DIR}/include/kfr/expressions/basic.hpp