Jack2
1.9.10
|
00001 /* 00002 Copyright (C) 2001 Paul Davis 00003 Copyright (C) 2004-2008 Grame 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 00019 */ 00020 00021 #include "JackSystemDeps.h" 00022 #include "JackLoopbackDriver.h" 00023 #include "JackDriverLoader.h" 00024 #include "JackEngineControl.h" 00025 #include "JackGraphManager.h" 00026 #include "JackError.h" 00027 #include <iostream> 00028 #include <assert.h> 00029 00030 namespace Jack 00031 { 00032 00033 // When used in "slave" mode 00034 00035 int JackLoopbackDriver::ProcessReadSync() 00036 { 00037 int res = 0; 00038 00039 // Loopback copy 00040 for (int i = 0; i < fCaptureChannels; i++) { 00041 memcpy(GetInputBuffer(i), GetOutputBuffer(i), sizeof(jack_default_audio_sample_t) * fEngineControl->fBufferSize); 00042 } 00043 00044 // Resume connected clients in the graph 00045 if (ResumeRefNum() < 0) { 00046 jack_error("JackLoopbackDriver::ProcessReadSync - ResumeRefNum error"); 00047 res = -1; 00048 } 00049 00050 return res; 00051 } 00052 00053 int JackLoopbackDriver::ProcessWriteSync() 00054 { 00055 // Suspend on connected clients in the graph 00056 if (SuspendRefNum() < 0) { 00057 jack_error("JackLoopbackDriver::ProcessWriteSync - SuspendRefNum error"); 00058 return -1; 00059 } 00060 return 0; 00061 } 00062 00063 int JackLoopbackDriver::ProcessReadAsync() 00064 { 00065 int res = 0; 00066 00067 // Loopback copy 00068 for (int i = 0; i < fCaptureChannels; i++) { 00069 memcpy(GetInputBuffer(i), GetOutputBuffer(i), sizeof(jack_default_audio_sample_t) * fEngineControl->fBufferSize); 00070 } 00071 00072 // Resume connected clients in the graph 00073 if (ResumeRefNum() < 0) { 00074 jack_error("JackLoopbackDriver::ProcessReadAsync - ResumeRefNum error"); 00075 res = -1; 00076 } 00077 00078 return res; 00079 } 00080 00081 int JackLoopbackDriver::ProcessWriteAsync() 00082 { 00083 return 0; 00084 } 00085 00086 } // end of namespace 00087 00088 #ifdef __cplusplus 00089 extern "C" 00090 { 00091 #endif 00092 00093 SERVER_EXPORT jack_driver_desc_t * driver_get_descriptor() 00094 { 00095 jack_driver_desc_t * desc; 00096 jack_driver_desc_filler_t filler; 00097 jack_driver_param_value_t value; 00098 00099 desc = jack_driver_descriptor_construct("loopback", JackDriverSlave, "Loopback backend", &filler); 00100 00101 value.i = 0; 00102 jack_driver_descriptor_add_parameter(desc, &filler, "channels", 'c', JackDriverParamInt, &value, NULL, "Maximum number of loopback ports", NULL); 00103 00104 return desc; 00105 } 00106 00107 SERVER_EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackLockedEngine* engine, Jack::JackSynchro* table, const JSList* params) 00108 { 00109 const JSList * node; 00110 const jack_driver_param_t * param; 00111 int channels = 2; 00112 00113 for (node = params; node; node = jack_slist_next (node)) { 00114 param = (const jack_driver_param_t *) node->data; 00115 00116 switch (param->character) { 00117 00118 case 'c': 00119 channels = param->value.ui; 00120 break; 00121 } 00122 } 00123 00124 Jack::JackDriverClientInterface* driver = new Jack::JackLoopbackDriver(engine, table); 00125 if (driver->Open(0, 0, 1, 1, channels, channels, false, "loopback", "loopback", 0, 0) == 0) { 00126 return driver; 00127 } else { 00128 delete driver; 00129 return NULL; 00130 } 00131 } 00132 00133 #ifdef __cplusplus 00134 } 00135 #endif