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.

141 lines
3.8KB

  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. jack_driver_desc_filler_t filler;
  81. jack_driver_param_value_t value;
  82. desc = jack_driver_descriptor_construct("loopback", "Loopback backend", &filler);
  83. value.i = 0;
  84. jack_driver_descriptor_add_parameter(desc, &filler, "channels", 'c', JackDriverParamInt, &value, NULL, "Maximum number of loopback ports", NULL);
  85. return desc;
  86. }
  87. SERVER_EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackLockedEngine* engine, Jack::JackSynchro* table, const JSList* params)
  88. {
  89. const JSList * node;
  90. const jack_driver_param_t * param;
  91. int channels = 2;
  92. for (node = params; node; node = jack_slist_next (node)) {
  93. param = (const jack_driver_param_t *) node->data;
  94. switch (param->character) {
  95. case 'c':
  96. channels = param->value.ui;
  97. break;
  98. }
  99. }
  100. Jack::JackDriverClientInterface* driver = new Jack::JackLoopbackDriver(engine, table);
  101. if (driver->Open(1, 1, channels, channels, false, "loopback", "loopback", 0, 0) == 0) {
  102. return driver;
  103. } else {
  104. delete driver;
  105. return NULL;
  106. }
  107. }
  108. #ifdef __cplusplus
  109. }
  110. #endif