JACK tools
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
2.8KB

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