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.

210 lines
6.2KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. Copyright (C) 2004-2006 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 "JackLoopbackDriver.h"
  17. #include "JackEngineControl.h"
  18. #include "JackGraphManager.h"
  19. #include <iostream>
  20. #include <assert.h>
  21. namespace Jack
  22. {
  23. int JackLoopbackDriver::Open(jack_nframes_t nframes,
  24. jack_nframes_t samplerate,
  25. int capturing,
  26. int playing,
  27. int inchannels,
  28. int outchannels,
  29. bool monitor,
  30. const char* capture_driver_name,
  31. const char* playback_driver_name,
  32. jack_nframes_t capture_latency,
  33. jack_nframes_t playback_latency)
  34. {
  35. return JackAudioDriver::Open(nframes,
  36. samplerate,
  37. capturing,
  38. playing,
  39. inchannels,
  40. outchannels,
  41. monitor,
  42. capture_driver_name,
  43. playback_driver_name,
  44. capture_latency,
  45. playback_latency);
  46. }
  47. int JackLoopbackDriver::Process()
  48. {
  49. assert(fCaptureChannels == fPlaybackChannels);
  50. // Loopback copy
  51. for (int i = 0; i < fCaptureChannels; i++) {
  52. memcpy(fGraphManager->GetBuffer(fCapturePortList[i], fEngineControl->fBufferSize),
  53. fGraphManager->GetBuffer(fPlaybackPortList[i], fEngineControl->fBufferSize),
  54. sizeof(float) * fEngineControl->fBufferSize);
  55. }
  56. fGraphManager->ResumeRefNum(fClientControl, fSynchroTable); // Signal all clients
  57. if (fEngineControl->fSyncMode) {
  58. if (fGraphManager->SuspendRefNum(fClientControl, fSynchroTable, fEngineControl->fTimeOutUsecs) < 0)
  59. jack_error("JackLoopbackDriver::ProcessSync SuspendRefNum error");
  60. }
  61. return 0;
  62. }
  63. void JackLoopbackDriver::PrintState()
  64. {
  65. int i;
  66. jack_port_id_t port_index;
  67. std::cout << "JackLoopbackDriver state" << std::endl;
  68. std::cout << "Input ports" << std::endl;
  69. for (i = 0; i < fPlaybackChannels; i++) {
  70. port_index = fCapturePortList[i];
  71. JackPort* port = fGraphManager->GetPort(port_index);
  72. std::cout << port->GetName() << std::endl;
  73. if (fGraphManager->GetConnectionsNum(port_index)) {}
  74. }
  75. std::cout << "Output ports" << std::endl;
  76. for (i = 0; i < fCaptureChannels; i++) {
  77. port_index = fPlaybackPortList[i];
  78. JackPort* port = fGraphManager->GetPort(port_index);
  79. std::cout << port->GetName() << std::endl;
  80. if (fGraphManager->GetConnectionsNum(port_index)) {}
  81. }
  82. }
  83. } // end of namespace
  84. /*
  85. #ifdef __cplusplus
  86. extern "C" {
  87. #endif
  88. jack_driver_desc_t * driver_get_descriptor ()
  89. {
  90. jack_driver_desc_t * desc;
  91. jack_driver_param_desc_t * params;
  92. unsigned int i;
  93. desc = (jack_driver_desc_t*)calloc (1, sizeof (jack_driver_desc_t));
  94. strcpy (desc->name, "dummy");
  95. desc->nparams = 5;
  96. params = (jack_driver_param_desc_t*)calloc (desc->nparams, sizeof (jack_driver_param_desc_t));
  97. i = 0;
  98. strcpy (params[i].name, "capture");
  99. params[i].character = 'C';
  100. params[i].type = JackDriverParamUInt;
  101. params[i].value.ui = 2U;
  102. strcpy (params[i].short_desc, "Number of capture ports");
  103. strcpy (params[i].long_desc, params[i].short_desc);
  104. i++;
  105. strcpy (params[i].name, "playback");
  106. params[i].character = 'P';
  107. params[i].type = JackDriverParamUInt;
  108. params[1].value.ui = 2U;
  109. strcpy (params[i].short_desc, "Number of playback ports");
  110. strcpy (params[i].long_desc, params[i].short_desc);
  111. i++;
  112. strcpy (params[i].name, "rate");
  113. params[i].character = 'r';
  114. params[i].type = JackDriverParamUInt;
  115. params[i].value.ui = 48000U;
  116. strcpy (params[i].short_desc, "Sample rate");
  117. strcpy (params[i].long_desc, params[i].short_desc);
  118. i++;
  119. strcpy (params[i].name, "period");
  120. params[i].character = 'p';
  121. params[i].type = JackDriverParamUInt;
  122. params[i].value.ui = 1024U;
  123. strcpy (params[i].short_desc, "Frames per period");
  124. strcpy (params[i].long_desc, params[i].short_desc);
  125. i++;
  126. strcpy (params[i].name, "wait");
  127. params[i].character = 'w';
  128. params[i].type = JackDriverParamUInt;
  129. params[i].value.ui = 21333U;
  130. strcpy (params[i].short_desc,
  131. "Number of usecs to wait between engine processes");
  132. strcpy (params[i].long_desc, params[i].short_desc);
  133. desc->params = params;
  134. return desc;
  135. }
  136. Jack::JackDriverClientInterface* driver_initialize(Jack::JackEngine* engine, Jack::JackSynchro** table, const JSList* params)
  137. {
  138. jack_nframes_t sample_rate = 48000;
  139. jack_nframes_t period_size = 1024;
  140. unsigned int capture_ports = 2;
  141. unsigned int playback_ports = 2;
  142. const JSList * node;
  143. const jack_driver_param_t * param;
  144. for (node = params; node; node = jack_slist_next (node)) {
  145. param = (const jack_driver_param_t *) node->data;
  146. switch (param->character) {
  147. case 'C':
  148. capture_ports = param->value.ui;
  149. break;
  150. case 'P':
  151. playback_ports = param->value.ui;
  152. break;
  153. case 'r':
  154. sample_rate = param->value.ui;
  155. break;
  156. case 'p':
  157. period_size = param->value.ui;
  158. break;
  159. }
  160. }
  161. Jack::JackDriverClientInterface* driver = new Jack::JackLoopbackDriver("loopback", engine, table);
  162. if (driver->Open(period_size, sample_rate, 1, 1, capture_ports, playback_ports, "loopback") == 0) {
  163. return driver;
  164. } else {
  165. delete driver;
  166. return NULL;
  167. }
  168. }
  169. #ifdef __cplusplus
  170. }
  171. #endif
  172. */