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.

136 lines
3.6KB

  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. // When used in "slave" mode
  27. int JackLoopbackDriver::ProcessReadSync()
  28. {
  29. int res = 0;
  30. // Loopback copy
  31. for (int i = 0; i < fCaptureChannels; i++) {
  32. memcpy(GetInputBuffer(i), GetOutputBuffer(i), sizeof(jack_default_audio_sample_t) * fEngineControl->fBufferSize);
  33. }
  34. // Resume connected clients in the graph
  35. if (ResumeRefNum() < 0) {
  36. jack_error("JackLoopbackDriver::ProcessReadSync - ResumeRefNum error");
  37. res = -1;
  38. }
  39. return res;
  40. }
  41. int JackLoopbackDriver::ProcessWriteSync()
  42. {
  43. // Suspend on connected clients in the graph
  44. if (SuspendRefNum() < 0) {
  45. jack_error("JackLoopbackDriver::ProcessWriteSync - SuspendRefNum error");
  46. return -1;
  47. }
  48. return 0;
  49. }
  50. int JackLoopbackDriver::ProcessReadAsync()
  51. {
  52. int res = 0;
  53. // Loopback copy
  54. for (int i = 0; i < fCaptureChannels; i++) {
  55. memcpy(GetInputBuffer(i), GetOutputBuffer(i), sizeof(jack_default_audio_sample_t) * fEngineControl->fBufferSize);
  56. }
  57. // Resume connected clients in the graph
  58. if (ResumeRefNum() < 0) {
  59. jack_error("JackLoopbackDriver::ProcessReadAsync - ResumeRefNum error");
  60. res = -1;
  61. }
  62. return res;
  63. }
  64. int JackLoopbackDriver::ProcessWriteAsync()
  65. {
  66. return 0;
  67. }
  68. } // end of namespace
  69. #ifdef __cplusplus
  70. extern "C"
  71. {
  72. #endif
  73. SERVER_EXPORT jack_driver_desc_t * driver_get_descriptor()
  74. {
  75. jack_driver_desc_t * desc;
  76. jack_driver_desc_filler_t filler;
  77. jack_driver_param_value_t value;
  78. desc = jack_driver_descriptor_construct("loopback", JackDriverSlave, "Loopback backend", &filler);
  79. value.i = 0;
  80. jack_driver_descriptor_add_parameter(desc, &filler, "channels", 'c', JackDriverParamInt, &value, NULL, "Maximum number of loopback ports", NULL);
  81. return desc;
  82. }
  83. SERVER_EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackLockedEngine* engine, Jack::JackSynchro* table, const JSList* params)
  84. {
  85. const JSList * node;
  86. const jack_driver_param_t * param;
  87. int channels = 2;
  88. for (node = params; node; node = jack_slist_next (node)) {
  89. param = (const jack_driver_param_t *) node->data;
  90. switch (param->character) {
  91. case 'c':
  92. channels = param->value.ui;
  93. break;
  94. }
  95. }
  96. Jack::JackDriverClientInterface* driver = new Jack::JackLoopbackDriver(engine, table);
  97. if (driver->Open(0, 0, 1, 1, channels, channels, false, "loopback", "loopback", 0, 0) == 0) {
  98. return driver;
  99. } else {
  100. delete driver;
  101. return NULL;
  102. }
  103. }
  104. #ifdef __cplusplus
  105. }
  106. #endif