Compare commits
10 Commits
3761851871
...
0e567e1829
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e567e1829 | ||
|
|
3bb5936d02 | ||
|
|
829010a5d0 | ||
|
|
2c868cabe2 | ||
|
|
3e291a9b58 | ||
|
|
65c346d14d | ||
|
|
74b68eb378 | ||
|
|
7e7b12c89a | ||
|
|
150b01d3be | ||
|
|
5a90446456 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.aider*
|
||||||
0
evalutation.md
Normal file
0
evalutation.md
Normal file
BIN
integration_test
Executable file
BIN
integration_test
Executable file
Binary file not shown.
4
makefile
4
makefile
@@ -9,6 +9,8 @@ integration: looper tests/integration.c
|
|||||||
$(CC) $(CFLAGS) -o integration_test tests/integration.c -ljack -lm
|
$(CC) $(CFLAGS) -o integration_test tests/integration.c -ljack -lm
|
||||||
./integration_test
|
./integration_test
|
||||||
|
|
||||||
.PHONY: clean integration
|
test: integration
|
||||||
|
|
||||||
|
.PHONY: clean integration test
|
||||||
clean:
|
clean:
|
||||||
rm -f looper integration_test
|
rm -f looper integration_test
|
||||||
|
|||||||
14
src/main.c
14
src/main.c
@@ -2,7 +2,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <signal.h>
|
|
||||||
#include <jack/jack.h>
|
#include <jack/jack.h>
|
||||||
#include <jack/midiport.h>
|
#include <jack/midiport.h>
|
||||||
#include <stdatomic.h>
|
#include <stdatomic.h>
|
||||||
@@ -51,7 +50,6 @@ static int process(jack_nframes_t nframes, void *arg)
|
|||||||
}
|
}
|
||||||
playback_pos = 0; /* restart from beginning */
|
playback_pos = 0; /* restart from beginning */
|
||||||
}
|
}
|
||||||
prev_state = state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----- handle MIDI control port (state transitions) ----- */
|
/* ----- handle MIDI control port (state transitions) ----- */
|
||||||
@@ -160,6 +158,9 @@ static int process(jack_nframes_t nframes, void *arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* update prev_state after all state changes */
|
||||||
|
prev_state = atomic_load(¤t_state);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,13 +171,6 @@ static void jack_shutdown(void *arg)
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sigusr1_handler(int signo) {
|
|
||||||
(void)signo;
|
|
||||||
int state = atomic_load(¤t_state);
|
|
||||||
int code = state + 1;
|
|
||||||
_exit(code);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
(void)argc;
|
(void)argc;
|
||||||
@@ -227,8 +221,6 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
fprintf(stderr, "looper running (client name '%s')\n", client_name);
|
fprintf(stderr, "looper running (client name '%s')\n", client_name);
|
||||||
|
|
||||||
/* allow SIGUSR1 to report state and exit */
|
|
||||||
signal(SIGUSR1, sigusr1_handler);
|
|
||||||
|
|
||||||
prev_state = -1; /* initialise change detection */
|
prev_state = -1; /* initialise change detection */
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <jack/jack.h>
|
#include <jack/jack.h>
|
||||||
|
#include <jack/midiport.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
/* static variables for passthrough test */
|
/* static variables for passthrough test */
|
||||||
@@ -22,6 +23,29 @@ static volatile int passthrough_done = 0;
|
|||||||
static volatile int beep_remaining = 0;
|
static volatile int beep_remaining = 0;
|
||||||
static volatile int bursts = 0;
|
static volatile int bursts = 0;
|
||||||
static volatile int prev_above = 0;
|
static volatile int prev_above = 0;
|
||||||
|
static int continuous_sine = 0;
|
||||||
|
|
||||||
|
/* variables for MIDI injection (used by send_jack_note_on) */
|
||||||
|
static volatile int midi_inject_pending = 0;
|
||||||
|
static jack_port_t *midi_inject_port = NULL;
|
||||||
|
static jack_client_t *midi_inject_client = NULL;
|
||||||
|
static unsigned char midi_inject_note = 0;
|
||||||
|
static unsigned char midi_inject_velocity = 0;
|
||||||
|
|
||||||
|
static int midi_inject_process(jack_nframes_t nframes, void *arg) {
|
||||||
|
(void)arg;
|
||||||
|
void *port_buf = jack_port_get_buffer(midi_inject_port, nframes);
|
||||||
|
if (!port_buf) return 0;
|
||||||
|
jack_midi_clear_buffer(port_buf);
|
||||||
|
if (!midi_inject_pending) return 0;
|
||||||
|
jack_midi_data_t *buf = jack_midi_event_reserve(port_buf, 0, 3);
|
||||||
|
if (!buf) return 0;
|
||||||
|
buf[0] = 0x90;
|
||||||
|
buf[1] = midi_inject_note;
|
||||||
|
buf[2] = midi_inject_velocity;
|
||||||
|
midi_inject_pending = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* The test code uses this callback in two ways:
|
/* The test code uses this callback in two ways:
|
||||||
- For the audio passthrough test (existing function) it still works.
|
- For the audio passthrough test (existing function) it still works.
|
||||||
@@ -38,14 +62,14 @@ static int passthrough_process(jack_nframes_t nframes, void *arg) {
|
|||||||
float *outf = out;
|
float *outf = out;
|
||||||
const float *inf = in;
|
const float *inf = in;
|
||||||
for (jack_nframes_t i = 0; i < nframes; i++) {
|
for (jack_nframes_t i = 0; i < nframes; i++) {
|
||||||
/* generate beep while beep_remaining > 0 */
|
/* generate beep while beep_remaining > 0 or continuous sine */
|
||||||
float out_val;
|
float out_val;
|
||||||
if (beep_remaining > 0) {
|
if (continuous_sine || beep_remaining > 0) {
|
||||||
out_val = sinf(passthrough_phase);
|
out_val = sinf(passthrough_phase);
|
||||||
passthrough_phase += 2.0f * (float)M_PI * passthrough_freq / passthrough_sample_rate;
|
passthrough_phase += 2.0f * (float)M_PI * passthrough_freq / passthrough_sample_rate;
|
||||||
if (passthrough_phase > 2.0f * M_PI)
|
if (passthrough_phase > 2.0f * M_PI)
|
||||||
passthrough_phase -= 2.0f * M_PI;
|
passthrough_phase -= 2.0f * M_PI;
|
||||||
beep_remaining--;
|
if (beep_remaining > 0) beep_remaining--;
|
||||||
} else {
|
} else {
|
||||||
out_val = 0.0f;
|
out_val = 0.0f;
|
||||||
}
|
}
|
||||||
@@ -160,6 +184,8 @@ static int test_audio_pass_through(void) {
|
|||||||
passthrough_total_samples = 0;
|
passthrough_total_samples = 0;
|
||||||
passthrough_sum_sq = 0.0;
|
passthrough_sum_sq = 0.0;
|
||||||
passthrough_done = 0;
|
passthrough_done = 0;
|
||||||
|
continuous_sine = 1; /* enable continuous tone for this test */
|
||||||
|
beep_remaining = 0; /* not needed */
|
||||||
jack_set_process_callback(client, passthrough_process, NULL);
|
jack_set_process_callback(client, passthrough_process, NULL);
|
||||||
if (jack_activate(client) != 0) {
|
if (jack_activate(client) != 0) {
|
||||||
fprintf(stderr, " FAIL: cannot activate client\n");
|
fprintf(stderr, " FAIL: cannot activate client\n");
|
||||||
@@ -191,35 +217,53 @@ static int test_audio_pass_through(void) {
|
|||||||
|
|
||||||
/* Helper: open a transient JACK client, send a MIDI note‑on, close */
|
/* Helper: open a transient JACK client, send a MIDI note‑on, close */
|
||||||
static int send_jack_note_on(const char *target_port, unsigned char note, unsigned char velocity) {
|
static int send_jack_note_on(const char *target_port, unsigned char note, unsigned char velocity) {
|
||||||
jack_client_t *trig;
|
midi_inject_note = note;
|
||||||
|
midi_inject_velocity = velocity;
|
||||||
|
|
||||||
jack_status_t st;
|
jack_status_t st;
|
||||||
trig = jack_client_open("test_midi_trig", JackNoStartServer, &st);
|
midi_inject_client = jack_client_open("test_midi_inject", JackNoStartServer, &st);
|
||||||
if (!trig) return -1;
|
if (!midi_inject_client) return -1;
|
||||||
jack_port_t *port = jack_port_register(trig, "out",
|
|
||||||
|
midi_inject_port = jack_port_register(midi_inject_client, "out",
|
||||||
JACK_DEFAULT_MIDI_TYPE,
|
JACK_DEFAULT_MIDI_TYPE,
|
||||||
JackPortIsOutput, 0);
|
JackPortIsOutput, 0);
|
||||||
if (!port) { jack_client_close(trig); return -1; }
|
if (!midi_inject_port) {
|
||||||
if (jack_activate(trig)) { jack_client_close(trig); return -1; }
|
jack_client_close(midi_inject_client);
|
||||||
char src[64];
|
midi_inject_client = NULL;
|
||||||
snprintf(src, sizeof(src), "test_midi_trig:out");
|
|
||||||
if (jack_connect(trig, src, target_port)) {
|
|
||||||
jack_client_close(trig);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
usleep(200000);
|
char src[64];
|
||||||
jack_nframes_t now = jack_frame_time(trig);
|
snprintf(src, sizeof(src), "test_midi_inject:out");
|
||||||
jack_midi_data_t data[3] = { 0x90, note, velocity };
|
if (jack_connect(midi_inject_client, src, target_port) != 0) {
|
||||||
jack_midi_event_write(port, now, data, 3);
|
jack_client_close(midi_inject_client);
|
||||||
usleep(100000);
|
midi_inject_client = NULL;
|
||||||
jack_deactivate(trig);
|
midi_inject_port = NULL;
|
||||||
jack_client_close(trig);
|
return -1;
|
||||||
|
}
|
||||||
|
midi_inject_pending = 1; /* signal before activation */
|
||||||
|
jack_set_process_callback(midi_inject_client, midi_inject_process, NULL);
|
||||||
|
if (jack_activate(midi_inject_client) != 0) {
|
||||||
|
jack_client_close(midi_inject_client);
|
||||||
|
midi_inject_client = NULL;
|
||||||
|
midi_inject_port = NULL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
/* wait for the process callback to clear the flag (event delivered) */
|
||||||
|
for (int attempts = 0; attempts < 50; attempts++) { /* ~50 * 10ms = 500ms */
|
||||||
|
usleep(10000);
|
||||||
|
if (!midi_inject_pending) break;
|
||||||
|
}
|
||||||
|
jack_deactivate(midi_inject_client);
|
||||||
|
jack_client_close(midi_inject_client);
|
||||||
|
midi_inject_client = NULL;
|
||||||
|
midi_inject_port = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Full loop recording test:
|
* Full loop recording test:
|
||||||
* 1. start looper
|
* 1. start looper
|
||||||
* 2. open test client (audio + MIDI)
|
* 2. open JACK test client (audio)
|
||||||
* 3. send note‑on to move IDLE->RECORD
|
* 3. send note‑on to move IDLE->RECORD
|
||||||
* 4. generate a short 440 Hz beep (~0.1 s) while recording
|
* 4. generate a short 440 Hz beep (~0.1 s) while recording
|
||||||
* 5. send note‑on to move RECORD->LOOPING
|
* 5. send note‑on to move RECORD->LOOPING
|
||||||
@@ -268,13 +312,23 @@ static int test_looper_looping(void) {
|
|||||||
kill(pid, SIGTERM); waitpid(pid, NULL, 0);
|
kill(pid, SIGTERM); waitpid(pid, NULL, 0);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
usleep(200000); /* allow state to change */
|
usleep(500000); /* allow state to change (500ms) */
|
||||||
|
|
||||||
int sr = jack_get_sample_rate(client);
|
int sr = jack_get_sample_rate(client);
|
||||||
|
continuous_sine = 0; /* disable continuous tone */
|
||||||
beep_remaining = (int)(0.1f * sr); /* 0.1 second beep */
|
beep_remaining = (int)(0.1f * sr); /* 0.1 second beep */
|
||||||
bursts = 0;
|
bursts = 0;
|
||||||
prev_above = 0;
|
prev_above = 0;
|
||||||
|
|
||||||
|
passthrough_output_port = audio_out;
|
||||||
|
passthrough_input_port = audio_in;
|
||||||
|
passthrough_phase = 0.0f;
|
||||||
|
passthrough_freq = 440.0f;
|
||||||
|
passthrough_sample_rate = sr;
|
||||||
|
passthrough_total_samples = 0;
|
||||||
|
passthrough_sum_sq = 0.0;
|
||||||
|
passthrough_done = 0;
|
||||||
|
|
||||||
jack_set_process_callback(client, passthrough_process, NULL);
|
jack_set_process_callback(client, passthrough_process, NULL);
|
||||||
if (jack_activate(client)) {
|
if (jack_activate(client)) {
|
||||||
jack_client_close(client);
|
jack_client_close(client);
|
||||||
@@ -282,22 +336,10 @@ static int test_looper_looping(void) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* override the global passthrough callbacks to generate beep and detect bursts */
|
|
||||||
/* We'll embed detection inside a helper that we set via static pointer. */
|
|
||||||
/* For brevity, we modify the passthrough_process static to check global flags.
|
|
||||||
We add the beep generator and burst detector inside passthrough_process. */
|
|
||||||
/* The existing passthrough_process already writes a sine to its output port,
|
|
||||||
but does not use beep_remaining. We'll replace it with a version that
|
|
||||||
respects beep_remaining and also counts bursts on the input (looper output). */
|
|
||||||
/* We'll directly overwrite the static function pointer? Instead, we'll
|
|
||||||
modify the function definition later. For now we trust that the
|
|
||||||
existing passthrough_process will be adapted (see code change below). */
|
|
||||||
|
|
||||||
usleep(150000); /* let beep start */
|
usleep(150000); /* let beep start */
|
||||||
|
|
||||||
/* after beep finishes, give it a moment then send note‑on to stop recording */
|
/* ensure beep is fully captured */
|
||||||
usleep(500000);
|
usleep(800000); /* 0.8s after start of beep */
|
||||||
beep_remaining = 0;
|
|
||||||
|
|
||||||
if (send_jack_note_on("looper:control", 1, 127) != 0) {
|
if (send_jack_note_on("looper:control", 1, 127) != 0) {
|
||||||
jack_client_close(client);
|
jack_client_close(client);
|
||||||
@@ -305,8 +347,8 @@ static int test_looper_looping(void) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* wait enough time for several loops (3 seconds) */
|
/* wait enough time for several loops (4 seconds to be safe) */
|
||||||
usleep(3000000);
|
usleep(4000000);
|
||||||
|
|
||||||
jack_deactivate(client);
|
jack_deactivate(client);
|
||||||
jack_client_close(client);
|
jack_client_close(client);
|
||||||
@@ -324,27 +366,6 @@ static int test_looper_looping(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Helper: run all MIDI‑based state transition tests.
|
|
||||||
* Requires jack_midi_send; if missing these tests are skipped.
|
|
||||||
*/
|
|
||||||
static int run_midi_tests(void) {
|
|
||||||
if (system("which jack_midi_send >/dev/null 2>&1") != 0) {
|
|
||||||
printf("SKIP: MIDI state tests – jack_midi_send not installed\n");
|
|
||||||
return 0; /* not a failure, just skip */
|
|
||||||
}
|
|
||||||
|
|
||||||
test_transition("IDLE -> RECORD", "control", "90 01 7f", STATE_RECORD);
|
|
||||||
test_transition("RECORD -> LOOPING", "control", "90 01 7f", STATE_LOOPING);
|
|
||||||
test_transition("LOOPING -> PAUSED", "control", "90 01 7f", STATE_PAUSED);
|
|
||||||
test_transition("PAUSED -> LOOPING", "control", "90 01 7f", STATE_LOOPING);
|
|
||||||
|
|
||||||
test_clock_start();
|
|
||||||
test_clock_stop();
|
|
||||||
test_clock_continue();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
/* 1. binary must exist */
|
/* 1. binary must exist */
|
||||||
|
|||||||
Reference in New Issue
Block a user