jack2 codebase
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.

93 lines
1.9KB

  1. /** @file cpu_load.c
  2. *
  3. */
  4. #include <stdio.h>
  5. #include <errno.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <math.h>
  9. #include <signal.h>
  10. #ifndef WIN32
  11. #include <unistd.h>
  12. #endif
  13. #include <jack/jack.h>
  14. jack_client_t *client;
  15. static void signal_handler ( int sig )
  16. {
  17. jack_client_close ( client );
  18. fprintf ( stderr, "signal received, exiting ...\n" );
  19. exit ( 0 );
  20. }
  21. /**
  22. * JACK calls this shutdown_callback if the server ever shuts down or
  23. * decides to disconnect the client.
  24. */
  25. void
  26. jack_shutdown ( void *arg )
  27. {
  28. exit ( 1 );
  29. }
  30. int
  31. main ( int argc, char *argv[] )
  32. {
  33. jack_options_t options = JackNullOption;
  34. jack_status_t status;
  35. /* open a client connection to the JACK server */
  36. client = jack_client_open ("jack_cpu_load", options, &status);
  37. if ( client == NULL )
  38. {
  39. fprintf ( stderr, "jack_client_open() failed, "
  40. "status = 0x%2.0x\n", status );
  41. if ( status & JackServerFailed )
  42. {
  43. fprintf ( stderr, "Unable to connect to JACK server\n" );
  44. }
  45. exit ( 1 );
  46. }
  47. jack_on_shutdown ( client, jack_shutdown, 0 );
  48. /* Tell the JACK server that we are ready to roll. Our
  49. * process() callback will start running now. */
  50. if ( jack_activate ( client ) )
  51. {
  52. fprintf ( stderr, "cannot activate client" );
  53. exit ( 1 );
  54. }
  55. /* install a signal handler to properly quits jack client */
  56. #ifdef WIN32
  57. signal ( SIGINT, signal_handler );
  58. signal ( SIGABRT, signal_handler );
  59. signal ( SIGTERM, signal_handler );
  60. #else
  61. signal ( SIGQUIT, signal_handler );
  62. signal ( SIGTERM, signal_handler );
  63. signal ( SIGHUP, signal_handler );
  64. signal ( SIGINT, signal_handler );
  65. #endif
  66. while (1)
  67. {
  68. printf("jack DSP load %f\n", jack_cpu_load(client));
  69. #ifdef WIN32
  70. Sleep ( 1000 );
  71. #else
  72. sleep ( 1 );
  73. #endif
  74. }
  75. jack_client_close ( client );
  76. exit ( 0 );
  77. }