27 |
#include "Engine.h" |
#include "Engine.h" |
28 |
#include "EngineChannel.h" |
#include "EngineChannel.h" |
29 |
|
|
30 |
|
#define LN_10_DIV_20 0.115129254649702 |
31 |
|
|
32 |
namespace LinuxSampler { namespace sfz { |
namespace LinuxSampler { namespace sfz { |
33 |
|
|
34 |
Voice::Voice() { |
Voice::Voice() { |
69 |
Voice::RegionInfo Voice::GetRegionInfo() { |
Voice::RegionInfo Voice::GetRegionInfo() { |
70 |
RegionInfo ri; |
RegionInfo ri; |
71 |
ri.UnityNote = pRegion->pitch_keycenter; |
ri.UnityNote = pRegion->pitch_keycenter; |
72 |
ri.FineTune = pRegion->tune; |
ri.FineTune = pRegion->tune + pRegion->transpose * 100; |
73 |
ri.Pan = int(pRegion->pan * 0.63); // convert from -100..100 to -64..63 |
ri.Pan = int(pRegion->pan * 0.63); // convert from -100..100 to -64..63 |
74 |
ri.SampleStartOffset = 0; // TODO: |
ri.SampleStartOffset = 0; // TODO: |
75 |
|
|
99 |
|
|
100 |
// rt_decay is in dB. Precalculate a suitable value for exp in |
// rt_decay is in dB. Precalculate a suitable value for exp in |
101 |
// GetReleaseTriggerAttenuation: -ln(10) / 20 * rt_decay |
// GetReleaseTriggerAttenuation: -ln(10) / 20 * rt_decay |
102 |
ri.ReleaseTriggerDecay = -0.115129254649702 * pRegion->rt_decay; |
ri.ReleaseTriggerDecay = -LN_10_DIV_20 * pRegion->rt_decay; |
103 |
|
|
104 |
return ri; |
return ri; |
105 |
} |
} |
113 |
} |
} |
114 |
|
|
115 |
double Voice::GetSampleAttenuation() { |
double Voice::GetSampleAttenuation() { |
116 |
return 1.0; // TODO: |
return exp(LN_10_DIV_20 * pRegion->volume); |
117 |
} |
} |
118 |
|
|
119 |
double Voice::GetVelocityAttenuation(uint8_t MIDIKeyVelocity) { |
double Voice::GetVelocityAttenuation(uint8_t MIDIKeyVelocity) { |
120 |
return double(MIDIKeyVelocity) / 127.0f; // TODO: |
return pRegion->amp_velcurve[MIDIKeyVelocity]; |
121 |
} |
} |
122 |
|
|
123 |
double Voice::GetVelocityRelease(uint8_t MIDIKeyVelocity) { |
double Voice::GetVelocityRelease(uint8_t MIDIKeyVelocity) { |
501 |
return expf(RgnInfo.ReleaseTriggerDecay * noteLength); |
return expf(RgnInfo.ReleaseTriggerDecay * noteLength); |
502 |
} |
} |
503 |
|
|
504 |
|
void Voice::ProcessGroupEvent(RTList<Event>::Iterator& itEvent) { |
505 |
|
dmsg(4,("Voice %x processGroupEvents event type=%d", this, itEvent->Type)); |
506 |
|
if (itEvent->Type == Event::type_control_change || |
507 |
|
(Type & Voice::type_controller_triggered) || |
508 |
|
itEvent->Param.Note.Key != MIDIKey) { |
509 |
|
dmsg(4,("Voice %x - kill", this)); |
510 |
|
if (pRegion->off_mode == ::sfz::OFF_NORMAL) { |
511 |
|
// turn off the voice by entering release envelope stage |
512 |
|
EnterReleaseStage(); |
513 |
|
} else { |
514 |
|
// kill the voice fast |
515 |
|
pEG1->enterFadeOutStage(); |
516 |
|
} |
517 |
|
} |
518 |
|
} |
519 |
|
|
520 |
}} // namespace LinuxSampler::sfz |
}} // namespace LinuxSampler::sfz |