67 |
EffectControl::SetMaxValue; |
EffectControl::SetMaxValue; |
68 |
EffectControl::SetType; |
EffectControl::SetType; |
69 |
EffectControl::SetDescription; |
EffectControl::SetDescription; |
70 |
|
EffectControl::SetPossibilities; |
71 |
}; |
}; |
72 |
|
|
73 |
//////////////////////////////////////////////////////////////////////////// |
//////////////////////////////////////////////////////////////////////////// |
74 |
// class 'LadspaEffect' |
// class 'LadspaEffect' |
75 |
|
|
76 |
LadspaEffect::LadspaEffect(EffectInfo* pInfo) throw (Exception) { |
LadspaEffect::LadspaEffect(EffectInfo* pInfo) throw (Exception) : Effect() { |
77 |
this->pInfo = dynamic_cast<LadspaEffectInfo*>(pInfo); |
this->pInfo = dynamic_cast<LadspaEffectInfo*>(pInfo); |
78 |
if (!this->pInfo) |
if (!this->pInfo) |
79 |
throw Exception("Effect key does not represent a LADSPA effect"); |
throw Exception("Effect key does not represent a LADSPA effect"); |
107 |
// those will be set later in InitEffect() |
// those will be set later in InitEffect() |
108 |
hEffect = NULL; |
hEffect = NULL; |
109 |
pDevice = NULL; |
pDevice = NULL; |
|
} |
|
|
|
|
|
LadspaEffect::~LadspaEffect() { |
|
|
if (!hEffect) return; |
|
|
if (pDescriptor->deactivate) |
|
|
pDescriptor->deactivate(hEffect); |
|
|
pDescriptor->cleanup(hEffect); |
|
|
DynamicLibraryClose(hDLL); |
|
|
} |
|
|
|
|
|
void LadspaEffect::RenderAudio(uint Samples) { |
|
|
// (re)assign audio input and audio output buffers |
|
|
int iInputPort = 0; |
|
|
int iOutputPort = 0; |
|
|
for (int iPort = 0; iPort < pDescriptor->PortCount; iPort++) { |
|
|
LADSPA_PortDescriptor pPortDescriptor = pDescriptor->PortDescriptors[iPort]; |
|
|
if (LADSPA_IS_PORT_AUDIO(pPortDescriptor)) { |
|
|
if (LADSPA_IS_PORT_INPUT(pPortDescriptor)) { |
|
|
pDescriptor->connect_port(hEffect, iPort, vInputChannels[iInputPort++]->Buffer()); |
|
|
} else if (LADSPA_IS_PORT_OUTPUT(pPortDescriptor)) { |
|
|
pDescriptor->connect_port(hEffect, iPort, vOutputChannels[iOutputPort++]->Buffer()); |
|
|
} |
|
|
} |
|
|
} |
|
110 |
|
|
111 |
// let the effect do its job |
// create control input and control output variables (effect parameters) |
112 |
pDescriptor->run(hEffect, Samples); |
// (they are going to be assigned to the actual LADSPA effect instance |
113 |
} |
// later in InitEffect() ) |
|
|
|
|
void LadspaEffect::InitEffect(AudioOutputDevice* pDevice) throw (Exception) { |
|
|
this->pDevice = pDevice; |
|
|
|
|
|
const int iInChannels = _getPortCountByType( |
|
|
pDescriptor, |
|
|
LADSPA_PORT_AUDIO | LADSPA_PORT_INPUT |
|
|
); |
|
|
const int iOutChannels = _getPortCountByType( |
|
|
pDescriptor, |
|
|
LADSPA_PORT_AUDIO | LADSPA_PORT_OUTPUT |
|
|
); |
|
114 |
const int iInControls = _getPortCountByType( |
const int iInControls = _getPortCountByType( |
115 |
pDescriptor, |
pDescriptor, |
116 |
LADSPA_PORT_CONTROL | LADSPA_PORT_INPUT |
LADSPA_PORT_CONTROL | LADSPA_PORT_INPUT |
119 |
pDescriptor, |
pDescriptor, |
120 |
LADSPA_PORT_CONTROL | LADSPA_PORT_OUTPUT |
LADSPA_PORT_CONTROL | LADSPA_PORT_OUTPUT |
121 |
); |
); |
|
|
|
|
// now create the actual LADSPA effect instance ... |
|
|
dmsg(1, ("Instantiating LADSPA effect '%s'.\n", pInfo->label.c_str())); |
|
|
hEffect = pDescriptor->instantiate(pDescriptor, pDevice->SampleRate()); |
|
|
if (!hEffect) |
|
|
throw Exception("Could not instantiate LADSPA effect '" + pInfo->label + "'"); |
|
|
|
|
|
// create audio input channels |
|
|
vInputChannels.resize(iInChannels); |
|
|
for (int i = 0; i < iInChannels; i++) { |
|
|
vInputChannels[i] = new AudioChannel(i, pDevice->MaxSamplesPerCycle()); |
|
|
} |
|
|
|
|
|
// create audio output channels |
|
|
vOutputChannels.resize(iOutChannels); |
|
|
for (int i = 0; i < iOutChannels; i++) { |
|
|
vOutputChannels[i] = new AudioChannel(i, pDevice->MaxSamplesPerCycle()); |
|
|
} |
|
|
|
|
|
// create and assign control input and control output variables (effect parameters) |
|
122 |
vInputControls.resize(iInControls); |
vInputControls.resize(iInControls); |
123 |
vOutputControls.resize(iOutControls); |
vOutputControls.resize(iOutControls); |
124 |
|
// create LadspaEffectControl instances and determine its informations |
125 |
|
// (value range, description, default value) |
126 |
int iInControl = 0; |
int iInControl = 0; |
127 |
int iOutControl = 0; |
int iOutControl = 0; |
128 |
for (int iPort = 0; iPort < pDescriptor->PortCount; iPort++) { |
for (int iPort = 0; iPort < pDescriptor->PortCount; iPort++) { |
131 |
if (LADSPA_IS_PORT_INPUT(pPortDescriptor)) { |
if (LADSPA_IS_PORT_INPUT(pPortDescriptor)) { |
132 |
LadspaEffectControl* pEffectControl = new LadspaEffectControl(); |
LadspaEffectControl* pEffectControl = new LadspaEffectControl(); |
133 |
vInputControls[iInControl++] = pEffectControl; |
vInputControls[iInControl++] = pEffectControl; |
134 |
pDescriptor->connect_port(hEffect, iPort, &pEffectControl->Value()); |
|
135 |
const float lower = getLowerB(iPort); |
const float lower = getLowerB(iPort); |
136 |
const float upper = getUpperB(iPort); |
const float upper = getUpperB(iPort); |
137 |
|
|
195 |
pEffectControl->SetMaxValue(upper); |
pEffectControl->SetMaxValue(upper); |
196 |
} |
} |
197 |
|
|
198 |
|
// boolean type? |
199 |
|
if (LADSPA_IS_HINT_TOGGLED(pPortDescriptor)) { |
200 |
|
std::vector<float> vPossibilities; |
201 |
|
vPossibilities.push_back(0.0f); |
202 |
|
vPossibilities.push_back(1.0f); |
203 |
|
pEffectControl->SetPossibilities(vPossibilities); |
204 |
|
} |
205 |
|
|
206 |
// retrieve human readable description about port |
// retrieve human readable description about port |
207 |
pEffectControl->SetDescription(pDescriptor->PortNames[iPort]); |
pEffectControl->SetDescription(pDescriptor->PortNames[iPort]); |
208 |
|
|
209 |
} else if (LADSPA_IS_PORT_OUTPUT(pPortDescriptor)) { |
} else if (LADSPA_IS_PORT_OUTPUT(pPortDescriptor)) { |
210 |
LadspaEffectControl* pEffectControl = new LadspaEffectControl(); |
LadspaEffectControl* pEffectControl = new LadspaEffectControl(); |
211 |
vOutputControls[iOutControl++] = pEffectControl; |
vOutputControls[iOutControl++] = pEffectControl; |
212 |
|
|
213 |
|
//TODO: init output controls like input controls above |
214 |
|
} |
215 |
|
} |
216 |
|
} |
217 |
|
} |
218 |
|
|
219 |
|
LadspaEffect::~LadspaEffect() { |
220 |
|
if (!hEffect) return; |
221 |
|
if (pDescriptor->deactivate) |
222 |
|
pDescriptor->deactivate(hEffect); |
223 |
|
pDescriptor->cleanup(hEffect); |
224 |
|
DynamicLibraryClose(hDLL); |
225 |
|
} |
226 |
|
|
227 |
|
EffectInfo* LadspaEffect::GetEffectInfo() { |
228 |
|
return pInfo; |
229 |
|
} |
230 |
|
|
231 |
|
void LadspaEffect::RenderAudio(uint Samples) { |
232 |
|
// (re)assign audio input and audio output buffers |
233 |
|
int iInputPort = 0; |
234 |
|
int iOutputPort = 0; |
235 |
|
for (int iPort = 0; iPort < pDescriptor->PortCount; iPort++) { |
236 |
|
LADSPA_PortDescriptor pPortDescriptor = pDescriptor->PortDescriptors[iPort]; |
237 |
|
if (LADSPA_IS_PORT_AUDIO(pPortDescriptor)) { |
238 |
|
if (LADSPA_IS_PORT_INPUT(pPortDescriptor)) { |
239 |
|
pDescriptor->connect_port(hEffect, iPort, vInputChannels[iInputPort++]->Buffer()); |
240 |
|
} else if (LADSPA_IS_PORT_OUTPUT(pPortDescriptor)) { |
241 |
|
pDescriptor->connect_port(hEffect, iPort, vOutputChannels[iOutputPort++]->Buffer()); |
242 |
|
} |
243 |
|
} |
244 |
|
} |
245 |
|
|
246 |
|
// let the effect do its job |
247 |
|
pDescriptor->run(hEffect, Samples); |
248 |
|
} |
249 |
|
|
250 |
|
void LadspaEffect::InitEffect(AudioOutputDevice* pDevice) throw (Exception) { |
251 |
|
this->pDevice = pDevice; |
252 |
|
|
253 |
|
const int iInChannels = _getPortCountByType( |
254 |
|
pDescriptor, |
255 |
|
LADSPA_PORT_AUDIO | LADSPA_PORT_INPUT |
256 |
|
); |
257 |
|
const int iOutChannels = _getPortCountByType( |
258 |
|
pDescriptor, |
259 |
|
LADSPA_PORT_AUDIO | LADSPA_PORT_OUTPUT |
260 |
|
); |
261 |
|
const int iInControls = vInputControls.size(); |
262 |
|
const int iOutControls = vOutputControls.size(); |
263 |
|
|
264 |
|
// now create the actual LADSPA effect instance ... |
265 |
|
dmsg(1, ("Instantiating LADSPA effect '%s'.\n", pInfo->label.c_str())); |
266 |
|
hEffect = pDescriptor->instantiate(pDescriptor, pDevice->SampleRate()); |
267 |
|
if (!hEffect) |
268 |
|
throw Exception("Could not instantiate LADSPA effect '" + pInfo->label + "'"); |
269 |
|
|
270 |
|
// create audio input channels |
271 |
|
vInputChannels.resize(iInChannels); |
272 |
|
for (int i = 0; i < iInChannels; i++) { |
273 |
|
vInputChannels[i] = new AudioChannel(i, pDevice->MaxSamplesPerCycle()); |
274 |
|
} |
275 |
|
|
276 |
|
// create audio output channels |
277 |
|
vOutputChannels.resize(iOutChannels); |
278 |
|
for (int i = 0; i < iOutChannels; i++) { |
279 |
|
vOutputChannels[i] = new AudioChannel(i, pDevice->MaxSamplesPerCycle()); |
280 |
|
} |
281 |
|
|
282 |
|
// assign (already created and initialized) control input and control |
283 |
|
// output variables (effect parameters) |
284 |
|
int iInControl = 0; |
285 |
|
int iOutControl = 0; |
286 |
|
for (int iPort = 0; iPort < pDescriptor->PortCount; iPort++) { |
287 |
|
LADSPA_PortDescriptor pPortDescriptor = pDescriptor->PortDescriptors[iPort]; |
288 |
|
if (LADSPA_IS_PORT_CONTROL(pPortDescriptor)) { |
289 |
|
if (LADSPA_IS_PORT_INPUT(pPortDescriptor)) { |
290 |
|
LadspaEffectControl* pEffectControl = |
291 |
|
(LadspaEffectControl*) vInputControls[iInControl++]; |
292 |
|
pDescriptor->connect_port(hEffect, iPort, &pEffectControl->Value()); |
293 |
|
} else if (LADSPA_IS_PORT_OUTPUT(pPortDescriptor)) { |
294 |
|
LadspaEffectControl* pEffectControl = |
295 |
|
(LadspaEffectControl*) vOutputControls[iOutControl++]; |
296 |
pDescriptor->connect_port(hEffect, iPort, &pEffectControl->Value()); |
pDescriptor->connect_port(hEffect, iPort, &pEffectControl->Value()); |
297 |
} |
} |
298 |
} |
} |