Merge branch 'master' into develop
[jack2.git] / common / JackLoopbackDriver.cpp
blob1eeb3223519f0477865e7e891df0765e0edf6016
1 /*
2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2004-2008 Grame
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.
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.
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.
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>
30 namespace Jack
33 // When used in "slave" mode
35 int JackLoopbackDriver::ProcessReadSync()
37 int res = 0;
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);
44 // Resume connected clients in the graph
45 if (ResumeRefNum() < 0) {
46 jack_error("JackLoopbackDriver::ProcessReadSync - ResumeRefNum error");
47 res = -1;
50 return res;
53 int JackLoopbackDriver::ProcessWriteSync()
55 // Suspend on connected clients in the graph
56 if (SuspendRefNum() < 0) {
57 jack_error("JackLoopbackDriver::ProcessWriteSync - SuspendRefNum error");
58 return -1;
60 return 0;
63 int JackLoopbackDriver::ProcessReadAsync()
65 int res = 0;
67 // Loopback copy
68 for (int i = 0; i < fCaptureChannels; i++) {
69 memcpy(GetInputBuffer(i), GetOutputBuffer(i), sizeof(jack_default_audio_sample_t) * fEngineControl->fBufferSize);
72 // Resume connected clients in the graph
73 if (ResumeRefNum() < 0) {
74 jack_error("JackLoopbackDriver::ProcessReadAsync - ResumeRefNum error");
75 res = -1;
78 return res;
81 int JackLoopbackDriver::ProcessWriteAsync()
83 return 0;
86 } // end of namespace
88 #ifdef __cplusplus
89 extern "C"
91 #endif
93 SERVER_EXPORT jack_driver_desc_t * driver_get_descriptor()
95 jack_driver_desc_t * desc;
96 jack_driver_desc_filler_t filler;
97 jack_driver_param_value_t value;
99 desc = jack_driver_descriptor_construct("loopback", JackDriverSlave, "Loopback backend", &filler);
101 value.i = 0;
102 jack_driver_descriptor_add_parameter(desc, &filler, "channels", 'c', JackDriverParamInt, &value, NULL, "Maximum number of loopback ports", NULL);
104 return desc;
107 SERVER_EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackLockedEngine* engine, Jack::JackSynchro* table, const JSList* params)
109 const JSList * node;
110 const jack_driver_param_t * param;
111 int channels = 2;
113 for (node = params; node; node = jack_slist_next (node)) {
114 param = (const jack_driver_param_t *) node->data;
116 switch (param->character) {
118 case 'c':
119 channels = param->value.ui;
120 break;
124 Jack::JackDriverClientInterface* driver = new Jack::JackLoopbackDriver(engine, table);
125 if (driver->Open(0, 0, 1, 1, channels, channels, false, "loopback", "loopback", 0, 0) == 0) {
126 return driver;
127 } else {
128 delete driver;
129 return NULL;
133 #ifdef __cplusplus
135 #endif