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:
7
engine.c
7
engine.c
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user