Minimizing I2S latency

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Minimizing I2S latency

1,140 Views
gertvierman
Contributor II

Hi all,

Short version: what parameters can be tuned in the LPC43xx to minimize I2s audio latency

Long version:

I'm developing a modular synthesizer (as in musical instrument) based on a bunch of LPC4330 CPU's. Each CPU runs a dedicated DSP algorithm (oscillators, filters, wave shapers, samplers, etc) with audio in and out through a codec on the I2S bus. The user can create sounds and effects by connecting audio paths of different modules with analogue cables and tuning parameters.

(Check Modular synthesizer - Wikipedia for a description, for those not familiar with the concept of a modular synth)

The basic system is functional, but I'm not happy with the latency of the audio path. Feedback is a common concept in modular synthesis, but with the current latencies I'm experiencing it is virtually impossible to get good results.

My current firmware configures the I2S bus at 48Khz with the fifo size set to 1. Audio is handled in the I2S IRQ as it comes in, and is sent out in the same function. Basically, something like this:

void i2s_init(void)
{
  I2S_AUDIO_FORMAT_T conf;
  conf.SampleRate = 48000;
  conf.ChannelNumber = 2;
  conf.WordWidth = 16;

  Chip_I2S_Init(LPC_I2S0);
  Chip_I2S_RxConfig(LPC_I2S0, &conf);
  Chip_I2S_TxConfig(LPC_I2S0, &conf);
  Chip_I2S_TxStop(LPC_I2S0);
  Chip_I2S_DisableMute(LPC_I2S0);
  Chip_I2S_TxStart(LPC_I2S0);
        
  Chip_I2S_Int_RxCmd(LPC_I2S0, ENABLE, 1);
  Chip_I2S_Int_TxCmd(LPC_I2S0, ENABLE, 1);
  NVIC_EnableIRQ(I2S0_IRQn);
}

void I2S0_IRQHandler(void)
{
  if(Chip_I2S_GetRxLevel(LPC_I2S0) > 0) {
  uint32_t v = Chip_I2S_Receive(LPC_I2S0);
  Chip_I2S_Send(LPC_I2S0, v);
}

This snippet simple echoes audio on the I2S bus, input to output. The codec used is the UDA1380.

Total round trip latency on audio is approx 1.26 msec at this time. Unfortunately, that's way to high to do things with feedback without ending up with comb filter effects all the time.

Any help is very much appreciated!

1 Reply

792 Views
Carlos_Mendoza
NXP Employee
NXP Employee

Hi Gert,

I would recommend  that you use the DMA to receive and send the data, this will help reduce the latency. Also, please make sure the CPU is running at the highest frequency, this will improve the processing time of the data. In addition, you could use receive and transmit ping pong bufffers, this way while one receive buffer is being filled, the other one is being processed an copied to a transmit buffer.


Hope it helps!

Best Regards,
Carlos Mendoza
Technical Support Engineer

0 Kudos