feat: replace mutex with lock-free ring buffer for real-time audio recording

Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
Loic Coenen
2026-05-04 22:53:24 +00:00
parent 256a06bc21
commit 5ed187a181
3 changed files with 41 additions and 5 deletions

View File

@@ -144,9 +144,10 @@ static int process_callback(jack_nframes_t nframes, void *arg) {
Clip *clip = &state->clips[clip_idx];
if (clip->state == CLIP_RECORDING) {
if (clip->write_position < MAX_BUFFER_SIZE && clip->buffer != NULL) {
clip->buffer[clip->write_position++] = audio_in[ch][i];
}
// Write to lock-free ring buffer instead of clip buffer directly
size_t wp = atomic_load(&state->record_write_pos[ch]);
state->record_buffer[ch][wp % MAX_BUFFER_SIZE] = audio_in[ch][i];
atomic_store(&state->record_write_pos[ch], wp + 1);
}
if (clip->state == CLIP_LOOPING && clip->buffer_size > 0 && clip->buffer != NULL) {