[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
I have the opensl working a little bit. There seem to be two ways for audio drivers to work:
1. callbacks from the audio subsystem to request more data
2. polling thread that writes data to the audio system as fast as possible
Opensl supports 1 but I couldn't seem to get it to work so ultimately I ended up using option 2. I copied the code from the pulse audio driver which does this in a loop
while (1){
void * data = al_voice_update(...);
pa_write(data);
}
I assume pa_write will block if pulse audio cannot accept any more data, otherwise it will enqueue the data to some buffer local to pulse audio and allow the above loop to continue.
In opensl the equivalent call to pa_write won't copy the data, it just enqueues whatever buffer you pass it to the audio object. So I have an additional check to see if the current queue is empty
while (1){
if (buffer_empty()){
void * data = al_voice_update(...);
enqueue(data);
} else {
rest(1);
}
}
Which works except the audio is noticeably choppy. al_voice_update always returns the same buffer so I can't queue up multiple buffers while one is being played. A possible solution is to copy the data to my own local buffer so opensl doesn't run out of data. Does that seem right?
(Option 1 doesn't seem compatible with Allegro's notion of streaming voices..)