How to perform non-blocking recording on the device?

Is it possible to write write (); function without blocking without using threads?

short buffer[BUFFER_LEN];
int readcount;

while ((readcount = sounds[index].read(buffer, BUFFER_LEN)))
    write(audio_device, buffer, readcount * sizeof(short));

Sounds are being played, but it blocks the program until it finishes playing.

+3
source share
1 answer

Using fcntlto set a flag O_NONBLOCKfor a file is likely to work, but you should be prepared to handle partial writes and EWOULDBLOCKerrors.

+3
source

Source: https://habr.com/ru/post/1781776/


All Articles