Optimization of execution time of audio capture call in c/c++ (ALSA) I am working on a Audio Deep Learning Project. In this C++ project I need to capture real-time audio and then do pre-processing and the pre-processed output is fed to the Deep Learning Network.

I am fetching 50 ms audio data in each call at 16000 sampling rate, i.e. 800 samples are fetched in the audio capture call.

Sometimes this call takes more than 50 ms, my processing code is taking ~30 ms. 

If the audio-capture + processing takes more than 50 ms, is that mean I lost some audio data?

Can the audio capture call be optimized?

Implementation Info:-
I have the working code on raspberry pi and my processing code is armv7 optimized.

Execution time is measured using std::chrono in c++ using high_resolution_clock.
Capture audio into a FIFO, and process the samples in that FIFO in a separate thread.  That way, timing variations in your processing thread won’t block the audio input.

Very commonly the audio input FIFO is implemented using a lock-free ring buffer so it never blocks.  A separate processing thread can poll the buffer at some suitable fixed rate (video frame rate or network data rate for a given MTU size, etc.)