57 |
pLFO1 = NULL; |
pLFO1 = NULL; |
58 |
pLFO2 = NULL; |
pLFO2 = NULL; |
59 |
pLFO3 = NULL; |
pLFO3 = NULL; |
60 |
|
KeyGroup = 0; |
61 |
} |
} |
62 |
|
|
63 |
Voice::~Voice() { |
Voice::~Voice() { |
121 |
MIDIKey = pNoteOnEvent->Key; |
MIDIKey = pNoteOnEvent->Key; |
122 |
pRegion = pInstrument->GetRegion(MIDIKey); |
pRegion = pInstrument->GetRegion(MIDIKey); |
123 |
PlaybackState = playback_state_ram; // we always start playback from RAM cache and switch then to disk if needed |
PlaybackState = playback_state_ram; // we always start playback from RAM cache and switch then to disk if needed |
|
Pos = 0; |
|
124 |
Delay = pNoteOnEvent->FragmentPos(); |
Delay = pNoteOnEvent->FragmentPos(); |
125 |
pTriggerEvent = pNoteOnEvent; |
pTriggerEvent = pNoteOnEvent; |
126 |
|
pKillEvent = NULL; |
127 |
|
|
128 |
if (!pRegion) { |
if (!pRegion) { |
129 |
std::cerr << "gig::Voice: No Region defined for MIDI key " << MIDIKey << std::endl << std::flush; |
std::cerr << "gig::Voice: No Region defined for MIDI key " << MIDIKey << std::endl << std::flush; |
130 |
Kill(); |
KillImmediately(); |
131 |
return -1; |
return -1; |
132 |
} |
} |
133 |
|
|
134 |
|
KeyGroup = pRegion->KeyGroup; |
135 |
|
|
136 |
// get current dimension values to select the right dimension region |
// get current dimension values to select the right dimension region |
137 |
//FIXME: controller values for selecting the dimension region here are currently not sample accurate |
//FIXME: controller values for selecting the dimension region here are currently not sample accurate |
138 |
uint DimValues[5] = {0,0,0,0,0}; |
uint DimValues[5] = {0,0,0,0,0}; |
236 |
std::cerr << "gig::Voice::Trigger() Error: Unknown dimension\n" << std::flush; |
std::cerr << "gig::Voice::Trigger() Error: Unknown dimension\n" << std::flush; |
237 |
} |
} |
238 |
} |
} |
239 |
::gig::DimensionRegion* pDimRgn = pRegion->GetDimensionRegionByValue(DimValues[4],DimValues[3],DimValues[2],DimValues[1],DimValues[0]); |
pDimRgn = pRegion->GetDimensionRegionByValue(DimValues[4],DimValues[3],DimValues[2],DimValues[1],DimValues[0]); |
240 |
|
|
241 |
|
// get starting crossfade volume level |
242 |
|
switch (pDimRgn->AttenuationController.type) { |
243 |
|
case ::gig::attenuation_ctrl_t::type_channelaftertouch: |
244 |
|
CrossfadeVolume = 1.0f; //TODO: aftertouch not supported yet |
245 |
|
break; |
246 |
|
case ::gig::attenuation_ctrl_t::type_velocity: |
247 |
|
CrossfadeVolume = CrossfadeAttenuation(pNoteOnEvent->Velocity); |
248 |
|
break; |
249 |
|
case ::gig::attenuation_ctrl_t::type_controlchange: //FIXME: currently not sample accurate |
250 |
|
CrossfadeVolume = CrossfadeAttenuation(pEngine->ControllerTable[pDimRgn->AttenuationController.controller_number]); |
251 |
|
break; |
252 |
|
case ::gig::attenuation_ctrl_t::type_none: // no crossfade defined |
253 |
|
default: |
254 |
|
CrossfadeVolume = 1.0f; |
255 |
|
} |
256 |
|
|
257 |
pSample = pDimRgn->pSample; // sample won't change until the voice is finished |
pSample = pDimRgn->pSample; // sample won't change until the voice is finished |
258 |
|
|
259 |
|
Pos = pDimRgn->SampleStartOffset; // offset where we should start playback of sample (0 - 2000 sample points) |
260 |
|
|
261 |
// Check if the sample needs disk streaming or is too short for that |
// Check if the sample needs disk streaming or is too short for that |
262 |
long cachedsamples = pSample->GetCache().Size / pSample->FrameSize; |
long cachedsamples = pSample->GetCache().Size / pSample->FrameSize; |
263 |
DiskVoice = cachedsamples < pSample->SamplesTotal; |
DiskVoice = cachedsamples < pSample->SamplesTotal; |
274 |
|
|
275 |
if (pDiskThread->OrderNewStream(&DiskStreamRef, pSample, MaxRAMPos, !RAMLoop) < 0) { |
if (pDiskThread->OrderNewStream(&DiskStreamRef, pSample, MaxRAMPos, !RAMLoop) < 0) { |
276 |
dmsg(1,("Disk stream order failed!\n")); |
dmsg(1,("Disk stream order failed!\n")); |
277 |
Kill(); |
KillImmediately(); |
278 |
return -1; |
return -1; |
279 |
} |
} |
280 |
dmsg(4,("Disk voice launched (cached samples: %d, total Samples: %d, MaxRAMPos: %d, RAMLooping: %s)\n", cachedsamples, pSample->SamplesTotal, MaxRAMPos, (RAMLoop) ? "yes" : "no")); |
dmsg(4,("Disk voice launched (cached samples: %d, total Samples: %d, MaxRAMPos: %d, RAMLooping: %s)\n", cachedsamples, pSample->SamplesTotal, MaxRAMPos, (RAMLoop) ? "yes" : "no")); |
605 |
} |
} |
606 |
#endif // ENABLE_FILTER |
#endif // ENABLE_FILTER |
607 |
|
|
|
// ************************************************ |
|
|
// TODO: ARTICULATION DATA HANDLING IS MISSING HERE |
|
|
// ************************************************ |
|
|
|
|
608 |
return 0; // success |
return 0; // success |
609 |
} |
} |
610 |
|
|
622 |
void Voice::Render(uint Samples) { |
void Voice::Render(uint Samples) { |
623 |
|
|
624 |
// Reset the synthesis parameter matrix |
// Reset the synthesis parameter matrix |
625 |
pEngine->ResetSynthesisParameters(Event::destination_vca, this->Volume * pEngine->GlobalVolume); |
pEngine->ResetSynthesisParameters(Event::destination_vca, this->Volume * this->CrossfadeVolume * pEngine->GlobalVolume); |
626 |
pEngine->ResetSynthesisParameters(Event::destination_vco, this->PitchBase); |
pEngine->ResetSynthesisParameters(Event::destination_vco, this->PitchBase); |
627 |
#if ENABLE_FILTER |
#if ENABLE_FILTER |
628 |
pEngine->ResetSynthesisParameters(Event::destination_vcfc, VCFCutoffCtrl.fvalue); |
pEngine->ResetSynthesisParameters(Event::destination_vcfc, VCFCutoffCtrl.fvalue); |
635 |
|
|
636 |
|
|
637 |
// Let all modulators write their parameter changes to the synthesis parameter matrix for the current audio fragment |
// Let all modulators write their parameter changes to the synthesis parameter matrix for the current audio fragment |
638 |
pEG1->Process(Samples, pEngine->pMIDIKeyInfo[MIDIKey].pEvents, pTriggerEvent, this->Pos, this->PitchBase * this->PitchBend); |
pEG1->Process(Samples, pEngine->pMIDIKeyInfo[MIDIKey].pEvents, pTriggerEvent, this->Pos, this->PitchBase * this->PitchBend, pKillEvent); |
639 |
#if ENABLE_FILTER |
#if ENABLE_FILTER |
640 |
pEG2->Process(Samples, pEngine->pMIDIKeyInfo[MIDIKey].pEvents, pTriggerEvent, this->Pos, this->PitchBase * this->PitchBend); |
pEG2->Process(Samples, pEngine->pMIDIKeyInfo[MIDIKey].pEvents, pTriggerEvent, this->Pos, this->PitchBase * this->PitchBend); |
641 |
#endif // ENABLE_FILTER |
#endif // ENABLE_FILTER |
676 |
DiskStreamRef.pStream = pDiskThread->AskForCreatedStream(DiskStreamRef.OrderID); |
DiskStreamRef.pStream = pDiskThread->AskForCreatedStream(DiskStreamRef.OrderID); |
677 |
if (!DiskStreamRef.pStream) { |
if (!DiskStreamRef.pStream) { |
678 |
std::cout << stderr << "Disk stream not available in time!" << std::endl << std::flush; |
std::cout << stderr << "Disk stream not available in time!" << std::endl << std::flush; |
679 |
Kill(); |
KillImmediately(); |
680 |
return; |
return; |
681 |
} |
} |
682 |
DiskStreamRef.pStream->IncrementReadPos(pSample->Channels * (RTMath::DoubleToInt(Pos) - MaxRAMPos)); |
DiskStreamRef.pStream->IncrementReadPos(pSample->Channels * (RTMath::DoubleToInt(Pos) - MaxRAMPos)); |
697 |
break; |
break; |
698 |
|
|
699 |
case playback_state_end: |
case playback_state_end: |
700 |
Kill(); // free voice |
KillImmediately(); // free voice |
701 |
break; |
break; |
702 |
} |
} |
703 |
|
|
704 |
|
|
|
#if ENABLE_FILTER |
|
705 |
// Reset synthesis event lists (except VCO, as VCO events apply channel wide currently) |
// Reset synthesis event lists (except VCO, as VCO events apply channel wide currently) |
706 |
|
pEngine->pSynthesisEvents[Event::destination_vca]->clear(); |
707 |
|
#if ENABLE_FILTER |
708 |
pEngine->pSynthesisEvents[Event::destination_vcfc]->clear(); |
pEngine->pSynthesisEvents[Event::destination_vcfc]->clear(); |
709 |
pEngine->pSynthesisEvents[Event::destination_vcfr]->clear(); |
pEngine->pSynthesisEvents[Event::destination_vcfr]->clear(); |
710 |
#endif // ENABLE_FILTER |
#endif // ENABLE_FILTER |
768 |
if (pCCEvent->Controller == pLFO3->ExtController) { |
if (pCCEvent->Controller == pLFO3->ExtController) { |
769 |
pLFO3->SendEvent(pCCEvent); |
pLFO3->SendEvent(pCCEvent); |
770 |
} |
} |
771 |
|
if (pDimRgn->AttenuationController.type == ::gig::attenuation_ctrl_t::type_controlchange && |
772 |
|
pCCEvent->Controller == pDimRgn->AttenuationController.controller_number) { // if crossfade event |
773 |
|
pEngine->pSynthesisEvents[Event::destination_vca]->alloc_assign(*pCCEvent); |
774 |
|
} |
775 |
} |
} |
776 |
|
|
777 |
pCCEvent = pEngine->pCCEvents->next(); |
pCCEvent = pEngine->pCCEvents->next(); |
811 |
if (pVCOEventList->last()) this->PitchBend = pitch; |
if (pVCOEventList->last()) this->PitchBend = pitch; |
812 |
} |
} |
813 |
|
|
814 |
|
// process volume / attenuation events (TODO: we only handle and _expect_ crossfade events here ATM !) |
815 |
|
{ |
816 |
|
RTEList<Event>* pVCAEventList = pEngine->pSynthesisEvents[Event::destination_vca]; |
817 |
|
Event* pVCAEvent = pVCAEventList->first(); |
818 |
|
if (Delay) { // skip events that happened before this voice was triggered |
819 |
|
while (pVCAEvent && pVCAEvent->FragmentPos() <= Delay) pVCAEvent = pVCAEventList->next(); |
820 |
|
} |
821 |
|
float crossfadevolume; |
822 |
|
while (pVCAEvent) { |
823 |
|
Event* pNextVCAEvent = pVCAEventList->next(); |
824 |
|
|
825 |
|
// calculate the influence length of this event (in sample points) |
826 |
|
uint end = (pNextVCAEvent) ? pNextVCAEvent->FragmentPos() : Samples; |
827 |
|
|
828 |
|
crossfadevolume = CrossfadeAttenuation(pVCAEvent->Value); |
829 |
|
|
830 |
|
float effective_volume = crossfadevolume * this->Volume * pEngine->GlobalVolume; |
831 |
|
|
832 |
|
// apply volume value to the volume parameter sequence |
833 |
|
for (uint i = pVCAEvent->FragmentPos(); i < end; i++) { |
834 |
|
pEngine->pSynthesisParameters[Event::destination_vca][i] = effective_volume; |
835 |
|
} |
836 |
|
|
837 |
|
pVCAEvent = pNextVCAEvent; |
838 |
|
} |
839 |
|
if (pVCAEventList->last()) this->CrossfadeVolume = crossfadevolume; |
840 |
|
} |
841 |
|
|
842 |
#if ENABLE_FILTER |
#if ENABLE_FILTER |
843 |
// process filter cutoff events |
// process filter cutoff events |
1062 |
} |
} |
1063 |
|
|
1064 |
/** |
/** |
1065 |
* Immediately kill the voice. |
* Immediately kill the voice. This method should not be used to kill |
1066 |
|
* a normal, active voice, because it doesn't take care of things like |
1067 |
|
* fading down the volume level to avoid clicks and regular processing |
1068 |
|
* until the kill event actually occured! |
1069 |
|
* |
1070 |
|
* @see Kill() |
1071 |
*/ |
*/ |
1072 |
void Voice::Kill() { |
void Voice::KillImmediately() { |
1073 |
if (DiskVoice && DiskStreamRef.State != Stream::state_unused) { |
if (DiskVoice && DiskStreamRef.State != Stream::state_unused) { |
1074 |
pDiskThread->OrderDeletionOfStream(&DiskStreamRef); |
pDiskThread->OrderDeletionOfStream(&DiskStreamRef); |
1075 |
} |
} |
1076 |
Reset(); |
Reset(); |
1077 |
} |
} |
1078 |
|
|
1079 |
|
/** |
1080 |
|
* Kill the voice in regular sense. Let the voice render audio until |
1081 |
|
* the kill event actually occured and then fade down the volume level |
1082 |
|
* very quickly and let the voice die finally. Unlike a normal release |
1083 |
|
* of a voice, a kill process cannot be cancalled and is therefore |
1084 |
|
* usually used for voice stealing and key group conflicts. |
1085 |
|
* |
1086 |
|
* @param pKillEvent - event which caused the voice to be killed |
1087 |
|
*/ |
1088 |
|
void Voice::Kill(Event* pKillEvent) { |
1089 |
|
this->pKillEvent = pKillEvent; |
1090 |
|
} |
1091 |
|
|
1092 |
}} // namespace LinuxSampler::gig |
}} // namespace LinuxSampler::gig |