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.

123 lines
4.2KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. Copyright (C) 2004-2008 Grame
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #include "JackDummyDriver.h"
  17. #include "JackDriverLoader.h"
  18. #include "JackThreadedDriver.h"
  19. #include "JackCompilerDeps.h"
  20. #include <iostream>
  21. #include <unistd.h>
  22. #include <math.h>
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. SERVER_EXPORT jack_driver_desc_t * driver_get_descriptor () {
  28. jack_driver_desc_t * desc;
  29. jack_driver_desc_filler_t filler;
  30. jack_driver_param_value_t value;
  31. desc = jack_driver_descriptor_construct("dummy", JackDriverMaster, "Timer based backend", &filler);
  32. value.ui = 2U;
  33. jack_driver_descriptor_add_parameter(desc, &filler, "capture", 'C', JackDriverParamUInt, &value, NULL, "Number of capture ports", NULL);
  34. jack_driver_descriptor_add_parameter(desc, &filler, "playback", 'P', JackDriverParamUInt, &value, NULL, "Number of playback ports", NULL);
  35. value.ui = 48000U;
  36. jack_driver_descriptor_add_parameter(desc, &filler, "rate", 'r', JackDriverParamUInt, &value, NULL, "Sample rate", NULL);
  37. value.i = 0;
  38. jack_driver_descriptor_add_parameter(desc, &filler, "monitor", 'm', JackDriverParamBool, &value, NULL, "Provide monitor ports for the output", NULL);
  39. value.ui = 1024U;
  40. jack_driver_descriptor_add_parameter(desc, &filler, "period", 'p', JackDriverParamUInt, &value, NULL, "Frames per period", NULL);
  41. value.ui = 21333U;
  42. jack_driver_descriptor_add_parameter(desc, &filler, "wait", 'w', JackDriverParamUInt, &value, NULL, "Number of usecs to wait between engine processes", NULL);
  43. return desc;
  44. }
  45. SERVER_EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackLockedEngine* engine, Jack::JackSynchro* table, const JSList* params) {
  46. jack_nframes_t sample_rate = 48000;
  47. jack_nframes_t buffer_size = 1024;
  48. unsigned int capture_ports = 2;
  49. unsigned int playback_ports = 2;
  50. int wait_time = 0;
  51. const JSList * node;
  52. const jack_driver_param_t * param;
  53. bool monitor = false;
  54. for (node = params; node; node = jack_slist_next (node)) {
  55. param = (const jack_driver_param_t *) node->data;
  56. switch (param->character) {
  57. case 'C':
  58. capture_ports = param->value.ui;
  59. break;
  60. case 'P':
  61. playback_ports = param->value.ui;
  62. break;
  63. case 'r':
  64. sample_rate = param->value.ui;
  65. break;
  66. case 'p':
  67. buffer_size = param->value.ui;
  68. break;
  69. case 'w':
  70. wait_time = param->value.ui;
  71. break;
  72. case 'm':
  73. monitor = param->value.i;
  74. break;
  75. }
  76. }
  77. if (wait_time > 0) {
  78. buffer_size = lroundf((float(wait_time) * float(sample_rate)) / 1000000.0f);
  79. }
  80. if (buffer_size > BUFFER_SIZE_MAX) {
  81. buffer_size = BUFFER_SIZE_MAX;
  82. jack_error("Buffer size set to %d", BUFFER_SIZE_MAX);
  83. }
  84. Jack::JackDriverClientInterface* driver = new Jack::JackThreadedDriver(new Jack::JackDummyDriver("system", "dummy_pcm", engine, table));
  85. if (driver->Open(buffer_size, sample_rate, 1, 1, capture_ports, playback_ports, monitor, "dummy", "dummy", 0, 0) == 0) {
  86. return driver;
  87. } else {
  88. delete driver;
  89. return NULL;
  90. }
  91. }
  92. #ifdef __cplusplus
  93. }
  94. #endif