LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   latency and audio programming in real-time (https://www.linuxquestions.org/questions/programming-9/latency-and-audio-programming-in-real-time-662282/)

tanoatlq 08-12-2008 02:21 PM

latency and audio programming in real-time
 
Hello,
I am not an expert about real-time programming issues, so I am here :-)
Suppose I have to play audio while displaying some stuff on the screen, and
that this displaying should go in time with the audio output. Now, my tools
to achieve this task is libsdl and alsa (I cannot use libsdl audio for various reasons),
however I would like to maintain discussion abstract from my solutions. From
what I read the best thing to do to avoid latency problem is run the code that
should output audio in a separate thread, but how to sync what I have to display
on the screen? I.e. how can other threads know how many samples were flushed
to audio output stream? I think a simple variable should solve (Perhaps this var
could even not need to be protected from race courses, because only the audio
thread update it, while the others read it only, isn't it?).
Any suggestion or papers?
Thanks,
tano

Mara 08-12-2008 02:38 PM

Most people would not synchronize it, just assume that when then started at the same time and the environment is more or less real-time, their latencies will be also the same. That may lead, of course, to problems.

Variable is a good idea, with atomic read/write operations it will be also very fast and protected from races (if you haven't used variables with atomic operations before, you may want to read more about them, but that's really simple: just a variable that is modified always in one step - there are special functions to perform such operations). You may set the variable in one thread and check it from time to time in the other one and re-synchronize if needed.

tanoatlq 08-12-2008 05:01 PM

Thanks! I will do another question more specific about the atomicity issue when
I will end studying the subject.


All times are GMT -5. The time now is 12:54 AM.