2021-12-22 01:52 AM
I have been going through the X-CUBE-MEMSMIC examples on the STWINKt development board. There are two examples 'AMicArray_Acoustic_SL' and 'AMicArray_Microphones_Streaming' are given.
AMicArray_Acoustic_SL - is sampling audio at 16k and providing the sound direction using a compiled library.
Also, AMicArray_Microphones_Streaming - is sampling audio at 96k and streaming it to USB audio.
Now I am trying to integrate both programs i.e. to get the audio samples --> Stream them to USB and also get the sound localization using the same samples.
However, when I am using 96k samples to the SoundLocalization API it is always throwing a sample_frequency_error. I have tried different configurations for sound localization API but nothing works.
My question is to integrate both functionalities in one, what sampling configuration is required to change or how to remove sample_frequency_error?
here is the code snapshot I am trying to configure for 96k samples.
void Audio_Libraries_Init(void)
{
volatile uint32_t error_value = 0;
/* Enable CRC peripheral to unlock the library */
__CRC_CLK_ENABLE();
/*Setup Source Localization static parameters*/
libSoundSourceLoc_Handler_Instance.channel_number = 4;
libSoundSourceLoc_Handler_Instance.M12_distance =DIAGONAL;
libSoundSourceLoc_Handler_Instance.M34_distance =DIAGONAL;
libSoundSourceLoc_Handler_Instance.sampling_frequency = AUDIO_IN_SAMPLING_FREQUENCY;
libSoundSourceLoc_Handler_Instance.algorithm = ACOUSTIC_SL_ALGORITHM_BMPH;
libSoundSourceLoc_Handler_Instance.ptr_M1_channels = 4;
libSoundSourceLoc_Handler_Instance.ptr_M2_channels = 4;
libSoundSourceLoc_Handler_Instance.ptr_M3_channels = 4;
libSoundSourceLoc_Handler_Instance.ptr_M4_channels = 4;
libSoundSourceLoc_Handler_Instance.samples_to_process = 4096; //Initial - 512;
AcousticSL_getMemorySize( &libSoundSourceLoc_Handler_Instance);
libSoundSourceLoc_Handler_Instance.pInternalMemory=(uint32_t *)malloc(libSoundSourceLoc_Handler_Instance.internal_memory_size);
error_value += AcousticSL_Init( &libSoundSourceLoc_Handler_Instance);
/*Setup Source Localization dynamic parameters*/
libSoundSourceLoc_Config_Instance.resolution =10;
libSoundSourceLoc_Config_Instance.threshold =15;
error_value += AcousticSL_setConfig(&libSoundSourceLoc_Handler_Instance, &libSoundSourceLoc_Config_Instance);
/*Error Management*/
if(error_value != 0U)
{
Error_Handler();
}
/*Malloc Failure*/
if(libSoundSourceLoc_Handler_Instance.pInternalMemory == NULL)
{
Error_Handler();
}
}
Solved! Go to Solution.
2022-01-10 03:30 AM
Hi @PJ.3 ,
The two libraries, as they have been built, support the data processing at 16, 32 and 48KHz. Our experts told me that they never checked them working at different sample frequencies.
In the last version of the X-CUBE-MEMSMIC1 (available online), the libraries have been released in their source code “as is�?, so that the user could modify them and check their functioning at 96KHz.
To do this in the libSoundSourceLoc_Init of libSoundSourceLoc.c is to cancel or modify this control below:
/*SAMPLING FREQUENCY*/
if( (pHandler->sampling_frequency == 16000U) || (pHandler->sampling_frequency == 32000U) || (pHandler->sampling_frequency == 48000U))
{
SLocInternal->sampling_frequency = pHandler->sampling_frequency;
}
else
{
SLocInternal->sampling_frequency = 16000; /*Set default Value*/
ret |= ACOUSTIC_SL_SAMPLING_FREQ_ERROR;
}
This suggestion is experimental, so please let me know if it is working in your project.
Is so, please click on Select as Best at the bottom of this post. This will help other users with the same issue to find the answer faster.
-Eleon
2022-01-10 03:30 AM
Hi @PJ.3 ,
The two libraries, as they have been built, support the data processing at 16, 32 and 48KHz. Our experts told me that they never checked them working at different sample frequencies.
In the last version of the X-CUBE-MEMSMIC1 (available online), the libraries have been released in their source code “as is�?, so that the user could modify them and check their functioning at 96KHz.
To do this in the libSoundSourceLoc_Init of libSoundSourceLoc.c is to cancel or modify this control below:
/*SAMPLING FREQUENCY*/
if( (pHandler->sampling_frequency == 16000U) || (pHandler->sampling_frequency == 32000U) || (pHandler->sampling_frequency == 48000U))
{
SLocInternal->sampling_frequency = pHandler->sampling_frequency;
}
else
{
SLocInternal->sampling_frequency = 16000; /*Set default Value*/
ret |= ACOUSTIC_SL_SAMPLING_FREQ_ERROR;
}
This suggestion is experimental, so please let me know if it is working in your project.
Is so, please click on Select as Best at the bottom of this post. This will help other users with the same issue to find the answer faster.
-Eleon