2-midi-looping #3
15
src/looper.c
15
src/looper.c
@@ -30,7 +30,8 @@ spsc_queue_t cmd_queue;
|
||||
static int pending_unregister_idx = -1;
|
||||
static int pending_unregister_cycle = 0;
|
||||
|
||||
/* Deferred free of old channel array (must not free while RT thread may hold pointer) */
|
||||
/* Deferred free of old channel array (must not free while RT thread may hold
|
||||
* pointer) */
|
||||
static struct channel_t *pending_old = NULL;
|
||||
static int pending_old_cycle = 0;
|
||||
|
||||
@@ -182,7 +183,8 @@ int process_callback(jack_nframes_t nframes, void *arg) {
|
||||
const float *f_in = (const float *)in;
|
||||
for (i = 0; i < nframes; i++) {
|
||||
if (active_channels[c].record_pos < LOOP_BUF_SIZE)
|
||||
active_channels[c].loop_buffer[active_channels[c].record_pos++] = f_in[i];
|
||||
active_channels[c].loop_buffer[active_channels[c].record_pos++] =
|
||||
f_in[i];
|
||||
f_out[i] = f_in[i];
|
||||
}
|
||||
} else {
|
||||
@@ -194,9 +196,11 @@ int process_callback(jack_nframes_t nframes, void *arg) {
|
||||
if (active_channels[c].loop_count > 0) {
|
||||
float *outf = (float *)out;
|
||||
for (i = 0; i < nframes; i++) {
|
||||
outf[i] = active_channels[c].loop_buffer[active_channels[c].playback_pos];
|
||||
outf[i] =
|
||||
active_channels[c].loop_buffer[active_channels[c].playback_pos];
|
||||
active_channels[c].playback_pos =
|
||||
(active_channels[c].playback_pos + 1) % active_channels[c].loop_count;
|
||||
(active_channels[c].playback_pos + 1) %
|
||||
active_channels[c].loop_count;
|
||||
}
|
||||
} else {
|
||||
memset(out, 0, sizeof(jack_default_audio_sample_t) * nframes);
|
||||
@@ -404,7 +408,8 @@ void looper_process_commands(jack_client_t *client) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Deferred free of old channel array – wait until RT thread has seen new pointer */
|
||||
/* Deferred free of old channel array – wait until RT thread has seen new
|
||||
* pointer */
|
||||
if (pending_old != NULL) {
|
||||
int current_cycle = atomic_load(&global_rt_cycles);
|
||||
if (current_cycle - pending_old_cycle >= 1) {
|
||||
|
||||
Reference in New Issue
Block a user