Skip to main content
Fib
Associate
Jan 8, 2019 4:43 PM UTC
Question

Correct use of SMR (Sound MeteR) library

Hello.

I'm trying to import the SMR module of the X-CUBE-AUDIO package in one of the projects I am working on. I wish to know the sound pressure level in dB on my microphones.

My application generates a PCM buffer filled this way: 32 samples in 16-bit format (16 samples for each channel). The sampling frequency is 16 kHz.

It seems that everything is set rightly but, when i call the smr_process function, the application goes in Hard Fault.

I am following the API call procedure shown in UM2031, pp. 16-17 (file attached).

Anyone could please help me understand what I'm doing wrong?

Below there's part of the code I am using.

The project runs on STM32F767 MCU.

/* SMR Manager */
void *pSmrPersistentMem = NULL;
void *pSmrScratchMem = NULL;
 
static smr_static_param_t smr_static_param;
static smr_dynamic_param_t smr_dynamic_param;
 
static buffer_t BufferHandler;
static buffer_t *pBufferHandler = &BufferHandler;
 
uint16_t PCM_Data_SMR[32]; 		/* PCM data buffer */
 
 
void AudioSMR_Init()
{
 int32_t error = SMR_ERROR_NONE;
  
 /* Allocat mem for Smr */
 pSmrPersistentMem = malloc(smr_persistent_mem_size); 	/* 0x188 */
 pSmrScratchMem = malloc(smr_scratch_mem_size); 	/* 0xF04 */
 
 /* Effect Initialization and configuration */
 /*-----------------------------------------*/
 /* Enables and resets CRC-32 from STM32 HW */
 __HAL_RCC_CRC_CLK_ENABLE();
 CRC->CR = CRC_CR_RESET;
 
 /* SMR effect reset */
 smr_reset(pSmrPersistentMem, pSmrScratchMem);
 
 /* SMR effect static parameters setting */
 smr_static_param.sampling_rate =16000; 			/* only sampling rate supported */
 
 smr_setParam(&smr_static_param, pSmrPersistentMem);
 
 /* SMR dynamic parameters that can be updated here every frame if required */
 smr_dynamic_param.enable = 1;		/* SMR module enabler */
 smr_dynamic_param.averaging_time = 100;
 smr_dynamic_param.filter_type = SMR_PREFILTER_NONE;
 
 smr_setConfig(&smr_dynamic_param, pSmrPersistentMem);
 
 /* I/O buffers settings */
 BufferHandler.nb_bytes_per_Sample = 2;			/* 16-bit */
 BufferHandler.nb_channels = 2; 					/* stereo */
 BufferHandler.data_ptr = PCM_Data_SMR;
 BufferHandler.buffer_size = 32/2; 		/* just half buffer is process (size per channel) */
 BufferHandler.mode = INTERLEAVED;
}
 
 
void AudioSMR_Process()
{
 int32_t error = SMR_ERROR_NONE;
 uint32_t sample = 0;
 
 /* output signal power sent to terminal IO */
 smr_getConfig(&smr_dynamic_param, pSmrPersistentMem);
 
 smr_process(pBufferHandler, pBufferHandler, pSmrPersistentMem);
 
 /* output signal power sent to terminal IO */
 smr_getConfig(&smr_dynamic_param, pSmrPersistentMem);
 
 printf("Left mean power=%ld dB\n", (int32_t) ( (float) smr_dynamic_param.mean_level_left*0.25) );
 printf("Right mean power=%ld dB\n", (int32_t) ( (float) smr_dynamic_param.mean_level_right*0.25));
}

    This topic has been closed for replies.

    2 replies

    jeantil88
    Associate
    Oct 27, 2020 1:07 PM UTC

    I am not an expert for this, but I think I read somewhere that it only support 48 kHz sampling frequency.

    MReyn
    Associate
    May 6, 2021 12:07 AM UTC

    Did you ever managed to get this to work? I'm trying to implement the same library but i have exactly the same error.