On Tue Jan 24 12:26:24 2023 +0000, Jinoh Kang wrote:
- Syntax: Redundant parentheses.
- CSE: the common subexpression (`frames_available *
impl->capture_wfx->nBlockAlign`) can be moved into its own variable. 3. Since we're fetching audio packets in a loop, there is no guarantee that the buffer won't overflow. How about:
SIZE_T packet_size = frames_available * impl->capture_wfx->nBlockAlign; if (tmp_buf_offset + packet_size > tmp_buf_size) { /* Defer processing until the next iteration of the worker loop. */ IAudioCaptureClient_ReleaseBuffer(impl->capture_client, 0); SetEvent(impl->audio_buf_event); break; } memcpy(tmp_buf + tmp_buf_offset, audio_buf, packet_size); tmp_buf_offset += packet_size; IAudioCaptureClient_ReleaseBuffer(impl->capture_client, frames_available);
and double (or triple) `tmp_buf_size` before `malloc()`. (The `SetEvent` can be replaced with a traker boolean flag that lets you bypass the wait entirely if you so prefer.)
Should I really double or triple the size?