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.

150 lines
4.3KB

  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::ProcessRead()
  27. {
  28. return (fEngineControl->fSyncMode) ? ProcessReadSync() : ProcessReadAsync();
  29. }
  30. int JackLoopbackDriver::ProcessWrite()
  31. {
  32. return (fEngineControl->fSyncMode) ? ProcessWriteSync() : ProcessWriteAsync();
  33. }
  34. int JackLoopbackDriver::ProcessReadSync()
  35. {
  36. int res = 0;
  37. // Loopback copy
  38. for (int i = 0; i < fCaptureChannels; i++) {
  39. memcpy(GetInputBuffer(i), GetOutputBuffer(i), sizeof(jack_default_audio_sample_t) * fEngineControl->fBufferSize);
  40. }
  41. if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) {
  42. jack_error("JackLoopbackDriver::ProcessReadSync - ResumeRefNum error");
  43. res = -1;
  44. }
  45. return res;
  46. }
  47. int JackLoopbackDriver::ProcessWriteSync()
  48. {
  49. if (fGraphManager->SuspendRefNum(&fClientControl, fSynchroTable, DRIVER_TIMEOUT_FACTOR * fEngineControl->fTimeOutUsecs) < 0) {
  50. jack_error("JackLoopbackDriver::ProcessWriteSync SuspendRefNum error");
  51. return -1;
  52. }
  53. return 0;
  54. }
  55. int JackLoopbackDriver::ProcessReadAsync()
  56. {
  57. int res = 0;
  58. // Loopback copy
  59. for (int i = 0; i < fCaptureChannels; i++) {
  60. memcpy(GetInputBuffer(i), GetOutputBuffer(i), sizeof(jack_default_audio_sample_t) * fEngineControl->fBufferSize);
  61. }
  62. if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) {
  63. jack_error("JackLoopbackDriver::ProcessReadAsync - ResumeRefNum error");
  64. res = -1;
  65. }
  66. return res;
  67. }
  68. int JackLoopbackDriver::ProcessWriteAsync()
  69. {
  70. return 0;
  71. }
  72. } // end of namespace
  73. #ifdef __cplusplus
  74. extern "C"
  75. {
  76. #endif
  77. SERVER_EXPORT jack_driver_desc_t * driver_get_descriptor()
  78. {
  79. jack_driver_desc_t * desc;
  80. unsigned int i;
  81. desc = (jack_driver_desc_t*)calloc (1, sizeof (jack_driver_desc_t));
  82. strcpy(desc->name, "loopback"); // size MUST be less then JACK_DRIVER_NAME_MAX + 1
  83. strcpy(desc->desc, "Loopback backend"); // size MUST be less then JACK_DRIVER_PARAM_DESC + 1
  84. desc->nparams = 1;
  85. desc->params = (jack_driver_param_desc_t*)calloc (desc->nparams, sizeof (jack_driver_param_desc_t));
  86. i = 0;
  87. strcpy(desc->params[i].name, "channels");
  88. desc->params[i].character = 'c';
  89. desc->params[i].type = JackDriverParamInt;
  90. desc->params[i].value.ui = 0;
  91. strcpy(desc->params[i].short_desc, "Maximum number of loopback ports");
  92. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  93. return desc;
  94. }
  95. SERVER_EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackLockedEngine* engine, Jack::JackSynchro* table, const JSList* params)
  96. {
  97. const JSList * node;
  98. const jack_driver_param_t * param;
  99. int channels = 2;
  100. for (node = params; node; node = jack_slist_next (node)) {
  101. param = (const jack_driver_param_t *) node->data;
  102. switch (param->character) {
  103. case 'c':
  104. channels = param->value.ui;
  105. break;
  106. }
  107. }
  108. Jack::JackDriverClientInterface* driver = new Jack::JackLoopbackDriver(engine, table);
  109. if (driver->Open(1, 1, channels, channels, false, "loopback", "loopback", 0, 0) == 0) {
  110. return driver;
  111. } else {
  112. delete driver;
  113. return NULL;
  114. }
  115. }
  116. #ifdef __cplusplus
  117. }
  118. #endif