Jack2 1.9.12

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 // Resume connected clients in the graph
45 if (ResumeRefNum() < 0) {
46 jack_error("JackLoopbackDriver::ProcessReadSync - ResumeRefNum error");
47 res = -1;
48 }
49
50 return res;
51 }
52
53 int JackLoopbackDriver::ProcessWriteSync()
54 {
55 // Suspend on connected clients in the graph
56 if (SuspendRefNum() < 0) {
57 jack_error("JackLoopbackDriver::ProcessWriteSync - SuspendRefNum error");
58 return -1;
59 }
60 return 0;
61 }
62
63 int JackLoopbackDriver::ProcessReadAsync()
64 {
65 int res = 0;
66
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);
70 }
71
72 // Resume connected clients in the graph
73 if (ResumeRefNum() < 0) {
74 jack_error("JackLoopbackDriver::ProcessReadAsync - ResumeRefNum error");
75 res = -1;
76 }
77
78 return res;
79 }
80
81 int JackLoopbackDriver::ProcessWriteAsync()
82 {
83 return 0;
84 }
85
86 } // end of namespace
87
88 #ifdef __cplusplus
89 extern "C"
90 {
91 #endif
92
93 SERVER_EXPORT jack_driver_desc_t * driver_get_descriptor()
94 {
95 jack_driver_desc_t * desc;
96 jack_driver_desc_filler_t filler;
97 jack_driver_param_value_t value;
98
99 desc = jack_driver_descriptor_construct("loopback", JackDriverSlave, "Loopback backend", &filler);
100
101 value.i = 0;
102 jack_driver_descriptor_add_parameter(desc, &filler, "channels", 'c', JackDriverParamInt, &value, NULL, "Maximum number of loopback ports", NULL);
103
104 return desc;
105 }
106
107 SERVER_EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackLockedEngine* engine, Jack::JackSynchro* table, const JSList* params)
108 {
109 const JSList * node;
110 const jack_driver_param_t * param;
111 int channels = 2;
112
113 for (node = params; node; node = jack_slist_next (node)) {
114 param = (const jack_driver_param_t *) node->data;
115
116 switch (param->character) {
117
118 case 'c':
119 channels = param->value.ui;
120 break;
121 }
122 }
123
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;
130 }
131 }
132
133 #ifdef __cplusplus
134 }
135 #endif
Jack::JackLockedEngine
Locked Engine, access to methods is serialized using a mutex.
Definition: JackLockedEngine.h:78
jack_driver_param_value_t
Definition: driver_interface.h:64
Jack::JackPosixSemaphore
Inter process synchronization using POSIX semaphore.
Definition: JackPosixSemaphore.h:36
jack_error
SERVER_EXPORT void jack_error(const char *fmt,...)
Definition: JackError.cpp:92
jack_driver_desc_filler_t
Definition: driver_interface.h:142
Jack::JackDriverClientInterface
The base interface for drivers clients.
Definition: JackDriver.h:114
Jack::JackLoopbackDriver
The loopback driver : to be used to "pipeline" applications connected in sequence.
Definition: JackLoopbackDriver.h:33
jack_driver_param_t
Definition: driver_interface.h:125
_JSList
Definition: linux/alsa/jslist.h:35
jack_driver_desc_t
Definition: driver_interface.h:132