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.

109 lines
3.4KB

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