2 * bufsize.c -- change JACK buffer size.
4 * Copyright (C) 2003 Jack O'Quin.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <jack/jack.h>
28 #include <jack/transport.h>
30 char *package
; /* program name */
31 jack_client_t
*client
;
32 jack_nframes_t nframes
;
33 int just_print_bufsize
=0;
35 void jack_shutdown(void *arg
)
37 fprintf(stderr
, "JACK shut down, exiting ...\n");
41 void signal_handler(int sig
)
43 jack_client_close(client
);
44 fprintf(stderr
, "signal received, exiting ...\n");
48 void parse_arguments(int argc
, char *argv
[])
51 package
= strrchr(argv
[0], '/');
58 just_print_bufsize
= 1;
62 fprintf(stderr
, "usage: %s <bufsize>\n", package
);
66 if (strspn (argv
[1], "0123456789") != strlen (argv
[1])) {
67 fprintf(stderr
, "usage: %s <bufsize>\n", package
);
71 nframes
= strtoul(argv
[1], NULL
, 0);
72 if (errno
== ERANGE
) {
73 fprintf(stderr
, "%s: invalid buffer size: %s (range is 1-16384)\n",
77 if (nframes
< 1 || nframes
> 16384) {
78 fprintf(stderr
, "%s: invalid buffer size: %s (range is 1-16384)\n",
84 void silent_function( const char *ignore
)
88 int main(int argc
, char *argv
[])
91 parse_arguments(argc
, argv
);
93 if (just_print_bufsize
)
94 jack_set_info_function( silent_function
);
96 /* become a JACK client */
97 if ((client
= jack_client_open(package
, JackNoStartServer
, NULL
)) == 0) {
98 fprintf(stderr
, "JACK server not running?\n");
103 signal(SIGQUIT
, signal_handler
);
104 signal(SIGHUP
, signal_handler
);
106 signal(SIGTERM
, signal_handler
);
107 signal(SIGINT
, signal_handler
);
109 jack_on_shutdown(client
, jack_shutdown
, 0);
111 if (just_print_bufsize
) {
112 fprintf(stdout
, "%d\n", jack_get_buffer_size( client
) );
117 rc
= jack_set_buffer_size(client
, nframes
);
119 fprintf(stderr
, "jack_set_buffer_size(): %s\n", strerror(rc
));
121 jack_client_close(client
);