29 |
float EGADSR::CalculateFadeOutCoeff() { |
float EGADSR::CalculateFadeOutCoeff() { |
30 |
const float sampleRate = 44100.0; // even if the sample rate will be 192kHz it won't hurt at all |
const float sampleRate = 44100.0; // even if the sample rate will be 192kHz it won't hurt at all |
31 |
const float killSteps = EG_MIN_RELEASE_TIME * sampleRate; |
const float killSteps = EG_MIN_RELEASE_TIME * sampleRate; |
32 |
return 1.0f / killSteps; |
return -1.0f / killSteps; |
33 |
} |
} |
34 |
|
|
35 |
EGADSR::EGADSR(gig::Engine* pEngine, Event::destination_t ModulationDestination) { |
EGADSR::EGADSR(gig::Engine* pEngine, Event::destination_t ModulationDestination) { |
58 |
RTList<Event>::Iterator itTransitionEvent = (itTriggerEvent) ? ++itTriggerEvent : pEvents->first(); |
RTList<Event>::Iterator itTransitionEvent = (itTriggerEvent) ? ++itTriggerEvent : pEvents->first(); |
59 |
|
|
60 |
// if the voice was killed in this fragment we only process the time before this kill event, then switch to 'stage_fadeout' |
// if the voice was killed in this fragment we only process the time before this kill event, then switch to 'stage_fadeout' |
61 |
int Samples = (itKillEvent) ? itKillEvent->FragmentPos() : (int) TotalSamples; |
int Samples = (itKillEvent) ? RTMath::Min(itKillEvent->FragmentPos(), pEngine->MaxFadeOutPos) : (int) TotalSamples; |
62 |
|
|
63 |
int iSample = TriggerDelay; |
int iSample = TriggerDelay; |
64 |
|
|
65 |
|
#if DEVMODE |
66 |
|
if (TriggerDelay > TotalSamples) { // FIXME: should be removed before the final release (purpose: just a sanity check for debugging) |
67 |
|
dmsg(1,("EGADSR: ERROR, TriggerDelay > Totalsamples\n")); |
68 |
|
int* i = NULL; |
69 |
|
(*i)++; // force a segfault |
70 |
|
} |
71 |
|
#endif // DEVMODE |
72 |
|
|
73 |
while (iSample < TotalSamples) { |
while (iSample < TotalSamples) { |
74 |
|
|
75 |
// if the voice was killed in this fragment and we already processed the time before this kill event |
// if the voice was killed in this fragment and we already processed the time before this kill event |
179 |
Level += FadeOutCoeff; |
Level += FadeOutCoeff; |
180 |
pEngine->pSynthesisParameters[ModulationDestination][iSample++] *= Level; |
pEngine->pSynthesisParameters[ModulationDestination][iSample++] *= Level; |
181 |
} |
} |
182 |
if (Level <= FadeOutCoeff) Stage = stage_end; |
Stage = stage_end; |
183 |
|
if (Level > -FadeOutCoeff) dmsg(1,("EGADSR: Warning, final fade out level too high, may result in click sound!\n")); |
184 |
} //Fall through here instead of breaking otherwise we can get back into stage_fadeout and loop forever! |
} //Fall through here instead of breaking otherwise we can get back into stage_fadeout and loop forever! |
185 |
case stage_end: { |
case stage_end: { |
186 |
while (iSample < TotalSamples) { |
while (iSample < TotalSamples) { |
190 |
} |
} |
191 |
} |
} |
192 |
} |
} |
193 |
|
|
194 |
|
#if DEVMODE |
195 |
|
if (itKillEvent && Stage != stage_end) { // FIXME: should be removed before the final release (purpose: just a sanity check for debugging) |
196 |
|
dmsg(1,("EGADSR: ERROR, voice killing not completed !!!\n")); |
197 |
|
dmsg(1,("EGADSR: Stage=%d,iSample=%d,Samples=%d, TotalSamples=%d, MaxFadoutPos=%d\n",Stage,iSample,Samples,TotalSamples,pEngine->MaxFadeOutPos)); |
198 |
|
} |
199 |
|
#endif // DEVMODE |
200 |
} |
} |
201 |
|
|
202 |
/** |
/** |