commit 0c54493208d5e61bac82eca6a26f232e544b9995 parent 2a3a3d2554f40f7507efa36880009efc670b326f Author: Hans Petter Selasky <hps@selasky.org> Date: Fri, 3 Apr 2020 13:23:27 +0200 Implement smart float class which return smooth values. Signed-off-by: Hans Petter Selasky <hps@selasky.org> Diffstat:
M | src/globals.h | | | 29 | +++++++++++++++++++++++++++++ |
1 file changed, 29 insertions(+), 0 deletions(-)
diff --git a/src/globals.h b/src/globals.h @@ -347,5 +347,34 @@ struct SYNTH_T { static float numRandom(void); //defined in Util.cpp for now }; +class smooth_float { +private: + bool init; + float curr_value; + float next_value; +public: + smooth_float() { + init = false; + next_value = curr_value = 0.0f; + }; + smooth_float(const float value) { + init = true; + next_value = curr_value = value; + }; + operator float() { + const float delta = (next_value - curr_value) / 128.0f; + curr_value += delta; + return (curr_value); + }; + void operator =(const float value) { + if (init) { + next_value = value; + } else { + next_value = curr_value = value; + init = true; + } + }; +}; + } #endif