Register a domain and help support LQ
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-12-2008, 02:21 PM   #1
Registered: Mar 2007
Posts: 157

Rep: Reputation: 30
latency and audio programming in real-time

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?
Old 08-12-2008, 02:38 PM   #2
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,545

Rep: Reputation: 160Reputation: 160
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.
Old 08-12-2008, 05:01 PM   #3
Registered: Mar 2007
Posts: 157

Original Poster
Rep: Reputation: 30
Thanks! I will do another question more specific about the atomicity issue when
I will end studying the subject.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Real Time Clock & Real Time Timer jiramak Linux - Newbie 1 09-05-2007 06:43 PM
LXer: Real-time garbage collection with Real-time Java LXer Syndicated Linux News 0 05-05-2007 12:16 PM
LXer: Real-time Linux gains real-time JVM LXer Syndicated Linux News 0 10-12-2006 10:54 AM
Real Time Programming cyberX Ubuntu 3 09-04-2006 10:19 AM
Real-Time programming javpogon Programming 5 09-04-2003 08:25 AM

All times are GMT -5. The time now is 08:57 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration