File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 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) {
6262 return (int32_t )MICROPY_FLOAT_C_FUN (round )(MICROPY_FLOAT_C_FUN (ldexp )(arg , BIQUAD_SHIFT ));
6363}
6464
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+
6576void common_hal_synthio_block_biquad_tick (mp_obj_t self_in , biquad_filter_state * filter_state ) {
6677 synthio_block_biquad_t * self = MP_OBJ_TO_PTR (self_in );
6778
6879 mp_float_t W0 = synthio_block_slot_get (& self -> f0 ) * synthio_global_W_scale ;
6980 mp_float_t Q = synthio_block_slot_get (& self -> Q );
7081
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+
7188 sincos_result_t sc ;
7289 fast_sincos (W0 , & sc );
7390
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ typedef struct synthio_block_biquad {
1515 mp_obj_base_t base ;
1616 synthio_filter_mode mode ;
1717 synthio_block_slot_t f0 , Q ;
18+ mp_float_t cached_W0 , cached_Q ;
1819} synthio_block_biquad_t ;
1920
2021void 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