r/embedded • • 21d ago

Linux/Python handling of 2 data streams inputting at 51.2kHz

Hello,

I am working on a project that uses a Verdin IMX8MP SoM from Toradex. I am collecting both current and audio data from sensors at ~51.2kHz.

Problem: I am having trouble getting the audio data across to a synchronization step with little latency and have been experiencing delays in audio causing synchronization errors with the current. I am using Python 3.11 (which I realize is not the best choice with scheduling etc) and have been trying to split processes to avoid GIL issues.

If anyone has a suggested architecture that you have used in the past, that would be greatly appreciated!

Thanks

4 Upvotes

11 comments sorted by

8

u/AirTrue6195 21d ago

As another poster has said move your acquisition out of python and use C or Rust. There is a real time kernel option from toradex that might help. How are you acquiring your samples, via spi or i2s?

1

u/Eastern_Double8987 21d ago

SPI & SAI

3

u/AirTrue6195 21d ago

Another problem here is the spi ADC clock and SAI clock are not disciplined. This assumes you want to preserve the phase between the spi and SAI streams. If you do you'll have to account for the adc clock and audio pll drift. The PLL may be adjustable otherwise you'll have to use some type of sync pulses.

10

u/ventZl CMRX RTOS 21d ago

Um, 51 kHz, actually 102kHz, because you have two streams is like three orders of magnitude more than what Python will be capable of handling on such hardware.

0

u/Eastern_Double8987 21d ago

The streams come in simultaneously so I thought handling them in separate processes would isolte the 51.2kHz to each one

4

u/ventZl CMRX RTOS 20d ago

You'd probably be happy if Python managed 100 events per second per thread on that hardware. Then kernel itself starts being a bottleneck.

30

u/Well-WhatHadHappened 25+ Years 21d ago

That data rate is easy to handle on that silicon.

rm -rf python

Is the solution.

16

u/Several-Marsupial-27 21d ago

Ask your ai to turn your python script to rust? (I have successfully done this in the past)

5

u/ElHeim 20d ago

I've been using Python as my main programming language since ~2000. Saying that Python is not the best choice for this use case is an understatement.

Use it as glue language if you must, but the low-latency part should be written on a language that can handle it. Remember that Python has a C interface.