jack1 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.

227 lines
4.9KB

  1. /*
  2. Copyright (C) 2002 Stefan Kost
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. $Id$
  15. */
  16. #include <math.h>
  17. #include <stdio.h>
  18. #include <memory.h>
  19. #include <unistd.h>
  20. #include <stdlib.h>
  21. #include <errno.h>
  22. #include <stdarg.h>
  23. #include <jack/solaris_driver.h>
  24. #include <jack/types.h>
  25. #include <jack/internal.h>
  26. #include <jack/engine.h>
  27. #include <jack/cycles.h>
  28. extern void store_work_time (int);
  29. extern void store_wait_time (int);
  30. extern void show_wait_times ();
  31. extern void show_work_times ();
  32. //== instance callbacks ========================================================
  33. static void
  34. solaris_driver_attach (solaris_driver_t *driver, jack_engine_t *engine)
  35. {
  36. }
  37. static void
  38. solaris_driver_detach (solaris_driver_t *driver, jack_engine_t *engine)
  39. {
  40. }
  41. static jack_nframes_t
  42. solaris_driver_wait (solaris_driver_t *driver, int extra_fd, int *status, float *delayed_usecs)
  43. {
  44. }
  45. static int
  46. solaris_driver_process (solaris_driver_t *driver, jack_nframes_t nframes)
  47. {
  48. }
  49. static int
  50. solaris_driver_audio_start (solaris_driver_t *driver)
  51. {
  52. }
  53. static int
  54. solaris_driver_audio_stop (solaris_driver_t *driver)
  55. {
  56. }
  57. //== instance creation/destruction =============================================
  58. /** create a new driver instance
  59. */
  60. static jack_driver_t *
  61. solaris_driver_new (char *name,
  62. jack_nframes_t frames_per_cycle,
  63. jack_nframes_t user_nperiods,
  64. jack_nframes_t rate,
  65. int capturing,
  66. int playing,
  67. DitherAlgorithm dither)
  68. {
  69. solaris_driver_t *driver;
  70. printf ("creating solaris driver ... %lu|%lu|%lu\n",
  71. frames_per_cycle, user_nperiods, rate);
  72. driver = (solaris_driver_t *) calloc (1, sizeof (solaris_driver_t));
  73. jack_driver_init ((jack_driver_t *) driver);
  74. driver->attach = (JackDriverAttachFunction) solaris_driver_attach;
  75. driver->detach = (JackDriverDetachFunction) solaris_driver_detach;
  76. driver->wait = (JackDriverWaitFunction) solaris_driver_wait;
  77. driver->process = (JackDriverProcessFunction) solaris_driver_process;
  78. driver->start = (JackDriverStartFunction) solaris_driver_audio_start;
  79. driver->stop = (JackDriverStopFunction) solaris_driver_audio_stop;
  80. return((jack_driver_t *) driver);
  81. }
  82. /** free all memory allocated by a driver instance
  83. */
  84. static void
  85. solaris_driver_delete (solaris_driver_t *driver)
  86. {
  87. free (driver);
  88. }
  89. //== driver "plugin" interface =================================================
  90. static void
  91. solaris_usage ()
  92. {
  93. fprintf (stderr, "\n"
  94. "solaris PCM driver args:\n"
  95. " -r sample-rate (default: 48kHz)\n"
  96. " -p frames-per-period (default: 1024)\n"
  97. " -n periods-per-hardware-buffer (default: 2)\n"
  98. " -D (duplex, default: yes)\n"
  99. " -C (capture, default: duplex)\n"
  100. " -P (playback, default: duplex)\n"
  101. " -z[r|t|s|-] (dither, rect|tri|shaped|off, default: off)\n"
  102. );
  103. }
  104. jack_driver_t *
  105. driver_initialize (int argc, char **argv)
  106. {
  107. jack_nframes_t srate = 48000;
  108. jack_nframes_t frames_per_interrupt = 1024;
  109. unsigned long user_nperiods = 2;
  110. int capture = FALSE;
  111. int playback = FALSE;
  112. DitherAlgorithm dither = None;
  113. int i;
  114. /* grrrr ... getopt() cannot be called in more than one "loop"
  115. per process instance. ridiculous, but true. why isn't there
  116. a getopt_reinitialize() function?
  117. */
  118. for (i = 1; i < argc; i++) {
  119. if (argv[i][0] == '-') {
  120. switch (argv[i][1]) {
  121. case 'D':
  122. capture = TRUE;
  123. playback = TRUE;
  124. break;
  125. case 'C':
  126. capture = TRUE;
  127. break;
  128. case 'P':
  129. playback = TRUE;
  130. break;
  131. case 'n':
  132. user_nperiods = atoi (argv[i+1]);
  133. i++;
  134. break;
  135. case 'r':
  136. srate = atoi (argv[i+1]);
  137. i++;
  138. break;
  139. case 'p':
  140. frames_per_interrupt = atoi (argv[i+1]);
  141. i++;
  142. break;
  143. case 'z':
  144. switch (argv[i][2]) {
  145. case '-':
  146. dither = None;
  147. break;
  148. case 'r':
  149. dither = Rectangular;
  150. break;
  151. case 's':
  152. dither = Shaped;
  153. break;
  154. case 't':
  155. default:
  156. dither = Triangular;
  157. break;
  158. }
  159. break;
  160. default:
  161. alsa_usage ();
  162. return NULL;
  163. }
  164. } else {
  165. alsa_usage ();
  166. return NULL;
  167. }
  168. }
  169. /* duplex is the default */
  170. if (!capture && !playback) {
  171. capture = TRUE;
  172. playback = TRUE;
  173. }
  174. return solaris_driver_new ("solaris_pcm", frames_per_interrupt,
  175. user_nperiods, srate, capture, playback, dither);
  176. }
  177. void
  178. driver_finish (jack_driver_t *driver)
  179. {
  180. solaris_driver_delete ((solaris_driver_t *) driver);
  181. }