From bdd8c21fcfff8041ea94a972903ce42e58c2a5c2 Mon Sep 17 00:00:00 2001 From: ozpv <39195175+ozpv@users.noreply.github.com> Date: Sat, 29 Aug 2026 23:04:49 -0500 Subject: add retain --- Core/Src/cs4272.c | 45 ++++++++++++--------------------------------- 1 file changed, 12 insertions(+), 33 deletions(-) (limited to 'Core/Src/cs4272.c') diff --git a/Core/Src/cs4272.c b/Core/Src/cs4272.c index 9a7f0d1..8ba9885 100755 --- a/Core/Src/cs4272.c +++ b/Core/Src/cs4272.c @@ -8,18 +8,10 @@ #include "i2c.h" #include "cs4272.h" #include "ringmod.h" +#include "retain.h" -const struct RingModParams params = { - 0.40f, - 156.0f, - 6.90f, - 0.18f, - true, -}; - -volatile int32_t rx_buffer[BUFFER_SIZE] __attribute__((section(".audio_buffers"))); -volatile int32_t tx_buffer[BUFFER_SIZE] __attribute__((section(".audio_buffers"))); -volatile float samples[BUFFER_SIZE] __attribute__((section(".sdram"))); +__attribute__((section(".audio_buffers"))) int32_t rx_buffer[BUFFER_SIZE]; +__attribute__((section(".audio_buffers"))) int32_t tx_buffer[BUFFER_SIZE]; const uint8_t CS4272_CONFIG[7] = { /* MODE CONTROL 1 @@ -58,35 +50,22 @@ const uint8_t CS4272_CONFIG[7] = { 0b00000010, }; -inline void int32_t_to_float(int32_t *in, float *out, const size_t range_min, const size_t range_max) { - for (size_t i = range_min; i < range_max; ++i) { - out[i] = ((float)(in[i] << 8)) / ((float)INT32_MAX); - } -} - -inline void float_to_int32_t(float *in, int32_t *out, const size_t range_min, const size_t range_max) { - for (size_t i = range_min; i < range_max; ++i) { - out[i] = ((int32_t)(in[i] * ((float)INT32_MAX))) >> 8; - } -} +//const struct RingModParams params = { +// 0.40f, +// 156.0f, +// 16.90f, +// 0.18f, +// false, +//}; void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hsai) { - int32_t_to_float((int32_t *)rx_buffer, (float *)samples, 0, BUFFER_SIZE / 2); - - ringmod((float *)samples, 0, BUFFER_SIZE / 2, ¶ms); - - float_to_int32_t((float *)samples, (int32_t *)tx_buffer, 0, BUFFER_SIZE / 2); + retain(rx_buffer, tx_buffer, 0, BUFFER_SIZE / 2, MONO); } void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai) { - int32_t_to_float((int32_t *)rx_buffer, (float *)samples, BUFFER_SIZE / 2, BUFFER_SIZE); - - ringmod((float *)samples, BUFFER_SIZE / 2, BUFFER_SIZE, ¶ms); - - float_to_int32_t((float *)samples, (int32_t *)tx_buffer, BUFFER_SIZE / 2, BUFFER_SIZE); + retain(rx_buffer, tx_buffer, BUFFER_SIZE / 2, BUFFER_SIZE, MONO); } - HAL_StatusTypeDef CS4272_ReadRegister(const uint8_t addr, uint8_t *data) { return HAL_I2C_Mem_Read(&hi2c4, CS4272_I2C_ADDR, addr, I2C_MEMADD_SIZE_8BIT, data, 1, HAL_MAX_DELAY); } -- cgit v1.2.3