Low latency audio under WEC2013

We develop on the Colibri IMX6 module under WEC2013 operating system. We would like to transmit audio with low latency (about 20ms or below) between the modules. Are there any low latency solution for this problem? For example: low latency audio API support available?
We tried the waveIn-waveOut functions from the mmsystem.h, but these not working well with small buffers (128 sample/buffer, 48kHz samplerate). My experience that the waveInProc() callback function is not called at intervals less than 35ms.

Sorry, but I am not sure I fully understand your question.

  • did you tested the wave* APIs on imx6 or you get those latencies on a different platform?
  • may you describe a bit more in detail the “big picture”? Are you sending/receiving audio between modules? you need short packets? Is the 48KHz sample rate fixed or you may change it if that gives lower latencies?

Sorry to reply with more questions than answer, but I would like to fully understand the issue.
Thank you for your patience.

Thank you your response.

I tested the Winmm API on imx6 colibri module. The test setup is as follows. I put the audio signal to the microphone input. When waveInProc() callback function was called, i inverted a gpio pin and i watched on oscilloscope (then I sent the samples over the network with udp protocol.) But the problem is that waveInProc() callback function called about 35ms period time instead of 2.6ms (128 sample@48kHz sample rate). The result: sent out 2.6ms audio over network, then nothing happened until ~32ms.

Short packet is important for low latency “realtime” audio transmission.

I tried with 48kHz and 8kHz sample rate, the result was same.

I read that WinMM API not optimal for low latency audio stream so i asked are there available other low latency audio support? ( For example: DirectSound, kernel streaming, ASIO, WASAPI, Portaudio, RTaudio… or omitting the operating system, direct register access)

Do you have a simple application we can use to reproduce the issue?
That would help understanding how to fix it.

Here is a simple program, only with the critical part.link text

Or here is another simple program. It loops back the mic input to line output.link text
I attach two oscilloscope photos.

Dear @vighbalazs,

Thank you for sharing the demo project. We are able to reproduce the issue and we would like to discuss it internally and will get back you early next week.

Dear @vighbalazs,

Thank you for your patience. We have tested it the same on Colibri T20, T30, the issue not exists on that. The latency around less than 1ms most of the times except after every 40 to 50 samples there is 60 to 160ms latency. Waveforms are uploaded here for your reference. You need to install Saleae Logic analyzer software to view the data.

Moreover this issue would be related to Audio DMA buffer and driver.

Thank you your response.

I don’t understand exactly, what is means: “after every 40 to 50 samples there is 60 to 160ms latency”? Is the latency 1ms until 40-50 samples and after that increase to 60-160ms?
I opened your waveforms, but I don’t known what signals I see (there are four random square and a sine wave). Is it input-output signals?

Is it possible to request the colibri iMX6 audio driver source code?

Dear @vighbalazs,

Please refer to these pictures for meaningful information

Full waveform:

Full waveform

Enlarged section A:

We ran your sample code on Colibri T20 and captured gpio toggling. You supposed to see the waveform as like in the picture, you might be seen default wave simulation from the software. Please click Open capture/setup and input the file, you will see the actual captured waveforms in Saleae Logic software.

We will get back you soon regarding iMX6 audio driver.

Your right, I saw the demo signals.

I tested with Colibri T20, but there is another problem. Every buffer filling generate callback, but not continously. The callbacks call after ~60ms break (as you measured).This latency is also too much, unsuitable for realtime audio.

you can find a new image that should fix the issue, but this requires some configuration.
You need to configure the audio input buffer size under HKEY_LOCAL_MACHINE\Drivers\Builtin\Audio by adding a DWORD parameter named InputBufferSize.
By default, the size is 4k, with delays between calls of around 30ms, if you reduce that to 256 bytes you should see your function called every 3ms. You can also use the priority256 parameter to increase IST priority (by decreasing the value that is currently 150) to reduce the jitter.
If you can quickly (one week) confirm that this fixes your problem we can include the fix in release 1.4, otherwise, it will be part of the 1.5 release cycle that still needs to be planned.

Thank you.
It looks like this has solved the problem on the input part. But there is still a problem on the output part. There is also a ~35ms period problem. The buffer queue that generated by the waveOutWrite() function will be played after ~35 ms period.

Issue is that the buffer size is fixed and audio driver will play (or collect) a whole buffer before returning control and do the next operation. If you can’t pack your samples in a single big one, I may try to apply same change on output, reducing buffer size, to overcome the issue. It will probably increase CPU load (more interrupts per second) but if you have a multi-core CPU that should be manageable.

Thanks your fast response.

It would be great, if you reduce the buffer size, as you did on input path. We use multi-core CPU.

Here’s a new image with same changes applied to outputpath:
Parameter is called OutputBufferSize.

Thank you.

Now the audio part is working well. This image doesn’t include programs in the start menu, but I could use it for testing. When will you release the release 1.4?

Is it possible to make these changes also to the apalis imx6 module?

Sorry, missing program menu entries is an issue due to the way I quickly built the image. All the relevant tools are there, in the \Windows folder, just missing icons in the menu.
Plan is to release 1.4 image before the end of the year.
Feature should already be supported on Apalis imx6, did you experienced issues there?

I experienced the same issue like on Colibri.

Yes, the BSP works in the same way on both form factors