Skip to content

Instantly share code, notes, and snippets.

@20kdc
Last active March 3, 2018 22:22
Show Gist options
  • Save 20kdc/10dc07b30b1d010e4de4c19c53bcb64b to your computer and use it in GitHub Desktop.
Save 20kdc/10dc07b30b1d010e4de4c19c53bcb64b to your computer and use it in GitHub Desktop.
init
while true
if audout does not contain buffer1
decode to buffer1, then schedule it
if audout does not contain buffer2
decode to buffer2, then schedule it.
wait for buffer finish. make sure timeout is a reasonable time for 3 buffers worth of audio to play in, just in case.
-- Modified from Ghabry's code
instance->LockMutex();
for (int index = 0; index < 2; index++) {
// If the function errors, we assume the buffer isn't there. Might want to change this.
bool contain = true;
// Either one or none of the buffers are playing, in which case this appends the buffers that aren't playing,
// or two buffers are playing due to some sort of freak accident,
audoutContainsAudioOutBuffer(source_buffer[index], &contain);
if (!contain) {
instance->Decode((uint8_t*)source_buffer[index]->buffer, buf_size);
audoutAppendAudioOutBuffer(source_buffer[index]);
}
}
instance->UnlockMutex();
// we don't do anything with the result values, but they have to be non-null
// Apparently, the timeout is documented as waiting until all buffers are finished.
// If this is true, comment this out, add a sleep for 1/2 buffer time
audoutWaitPlayFinish(&released_buffer, &released_count, U64_MAX);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment