BUFFER SIZE OF I2S

Hi Engineers,

I am developing an application which is kind of similar to an MP3 player.

I am reading an audio file of wav format from SD card using fatfs library f_read() function with buffer size of 1024 bytes.

and I am transmitting the buffer through i2s. What I found is the audio file is playing with more speed as expected and also experiencing

some pop and tick sounds. The clock configurations are all fine as LRCK is 44100, SWIDTH 16bit stereo.

I tried different sizes of buffer but still it didn't make any difference rather some speed variations.

Can anyone help me out solving this issue.

Thanks and regards,

Ajmal

Parents Reply
  • Before the expert comes, can you try to playback one of those fixed 1kHz tones, record the sound and send it to us? Then we can at least see if it somehow occurs periodically (e.g. related to when buffers are updated) or if it's a shift in the audio that is occuring (may be this is connected to your buffering!!??). Can you share how you have connected your audio dac, proper/good grounding and electrical connections, does starting external hfclk make any difference? or are you using xTAL crystal already?
Children
  • Hi susheel,

    I am using UDA1334 I2S DAC with 3 wire connection 

    LRCLK, BCLK, DIN i have connected this to P0.31, P0.30, P0.29 respectivley with GND and VCC.

    config.sdout_pin = NRFX_I2S_CONFIG_SDOUT_PIN;   //P0.29
    config.sck_pin = NRFX_I2S_CONFIG_SCK_PIN;            //P0.31
    config.lrck_pin = NRFX_I2S_CONFIG_LRCK_PIN;         //P0.30
    config.mck_pin = NRFX_I2S_CONFIG_MCK_PIN;         //P0.27

    are you using xTAL crystal already?

    I am not implementing external oscillator since i am able to achieve all the clocks according to standard 

    as mentioned in Table.1 configuration example. 

    can you try to playback one of those fixed 1kHz tones

    i didn't get which example it is. since I am using UDA1334 I2S DAC it has only audio jack option so how can I record?

    Thanks 

    Ajmal

  • I have implemented a delay of NRFX_DELAY_US(200000); after nrf_drv_i2s_start();

    it is working fine, I mean the audio playback speed is almost same as original but still

    some tick sound i can hear, however this is not the exact solution because it is not working if I modify the code.  The delay always needs to be change as i modify the code.

    ff_result = f_read(&file, (void *)Buff_1, sizeof(Buff_1), (UINT *)&bytes_written_1);
    if(ff_result != FR_OK)
    {
          NRF_LOG_RAW_INFO("%s", Buff_1);
    }

            prepare_tx_data_1(m_buffer_tx[0]);

            nrf_drv_i2s_buffers_t const initial_buffers = {
    .          p_tx_buffer = m_buffer_tx[0]
            };


       err_code = nrf_drv_i2s_start(&initial_buffers, I2S_DATA_BLOCK_WORDS, 0);
       APP_ERROR_CHECK(err_code);

       NRFX_DELAY_US(200000);

    here the size of I2S_DATA_BLOCK_WORDS is 8192 and the size of Buff_1 is 16384.

    so I am txing half buffer as initial_buffers and other half as next_buffers whenever it requests

    static void data_handler(nrfx_i2s_buffers_t* p_released, uint32_t status)
    {

               if (!(status & NRFX_I2S_STATUS_NEXT_BUFFERS_NEEDED))
              {
                  return;
              }


             if (!p_released->p_tx_buffer)
             {
                      nrf_drv_i2s_buffers_t const next_buffers = {
                         .p_tx_buffer = m_buffer_tx[1]
                     };
              APP_ERROR_CHECK(nrf_drv_i2s_next_buffers_set(&next_buffers));
             }
    }

    So I am really confused why it is happening and what is the relation of delay in this case.

  • Hi Ajmal,

    It is not clear to us why you are having those pop or tick sounds. The only explanation we can think of is that there is somewhere varying speed of data that is being transferred. It might help if you create a setting where a trigger to I2S transfer could toggle a GPIO and then you can see the distance between the toggles to see if this remains the same overall.

    For example if this is on the receiver end, you can connect EVENTS_RXPTRUPD ->PPI->GPIOTE in task mode to connect a pin to toggle everytime you receive this event.

Related