Jack2
1.9.8
|
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 if (ResumeRefNum() < 0) { 00045 jack_error("JackLoopbackDriver::ProcessReadSync - ResumeRefNum error"); 00046 res = -1; 00047 } 00048 00049 return res; 00050 } 00051 00052 int JackLoopbackDriver::ProcessWriteSync() 00053 { 00054 if (SuspendRefNum() < 0) { 00055 jack_error("JackLoopbackDriver::ProcessWriteSync SuspendRefNum error"); 00056 return -1; 00057 } 00058 return 0; 00059 } 00060 00061 int JackLoopbackDriver::ProcessReadAsync() 00062 { 00063 int res = 0; 00064 00065 // Loopback copy 00066 for (int i = 0; i < fCaptureChannels; i++) { 00067 memcpy(GetInputBuffer(i), GetOutputBuffer(i), sizeof(jack_default_audio_sample_t) * fEngineControl->fBufferSize); 00068 } 00069 00070 if (ResumeRefNum() < 0) { 00071 jack_error("JackLoopbackDriver::ProcessReadAsync - ResumeRefNum error"); 00072 res = -1; 00073 } 00074 00075 return res; 00076 } 00077 00078 int JackLoopbackDriver::ProcessWriteAsync() 00079 { 00080 return 0; 00081 } 00082 00083 } // end of namespace 00084 00085 #ifdef __cplusplus 00086 extern "C" 00087 { 00088 #endif 00089 00090 SERVER_EXPORT jack_driver_desc_t * driver_get_descriptor() 00091 { 00092 jack_driver_desc_t * desc; 00093 jack_driver_desc_filler_t filler; 00094 jack_driver_param_value_t value; 00095 00096 desc = jack_driver_descriptor_construct("loopback", JackDriverSlave, "Loopback backend", &filler); 00097 00098 value.i = 0; 00099 jack_driver_descriptor_add_parameter(desc, &filler, "channels", 'c', JackDriverParamInt, &value, NULL, "Maximum number of loopback ports", NULL); 00100 00101 return desc; 00102 } 00103 00104 SERVER_EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackLockedEngine* engine, Jack::JackSynchro* table, const JSList* params) 00105 { 00106 const JSList * node; 00107 const jack_driver_param_t * param; 00108 int channels = 2; 00109 00110 for (node = params; node; node = jack_slist_next (node)) { 00111 param = (const jack_driver_param_t *) node->data; 00112 00113 switch (param->character) { 00114 00115 case 'c': 00116 channels = param->value.ui; 00117 break; 00118 } 00119 } 00120 00121 Jack::JackDriverClientInterface* driver = new Jack::JackLoopbackDriver(engine, table); 00122 if (driver->Open(1, 1, channels, channels, false, "loopback", "loopback", 0, 0) == 0) { 00123 return driver; 00124 } else { 00125 delete driver; 00126 return NULL; 00127 } 00128 } 00129 00130 #ifdef __cplusplus 00131 } 00132 #endif