146 |
float subfragmentRate = GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE; |
float subfragmentRate = GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE; |
147 |
CrossfadeSmoother.trigger(crossfadeVolume, subfragmentRate); |
CrossfadeSmoother.trigger(crossfadeVolume, subfragmentRate); |
148 |
VolumeSmoother.trigger(pEngineChannel->MidiVolume, subfragmentRate); |
VolumeSmoother.trigger(pEngineChannel->MidiVolume, subfragmentRate); |
149 |
|
NoteVolumeSmoother.trigger(pNote ? pNote->Override.Volume : 1.f, subfragmentRate); |
150 |
|
|
151 |
// 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 |
152 |
long cachedsamples = GetSampleCacheSize() / SmplInfo.FrameSize; |
long cachedsamples = GetSampleCacheSize() / SmplInfo.FrameSize; |
186 |
} |
} |
187 |
|
|
188 |
Pitch = CalculatePitchInfo(PitchBend); |
Pitch = CalculatePitchInfo(PitchBend); |
189 |
|
NotePitch = (pNote) ? pNote->Override.Pitch : 1.0f; |
190 |
|
NoteCutoff = (pNote) ? pNote->Override.Cutoff : 1.0f; |
191 |
|
NoteResonance = (pNote) ? pNote->Override.Resonance : 1.0f; |
192 |
|
|
193 |
// the length of the decay and release curves are dependent on the velocity |
// the length of the decay and release curves are dependent on the velocity |
194 |
const double velrelease = 1 / GetVelocityRelease(itNoteOnEvent->Param.Note.Velocity); |
const double velrelease = 1 / GetVelocityRelease(itNoteOnEvent->Param.Note.Velocity); |
205 |
pSignalUnitRack->Trigger(); |
pSignalUnitRack->Trigger(); |
206 |
} |
} |
207 |
|
|
208 |
uint8_t pan = MIDIPan; |
const uint8_t pan = (pSignalUnitRack) ? pSignalUnitRack->GetEndpointUnit()->CalculatePan(MIDIPan) : MIDIPan; |
209 |
if (pSignalUnitRack) pan = pSignalUnitRack->GetEndpointUnit()->CalculatePan(MIDIPan); |
NotePanLeft = (pNote) ? AbstractEngine::PanCurveValueNorm(pNote->Override.Pan, 0 /*left*/ ) : 1.f; |
210 |
PanLeftSmoother.trigger(AbstractEngine::PanCurve[128 - pan], subfragmentRate); |
NotePanRight = (pNote) ? AbstractEngine::PanCurveValueNorm(pNote->Override.Pan, 1 /*right*/) : 1.f; |
211 |
PanRightSmoother.trigger(AbstractEngine::PanCurve[pan], subfragmentRate); |
PanLeftSmoother.trigger( |
212 |
|
AbstractEngine::PanCurve[128 - pan] * NotePanLeft, |
213 |
|
subfragmentRate |
214 |
|
); |
215 |
|
PanRightSmoother.trigger( |
216 |
|
AbstractEngine::PanCurve[pan] * NotePanRight, |
217 |
|
subfragmentRate |
218 |
|
); |
219 |
|
|
220 |
#ifdef CONFIG_INTERPOLATE_VOLUME |
#ifdef CONFIG_INTERPOLATE_VOLUME |
221 |
// setup initial volume in synthesis parameters |
// setup initial volume in synthesis parameters |
441 |
processCCEvents(itCCEvent, iSubFragmentEnd); |
processCCEvents(itCCEvent, iSubFragmentEnd); |
442 |
uint8_t pan = MIDIPan; |
uint8_t pan = MIDIPan; |
443 |
if (pSignalUnitRack != NULL) pan = pSignalUnitRack->GetEndpointUnit()->CalculatePan(MIDIPan); |
if (pSignalUnitRack != NULL) pan = pSignalUnitRack->GetEndpointUnit()->CalculatePan(MIDIPan); |
|
|
|
|
PanLeftSmoother.update(AbstractEngine::PanCurve[128 - pan]); |
|
|
PanRightSmoother.update(AbstractEngine::PanCurve[pan]); |
|
444 |
|
|
445 |
finalSynthesisParameters.fFinalPitch = Pitch.PitchBase * Pitch.PitchBend; |
PanLeftSmoother.update(AbstractEngine::PanCurve[128 - pan] * NotePanLeft); |
446 |
float fFinalVolume = VolumeSmoother.render() * CrossfadeSmoother.render(); |
PanRightSmoother.update(AbstractEngine::PanCurve[pan] * NotePanRight); |
447 |
|
|
448 |
|
finalSynthesisParameters.fFinalPitch = Pitch.PitchBase * Pitch.PitchBend * NotePitch; |
449 |
|
|
450 |
|
float fFinalVolume = VolumeSmoother.render() * CrossfadeSmoother.render() * NoteVolumeSmoother.render(); |
451 |
#ifdef CONFIG_PROCESS_MUTED_CHANNELS |
#ifdef CONFIG_PROCESS_MUTED_CHANNELS |
452 |
if (pChannel->GetMute()) fFinalVolume = 0; |
if (pChannel->GetMute()) fFinalVolume = 0; |
453 |
#endif |
#endif |
524 |
pSignalUnitRack->GetEndpointUnit()->CalculatePitch(finalSynthesisParameters.fFinalPitch); |
pSignalUnitRack->GetEndpointUnit()->CalculatePitch(finalSynthesisParameters.fFinalPitch); |
525 |
|
|
526 |
} |
} |
527 |
|
|
528 |
|
fFinalCutoff *= NoteCutoff; |
529 |
|
fFinalResonance *= NoteResonance; |
530 |
|
|
531 |
// limit the pitch so we don't read outside the buffer |
// limit the pitch so we don't read outside the buffer |
532 |
finalSynthesisParameters.fFinalPitch = RTMath::Min(finalSynthesisParameters.fFinalPitch, float(1 << CONFIG_MAX_PITCH)); |
finalSynthesisParameters.fFinalPitch = RTMath::Min(finalSynthesisParameters.fFinalPitch, float(1 << CONFIG_MAX_PITCH)); |
533 |
|
|
686 |
} |
} |
687 |
|
|
688 |
/** |
/** |
689 |
* Process given list of MIDI note on, note off and sustain pedal events |
* Process given list of MIDI note on, note off, sustain pedal events and |
690 |
* for the given time. |
* note synthesis parameter events for the given time. |
691 |
* |
* |
692 |
* @param itEvent - iterator pointing to the next event to be processed |
* @param itEvent - iterator pointing to the next event to be processed |
693 |
* @param End - youngest time stamp where processing should be stopped |
* @param End - youngest time stamp where processing should be stopped |
696 |
for (; itEvent && itEvent->FragmentPos() <= End; ++itEvent) { |
for (; itEvent && itEvent->FragmentPos() <= End; ++itEvent) { |
697 |
// some voice types ignore note off |
// some voice types ignore note off |
698 |
if (!(Type & (Voice::type_one_shot | Voice::type_release_trigger | Voice::type_controller_triggered))) { |
if (!(Type & (Voice::type_one_shot | Voice::type_release_trigger | Voice::type_controller_triggered))) { |
699 |
if (itEvent->Type == Event::type_release) { |
if (itEvent->Type == Event::type_release_key) { |
700 |
EnterReleaseStage(); |
EnterReleaseStage(); |
701 |
} else if (itEvent->Type == Event::type_cancel_release) { |
} else if (itEvent->Type == Event::type_cancel_release_key) { |
702 |
if (pSignalUnitRack == NULL) { |
if (pSignalUnitRack == NULL) { |
703 |
pEG1->update(EG::event_cancel_release, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
pEG1->update(EG::event_cancel_release, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
704 |
pEG2->update(EG::event_cancel_release, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
pEG2->update(EG::event_cancel_release, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
707 |
} |
} |
708 |
} |
} |
709 |
} |
} |
710 |
|
// process stop-note events (caused by built-in instrument script function note_off()) |
711 |
|
if (itEvent->Type == Event::type_release_note && pNote && |
712 |
|
pEngineChannel->pEngine->NoteByID( itEvent->Param.Note.ID ) == pNote) |
713 |
|
{ |
714 |
|
EnterReleaseStage(); |
715 |
|
} |
716 |
|
// process synthesis parameter events (caused by built-in realt-time instrument script functions) |
717 |
|
if (itEvent->Type == Event::type_note_synth_param && pNote && |
718 |
|
pEngineChannel->pEngine->NoteByID( itEvent->Param.NoteSynthParam.NoteID ) == pNote) |
719 |
|
{ |
720 |
|
switch (itEvent->Param.NoteSynthParam.Type) { |
721 |
|
case Event::synth_param_volume: |
722 |
|
NoteVolumeSmoother.update(itEvent->Param.NoteSynthParam.AbsValue); |
723 |
|
break; |
724 |
|
case Event::synth_param_pitch: |
725 |
|
NotePitch = itEvent->Param.NoteSynthParam.AbsValue; |
726 |
|
break; |
727 |
|
case Event::synth_param_pan: |
728 |
|
NotePanLeft = AbstractEngine::PanCurveValueNorm(itEvent->Param.NoteSynthParam.AbsValue, 0 /*left*/); |
729 |
|
NotePanRight = AbstractEngine::PanCurveValueNorm(itEvent->Param.NoteSynthParam.AbsValue, 1 /*right*/); |
730 |
|
break; |
731 |
|
case Event::synth_param_cutoff: |
732 |
|
NoteCutoff = itEvent->Param.NoteSynthParam.AbsValue; |
733 |
|
break; |
734 |
|
case Event::synth_param_resonance: |
735 |
|
NoteResonance = itEvent->Param.NoteSynthParam.AbsValue; |
736 |
|
break; |
737 |
|
} |
738 |
|
} |
739 |
} |
} |
740 |
} |
} |
741 |
|
|