From 5bdae0fc3c4243ca107ee93d4c55df12361d09c5 Mon Sep 17 00:00:00 2001 From: George Norton Date: Sat, 19 Aug 2023 01:05:33 +0100 Subject: [PATCH] Increase config buffer size, and make the bqf_transform function inline --- firmware/code/bqf.c | 15 ----------- firmware/code/bqf.h | 3 ++- firmware/code/bqf.inl | 36 +++++++++++++++++++++++++++ firmware/code/configuration_manager.c | 2 +- firmware/code/run.c | 3 ++- 5 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 firmware/code/bqf.inl diff --git a/firmware/code/bqf.c b/firmware/code/bqf.c index 21b67fb..191137c 100644 --- a/firmware/code/bqf.c +++ b/firmware/code/bqf.c @@ -467,21 +467,6 @@ void bqf_highshelf_config(double fs, double f0, double dBgain, double Q, coefficients->a2 = fix3_28_from_dbl(a2); } -fix3_28_t bqf_transform(fix3_28_t x, bqf_coeff_t *coefficients, bqf_mem_t *memory) { - fix3_28_t y = fix16_mul(coefficients->b0, x) - - fix16_mul(coefficients->a1, memory->y_1) + - fix16_mul(coefficients->b1, memory->x_1) - - fix16_mul(coefficients->a2, memory->y_2) + - fix16_mul(coefficients->b2, memory->x_2); - - memory->x_2 = memory->x_1; - memory->x_1 = x; - memory->y_2 = memory->y_1; - memory->y_1 = y; - - return y; -} - void bqf_memreset(bqf_mem_t *memory) { memory->x_1 = fix16_zero; memory->x_2 = fix16_zero; diff --git a/firmware/code/bqf.h b/firmware/code/bqf.h index 8e5933c..ed25384 100644 --- a/firmware/code/bqf.h +++ b/firmware/code/bqf.h @@ -65,7 +65,8 @@ void bqf_peaking_config(double, double, double, double, bqf_coeff_t *); void bqf_lowshelf_config(double, double, double, double, bqf_coeff_t *); void bqf_highshelf_config(double, double, double, double, bqf_coeff_t *); -fix3_28_t bqf_transform(fix3_28_t, bqf_coeff_t *, bqf_mem_t *); +static inline fix3_28_t bqf_transform(fix3_28_t, bqf_coeff_t *, bqf_mem_t *); void bqf_memreset(bqf_mem_t *); +#include "bqf.inl" #endif diff --git a/firmware/code/bqf.inl b/firmware/code/bqf.inl new file mode 100644 index 0000000..5fafdf5 --- /dev/null +++ b/firmware/code/bqf.inl @@ -0,0 +1,36 @@ +/** + * Copyright 2022 Colin Lam, Ploopy Corporation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPECIAL THANKS TO: + * Robert Bristow-Johnson, a.k.a. RBJ + * for his exceptional work on biquad formulae as applied to digital + * audio filtering, summarised in his pamphlet, "Audio EQ Cookbook". + */ + +static inline fix3_28_t bqf_transform(fix3_28_t x, bqf_coeff_t *coefficients, bqf_mem_t *memory) { + fix3_28_t y = fix16_mul(coefficients->b0, x) - + fix16_mul(coefficients->a1, memory->y_1) + + fix16_mul(coefficients->b1, memory->x_1) - + fix16_mul(coefficients->a2, memory->y_2) + + fix16_mul(coefficients->b2, memory->x_2); + + memory->x_2 = memory->x_1; + memory->x_1 = x; + memory->y_2 = memory->y_1; + memory->y_1 = y; + + return y; +} \ No newline at end of file diff --git a/firmware/code/configuration_manager.c b/firmware/code/configuration_manager.c index f030521..a4dea9e 100644 --- a/firmware/code/configuration_manager.c +++ b/firmware/code/configuration_manager.c @@ -74,7 +74,7 @@ const uint8_t *user_configuration = (const uint8_t *) (XIP_BASE + USER_CONFIGURA * should handle merging configurations where, for example, only a new * filter_configuration_tlv was received. */ -#define CFG_BUFFER_SIZE 256 +#define CFG_BUFFER_SIZE 512 static uint8_t working_configuration[2][CFG_BUFFER_SIZE]; static uint8_t inactive_working_configuration = 0; static uint8_t result_buffer[CFG_BUFFER_SIZE] = { U16_TO_U8S_LE(NOK), U16_TO_U8S_LE(0) }; diff --git a/firmware/code/run.c b/firmware/code/run.c index d6f13fd..6d96274 100644 --- a/firmware/code/run.c +++ b/firmware/code/run.c @@ -133,8 +133,9 @@ static void __no_inline_not_in_flash_func(_as_audio_packet)(struct usb_endpoint } } else { - for (int i = 0; i < samples; i++) + for (int i = 0; i < samples; i++) { out[i] = fix16_mul(norm_fix3_28_from_s16sample(in[i]), preprocessing.preamp); + } } multicore_fifo_push_blocking(samples);