Showing results for 
Search instead for 
Did you mean: 

Data types and sizes of PDM and PCM buffers for the pdm2pcm library

Associate III

I am performing audio acquisition from 4 MP34DT01-M microphones using SAI interface and pdm2pcm library on STM32H743.

My first question is about the types of variables used in the PDM and PCM buffers. I am storing data from 4 microphones in 32-bit slots (8 bits per microphone) in each frame.

Currently it looks like this in my case:

#define PDM_buffer_size 4096*4*6
#define PCM_buffer_size 4096*4
uint32_t PDM_buffer[PDM_buffer_size];
uint16_t PCM_buffer[PCM_buffer_size];
HAL_SAI_Receive_DMA(&hsai_BlockA1, (uint8_t*)PDM_buffer, PDM_buffer_size);
PDM_Filter(&(((uint8_t*)PDM_buffer)[0]), &(((uint16_t*)PCM_buffer)[0]), &PDM1_filter_handler);
PDM_Filter(&(((uint8_t*)PDM_buffer)[1]), &(((uint16_t*)PCM_buffer)[1]), &PDM2_filter_handler);
PDM_Filter(&(((uint8_t*)PDM_buffer)[2]), &(((uint16_t*)PCM_buffer)[2]), &PDM3_filter_handler);
PDM_Filter(&(((uint8_t*)PDM_buffer)[3]), &(((uint16_t*)PCM_buffer)[3]), &PDM4_filter_handler);

However, the declaration of HAL_SAI_Receive_DMA is as follows:

HAL_StatusTypeDef HAL_SAI_Receive_DMA(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size)

On the one hand the pointer is 8-bit and the buffer size is 16-bit and mine is 32-bit.

Please let me know if I have this right.

The other issue concerns the size of the buffers used. While the PCM_buffer is quite obvious and equal to the value of output_samples_number (the number of samples by request) multiplied by 4 microphones, with the PDM_buffer I already have a problem. I chose the value experimentally until it worked, whereas I have no idea why it already works with the six and not, for example, with the four. I am using a decimation ratio of 64.

Can you suggest how to get this data right?

ST Employee

Hello @RPuch.2,

X-CUBE-MEMSMIC1 (link) provides an example of multi-microphone audio acquisition. Unfortunately STM32H7 is not supported by the package, but you can have a look to the code in the Microphone_Streaming demo available for STM32F4 or STM32F7. It's a good starting point.

Following the above-mentioned example, you will see how to properly use the PDM_FIlter function and how to setup the buffer you need.


Best regards