Audio thread problems

I’m currently faced with latency problems when attempting to play wav samples
using threads. Ive got 3 SDL threads for testing purposes, each with their own
array of mix chunks to play continuesly. Upon executing one thread, the chunks
within that thread are played relatively smoothly and continuesly. However, as
more threads are executed, latency becomes a significant issue with wav samples
from each thread being played at varying and unpredictable rates. With this in
mind, could you please give me advice on how I could possibly achieve multiple
threads, continuesly and concurrently looping wav samples with minimal latency
and maximum consistency???

btw: Ive tried varying the chunk sizes and sample rates with no effect on
latency reduction. Im am using a sound blaster and running redhat 7.3.

Any help is much appreciated
Cheers

Alan Beltran wrote:

I’m currently faced with latency problems when attempting to play wav samples
using threads. Ive got 3 SDL threads for testing purposes, each with their own
array of mix chunks to play continuesly. Upon executing one thread, the chunks
within that thread are played relatively smoothly and continuesly. However, as
more threads are executed, latency becomes a significant issue with wav samples
from each thread being played at varying and unpredictable rates. With this in
mind, could you please give me advice on how I could possibly achieve multiple
threads, continuesly and concurrently looping wav samples with minimal latency
and maximum consistency???

Using separate threads for each audio clip is not a good idea. I am not
aware of any audio tasks that can’t be performed more efficiently in a
single thread.

A good rule of thumb: pretend that SDL_CreateThread pops up a warning
dialog that reads, “Are you sure you want to create this thread?” every
time it executes. Threads are kind of fun to play with, but they are
generally overused, and cause all sorts of headaches. (An entire class
at Georgia Tech, Advanced Operating Systems CS4210, is devoted almost
entirely to using threads safely. It was a very hard class.)

So try getting rid of your multiple threads and mixing everything
together in a single thread. Audio is easy to mix. There’s an example in
Programming Linux Games, http://www.overcode.net/~overcode/writing/plg/,
chapter 4. I bet your latency issues will go away.

-John–
John R. Hall, KG4RUO
http://www.overcode.net