File tree 2 files changed +18
-0
lines changed
2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -62,12 +62,29 @@ static int32_t biquad_scale_arg_float(mp_float_t arg) {
62
62
return (int32_t )MICROPY_FLOAT_C_FUN (round )(MICROPY_FLOAT_C_FUN (ldexp )(arg , BIQUAD_SHIFT ));
63
63
}
64
64
65
+ static int float_equal_or_update (
66
+ mp_float_t * cached ,
67
+ mp_float_t new ) {
68
+ // uses memcmp to avoid error about equality float comparison
69
+ if (memcmp (cached , & new , sizeof (mp_float_t ))) {
70
+ * cached = new ;
71
+ return false;
72
+ }
73
+ return true;
74
+ }
75
+
65
76
void common_hal_synthio_block_biquad_tick (mp_obj_t self_in , biquad_filter_state * filter_state ) {
66
77
synthio_block_biquad_t * self = MP_OBJ_TO_PTR (self_in );
67
78
68
79
mp_float_t W0 = synthio_block_slot_get (& self -> f0 ) * synthio_global_W_scale ;
69
80
mp_float_t Q = synthio_block_slot_get (& self -> Q );
70
81
82
+ // n.b., assumes that the `mode` field is read-only
83
+ // n.b., use of `&` is deliberate, avoids short-circuiting behavior
84
+ if (float_equal_or_update (& self -> cached_W0 , W0 ) & float_equal_or_update (& self -> cached_Q , Q )) {
85
+ return ;
86
+ }
87
+
71
88
sincos_result_t sc ;
72
89
fast_sincos (W0 , & sc );
73
90
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ typedef struct synthio_block_biquad {
15
15
mp_obj_base_t base ;
16
16
synthio_filter_mode mode ;
17
17
synthio_block_slot_t f0 , Q ;
18
+ mp_float_t cached_W0 , cached_Q ;
18
19
} synthio_block_biquad_t ;
19
20
20
21
void common_hal_synthio_block_biquad_tick (mp_obj_t self_in , biquad_filter_state * filter_state );
You can’t perform that action at this time.
0 commit comments