diff --git a/dsp.c b/dsp.c index 6e9f607..4b616dc 100644 --- a/dsp.c +++ b/dsp.c @@ -41,10 +41,10 @@ const int16_t sincos_tbl[48][2] = { {-24636, -21605 }, {-32698, -2143 }, {-27246, 18205 }, {-10533, 31029 } }; -int32_t acc_samp_s; -int32_t acc_samp_c; -int32_t acc_ref_s; -int32_t acc_ref_c; +float acc_samp_s; +float acc_samp_c; +float acc_ref_s; +float acc_ref_c; void dsp_process(int16_t *capture, size_t length) @@ -79,10 +79,10 @@ dsp_process(int16_t *capture, size_t length) ref_c = __SMLATT(sr, sc, ref_c); #endif } - acc_samp_s = samp_s; - acc_samp_c = samp_c; - acc_ref_s = ref_s; - acc_ref_c = ref_c; + acc_samp_s += samp_s; + acc_samp_c += samp_c; + acc_ref_s += ref_s; + acc_ref_c += ref_c; } void diff --git a/main.c b/main.c index 3c480fc..a346aeb 100644 --- a/main.c +++ b/main.c @@ -418,7 +418,16 @@ int16_t dump_buffer[AUDIO_BUFFER_LEN]; int16_t dump_selection = 0; #endif -volatile int16_t wait_count = 0; +volatile uint8_t wait_count = 0; +volatile uint8_t accumerate_count = 0; + +const int8_t bandwidth_accumerate_count[] = { + 1, // 1kHz + 3, // 300Hz + 10, // 100Hz + 33, // 30Hz + 100 // 10Hz +}; float measured[2][101][2]; @@ -426,8 +435,9 @@ static void wait_dsp(int count) { wait_count = count; - //reset_dsp_accumerator(); - while (wait_count) + accumerate_count = bandwidth_accumerate_count[bandwidth]; + reset_dsp_accumerator(); + while (accumerate_count > 0) __WFI(); } @@ -453,13 +463,16 @@ void i2s_end_callback(I2SDriver *i2sp, size_t offset, size_t n) (void)i2sp; (void)n; - if (wait_count > 0) { - if (wait_count == 1) + if (wait_count > 1) { + --wait_count; + } else if (wait_count > 0) { + if (accumerate_count > 0) { dsp_process(p, n); + accumerate_count--; + } #ifdef ENABLED_DUMP - duplicate_buffer_to_dump(p); + duplicate_buffer_to_dump(p); #endif - --wait_count; } #if PORT_SUPPORTS_RT diff --git a/nanovna.h b/nanovna.h index 876a6d3..341132b 100644 --- a/nanovna.h +++ b/nanovna.h @@ -312,7 +312,9 @@ typedef struct { int8_t _active_marker; uint8_t _domain_mode; /* 0bxxxxxffm : where ff: TD_FUNC m: DOMAIN_MODE */ uint8_t _marker_smith_format; + uint8_t _bandwidth; uint8_t _reserved[50]; + int32_t checksum; } properties_t; @@ -338,6 +340,7 @@ extern properties_t current_props; #define domain_mode current_props._domain_mode #define velocity_factor current_props._velocity_factor #define marker_smith_format current_props._marker_smith_format +#define bandwidth current_props._bandwidth int caldata_save(int id); int caldata_recall(int id); diff --git a/ui.c b/ui.c index cfb4fee..ff792b0 100644 --- a/ui.c +++ b/ui.c @@ -728,6 +728,13 @@ menu_transform_cb(int item) } } +static void +menu_bandwidth_cb(int item) +{ + bandwidth = item; + draw_menu(); +} + static void choose_active_marker(void) { @@ -1042,12 +1049,23 @@ const menuitem_t menu_transform[] = { { MT_NONE, NULL, NULL } // sentinel }; +const menuitem_t menu_bandwidth[] = { + { MT_CALLBACK, "1 kHz", menu_bandwidth_cb }, + { MT_CALLBACK, "300 Hz", menu_bandwidth_cb }, + { MT_CALLBACK, "100 Hz", menu_bandwidth_cb }, + { MT_CALLBACK, "30 Hz", menu_bandwidth_cb }, + { MT_CALLBACK, "10 Hz", menu_bandwidth_cb }, + { MT_CANCEL, S_LARROW" BACK", NULL }, + { MT_NONE, NULL, NULL } // sentinel +}; + const menuitem_t menu_display[] = { { MT_SUBMENU, "TRACE", menu_trace }, { MT_SUBMENU, "FORMAT", menu_format }, { MT_SUBMENU, "SCALE", menu_scale }, { MT_SUBMENU, "CHANNEL", menu_channel }, { MT_SUBMENU, "TRANSFORM", menu_transform }, + { MT_SUBMENU, "BANDWIDTH", menu_bandwidth }, { MT_CANCEL, S_LARROW" BACK", NULL }, { MT_NONE, NULL, NULL } // sentinel }; @@ -1454,6 +1472,11 @@ menu_item_modify_attribute(const menuitem_t *menu, int item, *bg = 0x0000; *fg = 0xffff; } + } else if (menu == menu_bandwidth) { + if (item == bandwidth) { + *bg = 0x0000; + *fg = 0xffff; + } } else if (menu == menu_transform) { if ((item == 0 && (domain_mode & DOMAIN_MODE) == DOMAIN_TIME) || (item == 1 && (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_IMPULSE)