29 |
|
|
30 |
namespace LinuxSampler { namespace gig { |
namespace LinuxSampler { namespace gig { |
31 |
|
|
|
const float Voice::FILTER_CUTOFF_COEFF(CalculateFilterCutoffCoeff()); |
|
|
|
|
|
float Voice::CalculateFilterCutoffCoeff() { |
|
|
return log(CONFIG_FILTER_CUTOFF_MAX / CONFIG_FILTER_CUTOFF_MIN); |
|
|
} |
|
|
|
|
32 |
Voice::Voice() { |
Voice::Voice() { |
33 |
pEngine = NULL; |
pEngine = NULL; |
34 |
pDiskThread = NULL; |
pDiskThread = NULL; |
147 |
long cachedsamples = pSample->GetCache().Size / pSample->FrameSize; |
long cachedsamples = pSample->GetCache().Size / pSample->FrameSize; |
148 |
DiskVoice = cachedsamples < pSample->SamplesTotal; |
DiskVoice = cachedsamples < pSample->SamplesTotal; |
149 |
|
|
150 |
|
const DLS::sample_loop_t& loopinfo = pDimRgn->pSampleLoops[0]; |
151 |
|
|
152 |
if (DiskVoice) { // voice to be streamed from disk |
if (DiskVoice) { // voice to be streamed from disk |
153 |
MaxRAMPos = cachedsamples - (pEngine->MaxSamplesPerCycle << CONFIG_MAX_PITCH) / pSample->Channels; //TODO: this calculation is too pessimistic and may better be moved to Render() method, so it calculates MaxRAMPos dependent to the current demand of sample points to be rendered (e.g. in case of JACK) |
MaxRAMPos = cachedsamples - (pEngine->MaxSamplesPerCycle << CONFIG_MAX_PITCH) / pSample->Channels; //TODO: this calculation is too pessimistic and may better be moved to Render() method, so it calculates MaxRAMPos dependent to the current demand of sample points to be rendered (e.g. in case of JACK) |
154 |
|
|
155 |
// check if there's a loop defined which completely fits into the cached (RAM) part of the sample |
// check if there's a loop defined which completely fits into the cached (RAM) part of the sample |
156 |
RAMLoop = (pSample->Loops && pSample->LoopEnd <= MaxRAMPos); |
RAMLoop = (pDimRgn->SampleLoops && (loopinfo.LoopStart + loopinfo.LoopLength) <= MaxRAMPos); |
157 |
|
|
158 |
if (pDiskThread->OrderNewStream(&DiskStreamRef, pSample, MaxRAMPos, !RAMLoop) < 0) { |
if (pDiskThread->OrderNewStream(&DiskStreamRef, pDimRgn, MaxRAMPos, !RAMLoop) < 0) { |
159 |
dmsg(1,("Disk stream order failed!\n")); |
dmsg(1,("Disk stream order failed!\n")); |
160 |
KillImmediately(); |
KillImmediately(); |
161 |
return -1; |
return -1; |
164 |
} |
} |
165 |
else { // RAM only voice |
else { // RAM only voice |
166 |
MaxRAMPos = cachedsamples; |
MaxRAMPos = cachedsamples; |
167 |
RAMLoop = (pSample->Loops != 0); |
RAMLoop = (pDimRgn->SampleLoops != 0); |
168 |
dmsg(4,("RAM only voice launched (Looping: %s)\n", (RAMLoop) ? "yes" : "no")); |
dmsg(4,("RAM only voice launched (Looping: %s)\n", (RAMLoop) ? "yes" : "no")); |
169 |
} |
} |
170 |
if (RAMLoop) { |
if (RAMLoop) { |
171 |
loop.uiTotalCycles = pSample->LoopPlayCount; |
loop.uiTotalCycles = pSample->LoopPlayCount; |
172 |
loop.uiCyclesLeft = pSample->LoopPlayCount; |
loop.uiCyclesLeft = pSample->LoopPlayCount; |
173 |
loop.uiStart = pSample->LoopStart; |
loop.uiStart = loopinfo.LoopStart; |
174 |
loop.uiEnd = pSample->LoopEnd; |
loop.uiEnd = loopinfo.LoopStart + loopinfo.LoopLength; |
175 |
loop.uiSize = pSample->LoopSize; |
loop.uiSize = loopinfo.LoopLength; |
176 |
} |
} |
177 |
|
|
178 |
// calculate initial pitch value |
// calculate initial pitch value |
531 |
else { |
else { |
532 |
cvalue = pDimRgn->VCFCutoff; |
cvalue = pDimRgn->VCFCutoff; |
533 |
} |
} |
534 |
cutoff *= float(cvalue) * 0.00787402f; // (1 / 127) |
cutoff *= float(cvalue); |
535 |
if (cutoff > 1.0) cutoff = 1.0; |
if (cutoff > 127.0f) cutoff = 127.0f; |
|
cutoff = (cutoff < 0.5 ? cutoff * 4826 - 1 : cutoff * 5715 - 449); |
|
|
if (cutoff < 1.0) cutoff = 1.0; |
|
536 |
|
|
537 |
// calculate resonance |
// calculate resonance |
538 |
float resonance = (float) (VCFResonanceCtrl.controller ? VCFResonanceCtrl.value : pDimRgn->VCFResonance) * 0.00787f; // 0.0..1.0 |
float resonance = (float) (VCFResonanceCtrl.controller ? VCFResonanceCtrl.value : pDimRgn->VCFResonance); |
539 |
|
|
540 |
VCFCutoffCtrl.fvalue = cutoff - 1.0; |
VCFCutoffCtrl.fvalue = cutoff; |
541 |
VCFResonanceCtrl.fvalue = resonance; |
VCFResonanceCtrl.fvalue = resonance; |
542 |
} |
} |
543 |
else { |
else { |
735 |
VCFCutoffCtrl.value == ccvalue; |
VCFCutoffCtrl.value == ccvalue; |
736 |
if (pDimRgn->VCFCutoffControllerInvert) ccvalue = 127 - ccvalue; |
if (pDimRgn->VCFCutoffControllerInvert) ccvalue = 127 - ccvalue; |
737 |
if (ccvalue < pDimRgn->VCFVelocityScale) ccvalue = pDimRgn->VCFVelocityScale; |
if (ccvalue < pDimRgn->VCFVelocityScale) ccvalue = pDimRgn->VCFVelocityScale; |
738 |
float cutoff = CutoffBase * float(ccvalue) * 0.00787402f; // (1 / 127) |
float cutoff = CutoffBase * float(ccvalue); |
739 |
if (cutoff > 1.0) cutoff = 1.0; |
if (cutoff > 127.0f) cutoff = 127.0f; |
|
cutoff = (cutoff < 0.5 ? cutoff * 4826 - 1 : cutoff * 5715 - 449); |
|
|
if (cutoff < 1.0) cutoff = 1.0; |
|
740 |
|
|
741 |
VCFCutoffCtrl.fvalue = cutoff - 1.0; // needed for initialization of fFinalCutoff next time |
VCFCutoffCtrl.fvalue = cutoff; // needed for initialization of fFinalCutoff next time |
742 |
fFinalCutoff = cutoff; |
fFinalCutoff = cutoff; |
743 |
} |
} |
744 |
|
|
746 |
// convert absolute controller value to differential |
// convert absolute controller value to differential |
747 |
const int ctrldelta = itEvent->Param.CC.Value - VCFResonanceCtrl.value; |
const int ctrldelta = itEvent->Param.CC.Value - VCFResonanceCtrl.value; |
748 |
VCFResonanceCtrl.value = itEvent->Param.CC.Value; |
VCFResonanceCtrl.value = itEvent->Param.CC.Value; |
749 |
const float resonancedelta = (float) ctrldelta * 0.00787f; // 0.0..1.0 |
const float resonancedelta = (float) ctrldelta; |
750 |
fFinalResonance += resonancedelta; |
fFinalResonance += resonancedelta; |
751 |
// needed for initialization of parameter |
// needed for initialization of parameter |
752 |
VCFResonanceCtrl.fvalue = itEvent->Param.CC.Value * 0.00787f; |
VCFResonanceCtrl.fvalue = itEvent->Param.CC.Value; |
753 |
} |
} |
754 |
|
|
755 |
/** |
/** |
834 |
|
|
835 |
// if filter enabled then update filter coefficients |
// if filter enabled then update filter coefficients |
836 |
if (SYNTHESIS_MODE_GET_FILTER(SynthesisMode)) { |
if (SYNTHESIS_MODE_GET_FILTER(SynthesisMode)) { |
837 |
finalSynthesisParameters.filterLeft.SetParameters(fFinalCutoff + 1.0, fFinalResonance, pEngine->SampleRate); |
finalSynthesisParameters.filterLeft.SetParameters(fFinalCutoff, fFinalResonance, pEngine->SampleRate); |
838 |
finalSynthesisParameters.filterRight.SetParameters(fFinalCutoff + 1.0, fFinalResonance, pEngine->SampleRate); |
finalSynthesisParameters.filterRight.SetParameters(fFinalCutoff, fFinalResonance, pEngine->SampleRate); |
839 |
} |
} |
840 |
|
|
841 |
// do we need resampling? |
// do we need resampling? |
872 |
if (EG1.active()) { |
if (EG1.active()) { |
873 |
|
|
874 |
// if sample has a loop and loop start has been reached in this subfragment, send a special event to EG1 to let it finish the attack hold stage |
// if sample has a loop and loop start has been reached in this subfragment, send a special event to EG1 to let it finish the attack hold stage |
875 |
if (pSample->Loops && Pos <= pSample->LoopStart && pSample->LoopStart < newPos) { |
if (pDimRgn->SampleLoops && Pos <= pDimRgn->pSampleLoops[0].LoopStart && pDimRgn->pSampleLoops[0].LoopStart < newPos) { |
876 |
EG1.update(EGADSR::event_hold_end, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
EG1.update(EGADSR::event_hold_end, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
877 |
} |
} |
878 |
|
|