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.

115 lines
3.7KB

  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 "JackSystemDeps.h"
  17. #include "JackServerGlobals.h"
  18. #include "JackLoopbackDriver.h"
  19. #include "JackDriverLoader.h"
  20. #include "JackEngineControl.h"
  21. #include "JackGraphManager.h"
  22. #include "JackError.h"
  23. #include <iostream>
  24. #include <assert.h>
  25. namespace Jack
  26. {
  27. int JackLoopbackDriver::Process()
  28. {
  29. // Loopback copy
  30. for (int i = 0; i < fCaptureChannels; i++) {
  31. memcpy(GetInputBuffer(i), GetOutputBuffer(i), sizeof(float) * fEngineControl->fBufferSize);
  32. }
  33. fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable); // Signal all clients
  34. if (fEngineControl->fSyncMode) {
  35. if (fGraphManager->SuspendRefNum(&fClientControl, fSynchroTable, DRIVER_TIMEOUT_FACTOR * fEngineControl->fTimeOutUsecs) < 0) {
  36. jack_error("JackLoopbackDriver::ProcessSync SuspendRefNum error");
  37. return -1;
  38. }
  39. }
  40. return 0;
  41. }
  42. } // end of namespace
  43. #ifdef __cplusplus
  44. extern "C"
  45. {
  46. #endif
  47. SERVER_EXPORT jack_driver_desc_t * driver_get_descriptor()
  48. {
  49. jack_driver_desc_t * desc;
  50. unsigned int i;
  51. desc = (jack_driver_desc_t*)calloc (1, sizeof (jack_driver_desc_t));
  52. strcpy(desc->name, "loopback"); // size MUST be less then JACK_DRIVER_NAME_MAX + 1
  53. strcpy(desc->desc, "Loppback backend"); // size MUST be less then JACK_DRIVER_PARAM_DESC + 1
  54. desc->nparams = 1;
  55. desc->params = (jack_driver_param_desc_t*)calloc (desc->nparams, sizeof (jack_driver_param_desc_t));
  56. i = 0;
  57. strcpy(desc->params[i].name, "channels");
  58. desc->params[i].character = 'c';
  59. desc->params[i].type = JackDriverParamInt;
  60. desc->params[i].value.ui = 0;
  61. strcpy(desc->params[i].short_desc, "Loopback ports");
  62. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  63. return desc;
  64. }
  65. SERVER_EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackLockedEngine* engine, Jack::JackSynchro* table, const JSList* params)
  66. {
  67. const JSList * node;
  68. const jack_driver_param_t * param;
  69. int channels = 2;
  70. for (node = params; node; node = jack_slist_next (node)) {
  71. param = (const jack_driver_param_t *) node->data;
  72. switch (param->character) {
  73. case 'c':
  74. channels = param->value.ui;
  75. break;
  76. }
  77. }
  78. Jack::JackDriverClientInterface* driver = new Jack::JackLoopbackDriver(engine, table);
  79. if (driver->Open(Jack::JackServerGlobals::fInstance->GetEngineControl()->fBufferSize,
  80. Jack::JackServerGlobals::fInstance->GetEngineControl()->fSampleRate,
  81. 1, 1,
  82. channels, channels,
  83. false,
  84. "loopback", "loopback", 0, 0) == 0) {
  85. return driver;
  86. } else {
  87. delete driver;
  88. return NULL;
  89. }
  90. }
  91. #ifdef __cplusplus
  92. }
  93. #endif