fix: replace usleep with nanosleep and fix const correctness in tests
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
#include <jack/jack.h>
|
#include <jack/jack.h>
|
||||||
#include <jack/midiport.h>
|
#include <jack/midiport.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
/* static variables for passthrough test */
|
/* static variables for passthrough test */
|
||||||
static jack_port_t *passthrough_output_port = NULL;
|
static jack_port_t *passthrough_output_port = NULL;
|
||||||
@@ -32,6 +33,13 @@ static jack_client_t *midi_inject_client = NULL;
|
|||||||
static unsigned char midi_inject_note = 0;
|
static unsigned char midi_inject_note = 0;
|
||||||
static unsigned char midi_inject_velocity = 0;
|
static unsigned char midi_inject_velocity = 0;
|
||||||
|
|
||||||
|
static void safe_usleep(unsigned int usec) {
|
||||||
|
struct timespec ts;
|
||||||
|
ts.tv_sec = usec / 1000000;
|
||||||
|
ts.tv_nsec = (usec % 1000000) * 1000L;
|
||||||
|
nanosleep(&ts, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static int midi_inject_process(jack_nframes_t nframes, void *arg) {
|
static int midi_inject_process(jack_nframes_t nframes, void *arg) {
|
||||||
(void)arg;
|
(void)arg;
|
||||||
if (!midi_inject_port) return 0;
|
if (!midi_inject_port) return 0;
|
||||||
@@ -57,8 +65,8 @@ static int passthrough_process(jack_nframes_t nframes, void *arg) {
|
|||||||
(void)arg;
|
(void)arg;
|
||||||
jack_default_audio_sample_t *out =
|
jack_default_audio_sample_t *out =
|
||||||
(jack_default_audio_sample_t *)jack_port_get_buffer(passthrough_output_port, nframes);
|
(jack_default_audio_sample_t *)jack_port_get_buffer(passthrough_output_port, nframes);
|
||||||
jack_default_audio_sample_t *in =
|
const jack_default_audio_sample_t *in =
|
||||||
(jack_default_audio_sample_t *)jack_port_get_buffer(passthrough_input_port, nframes);
|
(const jack_default_audio_sample_t *)jack_port_get_buffer(passthrough_input_port, nframes);
|
||||||
if (!out || !in) return 0;
|
if (!out || !in) return 0;
|
||||||
float *outf = out;
|
float *outf = out;
|
||||||
const float *inf = in;
|
const float *inf = in;
|
||||||
@@ -195,7 +203,7 @@ static int test_audio_pass_through(void) {
|
|||||||
waitpid(pid, NULL, 0);
|
waitpid(pid, NULL, 0);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
usleep(2200000); /* 2.2 seconds */
|
safe_usleep(2200000);
|
||||||
int saw_input = passthrough_done;
|
int saw_input = passthrough_done;
|
||||||
double rms = passthrough_total_samples > 0 ?
|
double rms = passthrough_total_samples > 0 ?
|
||||||
sqrt(passthrough_sum_sq / passthrough_total_samples) : 0.0;
|
sqrt(passthrough_sum_sq / passthrough_total_samples) : 0.0;
|
||||||
@@ -349,7 +357,7 @@ static int test_looper_looping(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* wait enough time for several loops (4 seconds to be safe) */
|
/* wait enough time for several loops (4 seconds to be safe) */
|
||||||
usleep(4000000);
|
safe_usleep(4000000);
|
||||||
|
|
||||||
jack_deactivate(client);
|
jack_deactivate(client);
|
||||||
jack_client_close(client);
|
jack_client_close(client);
|
||||||
@@ -390,7 +398,7 @@ static int test_multiple_channels(void) {
|
|||||||
}
|
}
|
||||||
/* wait long enough for the looper's main loop to process the add command
|
/* wait long enough for the looper's main loop to process the add command
|
||||||
(it sleeps for 1 second between checks, so 1.5 s is safe) */
|
(it sleeps for 1 second between checks, so 1.5 s is safe) */
|
||||||
usleep(1500000);
|
safe_usleep(1500000);
|
||||||
|
|
||||||
int found = 0;
|
int found = 0;
|
||||||
const char **ports = jack_get_ports(client, NULL, JACK_DEFAULT_AUDIO_TYPE, 0);
|
const char **ports = jack_get_ports(client, NULL, JACK_DEFAULT_AUDIO_TYPE, 0);
|
||||||
@@ -500,7 +508,7 @@ static int test_control_key_modifier(void) {
|
|||||||
fprintf(stderr, " FAIL: send note 62 for loop\n");
|
fprintf(stderr, " FAIL: send note 62 for loop\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
usleep(2000000); /* wait for a few loops */
|
safe_usleep(2000000);
|
||||||
jack_deactivate(client);
|
jack_deactivate(client);
|
||||||
jack_client_close(client);
|
jack_client_close(client);
|
||||||
kill(pid, SIGTERM);
|
kill(pid, SIGTERM);
|
||||||
@@ -613,7 +621,7 @@ static int test_bind_channel(void) {
|
|||||||
fprintf(stderr, " FAIL: toggle for loop\n");
|
fprintf(stderr, " FAIL: toggle for loop\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
usleep(2000000);
|
safe_usleep(2000000);
|
||||||
jack_deactivate(client);
|
jack_deactivate(client);
|
||||||
jack_client_close(client);
|
jack_client_close(client);
|
||||||
kill(pid, SIGTERM);
|
kill(pid, SIGTERM);
|
||||||
@@ -741,7 +749,7 @@ static int test_bind_unbind(void) {
|
|||||||
fprintf(stderr, " FAIL: toggle for loop\n");
|
fprintf(stderr, " FAIL: toggle for loop\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
usleep(2000000);
|
safe_usleep(2000000);
|
||||||
jack_deactivate(client);
|
jack_deactivate(client);
|
||||||
jack_client_close(client);
|
jack_client_close(client);
|
||||||
kill(pid, SIGTERM);
|
kill(pid, SIGTERM);
|
||||||
@@ -776,7 +784,7 @@ static int test_remove_channel(void) {
|
|||||||
fprintf(stderr, " FAIL: send note 60 failed\n");
|
fprintf(stderr, " FAIL: send note 60 failed\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
usleep(1500000);
|
safe_usleep(1500000);
|
||||||
/* verify channel1_input exists */
|
/* verify channel1_input exists */
|
||||||
const char **ports = jack_get_ports(client, NULL, JACK_DEFAULT_AUDIO_TYPE, 0);
|
const char **ports = jack_get_ports(client, NULL, JACK_DEFAULT_AUDIO_TYPE, 0);
|
||||||
int found = 0;
|
int found = 0;
|
||||||
@@ -803,7 +811,7 @@ static int test_remove_channel(void) {
|
|||||||
fprintf(stderr, " FAIL: send note 61 failed\n");
|
fprintf(stderr, " FAIL: send note 61 failed\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
usleep(1500000);
|
safe_usleep(1500000);
|
||||||
/* verify channel1_input has disappeared */
|
/* verify channel1_input has disappeared */
|
||||||
ports = jack_get_ports(client, NULL, JACK_DEFAULT_AUDIO_TYPE, 0);
|
ports = jack_get_ports(client, NULL, JACK_DEFAULT_AUDIO_TYPE, 0);
|
||||||
int still_found = 0;
|
int still_found = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user