Well, you understand that I will explain the problem: I use a library called ClanLIB (not my choice), this library, SEEMLY (I'm not sure even reading sourcE), creates a stream that processes the sound.
This stream, when the buffer is empty, tries to get more data, usually it is perplexing when the data generation library is too slow to provide more data before the sound card reaches the end of the buffer.
So, I added my own stream, which continues to generate sound in the background.
This worked fine, except that my own thread sometimes took up too much CPU time and slowed down everything else. To fix this, I added conditional wait.
Conditional wait occurs when the buffer is full, and when ClanLIB requests more data, the wait signaling is signaled, so the buffer write stream resumes (until it is full again).
My problem is that since I added this conditional wait, ClanLIB sound stream and my own music stream, SOMETIMES get a runaway playing music while the rest of the application freezes.
What strange condition can cause this?
pseudo code:
start_sound_thread();
do_lots_of_stuff();
quit();
While(true)
{
play(buffer);
if(buffer_empty)
{
mutex.lock()
buffer = buffer2;
if(buffer2_full)
{
signal(cond1);
buffer2_full = false;
}
mutex.unlock()
}
}
while(true)
{
mutex.lock()
if( check_free_space(buffer2) == 0)
{
buffer2_full = true;
condition_wait(cond1);
}
write_music(buffer2);
mutex.unlock()
}
source
share