Disable interrupts while reconfiguring, reset all filters if one has a type change.

This commit is contained in:
George Norton 2023-06-17 23:35:30 +01:00
parent 74a36a3ed6
commit 150eed2b8a
3 changed files with 19 additions and 9 deletions

View File

@ -483,8 +483,8 @@ fix16_t bqf_transform(fix16_t x, bqf_coeff_t *coefficients, bqf_mem_t *memory) {
}
void bqf_memreset(bqf_mem_t *memory) {
memory->x_1 = fix16_from_dbl(0.0);
memory->x_2 = fix16_from_dbl(0.0);
memory->y_1 = fix16_from_dbl(0.0);
memory->y_2 = fix16_from_dbl(0.0);
memory->x_1 = fix16_zero;
memory->x_2 = fix16_zero;
memory->y_1 = fix16_zero;
memory->y_2 = fix16_zero;
}

View File

@ -140,17 +140,17 @@ void apply_filter_configuration(filter_configuration_tlv *filters) {
uint8_t *ptr = (uint8_t *)filters->header.value;
const uint8_t *end = (uint8_t *)filters + filters->header.length;
filter_stages = 0;
bool type_changed = false;
while ((ptr + 4) < end) {
const uint8_t type = *ptr;
// If you reset the memory, you can hear it when you move the sliders on the UI,
// is it perhaps OK to leave these and let the old values drop off over time?
// Ensure we at least clear the memory if the filter type changes, as this can sound bad.
static uint8_t bqf_filter_types[MAX_FILTER_STAGES] = { 0xFF };
// so try to preserve our remembered values.
// If a filter type changes, we do a memory reset.
static uint8_t bqf_filter_types[MAX_FILTER_STAGES] = { };
if (type != bqf_filter_types[filter_stages]) {
bqf_memreset(&bqf_filters_mem_left[filter_stages]);
bqf_memreset(&bqf_filters_mem_right[filter_stages]);
bqf_filter_types[filter_stages] = type;
type_changed = true;
}
switch (type) {
@ -168,6 +168,13 @@ void apply_filter_configuration(filter_configuration_tlv *filters) {
}
filter_stages++;
}
if (type_changed) {
for (int i=0; i<MAX_FILTER_STAGES; i++) {
bqf_memreset(&bqf_filters_mem_left[i]);
bqf_memreset(&bqf_filters_mem_right[i]);
}
}
}
bool validate_configuration(tlv_header *config) {
@ -476,9 +483,11 @@ void config_in_packet(struct usb_endpoint *ep) {
void apply_core1_config() {
if (reload_config) {
uint32_t ints = save_and_disable_interrupts();
reload_config = false;
const uint8_t active_configuration = inactive_working_configuration ? 0 : 1;
apply_configuration((tlv_header*) working_configuration[active_configuration]);
restore_interrupts(ints);
}
}
#endif

View File

@ -28,6 +28,7 @@ typedef int32_t fix16_t;
static const fix16_t fix16_overflow = 0x80000000;
static const fix16_t fix16_one = 0x00008000;
static const fix16_t fix16_zero = 0x00000000;
fix16_t fix16_from_int(int16_t);
int16_t fix16_to_int(fix16_t);