/[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 3625 by schoenebeck, Thu Oct 3 13:37:25 2019 UTC revision 3721 by schoenebeck, Mon Jan 20 15:10:05 2020 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)      // converts ::gig::lfo_wave_t (libgig) -> LFO::wave_t (LinuxSampler)
47      inline LFO::wave_t fromGigLfoWave(::gig::lfo_wave_t wave) {      inline LFO::wave_t fromGigLfoWave(::gig::lfo_wave_t wave) {
48          // simply assuming equally mapped enums on both sides          // simply assuming equally mapped enums on both sides
49          return static_cast<LFO::wave_t>(wave);          return static_cast<LFO::wave_t>(wave);
50      }      }
51    
52        // Returns true for GigaStudio's original filter types (which are resembled
53        // by LS very accurately with same frequency response and patch settings
54        // behaviour), false for our own LS specific filter implementation types.
55        constexpr bool isGStFilterType(::gig::vcf_type_t type) {
56            return type == ::gig::vcf_type_lowpass ||
57                   type == ::gig::vcf_type_lowpassturbo ||
58                   type == ::gig::vcf_type_bandpass ||
59                   type == ::gig::vcf_type_highpass ||
60                   type == ::gig::vcf_type_bandreject;
61        }
62    
63      Voice::Voice() {      Voice::Voice() {
64          pEngine = NULL;          pEngine = NULL;
65          pEG1 = &EG1;          pEG1 = &EG1;
# Line 143  namespace LinuxSampler { namespace gig { Line 164  namespace LinuxSampler { namespace gig {
164          // Not used so far          // Not used so far
165      }      }
166    
167        uint8_t Voice::MinCutoff() const {
168            // If there's a cutoff controller defined then VCFVelocityScale means
169            // "minimum cutoff". If there is no MIDI controller defined for cutoff
170            // then VCFVelocityScale is already taken into account on libgig side
171            // instead by call to pRegion->GetVelocityCutoff(MIDIKeyVelocity).
172            return pRegion->VCFVelocityScale;
173        }
174    
175        // This is called on any cutoff controller changes, however not when the
176        // voice is triggered. So the initial cutoff value is retrieved by a call
177        // to CalculateFinalCutoff() instead.
178      void Voice::ProcessCutoffEvent(RTList<Event>::Iterator& itEvent) {      void Voice::ProcessCutoffEvent(RTList<Event>::Iterator& itEvent) {
179          int ccvalue = itEvent->Param.CC.Value;          if (VCFCutoffCtrl.value == itEvent->Param.CC.Value) return;
180          if (VCFCutoffCtrl.value == ccvalue) return;          float ccvalue = VCFCutoffCtrl.value = itEvent->Param.CC.Value;
181          VCFCutoffCtrl.value = ccvalue;  
182          if (pRegion->VCFCutoffControllerInvert)  ccvalue = 127 - ccvalue;          // if the selected filter type is an official GigaStudio filter type
183          if (ccvalue < pRegion->VCFVelocityScale) ccvalue = pRegion->VCFVelocityScale;          // then we preserve the original (no matter how odd) historical GSt
184          float cutoff = CutoffBase * float(ccvalue);          // behaviour identically; for our own filter types though we deviate to
185            // more meaningful behaviours where appropriate
186            const bool isGStFilter = isGStFilterType(pRegion->VCFType);
187    
188            if (pRegion->VCFCutoffControllerInvert) ccvalue = 127 - ccvalue;
189            // interpret "minimum cutoff" not simply as hard limit, rather
190            // restrain it to min_cutoff..127 range, but spanned / remapped over
191            // the entire controller range (0..127) to avoid a "dead" lower
192            // controller zone (that is to avoid a certain CC value range where
193            // the controller would not change the cutoff frequency)
194            ccvalue = MinCutoff() + (ccvalue / 127.f) * float(127 - MinCutoff());
195    
196            float cutoff = CutoffBase * ccvalue;
197          if (cutoff > 127.0f) cutoff = 127.0f;          if (cutoff > 127.0f) cutoff = 127.0f;
198    
199          VCFCutoffCtrl.fvalue = cutoff; // needed for initialization of fFinalCutoff next time          // the filter implementations of the original GSt filter types take an
200          fFinalCutoff = cutoff;          // abstract cutoff parameter range of 0..127, whereas our own filter
201            // types take a cutoff parameter in Hz, so remap here:
202            // 0 .. 127 [lin] -> 21 Hz .. 18 kHz [x^4] (center @2.2 kHz)
203            if (!isGStFilter) {
204                cutoff = (cutoff + 29.f) / (127.f + 29.f);
205                cutoff = cutoff * cutoff * cutoff * cutoff * 18000.f;
206                if (cutoff > 0.49f * pEngine->SampleRate)
207                    cutoff = 0.49f * pEngine->SampleRate;
208            }
209    
210            fFinalCutoff = VCFCutoffCtrl.fvalue = cutoff;
211      }      }
212    
213      double Voice::CalculateCrossfadeVolume(uint8_t MIDIKeyVelocity) {      double Voice::CalculateCrossfadeVolume(uint8_t MIDIKeyVelocity) {
# Line 419  namespace LinuxSampler { namespace gig { Line 473  namespace LinuxSampler { namespace gig {
473          return cutoff;          return cutoff;
474      }      }
475    
476        // This is just called when the voice is triggered. On any subsequent cutoff
477        // controller changes ProcessCutoffEvent() is called instead.
478      float Voice::CalculateFinalCutoff(float cutoffBase) {      float Voice::CalculateFinalCutoff(float cutoffBase) {
479          int cvalue;          // if the selected filter type is an official GigaStudio filter type
480            // then we preserve the original (no matter how odd) historical GSt
481            // behaviour identically; for our own filter types though we deviate to
482            // more meaningful behaviours where appropriate
483            const bool isGStFilter = isGStFilterType(pRegion->VCFType);
484    
485            // get current cutoff CC or velocity value (always 0..127)
486            float cvalue;
487          if (VCFCutoffCtrl.controller) {          if (VCFCutoffCtrl.controller) {
488              cvalue = GetGigEngineChannel()->ControllerTable[VCFCutoffCtrl.controller];              cvalue = GetGigEngineChannel()->ControllerTable[VCFCutoffCtrl.controller];
489              if (pRegion->VCFCutoffControllerInvert) cvalue = 127 - cvalue;              if (pRegion->VCFCutoffControllerInvert) cvalue = 127 - cvalue;
490              // VCFVelocityScale in this case means Minimum cutoff              if (isGStFilter) {
491              if (cvalue < pRegion->VCFVelocityScale) cvalue = pRegion->VCFVelocityScale;                  // VCFVelocityScale in this case means "minimum cutoff" for GSt
492          }                  if (cvalue < MinCutoff()) cvalue = MinCutoff();
493          else {              } else {
494                    // for our own filter types we interpret "minimum cutoff"
495                    // differently: GSt handles this as a simple hard limit with the
496                    // consequence that a certain range of the controller is simply
497                    // dead; so for our filter types we rather remap that to
498                    // restrain within the min_cutoff..127 range as well, but
499                    // effectively spanned over the entire controller range (0..127)
500                    // to avoid such a "dead" lower controller zone
501                    cvalue = MinCutoff() + (cvalue / 127.f) * float(127 - MinCutoff());
502                }
503            } else {
504                // in case of velocity, VCFVelocityScale parameter is already
505                // handled on libgig side (so by calling
506                // pRegion->GetVelocityCutoff(velo) in CalculateCutoffBase() above)
507              cvalue = pRegion->VCFCutoff;              cvalue = pRegion->VCFCutoff;
508          }          }
509          float fco = cutoffBase * float(cvalue);  
510            float fco = cutoffBase * cvalue;
511          if (fco > 127.0f) fco = 127.0f;          if (fco > 127.0f) fco = 127.0f;
512    
513            // the filter implementations of the original GSt filter types take an
514            // abstract cutoff parameter range of 0..127, ...
515            if (isGStFilter)
516                return fco;
517    
518            // ... whereas our own filter types take a cutoff parameter in Hz, so
519            // remap here 0 .. 127 [lin] -> 21 Hz .. 18 kHz [x^4] (center @2.2 kHz)
520            fco = (fco + 29.f) / (127.f + 29.f);
521            fco = fco * fco * fco * fco * 18000.f;
522            if (fco > 0.49f * pEngine->SampleRate)
523                fco = 0.49f * pEngine->SampleRate;
524          return fco;          return fco;
525      }      }
526    

Legend:
Removed from v.3625  
changed lines
  Added in v.3721

  ViewVC Help
Powered by ViewVC