| 1 |
/* |
|---|
| 2 |
* bufsize.c -- change JACK buffer size. |
|---|
| 3 |
* |
|---|
| 4 |
* Copyright (C) 2003 Jack O'Quin. |
|---|
| 5 |
* |
|---|
| 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. |
|---|
| 10 |
* |
|---|
| 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. |
|---|
| 15 |
* |
|---|
| 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. |
|---|
| 19 |
*/ |
|---|
| 20 |
|
|---|
| 21 |
#include <stdio.h> |
|---|
| 22 |
#include <errno.h> |
|---|
| 23 |
#include <unistd.h> |
|---|
| 24 |
#include <signal.h> |
|---|
| 25 |
#include <stdlib.h> |
|---|
| 26 |
#include <string.h> |
|---|
| 27 |
#include <jack/jack.h> |
|---|
| 28 |
#include <jack/transport.h> |
|---|
| 29 |
|
|---|
| 30 |
char *package; /* program name */ |
|---|
| 31 |
jack_client_t *client; |
|---|
| 32 |
jack_nframes_t nframes; |
|---|
| 33 |
int just_print_bufsize=0; |
|---|
| 34 |
|
|---|
| 35 |
void jack_shutdown(void *arg) |
|---|
| 36 |
{ |
|---|
| 37 |
fprintf(stderr, "JACK shut down, exiting ...\n"); |
|---|
| 38 |
exit(1); |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
void signal_handler(int sig) |
|---|
| 42 |
{ |
|---|
| 43 |
jack_client_close(client); |
|---|
| 44 |
fprintf(stderr, "signal received, exiting ...\n"); |
|---|
| 45 |
exit(0); |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
void parse_arguments(int argc, char *argv[]) |
|---|
| 49 |
{ |
|---|
| 50 |
|
|---|
| 51 |
/* basename $0 */ |
|---|
| 52 |
package = strrchr(argv[0], '/'); |
|---|
| 53 |
if (package == 0) |
|---|
| 54 |
package = argv[0]; |
|---|
| 55 |
else |
|---|
| 56 |
package++; |
|---|
| 57 |
|
|---|
| 58 |
if (argc==1) { |
|---|
| 59 |
just_print_bufsize = 1; |
|---|
| 60 |
return; |
|---|
| 61 |
} |
|---|
| 62 |
if (argc < 2) { |
|---|
| 63 |
fprintf(stderr, "usage: %s <bufsize>\n", package); |
|---|
| 64 |
exit(9); |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
nframes = strtoul(argv[1], NULL, 0); |
|---|
| 68 |
if (errno == ERANGE) { |
|---|
| 69 |
fprintf(stderr, "%s: invalid buffer size: %s\n", |
|---|
| 70 |
package, argv[1]); |
|---|
| 71 |
exit(2); |
|---|
| 72 |
} |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
int main(int argc, char *argv[]) |
|---|
| 76 |
{ |
|---|
| 77 |
int rc; |
|---|
| 78 |
|
|---|
| 79 |
parse_arguments(argc, argv); |
|---|
| 80 |
|
|---|
| 81 |
/* become a JACK client */ |
|---|
| 82 |
if ((client = jack_client_new(package)) == 0) { |
|---|
| 83 |
fprintf(stderr, "JACK server not running?\n"); |
|---|
| 84 |
exit(1); |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
signal(SIGQUIT, signal_handler); |
|---|
| 88 |
signal(SIGTERM, signal_handler); |
|---|
| 89 |
signal(SIGHUP, signal_handler); |
|---|
| 90 |
signal(SIGINT, signal_handler); |
|---|
| 91 |
|
|---|
| 92 |
jack_on_shutdown(client, jack_shutdown, 0); |
|---|
| 93 |
|
|---|
| 94 |
if (just_print_bufsize) { |
|---|
| 95 |
fprintf(stdout, "%d\n", jack_get_buffer_size( client ) ); |
|---|
| 96 |
rc=0; |
|---|
| 97 |
} |
|---|
| 98 |
else |
|---|
| 99 |
{ |
|---|
| 100 |
rc = jack_set_buffer_size(client, nframes); |
|---|
| 101 |
if (rc) |
|---|
| 102 |
fprintf(stderr, "jack_set_buffer_size(): %s\n", strerror(rc)); |
|---|
| 103 |
} |
|---|
| 104 |
jack_client_close(client); |
|---|
| 105 |
|
|---|
| 106 |
return rc; |
|---|
| 107 |
} |
|---|