Jack2  1.9.8
JackLoopbackDriver.cpp
1 /*
2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2004-2008 Grame
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 
19 */
20 
21 #include "JackSystemDeps.h"
22 #include "JackLoopbackDriver.h"
23 #include "JackDriverLoader.h"
24 #include "JackEngineControl.h"
25 #include "JackGraphManager.h"
26 #include "JackError.h"
27 #include <iostream>
28 #include <assert.h>
29 
30 namespace Jack
31 {
32 
33 // When used in "slave" mode
34 
35 int JackLoopbackDriver::ProcessReadSync()
36 {
37  int res = 0;
38 
39  // Loopback copy
40  for (int i = 0; i < fCaptureChannels; i++) {
41  memcpy(GetInputBuffer(i), GetOutputBuffer(i), sizeof(jack_default_audio_sample_t) * fEngineControl->fBufferSize);
42  }
43 
44  if (ResumeRefNum() < 0) {
45  jack_error("JackLoopbackDriver::ProcessReadSync - ResumeRefNum error");
46  res = -1;
47  }
48 
49  return res;
50 }
51 
52 int JackLoopbackDriver::ProcessWriteSync()
53 {
54  if (SuspendRefNum() < 0) {
55  jack_error("JackLoopbackDriver::ProcessWriteSync SuspendRefNum error");
56  return -1;
57  }
58  return 0;
59 }
60 
61 int JackLoopbackDriver::ProcessReadAsync()
62 {
63  int res = 0;
64 
65  // Loopback copy
66  for (int i = 0; i < fCaptureChannels; i++) {
67  memcpy(GetInputBuffer(i), GetOutputBuffer(i), sizeof(jack_default_audio_sample_t) * fEngineControl->fBufferSize);
68  }
69 
70  if (ResumeRefNum() < 0) {
71  jack_error("JackLoopbackDriver::ProcessReadAsync - ResumeRefNum error");
72  res = -1;
73  }
74 
75  return res;
76 }
77 
78 int JackLoopbackDriver::ProcessWriteAsync()
79 {
80  return 0;
81 }
82 
83 } // end of namespace
84 
85 #ifdef __cplusplus
86 extern "C"
87 {
88 #endif
89 
90  SERVER_EXPORT jack_driver_desc_t * driver_get_descriptor()
91  {
92  jack_driver_desc_t * desc;
95 
96  desc = jack_driver_descriptor_construct("loopback", JackDriverSlave, "Loopback backend", &filler);
97 
98  value.i = 0;
99  jack_driver_descriptor_add_parameter(desc, &filler, "channels", 'c', JackDriverParamInt, &value, NULL, "Maximum number of loopback ports", NULL);
100 
101  return desc;
102  }
103 
104  SERVER_EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackLockedEngine* engine, Jack::JackSynchro* table, const JSList* params)
105  {
106  const JSList * node;
107  const jack_driver_param_t * param;
108  int channels = 2;
109 
110  for (node = params; node; node = jack_slist_next (node)) {
111  param = (const jack_driver_param_t *) node->data;
112 
113  switch (param->character) {
114 
115  case 'c':
116  channels = param->value.ui;
117  break;
118  }
119  }
120 
121  Jack::JackDriverClientInterface* driver = new Jack::JackLoopbackDriver(engine, table);
122  if (driver->Open(1, 1, channels, channels, false, "loopback", "loopback", 0, 0) == 0) {
123  return driver;
124  } else {
125  delete driver;
126  return NULL;
127  }
128  }
129 
130 #ifdef __cplusplus
131 }
132 #endif