21 |
***************************************************************************/ |
***************************************************************************/ |
22 |
|
|
23 |
#include "SfzSignalUnitRack.h" |
#include "SfzSignalUnitRack.h" |
24 |
#include "Voice.h" |
#include "Engine.h" |
25 |
#include <SF.h> |
|
26 |
|
#define _200TH_ROOT_OF_10 1.011579454259899 |
27 |
|
|
28 |
namespace LinuxSampler { namespace sfz { |
namespace LinuxSampler { namespace sfz { |
29 |
|
|
30 |
|
double ToRatio(int Centibels) { |
31 |
|
if (Centibels == 0) return 1.0; |
32 |
|
return pow(_200TH_ROOT_OF_10, Centibels); |
33 |
|
} |
34 |
|
|
35 |
SfzSignalUnit::SfzSignalUnit(SfzSignalUnitRack* rack): SignalUnit(rack), pVoice(rack->pVoice) { |
SfzSignalUnit::SfzSignalUnit(SfzSignalUnitRack* rack): SignalUnit(rack), pVoice(rack->pVoice) { |
36 |
|
|
37 |
} |
} |
65 |
void XFInCCUnit::Calculate() { |
void XFInCCUnit::Calculate() { |
66 |
float l = 1; |
float l = 1; |
67 |
|
|
68 |
for (int i = 0; i < Ctrls.size(); i++) { |
RTList<CC>::Iterator ctrl = pCtrls->first(); |
69 |
|
RTList<CC>::Iterator end = pCtrls->end(); |
70 |
|
for(; ctrl != end; ++ctrl) { |
71 |
float c = 1; |
float c = 1; |
72 |
int influence = Ctrls[i].Influence; |
int influence = (*ctrl).Influence; |
73 |
int lo = influence & 0xff; |
int lo = influence & 0xff; |
74 |
int hi = influence >> 8; |
int hi = influence >> 8; |
75 |
if (Ctrls[i].Value <= lo) { |
if ((*ctrl).Value <= lo) { |
76 |
c = 0; |
c = 0; |
77 |
} else if (Ctrls[i].Value >= hi) { |
} else if ((*ctrl).Value >= hi) { |
78 |
c = 1; |
c = 1; |
79 |
} else { |
} else { |
80 |
float xfVelSize = hi - lo; |
float xfVelSize = hi - lo; |
81 |
float velPos = Ctrls[i].Value - lo; |
float velPos = (*ctrl).Value - lo; |
82 |
c = velPos / xfVelSize; |
c = velPos / xfVelSize; |
83 |
if (pVoice->pRegion->xf_cccurve == ::sfz::POWER) { |
if (pVoice->pRegion->xf_cccurve == ::sfz::POWER) { |
84 |
c = sin(c * M_PI / 2.0); |
c = sin(c * M_PI / 2.0); |
98 |
void XFOutCCUnit::Calculate() { |
void XFOutCCUnit::Calculate() { |
99 |
float l = 1; |
float l = 1; |
100 |
|
|
101 |
for (int i = 0; i < Ctrls.size(); i++) { |
RTList<CC>::Iterator ctrl = pCtrls->first(); |
102 |
|
RTList<CC>::Iterator end = pCtrls->end(); |
103 |
|
for(; ctrl != end; ++ctrl) { |
104 |
float c = 1; |
float c = 1; |
105 |
int influence = Ctrls[i].Influence; |
int influence = (*ctrl).Influence; |
106 |
int lo = influence & 0xff; |
int lo = influence & 0xff; |
107 |
int hi = influence >> 8; |
int hi = influence >> 8; |
108 |
if (Ctrls[i].Value >= hi) { |
if ((*ctrl).Value >= hi) { |
109 |
c = 0; |
c = 0; |
110 |
} else if (Ctrls[i].Value <= lo) { |
} else if ((*ctrl).Value <= lo) { |
111 |
c = 1; |
c = 1; |
112 |
} else { |
} else { |
113 |
float xfVelSize = hi - lo; |
float xfVelSize = hi - lo; |
114 |
float velPos = Ctrls[i].Value - lo; |
float velPos = (*ctrl).Value - lo; |
115 |
c = 1.0f - velPos / xfVelSize; |
c = 1.0f - velPos / xfVelSize; |
116 |
if (pVoice->pRegion->xf_cccurve == ::sfz::POWER) { |
if (pVoice->pRegion->xf_cccurve == ::sfz::POWER) { |
117 |
c = sin(c * M_PI / 2.0); |
c = sin(c * M_PI / 2.0); |
344 |
} |
} |
345 |
|
|
346 |
void CCUnit::Trigger() { |
void CCUnit::Trigger() { |
347 |
for (int i = 0; i < Ctrls.size(); i++) { |
RTList<CC>::Iterator ctrl = pCtrls->first(); |
348 |
Ctrls[i].Value = pVoice->GetControllerValue(Ctrls[i].Controller); |
RTList<CC>::Iterator end = pCtrls->end(); |
349 |
if (Ctrls[i].pSmoother != NULL) Ctrls[i].pSmoother->setValue(Ctrls[i].Value); |
for(; ctrl != end; ++ctrl) { |
350 |
|
(*ctrl).Value = pVoice->GetControllerValue((*ctrl).Controller); |
351 |
|
if ((*ctrl).pSmoother != NULL) (*ctrl).pSmoother->setValue((*ctrl).Value); |
352 |
} |
} |
353 |
CCSignalUnit::Trigger(); |
CCSignalUnit::Trigger(); |
354 |
} |
} |
355 |
|
|
356 |
void CCUnit::SetCCs(::sfz::Array<int>& cc) { |
void CCUnit::SetCCs(::sfz::Array<int>& cc) { |
357 |
RemoveAllCCs(); |
RemoveAllCCs(); |
358 |
for (int i = 0; i < 128; i++) { |
for (int i = 0; i < 128; i++) { |
359 |
if (cc[i] != 0) AddCC(i, cc[i]); |
if (cc[i] != 0) AddCC(i, cc[i]); |
360 |
} |
} |
361 |
} |
} |
362 |
|
|
363 |
void CCUnit::SetCCs(ArrayList< ::sfz::CC>& cc) { |
void CCUnit::SetCCs(ArrayList< ::sfz::CC>& cc) { |
364 |
RemoveAllCCs(); |
RemoveAllCCs(); |
365 |
for (int i = 0; i < cc.size(); i++) { |
for (int i = 0; i < cc.size(); i++) { |
366 |
if (cc[i].Influence != 0) { |
if (cc[i].Influence != 0) { |
367 |
short int curve = cc[i].Curve; |
short int curve = cc[i].Curve; |
368 |
if (curve >= GetCurveCount()) curve = -1; |
if (curve >= GetCurveCount()) curve = -1; |
369 |
AddSmoothCC(cc[i].Controller, cc[i].Influence, curve, cc[i].Smooth); |
AddSmoothCC(cc[i].Controller, cc[i].Influence, curve, cc[i].Smooth); |
370 |
} |
} |
371 |
} |
} |
372 |
} |
} |
373 |
|
|
374 |
void CCUnit::AddSmoothCC(uint8_t Controller, float Influence, short int Curve, float Smooth) { |
void CCUnit::AddSmoothCC(uint8_t Controller, float Influence, short int Curve, float Smooth) { |
375 |
AddCC(Controller, Influence, Curve); |
AddCC(Controller, Influence, Curve); |
376 |
} |
} |
377 |
|
|
378 |
int CCUnit::GetCurveCount() { |
int CCUnit::GetCurveCount() { |
379 |
return pVoice->pRegion->GetInstrument()->curves.size(); |
return pVoice->pRegion->GetInstrument()->curves.size(); |
380 |
} |
} |
381 |
|
|
382 |
::sfz::Curve* CCUnit::GetCurve(int idx) { |
::sfz::Curve* CCUnit::GetCurve(int idx) { |
383 |
return &pVoice->pRegion->GetInstrument()->curves[idx]; |
return &pVoice->pRegion->GetInstrument()->curves[idx]; |
384 |
} |
} |
385 |
|
|
386 |
double CCUnit::GetSampleRate() { |
double CCUnit::GetSampleRate() { |
387 |
return pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE; |
return pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE; |
388 |
} |
} |
389 |
|
|
390 |
|
|
391 |
|
SmoothCCUnit::~SmoothCCUnit() { |
392 |
|
if (pSmoothers != NULL) delete pSmoothers; |
393 |
|
} |
394 |
|
|
395 |
|
void SmoothCCUnit::AddSmoothCC(uint8_t Controller, float Influence, short int Curve, float Smooth) { |
396 |
|
if (Smooth > 0) { |
397 |
|
if (pSmoothers->poolIsEmpty()) { |
398 |
|
std::cerr << "Maximum number of smoothers reached" << std::endl; |
399 |
|
return; |
400 |
|
} |
401 |
|
Smoother* smoother = &(*(pSmoothers->allocAppend())); |
402 |
|
smoother->trigger(Smooth / 1000.0f, GetSampleRate()); |
403 |
|
AddCC(Controller, Influence, Curve, smoother); |
404 |
|
} else { |
405 |
|
AddCC(Controller, Influence, Curve); |
406 |
|
} |
407 |
|
} |
408 |
|
|
409 |
void SmoothCCUnit::AddSmoothCC(uint8_t Controller, float Influence, short int Curve, float Smooth) { |
void SmoothCCUnit::InitSmoothers(Pool<Smoother>* pSmootherPool) { |
410 |
if (Smooth > 0) { |
if (pSmoothers != NULL) delete pSmoothers; |
411 |
if (Smoothers.size() >= Smoothers.capacity()) { |
pSmoothers = new RTList<Smoother>(pSmootherPool); |
412 |
std::cerr << "Maximum number of smoothers reached" << std::endl; |
} |
413 |
return; |
|
414 |
} |
void SmoothCCUnit::InitCCList(Pool<CC>* pCCPool, Pool<Smoother>* pSmootherPool) { |
415 |
|
CurveCCUnit::InitCCList(pCCPool, pSmootherPool); |
416 |
Smoothers.increment().trigger(Smooth / 1000.0f, GetSampleRate()); |
InitSmoothers(pSmootherPool); |
417 |
AddCC(Controller, Influence, Curve, &Smoothers[Smoothers.size() - 1]); |
} |
|
} else { |
|
|
AddCC(Controller, Influence, Curve); |
|
|
} |
|
|
} |
|
418 |
|
|
419 |
|
|
420 |
EndpointUnit::EndpointUnit(SfzSignalUnitRack* rack) |
EndpointUnit::EndpointUnit(SfzSignalUnitRack* rack) |
525 |
|
|
526 |
if (dB >= -144) { |
if (dB >= -144) { |
527 |
if (amp == 0 && eg->suAmpOnCC.GetCCCount() == 0) amp = 1.0f; |
if (amp == 0 && eg->suAmpOnCC.GetCCCount() == 0) amp = 1.0f; |
528 |
amp *= ::sf2::ToRatio(dB * 10.0); |
amp *= ToRatio(dB * 10.0); |
529 |
} |
} |
530 |
|
|
531 |
vol += amp * eg->GetLevel(); |
vol += amp * eg->GetLevel(); |
534 |
AmpLFOUnit* u = &(GetRack()->suAmpLFO); |
AmpLFOUnit* u = &(GetRack()->suAmpLFO); |
535 |
CCSignalUnit* u2 = &(GetRack()->suAmpLFO.suDepthOnCC); |
CCSignalUnit* u2 = &(GetRack()->suAmpLFO.suDepthOnCC); |
536 |
float f = u2->Active() ? u2->GetLevel() : 0; |
float f = u2->Active() ? u2->GetLevel() : 0; |
537 |
vol *= u->Active() ? ::sf2::ToRatio((u->GetLevel() * (u->pLfoInfo->volume + f) * 10.0)) : 1; |
vol *= u->Active() ? ToRatio((u->GetLevel() * (u->pLfoInfo->volume + f) * 10.0)) : 1; |
538 |
|
|
539 |
vol *= ::sf2::ToRatio(GetRack()->suVolOnCC.GetLevel() * 10.0); |
vol *= ToRatio(GetRack()->suVolOnCC.GetLevel() * 10.0); |
540 |
|
|
541 |
for (int i = 0; i < GetRack()->volLFOs.size(); i++) { |
for (int i = 0; i < GetRack()->volLFOs.size(); i++) { |
542 |
LFOv2Unit* lfo = GetRack()->volLFOs[i]; |
LFOv2Unit* lfo = GetRack()->volLFOs[i]; |
543 |
if (!lfo->Active()) continue; |
if (!lfo->Active()) continue; |
544 |
|
|
545 |
float f = lfo->suVolOnCC.Active() ? lfo->suVolOnCC.GetLevel() : 0; |
float f = lfo->suVolOnCC.Active() ? lfo->suVolOnCC.GetLevel() : 0; |
546 |
vol *= ::sf2::ToRatio(lfo->GetLevel() * (lfo->pLfoInfo->volume + f) * 10.0); |
vol *= ToRatio(lfo->GetLevel() * (lfo->pLfoInfo->volume + f) * 10.0); |
547 |
} |
} |
548 |
|
|
549 |
if (suXFInCC.Active()) vol *= suXFInCC.GetLevel(); |
if (suXFInCC.Active()) vol *= suXFInCC.GetLevel(); |
701 |
for (int i = 0; i < LFOs.capacity(); i++) { |
for (int i = 0; i < LFOs.capacity(); i++) { |
702 |
LFOs[i] = new LFOv2Unit(this); |
LFOs[i] = new LFOv2Unit(this); |
703 |
LFOs[i]->pVoice = voice; |
LFOs[i]->pVoice = voice; |
704 |
|
LFOs[i]->suDepthOnCC.pVoice = voice; |
705 |
|
LFOs[i]->suFreqOnCC.pVoice = voice; |
706 |
LFOs[i]->suFadeEG.pVoice = voice; |
LFOs[i]->suFadeEG.pVoice = voice; |
707 |
LFOs[i]->suVolOnCC.pVoice = voice; |
LFOs[i]->suVolOnCC.pVoice = voice; |
708 |
LFOs[i]->suPitchOnCC.pVoice = voice; |
LFOs[i]->suPitchOnCC.pVoice = voice; |
723 |
} |
} |
724 |
} |
} |
725 |
|
|
726 |
|
void SfzSignalUnitRack::InitRTLists() { |
727 |
|
Pool<CCSignalUnit::CC>* pCCPool = pVoice->pEngine->pCCPool; |
728 |
|
Pool<Smoother>* pSmootherPool = pVoice->pEngine->pSmootherPool; |
729 |
|
|
730 |
|
suVolOnCC.InitCCList(pCCPool, pSmootherPool); |
731 |
|
suEndpoint.suXFInCC.InitCCList(pCCPool, pSmootherPool); |
732 |
|
suEndpoint.suXFOutCC.InitCCList(pCCPool, pSmootherPool); |
733 |
|
suEndpoint.suPanOnCC.InitCCList(pCCPool, pSmootherPool); |
734 |
|
suPitchLFO.suDepthOnCC.InitCCList(pCCPool, pSmootherPool); |
735 |
|
suPitchLFO.suFreqOnCC.InitCCList(pCCPool, pSmootherPool); |
736 |
|
suFilLFO.suDepthOnCC.InitCCList(pCCPool, pSmootherPool); |
737 |
|
suFilLFO.suFreqOnCC.InitCCList(pCCPool, pSmootherPool); |
738 |
|
suAmpLFO.suDepthOnCC.InitCCList(pCCPool, pSmootherPool); |
739 |
|
suAmpLFO.suFreqOnCC.InitCCList(pCCPool, pSmootherPool); |
740 |
|
|
741 |
|
for (int i = 0; i < EGs.capacity(); i++) { |
742 |
|
EGs[i]->suAmpOnCC.InitCCList(pCCPool, pSmootherPool); |
743 |
|
EGs[i]->suVolOnCC.InitCCList(pCCPool, pSmootherPool); |
744 |
|
EGs[i]->suPitchOnCC.InitCCList(pCCPool, pSmootherPool); |
745 |
|
EGs[i]->suCutoffOnCC.InitCCList(pCCPool, pSmootherPool); |
746 |
|
EGs[i]->suResOnCC.InitCCList(pCCPool, pSmootherPool); |
747 |
|
EGs[i]->suPanOnCC.InitCCList(pCCPool, pSmootherPool); |
748 |
|
} |
749 |
|
|
750 |
|
for (int i = 0; i < LFOs.capacity(); i++) { |
751 |
|
LFOs[i]->suDepthOnCC.InitCCList(pCCPool, pSmootherPool); |
752 |
|
LFOs[i]->suFreqOnCC.InitCCList(pCCPool, pSmootherPool); |
753 |
|
LFOs[i]->suVolOnCC.InitCCList(pCCPool, pSmootherPool); |
754 |
|
LFOs[i]->suPitchOnCC.InitCCList(pCCPool, pSmootherPool); |
755 |
|
LFOs[i]->suFreqOnCC.InitCCList(pCCPool, pSmootherPool); |
756 |
|
LFOs[i]->suPanOnCC.InitCCList(pCCPool, pSmootherPool); |
757 |
|
LFOs[i]->suCutoffOnCC.InitCCList(pCCPool, pSmootherPool); |
758 |
|
LFOs[i]->suResOnCC.InitCCList(pCCPool, pSmootherPool); |
759 |
|
} |
760 |
|
} |
761 |
|
|
762 |
void SfzSignalUnitRack::Trigger() { |
void SfzSignalUnitRack::Trigger() { |
763 |
EGs.clear(); |
EGs.clear(); |
764 |
volEGs.clear(); |
volEGs.clear(); |
941 |
} |
} |
942 |
} |
} |
943 |
|
|
944 |
|
void SfzSignalUnitRack::Reset() { |
945 |
|
suVolOnCC.RemoveAllCCs(); |
946 |
|
suEndpoint.suXFInCC.RemoveAllCCs(); |
947 |
|
suEndpoint.suXFOutCC.RemoveAllCCs(); |
948 |
|
suEndpoint.suPanOnCC.RemoveAllCCs(); |
949 |
|
suPitchLFO.suDepthOnCC.RemoveAllCCs(); |
950 |
|
suPitchLFO.suFreqOnCC.RemoveAllCCs(); |
951 |
|
suFilLFO.suDepthOnCC.RemoveAllCCs(); |
952 |
|
suFilLFO.suFreqOnCC.RemoveAllCCs(); |
953 |
|
suAmpLFO.suDepthOnCC.RemoveAllCCs(); |
954 |
|
suAmpLFO.suFreqOnCC.RemoveAllCCs(); |
955 |
|
|
956 |
|
for (int i = 0; i < EGs.capacity(); i++) { |
957 |
|
EGs[i]->suAmpOnCC.RemoveAllCCs(); |
958 |
|
EGs[i]->suVolOnCC.RemoveAllCCs(); |
959 |
|
EGs[i]->suPitchOnCC.RemoveAllCCs(); |
960 |
|
EGs[i]->suCutoffOnCC.RemoveAllCCs(); |
961 |
|
EGs[i]->suResOnCC.RemoveAllCCs(); |
962 |
|
EGs[i]->suPanOnCC.RemoveAllCCs(); |
963 |
|
} |
964 |
|
|
965 |
|
for (int i = 0; i < LFOs.capacity(); i++) { |
966 |
|
LFOs[i]->suDepthOnCC.RemoveAllCCs(); |
967 |
|
LFOs[i]->suFreqOnCC.RemoveAllCCs(); |
968 |
|
LFOs[i]->suVolOnCC.RemoveAllCCs(); |
969 |
|
LFOs[i]->suPitchOnCC.RemoveAllCCs(); |
970 |
|
LFOs[i]->suFreqOnCC.RemoveAllCCs(); |
971 |
|
LFOs[i]->suPanOnCC.RemoveAllCCs(); |
972 |
|
LFOs[i]->suCutoffOnCC.RemoveAllCCs(); |
973 |
|
LFOs[i]->suResOnCC.RemoveAllCCs(); |
974 |
|
} |
975 |
|
} |
976 |
|
|
977 |
}} // namespace LinuxSampler::sfz |
}} // namespace LinuxSampler::sfz |