2025-04-07 12:43 AM
Can someone please guide me with 8KHz audio, echo cancellation is almost perfect for 16khz audio on stm32u5, but seems problematic at 8KHz, i've tested pass-through (loopback, mic connect to speaker) at 8Khz and it is clear when AEC is disabled, also when pre-processor is disabled and AEC is enabled, it can remove the echo but I need pre-processor for agc, ns related stuff.
#ifdef SPX_EC_FS_8000
#define ECHO_BUFF 128U
#define NN_MAX 128
#define NN 128
#define FS (uint16_t)8000
#elif defined (SPX_EC_FS_16000)
#define ECHO_BUFF 128U
#define NN_MAX 128
#define NN 128
#define FS (uint16_t)16000
#elif defined (SPX_EC_FS_32000)
#define ECHO_BUFF (32*8)
#define NN_MAX (32*8)
#define NN (32*8)
#define FS (uint16_t)32000
#elif defined (SPX_EC_FS_48000)
I've tried to change ECHO_BUFF to 64 as well, but no success so far, maybe this library isn't tested for 8KHz audio, but speexdsp support 8KHz, reason I'm trying to achieve aec at 8KHz is because VOCODER for audio compression supports only 8KHz.
Solved! Go to Solution.
2025-04-16 2:49 AM
figured it out, removed library source files and added AcousticEC_CM33F_wc32_ot.a in the project, it works.
2025-04-10 12:49 AM
Hello @programmer131
First, can you share how you initializing the library? Lets verify together if there’s some weird value in the AcousticEC configuration.
The AcousticEC library is based on Speex, an open-source codec from the Xiph.org foundation. It relies on FFT calculations, filters, and acoustic models that require a minimum of ECHO_BUFF samples. By defining SPX_EC_FS_8000 in your configuration file, the library mandatorily requires 16 ms of audio data. This buffer management is handled internally by AcousticEC_Data_Input, which returns 1 only if data collection is complete. AcousticEC_Process must be called only in this case to ensure the library processes data correctly.
This also means there’s a 16ms delay in the processing chain, but it’s intended to work in real-time. So, while there’s an initial delay of 16 ms, you’ll have new data processed every millisecond thereafter.
Which echo tail length value are you using? Speex calculates FFTs, and power-of-two values are commonly used to optimize FFT calculations. Honestly, I've never used values other than 256/512/1024 for this reason, so I suggest you try these to see if the issue still
Furthermore, the macros that you’re reporting here are related to the low-level part of the library. Don’t modify them because they refer to Speex reference values. Our library is built on top of Speex specifications. Any modification on Speex isn’t supported.
Act on the exposed configuration parameters only (AcousticEC_Handler_t and AcousticEC_Config_t).
If you'd like to increase the filter effect, I suggest you and update the tail_length value in the handler struct and all the noise and echo suppress values in the config struct. The higher are those values, the higher will be the filtering effect at the cost of a worst speech quality and intelligibility.
Best regards,
Simone
2025-04-10 1:04 AM
EchoHandlerInstance.tail_length=128;
EchoHandlerInstance.preprocess_init = 1;
EchoHandlerInstance.ptr_primary_channels=1;
EchoHandlerInstance.ptr_reference_channels=1;
EchoHandlerInstance.ptr_output_channels=1;
AcousticEC_getMemorySize(&EchoHandlerInstance);
EchoHandlerInstance.pInternalMemory = (uint32_t *)malloc(EchoHandlerInstance.internal_memory_size);
if(EchoHandlerInstance.pInternalMemory == NULL)
{
while(1);
}
error_value = AcousticEC_Init((AcousticEC_Handler_t *)&EchoHandlerInstance);
if(error_value != 0)
{
while(1);
}
EchoConfigInstance.preprocess_state = ACOUSTIC_EC_PREPROCESS_ENABLE;
EchoConfigInstance.AGC_value = 0;
EchoConfigInstance.noise_suppress_default = -15; /* Default: -15 */
EchoConfigInstance.echo_suppress_default = -40; /* Default: -40 */
EchoConfigInstance.echo_suppress_active = -15; /* Default: -15 */
EchoConfigInstance.residual_echo_remove = 1; /* Default: 1 */
even at 16KHz, tail length greater than 256 is causing noise,
but at 8KHz, same configuration with 128 tail length is problematic.
here i push data every ms for echo cancellation
void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hsai)
{
int16_t echoOut[16];
if(AcousticEC_Data_Input(inbuff, outbuff, echoOut, (AcousticEC_Handler_t *)&EchoHandlerInstance)){
shouldProcess=1;
}
for(int i = 0;i<16; i++)
{
outbuff[i]=echoOut[i];
}
}
void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai)
{
int16_t echoOut[16];
if(AcousticEC_Data_Input(&inbuff[16], &outbuff[16], echoOut, (AcousticEC_Handler_t *)&EchoHandlerInstance)){
shouldProcess=1;
}
for(int i = 0;i<16; i++)
{
outbuff[i+16]=echoOut[i];
}
}
2025-04-13 9:52 PM
seems issue with processing delay, for NN=128, at 8KHz, it takes almost 16-17ms for processing 16ms of audio (128 samples), need to select mcu with more processing power.
2025-04-16 2:49 AM
figured it out, removed library source files and added AcousticEC_CM33F_wc32_ot.a in the project, it works.
2025-04-23 7:00 AM
Hi programmer131,
I have a quick question for you. Did you use the precompiled library from ST that relies on double-precision FPU instructions? If so, did you run into any compatibility issues, considering that the STM32 U5 is based on a single-precision FPU?
Or did you generate the .a file yourself using the source files?
I look forward to your reply.
Kind regards,
Edu
2025-04-24 2:44 AM
I've tried both ways, didn't notice any issue related to FPU, will test again.