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.

133 lines
3.5KB

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