Basic Audio Signal Processing Library

Dependents:   unzen_sample_nucleo_f746 skeleton_unzen_nucleo_f746 ifmag_noise_canceller synthesizer_f746

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers hysteresis.cpp Source File

hysteresis.cpp

00001 #include "amakusa.h"
00002 
00003 #define ROUND_OFFSET 0x2
00004 
00005 amakusa::Hysteresis::Hysteresis( int32_t min_input, int32_t max_input )
00006 {
00007     this->min = min_input;
00008     this->max = max_input;
00009     this->last_value = 0;
00010 }
00011 
00012 int32_t amakusa::Hysteresis::run(int32_t in_data)
00013 {
00014     if ( in_data == this->last_value )
00015         ;   // do nothing;
00016     else 
00017         this->last_value = ( in_data + ROUND_OFFSET  + ( in_data > this->last_value ? - 1 : 1 ) ) & 0xFFFFFFFC;
00018         
00019     if ( this->last_value > this->max )
00020         this->last_value = this->max;
00021     else if ( this->last_value < this->min )
00022         this->last_value = this->min;
00023         
00024     return this->last_value;
00025 }