This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Why Thingy52 PDM sample code skip buffer ?

I am using thing SDK. And,following function is part of thingy SDK.
Could someone can explain why the following function needs skip 31 times?

static void drv_audio_pdm_event_handler(uint32_t *p_buffer, uint16_t length)
{
    ASSERT(length == CONFIG_PDM_BUFFER_SIZE_SAMPLES);

    if (m_skip_buffers)  //m_skip_buffers-->31
    {
        m_skip_buffers -= 1;
    }
    else
    {
        m_buffer_handler((int16_t *)p_buffer, length);//static void m_audio_buffer_handler(int16_t *p_buffer, uint16_t samples)
    }
}

Parents
  • Hi

    The m_skip_buffers counter is controlled by the following define in drv_audio_config.h:

    // <o> PDM Microphone Transient State Length [ms] <1-1000>
    // <i> Set the length of the PDM microphone transient state. In this state, the microphone produces invalid data after wakeup or after it is powered on.
    #define CONFIG_PDM_TRANSIENT_STATE_LEN 500

    Apparently some of these PDM microphones need some time after startup before they produce valid data, so to avoid unwanted clicks or noise when starting the microphone it is necessary to ignore the first 500ms of audio data produced. 

    Best regards
    Torbjørn

  • Hi overbekk

    Thank's for your response.

    I have another question. How to verify the data via the oscilloscope.

    I am going to use following C code to explain my question.

    static int validdata = 0;
    static void m_audio_buffer_handler(int16_t *p_buffer, uint16_t samples)
    {
        uint32_t     err_code;
        pdm_buf_t  * p_pdm_buf = NULL;
        uint32_t     pdm_buf_addr;
    	
    
    int8_t *ptr = (int8_t *)p_buffer;
    if(validdata < 1){
    	NRF_LOG_INFO("[%d] 0x%04x 0x%04x 0x%04x 0x%04x\r\n", samples, *p_buffer , *(p_buffer+1) , *(p_buffer+2), *(p_buffer+3));
    }
    validdata++;
    
        for(uint32_t i = 0; i < PDM_BUF_NUM; i++)
        {
            if ( m_pdm_buf[i].free == true )
            {
                m_pdm_buf[i].free    = false;
                m_pdm_buf[i].samples = samples;
                for (uint32_t j = 0; j < samples; j++)
                {
                    m_pdm_buf[i].buf[j] = p_buffer[j];
                }
                p_pdm_buf = &m_pdm_buf[i];
                pdm_buf_addr = (uint32_t)&m_pdm_buf[i];
    
                break;
            }
        }
    
        if (p_pdm_buf != NULL)
        {
            err_code = app_sched_event_put(&pdm_buf_addr, sizeof(pdm_buf_t *), m_audio_process);
            APP_ERROR_CHECK(err_code);
        }
        else
        {
            NRF_LOG_INFO("m_audio_buffer_handler: BUFFER FULL!!\r\n");
        }
    }

    drv_audio_pdm_event_handler() will skip invalid data then send valid data to m_audio_buffer_handler() to process.

    When I get CLK and DIN via an occilloscope's trigger function these data are invalid at the beginning(microphone wake up). Because occilloscope's trigger function can not get valid data so can not verify thes data with print out information .

    So,How to verify CLK and DIN via the oscilloscope ?

  • Hi

    I am a bit unsure what you are trying to do. 

    Do you want to trigger the scope once the first valid data is sent from the microphone?

    If so maybe you could set a GPIO in the drv_audio_pdm_event_handler(..) function once the m_skip_buffers counter reaches 0, and use this signal to trigger the oscilloscope?

    Best regards
    Torbjørn

Reply Children
Related