diff --git a/engine.c b/engine.c index 0eac350..aa0af00 100644 --- a/engine.c +++ b/engine.c @@ -1,5 +1,7 @@ #include "engine.h" #include "carla.h" + +#define MAX_NFRAMES 8192 #include #include #include @@ -125,13 +127,11 @@ static int process_callback(jack_nframes_t nframes, void *arg) { for (int ch = 0; ch < MAX_CHANNELS; ch++) { memset(audio_out[ch], 0, sizeof(jack_default_audio_sample_t) * nframes); - // Create temporary buffer for rack processing - float *rack_in = malloc(nframes * sizeof(float)); - float *rack_out = malloc(nframes * sizeof(float)); - - if (!rack_in || !rack_out) { - free(rack_in); - free(rack_out); + // Use stack-allocated buffers (max MAX_NFRAMES samples) + float rack_in[MAX_NFRAMES]; + float rack_out[MAX_NFRAMES]; + if (nframes > MAX_NFRAMES) { + // Should never happen with JACK, but guard continue; } @@ -164,8 +164,6 @@ static int process_callback(jack_nframes_t nframes, void *arg) { // Copy to output memcpy(audio_out[ch], rack_out, nframes * sizeof(jack_default_audio_sample_t)); - free(rack_in); - free(rack_out); } return 0;