HysteresisProcessing.cpp (1414B)
1 #include "HysteresisProcessing.h" 2 #include <cmath> 3 4 HysteresisProcessing::HysteresisProcessing() 5 { 6 } 7 8 void HysteresisProcessing::reset() 9 { 10 M_n1 = 0.0; 11 H_n1 = 0.0; 12 H_d_n1 = 0.0; 13 14 hpState.coth = 0.0; 15 hpState.nearZero = false; 16 } 17 18 void HysteresisProcessing::setSampleRate (double newSR) 19 { 20 fs = newSR; 21 T = 1.0 / fs; 22 Talpha = T / 1.9; 23 hysteresisSTN.prepare (newSR); 24 } 25 26 void HysteresisProcessing::cook (double drive, double width, double sat, bool v1) 27 { 28 hysteresisSTN.setParams ((float) sat, (float) width); 29 30 hpState.M_s = 0.5 + 1.5 * (1.0 - sat); 31 hpState.a = hpState.M_s / (0.01 + 6.0 * drive); 32 hpState.c = std::sqrt (1.0f - width) - 0.01; 33 hpState.k = 0.47875; 34 upperLim = 20.0; 35 36 if (v1) 37 { 38 hpState.k = 27.0e3; 39 hpState.c = 1.7e-1; 40 hpState.M_s *= 50000.0; 41 hpState.a = hpState.M_s / (0.01 + 40.0 * drive); 42 upperLim = 100000.0; 43 } 44 45 hpState.nc = 1.0 - hpState.c; 46 hpState.M_s_oa = hpState.M_s / hpState.a; 47 hpState.M_s_oa_talpha = HysteresisOps::HysteresisState::alpha * hpState.M_s_oa; 48 hpState.M_s_oa_tc = hpState.c * hpState.M_s_oa; 49 hpState.M_s_oa_tc_talpha = HysteresisOps::HysteresisState::alpha * hpState.M_s_oa_tc; 50 hpState.M_s_oaSq_tc_talpha = hpState.M_s_oa_tc_talpha / hpState.a; 51 hpState.M_s_oaSq_tc_talphaSq = HysteresisOps::HysteresisState::alpha * hpState.M_s_oaSq_tc_talpha; 52 }