<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>I2S Playback Latency</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/86677/i2s-playback-latency</link><description>Hi, 
 I am using SGTL5000 CODEC to playback the LINEIN and I am using the SGTL5000 driver from this link 
 I am using this I2S configuration 
 
 For I2S Loopback code itself the latency is around 18ms, 
 
 
 Can you guide me on how can i reduce the latency</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 07 Apr 2022 18:52:11 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/86677/i2s-playback-latency" /><item><title>RE: I2S Playback Latency</title><link>https://devzone.nordicsemi.com/thread/362448?ContentTypeID=1</link><pubDate>Thu, 07 Apr 2022 18:52:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fff4690a-f578-4423-a9f1-a7a3e1ce3cf8</guid><dc:creator>Sunil vignesh</dc:creator><description>&lt;p&gt;Hi Sigurd,&lt;/p&gt;
&lt;p&gt;Here is the configure of I2S&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt; // Initialize I2S 
    m_i2s_config.sck_pin      = DRV_SGTL5000_I2S_PIN_BCLK;
    m_i2s_config.lrck_pin     = DRV_SGTL5000_I2S_PIN_LRCLK;
    m_i2s_config.mck_pin      = DRV_SGTL5000_I2S_PIN_MCLK;
    m_i2s_config.sdout_pin    = DRV_SGTL5000_I2S_PIN_TX;
    m_i2s_config.sdin_pin     = DRV_SGTL5000_I2S_PIN_RX;
    m_i2s_config.irq_priority = DRV_SGTL5000_I2S_IRQPriority;
    m_i2s_config.mode         = NRF_I2S_MODE_MASTER;
    m_i2s_config.format       = NRF_I2S_FORMAT_I2S;
    m_i2s_config.alignment    = NRF_I2S_ALIGN_LEFT;
    m_i2s_config.sample_width = NRF_I2S_SWIDTH_16BIT;
    m_i2s_config.channels     = NRF_I2S_CHANNELS_LEFT;
    m_i2s_config.mck_setup    = NRF_I2S_MCK_32MDIV8; 
    m_i2s_config.ratio        = NRF_I2S_RATIO_96X;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and the Frame size is&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define AUDIO_FRAME_WORDS                   320
#define AUDIO_SAMPLE_LEN                  AUDIO_FRAME_WORDS/2
#define I2S_BUFFER_SIZE_WORDS               AUDIO_FRAME_WORDS * 2   // Double buffered - I2S lib will switch between using first and second half
static uint32_t  m_i2s_tx_buffer[I2S_BUFFER_SIZE_WORDS];
static uint32_t  m_i2s_rx_buffer[I2S_BUFFER_SIZE_WORDS];


int main()
{
..
 // Enable audio
    drv_sgtl5000_init_t sgtl_drv_params;
    sgtl_drv_params.i2s_tx_buffer           = (void*)m_i2s_tx_buffer;
    sgtl_drv_params.i2s_rx_buffer           = (void*)m_i2s_rx_buffer;
    sgtl_drv_params.i2s_buffer_size_words   = I2S_BUFFER_SIZE_WORDS/2;
    sgtl_drv_params.i2s_evt_handler         = i2s_sgtl5000_driver_evt_handler;
    sgtl_drv_params.fs                      = DRV_SGTL5000_FS_31250HZ;
    
    m_i2s_tx_buffer[0] = 167;
    m_i2s_tx_buffer[I2S_BUFFER_SIZE_WORDS/2] = 167;
    NRF_LOG_INFO(&amp;quot;size of  m_i2s_tx_buffer %d, %d&amp;quot;, sizeof(m_i2s_tx_buffer) / sizeof(uint32_t), I2S_BUFFER_SIZE_WORDS);
    NRF_LOG_INFO(&amp;quot;i2s_initial_tx_buffer addr1: %d, addr2: %d&amp;quot;, m_i2s_tx_buffer, m_i2s_tx_buffer + I2S_BUFFER_SIZE_WORDS/2);
    NRF_LOG_INFO(&amp;quot;i2s_initial_Rx_buffer addr1: %d, addr2: %d&amp;quot;, m_i2s_rx_buffer, m_i2s_rx_buffer + I2S_BUFFER_SIZE_WORDS/2);
    ..
    ..
    drv_sgtl5000_start();
    }
    
    uint32_t drv_sgtl5000_start(void)
{
    if (m_state == SGTL5000_STATE_IDLE)
    {
        m_state = SGTL5000_STATE_RUNNING;
        nrf_drv_i2s_buffers_t const initial_buffers = {
            .p_tx_buffer = m_external_i2s_buffer.tx_buffer,
            .p_rx_buffer = m_external_i2s_buffer.rx_buffer,
        };
        (void)nrf_drv_i2s_start(&amp;amp;initial_buffers, (m_external_i2s_buffer.buffer_size_words/2), 0);
        
        return NRF_SUCCESS;
    }
    
    return NRF_ERROR_INVALID_STATE;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I have check that we are initializing the I2S with 160 words.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S Playback Latency</title><link>https://devzone.nordicsemi.com/thread/362419?ContentTypeID=1</link><pubDate>Thu, 07 Apr 2022 15:12:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:828c2be5-0404-41cf-974f-a3455907908d</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;It&amp;#39;s an&amp;nbsp;&lt;span&gt;unofficial example, and I don&amp;#39;t have the HW to test here. The only thing I can see that could perhaps&amp;nbsp;affect&amp;nbsp;this is what&amp;nbsp;AUDIO_FRAME_WORDS is set to, and&amp;nbsp;what frequency you run the I2S at.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>