fix: use persistent MIDI client and fix save_ring race condition
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
This commit is contained in:
15
src/looper.c
15
src/looper.c
@@ -127,11 +127,12 @@ int process_callback(jack_nframes_t nframes, void *arg) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* push loop output into save ring if saving */
|
||||
if (channels[c].save_ring != NULL) {
|
||||
// push loop output into save ring if saving (atomic load)
|
||||
RingBuf *r = atomic_load_explicit(&channels[c].save_ring, memory_order_acquire);
|
||||
if (r != NULL) {
|
||||
if (state == STATE_LOOPING && channels[c].loop_count > 0) {
|
||||
float *outf = (float *)out;
|
||||
ring_write(channels[c].save_ring, outf, nframes);
|
||||
ring_write(r, outf, nframes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,7 +200,7 @@ int looper_init(jack_client_t *client) {
|
||||
channels[0].loop_count = 0;
|
||||
channels[0].record_pos = 0;
|
||||
channels[0].playback_pos = 0;
|
||||
channels[0].save_ring = NULL;
|
||||
atomic_store_explicit(&channels[0].save_ring, NULL, memory_order_release);
|
||||
|
||||
channels[0].audio_in = jack_port_register(
|
||||
client, "input", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
|
||||
@@ -257,7 +258,9 @@ static void *writer_thread(void *arg) {
|
||||
|
||||
ring_destroy(ring);
|
||||
free(ring);
|
||||
ch->save_ring = NULL;
|
||||
atomic_store_explicit(&ch->save_ring, NULL, memory_order_release);
|
||||
ring_destroy(ring);
|
||||
free(ring);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -326,7 +329,7 @@ void looper_process_commands(jack_client_t *client) {
|
||||
if (ring) {
|
||||
size_t sz = (size_t)channels[0].loop_count * 2;
|
||||
if (ring_init(ring, sz) == 0) {
|
||||
channels[0].save_ring = ring;
|
||||
atomic_store_explicit(&channels[0].save_ring, ring, memory_order_release);
|
||||
pthread_t th;
|
||||
pthread_create(&th, NULL, writer_thread, &channels[0]);
|
||||
pthread_detach(th);
|
||||
|
||||
Reference in New Issue
Block a user