forked from mod-audio/mod-xrun
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjack_xruntotal.c
executable file
·120 lines (94 loc) · 2.42 KB
/
jack_xruntotal.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <stdbool.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <jack/jack.h>
static volatile bool _jack_shutdown = false;
static volatile int _jack_xruns = 0;
static volatile jack_client_t* _jack_client = NULL;
static uint32_t _buffer_size = 0;
static uint32_t _sleep_time = 1;
static void signal_handler(int frame)
{
_jack_shutdown = true;
return;
// unused
(void)frame;
}
static void shutdown_callback(void* arg)
{
_jack_client = NULL;
_jack_shutdown = true;
return;
// unused
(void)arg;
}
static int bufsize_callback(uint32_t bufsize, void* arg)
{
_buffer_size = bufsize;
return 0;
// unused
(void)arg;
}
static int xrun_callback(void* arg)
{
++_jack_xruns;
return 0;
// unused
(void)arg;
}
int main(void)
{
jack_client_t* const client = jack_client_open("jack_xruntotal", JackNoStartServer, NULL);
if (client == NULL)
{
printf("Failed to open jack client\n");
return 1;
}
struct sigaction sterm;
sterm.sa_handler = signal_handler;
sterm.sa_flags = SA_RESTART;
sterm.sa_restorer = NULL;
sigemptyset(&sterm.sa_mask);
sigaction(SIGINT, &sterm, NULL);
sigaction(SIGTERM, &sterm, NULL);
jack_on_shutdown(client, shutdown_callback, NULL);
jack_set_buffer_size_callback(client, bufsize_callback, NULL);
jack_set_xrun_callback(client, xrun_callback, NULL);
_buffer_size = jack_get_buffer_size(client);
_jack_client = client;
if (_buffer_size == 0)
{
printf("JACK failed to report buffer size\n");
jack_client_close(client);
return 1;
}
if (jack_activate(client) != 0)
{
printf("Failed to activate jack client\n");
jack_client_close(client);
return 1;
}
int xrun_count, last_xruns = 0;
while (! _jack_shutdown)
{
xrun_count = _jack_xruns - last_xruns;
if (xrun_count != 0)
{
//jack_set_buffer_size(client, _buffer_size);
last_xruns = _jack_xruns;
}
// Print number of xruns
printf("%i \n", _jack_xruns);
// Flush the output buffer (needed for i3blocks and others )
fflush(stdout);
sleep(_sleep_time);
}
if (_jack_client != NULL)
{
_jack_client = NULL;
jack_deactivate(client);
jack_client_close(client);
}
return 0;
}