![]() |
Mixxx
|
00001 /*************************************************************************** 00002 * * 00003 * This program is free software; you can redistribute it and/or modify * 00004 * it under the terms of the GNU General Public License as published by * 00005 * the Free Software Foundation; either version 2 of the License, or * 00006 * (at your option) any later version. * 00007 * * 00008 ***************************************************************************/ 00009 00010 #include <QtCore> 00011 00012 #include "engineladspa.h" 00013 00014 #include "controlpotmeter.h" 00015 #include "ladspa/ladspacontrol.h" 00016 #include "sampleutil.h" 00017 00018 EngineLADSPA * EngineLADSPA::m_pEngine = NULL; 00019 00020 EngineLADSPA::EngineLADSPA() 00021 { 00022 m_pEngine = this; 00023 00024 m_bufferSize = 0; 00025 m_pBufferLeft[0] = NULL; 00026 } 00027 00028 EngineLADSPA::~EngineLADSPA() 00029 { 00030 } 00031 00032 void EngineLADSPA::process(const CSAMPLE * pIn, const CSAMPLE * pOut, const int iBufferSize) 00033 { 00034 if (iBufferSize != m_bufferSize) 00035 { 00036 m_bufferSize = iBufferSize; 00037 m_monoBufferSize = m_bufferSize / 2; 00038 //qDebug() << "LADSPA: setBufferSize: " << m_monoBufferSize << " (" << m_bufferSize << ")"; 00039 LADSPAControl::setBufferSize(m_monoBufferSize); 00040 00041 if (m_pBufferLeft[0] != NULL) 00042 { 00043 delete [] m_pBufferLeft[0]; 00044 delete [] m_pBufferLeft[1]; 00045 delete [] m_pBufferRight[0]; 00046 delete [] m_pBufferRight[1]; 00047 } 00048 m_pBufferLeft[0] = new CSAMPLE[m_monoBufferSize]; 00049 m_pBufferLeft[1] = new CSAMPLE[m_monoBufferSize]; 00050 m_pBufferRight[0] = new CSAMPLE[m_monoBufferSize]; 00051 m_pBufferRight[1] = new CSAMPLE[m_monoBufferSize]; 00052 } 00053 00054 EngineLADSPAControlConnectionLinkedList::iterator connection = m_Connections.begin(); 00055 while (connection != m_Connections.end()) 00056 { 00057 if ((*connection)->remove) 00058 { 00059 EngineLADSPAControlConnection *con = *connection; 00060 delete con->control; 00061 delete con->potmeter; 00062 con->control = NULL; 00063 connection = m_Connections.erase(connection); 00064 } 00065 else 00066 { 00067 (*connection)->control->setValue((*connection)->potmeter->get()); 00068 ++connection; 00069 } 00070 } 00071 00072 SampleUtil::deinterleaveBuffer(m_pBufferLeft[0], m_pBufferRight[0], 00073 pIn, m_monoBufferSize); 00074 00075 LADSPAInstanceLinkedList::iterator instance = m_Instances.begin(); 00076 while (instance != m_Instances.end()) 00077 { 00078 if ((*instance)->remove) 00079 instance = m_Instances.erase(instance); 00080 else 00081 { 00082 if ((*instance)->isEnabled()) 00083 { 00084 //qDebug() << "enabled"; 00085 CSAMPLE wet = (CSAMPLE)(*instance)->getWet(); 00086 if ((*instance)->isInplaceBroken() || wet < 1.0) 00087 { 00088 CSAMPLE dry = 1.0 - wet; 00089 (*instance)->process(m_pBufferLeft[0], m_pBufferRight[0], 00090 m_pBufferLeft[1], m_pBufferRight[1], 00091 m_monoBufferSize); 00092 // TODO: Use run_adding() if possible 00093 SampleUtil::copy2WithGain(m_pBufferLeft[0], m_pBufferLeft[0], dry, 00094 m_pBufferLeft[1], wet, m_monoBufferSize); 00095 SampleUtil::copy2WithGain(m_pBufferRight[0], m_pBufferRight[0], dry, 00096 m_pBufferRight[1], wet, m_monoBufferSize); 00097 } 00098 else 00099 { 00100 (*instance)->process(m_pBufferLeft[0], m_pBufferRight[0], 00101 m_pBufferLeft[0], m_pBufferRight[0], 00102 m_monoBufferSize); 00103 } 00104 } 00105 ++instance; 00106 } 00107 } 00108 00109 CSAMPLE * pOutput = (CSAMPLE *)pOut; 00110 SampleUtil::interleaveBuffer(pOutput, 00111 m_pBufferLeft[0], m_pBufferRight[0], 00112 m_monoBufferSize); 00113 } 00114 00115 void EngineLADSPA::addInstance(LADSPAInstance * instance) 00116 { 00117 m_Instances.append(instance); 00118 } 00119 00120 EngineLADSPAControlConnection * EngineLADSPA::addControl(ControlObject * potmeter, LADSPAControl * control) 00121 { 00122 EngineLADSPAControlConnection * connection = new EngineLADSPAControlConnection; 00123 connection->potmeter = potmeter; 00124 connection->control = control; 00125 connection->remove = 0; 00126 m_Connections.append(connection); 00127 return connection; 00128 } 00129 00130 EngineLADSPA * EngineLADSPA::getEngine() 00131 { 00132 return m_pEngine; 00133 }