Value_Smoothing_Filter.h (2212B)
1 2 /*******************************************************************************/ 3 /* Copyright (C) 2008-2020 Jonathan Moore Liles */ 4 /* */ 5 /* This program is free software; you can redistribute it and/or modify it */ 6 /* under the terms of the GNU General Public License as published by the */ 7 /* Free Software Foundation; either version 2 of the License, or (at your */ 8 /* option) any later version. */ 9 /* */ 10 /* This program is distributed in the hope that it will be useful, but WITHOUT */ 11 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 12 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */ 13 /* more details. */ 14 /* */ 15 /* You should have received a copy of the GNU General Public License along */ 16 /* with This program; see the file COPYING. If not,write to the Free Software */ 17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 18 /*******************************************************************************/ 19 20 #ifndef VALUE_SMOOTHING_FILTER_H 21 #define VALUE_SMOOTHING_FILTER_H 22 23 typedef unsigned long nframes_t; 24 typedef float sample_t; 25 26 class Value_Smoothing_Filter 27 { 28 float w, g1, g2, t; 29 30 float _cutoff; 31 32 bool _reset_on_next_apply; 33 34 public: 35 36 Value_Smoothing_Filter ( ) 37 { 38 g1 = g2 = 0; 39 _cutoff = 10.0f; 40 t = 0.0001f; 41 _reset_on_next_apply = false; 42 } 43 44 void reset_on_next_apply ( bool v ) { _reset_on_next_apply = v; } 45 46 void cutoff ( float v ) { _cutoff = v; } 47 void thresh ( float t_ ) { t = t_; } 48 49 void reset ( float v ) { g2 = g1 = v; } 50 51 inline bool target_reached ( float gt ) const { return gt == g2; } 52 53 void sample_rate ( nframes_t n ); 54 55 bool apply( sample_t * __restrict__ dst, nframes_t nframes, float gt ); 56 }; 57 58 #endif