1
2 /*
3 * Diverse Bristol audio routines.
4 * Copyright (c) by Nick Copeland <nickycopeland@hotmail.com> 1996,2012
5 *
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22 /*
23 * This file was taken out of the engine and moved to the audio library where
24 * it correctly lies however it incorporates a few flags from bristol.h header
25 * file that should really be removed to keep them independent. That is for
26 * later study.
27 */
28
29 /*#define DEBUG */
30
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <unistd.h>
34 #include <fcntl.h>
35 #include <signal.h>
36 #include <stdio.h>
37 #include <string.h>
38
39 #ifdef _BRISTOL_JACK
40 #include <jack/jack.h>
41
42 jack_client_t *handle;
43
44 static int samplecount, samplerate;
45
46 static char *regname = "bgetstats";
47
48 static int
bristolJackTest()49 bristolJackTest()
50 {
51 if ((handle = jack_client_open(regname, 0, NULL)) == 0)
52 return(-1);
53
54 samplerate = jack_get_sample_rate(handle);
55 samplecount = jack_get_buffer_size(handle);
56
57 jack_client_close(handle);
58
59 return(0);
60 }
61
62 /*
63 * This should go out as the first release with Jack. After that the interface
64 * will change - at the moment Jack subsumes Bristol, and this is the wrong
65 * way around. The audiomain structure is buried inside the jack structure,
66 * but I would prefer the contrary. In addition, with it the contrary then
67 * it would be easier to integrate alternative distribution drivers (DSSI).
68 */
69 #endif /* _BRISTOL_JACK */
70 int
main(int argc,char * argv[])71 main(int argc, char *argv[])
72 {
73 int outfd, nullfd;
74 char lbuf[80];
75
76 #ifdef _BRISTOL_JACK /* _BRISTOL_JACK */
77 // printf("%s: connect to jackd to find samplerate and period size\n",
78 // argv[0]);
79
80 /* I don't want all the output from jack, redirect it */
81 outfd = dup(STDOUT_FILENO);
82 nullfd = open("/dev/null", O_WRONLY);
83 dup2(nullfd, STDOUT_FILENO);
84 dup2(nullfd, STDERR_FILENO);
85
86 if (bristolJackTest() != 0)
87 return(-1);
88
89 snprintf(lbuf, 80, "JACKSTATS: %i %i\n", samplerate, samplecount);
90
91 nullfd = write(outfd, lbuf, strlen(lbuf));
92
93 return(0);
94 #else
95 printf("This should connect to jack but it does not appear to be compiled\n");
96 return(-2);
97 #endif /* _BRISTOL_JACK */
98
99 }
100
101