90 lines
3.1 KiB
C
90 lines
3.1 KiB
C
#include "test_common.h"
|
||
|
||
static int test_audio_pass_through(void) {
|
||
printf("Test: audio pass‑through (connectivity)\n");
|
||
pid_t pid = start_looper();
|
||
if (pid < 0) return 1;
|
||
jack_client_t *client;
|
||
jack_status_t status;
|
||
client = jack_client_open("test_passthrough", JackNoStartServer, &status);
|
||
if (client == NULL) {
|
||
fprintf(stderr, " SKIP: cannot open JACK client (server not running?)\n");
|
||
kill(pid, SIGTERM);
|
||
waitpid(pid, NULL, 0);
|
||
return 1;
|
||
}
|
||
jack_port_t *output_port = jack_port_register(client, "output",
|
||
JACK_DEFAULT_AUDIO_TYPE,
|
||
JackPortIsOutput, 0);
|
||
jack_port_t *input_port = jack_port_register(client, "input",
|
||
JACK_DEFAULT_AUDIO_TYPE,
|
||
JackPortIsInput, 0);
|
||
if (!output_port || !input_port) {
|
||
fprintf(stderr, " FAIL: could not register ports\n");
|
||
jack_client_close(client);
|
||
kill(pid, SIGTERM);
|
||
waitpid(pid, NULL, 0);
|
||
return 1;
|
||
}
|
||
safe_usleep(200000);
|
||
const char *looper_input = "looper:input";
|
||
const char *looper_output = "looper:output";
|
||
char my_output[64], my_input[64];
|
||
snprintf(my_output, sizeof(my_output), "test_passthrough:output");
|
||
snprintf(my_input, sizeof(my_input), "test_passthrough:input");
|
||
if (jack_connect(client, my_output, looper_input) != 0) {
|
||
fprintf(stderr, " FAIL: cannot connect\n");
|
||
jack_client_close(client);
|
||
kill(pid, SIGTERM);
|
||
waitpid(pid, NULL, 0);
|
||
return 1;
|
||
}
|
||
if (jack_connect(client, looper_output, my_input) != 0) {
|
||
fprintf(stderr, " FAIL: cannot connect\n");
|
||
jack_client_close(client);
|
||
kill(pid, SIGTERM);
|
||
waitpid(pid, NULL, 0);
|
||
return 1;
|
||
}
|
||
passthrough_output_port = output_port;
|
||
passthrough_input_port = input_port;
|
||
passthrough_phase = 0.0f;
|
||
passthrough_freq = 440.0f;
|
||
passthrough_sample_rate = jack_get_sample_rate(client);
|
||
passthrough_total_samples = 0;
|
||
passthrough_sum_sq = 0.0;
|
||
passthrough_done = 0;
|
||
continuous_sine = 1;
|
||
beep_remaining = 0;
|
||
jack_set_process_callback(client, passthrough_process, NULL);
|
||
if (jack_activate(client) != 0) {
|
||
fprintf(stderr, " FAIL: cannot activate client\n");
|
||
jack_client_close(client);
|
||
kill(pid, SIGTERM);
|
||
waitpid(pid, NULL, 0);
|
||
return 1;
|
||
}
|
||
safe_usleep(2200000);
|
||
int saw_input = passthrough_done;
|
||
double rms = passthrough_total_samples > 0 ?
|
||
sqrt(passthrough_sum_sq / passthrough_total_samples) : 0.0;
|
||
jack_deactivate(client);
|
||
jack_client_close(client);
|
||
kill(pid, SIGTERM);
|
||
waitpid(pid, NULL, 0);
|
||
if (!saw_input) {
|
||
fprintf(stderr, " FAIL: looper did not produce output (no callback run?)\n");
|
||
return 1;
|
||
}
|
||
if (rms < 0.001) {
|
||
fprintf(stderr, " FAIL: looper output RMS too small (%.6f)\n", rms);
|
||
return 1;
|
||
}
|
||
printf(" PASS (RMS %.6f)\n", rms);
|
||
return 0;
|
||
}
|
||
|
||
int test_audio(void) {
|
||
return test_audio_pass_through();
|
||
}
|