/[svn]/linuxsampler/trunk/src/engines/gig/Voice.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/gig/Voice.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3444 by schoenebeck, Sun Dec 23 19:32:11 2018 UTC revision 3652 by schoenebeck, Wed Dec 11 11:10:24 2019 UTC
# Line 33  Line 33 
33    
34  namespace LinuxSampler { namespace gig {  namespace LinuxSampler { namespace gig {
35    
36        // sanity checks: fromGigLfoWave() assumes equally mapped enums
37        static_assert(int64_t(::gig::lfo_wave_sine) == int64_t(LFO::wave_sine),
38                      "enum LFO::wave_t not equally value mapped to libgig's enum ::gig::lfo_wave_t");
39        static_assert(int64_t(::gig::lfo_wave_triangle) == int64_t(LFO::wave_triangle),
40                      "enum LFO::wave_t not equally value mapped to libgig's enum ::gig::lfo_wave_t");
41        static_assert(int64_t(::gig::lfo_wave_saw) == int64_t(LFO::wave_saw),
42                      "enum LFO::wave_t not equally value mapped to libgig's enum ::gig::lfo_wave_t");
43        static_assert(int64_t(::gig::lfo_wave_square) == int64_t(LFO::wave_square),
44                      "enum LFO::wave_t not equally value mapped to libgig's enum ::gig::lfo_wave_t");
45    
46        // converts ::gig::lfo_wave_t (libgig) -> LFO::wave_t (LinuxSampler)
47        inline LFO::wave_t fromGigLfoWave(::gig::lfo_wave_t wave) {
48            // simply assuming equally mapped enums on both sides
49            return static_cast<LFO::wave_t>(wave);
50        }
51    
52      Voice::Voice() {      Voice::Voice() {
53          pEngine = NULL;          pEngine = NULL;
54          pEG1 = &EG1;          pEG1 = &EG1;
# Line 273  namespace LinuxSampler { namespace gig { Line 289  namespace LinuxSampler { namespace gig {
289                  bLFO1Enabled         = false;                  bLFO1Enabled         = false;
290          }          }
291          if (bLFO1Enabled) {          if (bLFO1Enabled) {
292              pLFO1->trigger(pRegion->LFO1Frequency,              pLFO1->trigger(fromGigLfoWave(pRegion->LFO1WaveForm),
293                             start_level_min,                             pRegion->LFO1Frequency,
294                               pRegion->LFO1Phase,
295                               LFO::start_level_mid, // see https://sourceforge.net/p/linuxsampler/mailman/linuxsampler-devel/thread/2189307.cNP0Xbctxq%40silver/#msg36774029
296                             lfo1_internal_depth,                             lfo1_internal_depth,
297                             pRegion->LFO1ControlDepth,                             pRegion->LFO1ControlDepth,
298                             pRegion->LFO1FlipPhase,                             pRegion->LFO1FlipPhase,
299                             pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);                             pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
300              pLFO1->updateByMIDICtrlValue(pLFO1->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO1->ExtController] : 0);              pLFO1->updateByMIDICtrlValue(pLFO1->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO1->ExtController] : 0);
301              pLFO1->setScriptDepthFactor(pNote->Override.AmpLFODepth);              pLFO1->setScriptDepthFactor(
302              pLFO1->setScriptFrequencyFactor(pNote->Override.AmpLFOFreq, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);                  pNote->Override.AmpLFODepth.Value,
303                    pNote->Override.AmpLFODepth.Final
304                );
305                if (pNote->Override.AmpLFOFreq.isFinal())
306                    pLFO1->setScriptFrequencyFinal(
307                        pNote->Override.AmpLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE
308                    );
309                else
310                    pLFO1->setScriptFrequencyFactor(
311                        pNote->Override.AmpLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE
312                    );
313          }          }
314      }      }
315    
# Line 319  namespace LinuxSampler { namespace gig { Line 347  namespace LinuxSampler { namespace gig {
347                  bLFO2Enabled         = false;                  bLFO2Enabled         = false;
348          }          }
349          if (bLFO2Enabled) {          if (bLFO2Enabled) {
350              pLFO2->trigger(pRegion->LFO2Frequency,              pLFO2->trigger(fromGigLfoWave(pRegion->LFO2WaveForm),
351                             start_level_max,                             pRegion->LFO2Frequency,
352                               pRegion->LFO2Phase,
353                               LFO::start_level_mid, // see https://sourceforge.net/p/linuxsampler/mailman/linuxsampler-devel/thread/2189307.cNP0Xbctxq%40silver/#msg36774029
354                             lfo2_internal_depth,                             lfo2_internal_depth,
355                             pRegion->LFO2ControlDepth,                             pRegion->LFO2ControlDepth,
356                             pRegion->LFO2FlipPhase,                             pRegion->LFO2FlipPhase,
357                             pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);                             pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
358              pLFO2->updateByMIDICtrlValue(pLFO2->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO2->ExtController] : 0);              pLFO2->updateByMIDICtrlValue(pLFO2->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO2->ExtController] : 0);
359              pLFO2->setScriptDepthFactor(pNote->Override.CutoffLFODepth);              pLFO2->setScriptDepthFactor(
360              pLFO2->setScriptFrequencyFactor(pNote->Override.CutoffLFOFreq, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);                  pNote->Override.CutoffLFODepth.Value,
361                    pNote->Override.CutoffLFODepth.Final
362                );
363                if (pNote->Override.CutoffLFOFreq.isFinal())
364                    pLFO2->setScriptFrequencyFinal(pNote->Override.CutoffLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
365                else
366                    pLFO2->setScriptFrequencyFactor(pNote->Override.CutoffLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
367          }          }
368      }      }
369    
# Line 365  namespace LinuxSampler { namespace gig { Line 401  namespace LinuxSampler { namespace gig {
401                  bLFO3Enabled         = false;                  bLFO3Enabled         = false;
402          }          }
403          if (bLFO3Enabled) {          if (bLFO3Enabled) {
404              pLFO3->trigger(pRegion->LFO3Frequency,              pLFO3->trigger(fromGigLfoWave(pRegion->LFO3WaveForm),
405                             start_level_mid,                             pRegion->LFO3Frequency,
406                               pRegion->LFO3Phase,
407                               LFO::start_level_max, // see https://sourceforge.net/p/linuxsampler/mailman/linuxsampler-devel/thread/2189307.cNP0Xbctxq%40silver/#msg36774029
408                             lfo3_internal_depth,                             lfo3_internal_depth,
409                             pRegion->LFO3ControlDepth,                             pRegion->LFO3ControlDepth,
410                             false,                             pRegion->LFO3FlipPhase,
411                             pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);                             pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
412              pLFO3->updateByMIDICtrlValue(pLFO3->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO3->ExtController] : 0);              pLFO3->updateByMIDICtrlValue(pLFO3->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO3->ExtController] : 0);
413              pLFO3->setScriptDepthFactor(pNote->Override.PitchLFODepth);              pLFO3->setScriptDepthFactor(
414              pLFO3->setScriptFrequencyFactor(pNote->Override.PitchLFOFreq, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);                  pNote->Override.PitchLFODepth.Value,
415                    pNote->Override.PitchLFODepth.Final
416                );
417                if (pNote->Override.PitchLFOFreq.isFinal())
418                    pLFO3->setScriptFrequencyFinal(pNote->Override.PitchLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
419                else
420                    pLFO3->setScriptFrequencyFactor(pNote->Override.PitchLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
421          }          }
422      }      }
423    
# Line 385  namespace LinuxSampler { namespace gig { Line 429  namespace LinuxSampler { namespace gig {
429          return cutoff;          return cutoff;
430      }      }
431    
432        /// Returns true for GigaStudio's original filter types.
433        constexpr bool isGStFilterType(::gig::vcf_type_t type) {
434            return type == ::gig::vcf_type_lowpass ||
435                   type == ::gig::vcf_type_lowpassturbo ||
436                   type == ::gig::vcf_type_bandpass ||
437                   type == ::gig::vcf_type_highpass ||
438                   type == ::gig::vcf_type_bandreject;
439        }
440    
441      float Voice::CalculateFinalCutoff(float cutoffBase) {      float Voice::CalculateFinalCutoff(float cutoffBase) {
442          int cvalue;          int cvalue;
443          if (VCFCutoffCtrl.controller) {          if (VCFCutoffCtrl.controller) {
# Line 399  namespace LinuxSampler { namespace gig { Line 452  namespace LinuxSampler { namespace gig {
452          float fco = cutoffBase * float(cvalue);          float fco = cutoffBase * float(cvalue);
453          if (fco > 127.0f) fco = 127.0f;          if (fco > 127.0f) fco = 127.0f;
454    
455            // the filter implementations of the original GSt filter types take an
456            // abstract cutoff parameter range of 0..127, ...
457            if (isGStFilterType(pRegion->VCFType))
458                return fco;
459    
460            // ... whereas our own filter types take a cutoff parameter in Hz, so
461            // remap here 0 .. 127 [lin] -> 21 Hz .. 18 kHz [x^4] (center @2.2 kHz)
462            fco = (fco + 29.f) / (127.f + 29.f);
463            fco = fco * fco * fco * fco * 18000.f;
464            if (fco > 0.49f * pEngine->SampleRate)
465                fco = 0.49f * pEngine->SampleRate;
466          return fco;          return fco;
467      }      }
468    
# Line 476  namespace LinuxSampler { namespace gig { Line 540  namespace LinuxSampler { namespace gig {
540              pRegion->EG1Options.ReleaseCancel              pRegion->EG1Options.ReleaseCancel
541          );          );
542          EG1.trigger(pRegion->EG1PreAttack,          EG1.trigger(pRegion->EG1PreAttack,
543                      RTMath::Max(pRegion->EG1Attack, 0.0316) * egInfo.Attack,                      (pNote && pNote->Override.Attack.isFinal()) ?
544                            pNote->Override.Attack.Value :
545                            RTMath::Max(pRegion->EG1Attack, 0.0316) * egInfo.Attack,
546                      pRegion->EG1Hold,                      pRegion->EG1Hold,
547                      pRegion->EG1Decay1 * egInfo.Decay * velrelease,                      (pNote && pNote->Override.Decay.isFinal()) ?
548                      pRegion->EG1Decay2 * egInfo.Decay * velrelease,                          pNote->Override.Decay.Value :
549                            pRegion->EG1Decay1 * egInfo.Decay * velrelease,
550                        (pNote && pNote->Override.Decay.isFinal()) ?
551                            pNote->Override.Decay.Value :
552                            pRegion->EG1Decay2 * egInfo.Decay * velrelease,
553                      pRegion->EG1InfiniteSustain,                      pRegion->EG1InfiniteSustain,
554                      pRegion->EG1Sustain * (pNote ? pNote->Override.Sustain : 1.f),                      (pNote && pNote->Override.Sustain.Final) ?
555                      RTMath::Max(pRegion->EG1Release * velrelease, 0.014) * egInfo.Release,                          uint(pNote->Override.Sustain.Value * 1000.f) :
556                            pRegion->EG1Sustain * (pNote ? pNote->Override.Sustain.Value : 1.f),
557                        (pNote && pNote->Override.Release.isFinal()) ?
558                            pNote->Override.Release.Value :
559                            RTMath::Max(pRegion->EG1Release * velrelease, 0.014) * egInfo.Release,
560                      velocityAttenuation,                      velocityAttenuation,
561                      sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);                      sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
562      }      }
# Line 496  namespace LinuxSampler { namespace gig { Line 570  namespace LinuxSampler { namespace gig {
570              pRegion->EG2Options.ReleaseCancel              pRegion->EG2Options.ReleaseCancel
571          );          );
572          EG2.trigger(uint(RgnInfo.EG2PreAttack),          EG2.trigger(uint(RgnInfo.EG2PreAttack),
573                      RgnInfo.EG2Attack * egInfo.Attack,                      (pNote && pNote->Override.CutoffAttack.isFinal()) ?
574                            pNote->Override.CutoffAttack.Value :
575                            RgnInfo.EG2Attack * egInfo.Attack,
576                      false,                      false,
577                      RgnInfo.EG2Decay1 * egInfo.Decay * velrelease,                      (pNote && pNote->Override.CutoffDecay.isFinal()) ?
578                      RgnInfo.EG2Decay2 * egInfo.Decay * velrelease,                          pNote->Override.CutoffDecay.Value :
579                            RgnInfo.EG2Decay1 * egInfo.Decay * velrelease,
580                        (pNote && pNote->Override.CutoffDecay.isFinal()) ?
581                            pNote->Override.CutoffDecay.Value :
582                            RgnInfo.EG2Decay2 * egInfo.Decay * velrelease,
583                      RgnInfo.EG2InfiniteSustain,                      RgnInfo.EG2InfiniteSustain,
584                      uint(RgnInfo.EG2Sustain),                      (pNote && pNote->Override.CutoffSustain.Final) ?
585                      RgnInfo.EG2Release * egInfo.Release * velrelease,                          uint(pNote->Override.CutoffSustain.Value * 1000.f) :
586                            uint(RgnInfo.EG2Sustain),
587                        (pNote && pNote->Override.CutoffRelease.isFinal()) ?
588                            pNote->Override.CutoffRelease.Value :
589                            RgnInfo.EG2Release * egInfo.Release * velrelease,
590                      velocityAttenuation,                      velocityAttenuation,
591                      sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);                      sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
592      }      }
# Line 545  namespace LinuxSampler { namespace gig { Line 629  namespace LinuxSampler { namespace gig {
629      }      }
630    
631      release_trigger_t Voice::GetReleaseTriggerFlags() {      release_trigger_t Voice::GetReleaseTriggerFlags() {
632          release_trigger_t flags = release_trigger_noteoff; //HACK: currently this method is actually only called by EngineBase if it already knows that this voice requires release trigger, so I took the short way instead of checking (again) the existence of a ::gig::dimension_releasetrigger          release_trigger_t flags =
633                (pRegion->NoNoteOffReleaseTrigger) ?
634                    release_trigger_none : release_trigger_noteoff; //HACK: currently this method is actually only called by EngineBase if it already knows that this voice requires release trigger, so I took the short way instead of checking (again) the existence of a ::gig::dimension_releasetrigger
635          switch (pRegion->SustainReleaseTrigger) {          switch (pRegion->SustainReleaseTrigger) {
636              case ::gig::sust_rel_trg_none:              case ::gig::sust_rel_trg_none:
637                  break;                  break;

Legend:
Removed from v.3444  
changed lines
  Added in v.3652

  ViewVC Help
Powered by ViewVC