@@ -30,17 +30,16 @@ struct smf_state {
30
30
double g0 , m0 , m1 , c0 , c1 ;
31
31
};
32
32
33
- #define SMF_RISE_TIME (x ) (0.349/(( x)/1000.0))
33
+ #define SMF_RISE_TIME (x ) (( x)/1000.0/2.1972) /* 10%-90% rise time in ms (one pole only) */
34
34
35
35
static inline void smf_reset (struct smf_state * state )
36
36
{
37
37
state -> m0 = state -> m1 = 0.0 ;
38
38
}
39
39
40
- static inline void smf_asym_init (struct smf_state * state , double fs , double f0 , double sens_rise , double sens_fall )
40
+ static inline void smf_asym_init (struct smf_state * state , double fs , double tc , double sens_rise , double sens_fall )
41
41
{
42
- const double gc = tan (M_PI * (f0 /fs ));
43
- state -> g0 = 2.0 * gc /(1.0 + gc );
42
+ state -> g0 = 1.0 - exp (-1.0 /(fs * tc ));
44
43
state -> c0 = sens_rise * 4.0 ;
45
44
state -> c1 = sens_fall * 4.0 ;
46
45
smf_reset (state );
@@ -54,9 +53,9 @@ static inline void smf_init(struct smf_state *state, double fs, double f0, doubl
54
53
static inline double smf_run_c (struct smf_state * state , double s , const double c )
55
54
{
56
55
double g = state -> g0 + c * fabs (state -> m0 - state -> m1 );
57
- if (g > 1.0 ) g = 1.0 ;
58
- state -> m0 = state -> m0 + g * (s - state -> m0 );
59
- state -> m1 = state -> m1 + g * (state -> m0 - state -> m1 );
56
+ if (g > 0.39 ) g = 0.39 ;
57
+ state -> m0 = g * (s - state -> m0 ) + state -> m0 ;
58
+ state -> m1 = g * (state -> m0 - state -> m1 ) + state -> m1 ;
60
59
return state -> m1 ;
61
60
}
62
61
0 commit comments