/[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 3017 by schoenebeck, Wed Oct 19 12:28:40 2016 UTC revision 3625 by schoenebeck, Thu Oct 3 13:37:25 2019 UTC
# Line 4  Line 4 
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *   Copyright (C) 2005 - 2008 Christian Schoenebeck                       *   *   Copyright (C) 2005 - 2008 Christian Schoenebeck                       *
7   *   Copyright (C) 2009 - 2015 Christian Schoenebeck and Grigor Iliev      *   *   Copyright (C) 2009 Christian Schoenebeck and Grigor Iliev             *
8     *   Copyright (C) 2010 - 2017 Christian Schoenebeck and Andreas Persson   *
9   *                                                                         *   *                                                                         *
10   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
11   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 32  Line 33 
33    
34  namespace LinuxSampler { namespace gig {  namespace LinuxSampler { namespace gig {
35    
36        // converts ::gig::lfo_wave_t (libgig) -> LFO::wave_t (LinuxSampler)
37        inline LFO::wave_t fromGigLfoWave(::gig::lfo_wave_t wave) {
38            // simply assuming equally mapped enums on both sides
39            return static_cast<LFO::wave_t>(wave);
40        }
41    
42      Voice::Voice() {      Voice::Voice() {
43          pEngine = NULL;          pEngine = NULL;
44          pEG1 = &EG1;          pEG1 = &EG1;
# Line 58  namespace LinuxSampler { namespace gig { Line 65  namespace LinuxSampler { namespace gig {
65          si.ChannelCount     = pSample->Channels;          si.ChannelCount     = pSample->Channels;
66          si.FrameSize        = pSample->FrameSize;          si.FrameSize        = pSample->FrameSize;
67          si.BitDepth         = pSample->BitDepth;          si.BitDepth         = pSample->BitDepth;
68          si.TotalFrameCount  = pSample->SamplesTotal;          si.TotalFrameCount  = (uint)pSample->SamplesTotal;
69    
70          si.HasLoops       = pRegion->SampleLoops;          si.HasLoops       = pRegion->SampleLoops;
71          si.LoopStart      = (si.HasLoops) ? pRegion->pSampleLoops[0].LoopStart  : 0;          si.LoopStart      = (si.HasLoops) ? pRegion->pSampleLoops[0].LoopStart  : 0;
# Line 272  namespace LinuxSampler { namespace gig { Line 279  namespace LinuxSampler { namespace gig {
279                  bLFO1Enabled         = false;                  bLFO1Enabled         = false;
280          }          }
281          if (bLFO1Enabled) {          if (bLFO1Enabled) {
282              pLFO1->trigger(pRegion->LFO1Frequency,              pLFO1->trigger(fromGigLfoWave(pRegion->LFO1WaveForm),
283                             start_level_min,                             pRegion->LFO1Frequency,
284                               pRegion->LFO1Phase,
285                               LFO::start_level_mid, // see https://sourceforge.net/p/linuxsampler/mailman/linuxsampler-devel/thread/2189307.cNP0Xbctxq%40silver/#msg36774029
286                             lfo1_internal_depth,                             lfo1_internal_depth,
287                             pRegion->LFO1ControlDepth,                             pRegion->LFO1ControlDepth,
288                             pRegion->LFO1FlipPhase,                             pRegion->LFO1FlipPhase,
289                             pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);                             pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
290              pLFO1->update(pLFO1->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO1->ExtController] : 0);              pLFO1->updateByMIDICtrlValue(pLFO1->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO1->ExtController] : 0);
291                pLFO1->setScriptDepthFactor(
292                    pNote->Override.AmpLFODepth.Value,
293                    pNote->Override.AmpLFODepth.Final
294                );
295                if (pNote->Override.AmpLFOFreq.isFinal())
296                    pLFO1->setScriptFrequencyFinal(
297                        pNote->Override.AmpLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE
298                    );
299                else
300                    pLFO1->setScriptFrequencyFactor(
301                        pNote->Override.AmpLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE
302                    );
303          }          }
304      }      }
305    
# Line 316  namespace LinuxSampler { namespace gig { Line 337  namespace LinuxSampler { namespace gig {
337                  bLFO2Enabled         = false;                  bLFO2Enabled         = false;
338          }          }
339          if (bLFO2Enabled) {          if (bLFO2Enabled) {
340              pLFO2->trigger(pRegion->LFO2Frequency,              pLFO2->trigger(fromGigLfoWave(pRegion->LFO2WaveForm),
341                             start_level_max,                             pRegion->LFO2Frequency,
342                               pRegion->LFO2Phase,
343                               LFO::start_level_mid, // see https://sourceforge.net/p/linuxsampler/mailman/linuxsampler-devel/thread/2189307.cNP0Xbctxq%40silver/#msg36774029
344                             lfo2_internal_depth,                             lfo2_internal_depth,
345                             pRegion->LFO2ControlDepth,                             pRegion->LFO2ControlDepth,
346                             pRegion->LFO2FlipPhase,                             pRegion->LFO2FlipPhase,
347                             pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);                             pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
348              pLFO2->update(pLFO2->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO2->ExtController] : 0);              pLFO2->updateByMIDICtrlValue(pLFO2->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO2->ExtController] : 0);
349                pLFO2->setScriptDepthFactor(
350                    pNote->Override.CutoffLFODepth.Value,
351                    pNote->Override.CutoffLFODepth.Final
352                );
353                if (pNote->Override.CutoffLFOFreq.isFinal())
354                    pLFO2->setScriptFrequencyFinal(pNote->Override.CutoffLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
355                else
356                    pLFO2->setScriptFrequencyFactor(pNote->Override.CutoffLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
357          }          }
358      }      }
359    
# Line 360  namespace LinuxSampler { namespace gig { Line 391  namespace LinuxSampler { namespace gig {
391                  bLFO3Enabled         = false;                  bLFO3Enabled         = false;
392          }          }
393          if (bLFO3Enabled) {          if (bLFO3Enabled) {
394              pLFO3->trigger(pRegion->LFO3Frequency,              pLFO3->trigger(fromGigLfoWave(pRegion->LFO3WaveForm),
395                             start_level_mid,                             pRegion->LFO3Frequency,
396                               pRegion->LFO3Phase,
397                               LFO::start_level_max, // see https://sourceforge.net/p/linuxsampler/mailman/linuxsampler-devel/thread/2189307.cNP0Xbctxq%40silver/#msg36774029
398                             lfo3_internal_depth,                             lfo3_internal_depth,
399                             pRegion->LFO3ControlDepth,                             pRegion->LFO3ControlDepth,
400                             false,                             pRegion->LFO3FlipPhase,
401                             pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);                             pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
402              pLFO3->update(pLFO3->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO3->ExtController] : 0);              pLFO3->updateByMIDICtrlValue(pLFO3->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO3->ExtController] : 0);
403                pLFO3->setScriptDepthFactor(
404                    pNote->Override.PitchLFODepth.Value,
405                    pNote->Override.PitchLFODepth.Final
406                );
407                if (pNote->Override.PitchLFOFreq.isFinal())
408                    pLFO3->setScriptFrequencyFinal(pNote->Override.PitchLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
409                else
410                    pLFO3->setScriptFrequencyFactor(pNote->Override.PitchLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
411          }          }
412      }      }
413    
# Line 461  namespace LinuxSampler { namespace gig { Line 502  namespace LinuxSampler { namespace gig {
502      }      }
503    
504      void Voice::TriggerEG1(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) {      void Voice::TriggerEG1(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) {
505            EG1.setStateOptions(
506                pRegion->EG1Options.AttackCancel,
507                pRegion->EG1Options.AttackHoldCancel,
508                pRegion->EG1Options.Decay1Cancel,
509                pRegion->EG1Options.Decay2Cancel,
510                pRegion->EG1Options.ReleaseCancel
511            );
512          EG1.trigger(pRegion->EG1PreAttack,          EG1.trigger(pRegion->EG1PreAttack,
513                      RTMath::Max(pRegion->EG1Attack, 0.0316) * egInfo.Attack,                      (pNote && pNote->Override.Attack.isFinal()) ?
514                            pNote->Override.Attack.Value :
515                            RTMath::Max(pRegion->EG1Attack, 0.0316) * egInfo.Attack,
516                      pRegion->EG1Hold,                      pRegion->EG1Hold,
517                      pRegion->EG1Decay1 * egInfo.Decay * velrelease,                      (pNote && pNote->Override.Decay.isFinal()) ?
518                      pRegion->EG1Decay2 * egInfo.Decay * velrelease,                          pNote->Override.Decay.Value :
519                            pRegion->EG1Decay1 * egInfo.Decay * velrelease,
520                        (pNote && pNote->Override.Decay.isFinal()) ?
521                            pNote->Override.Decay.Value :
522                            pRegion->EG1Decay2 * egInfo.Decay * velrelease,
523                      pRegion->EG1InfiniteSustain,                      pRegion->EG1InfiniteSustain,
524                      pRegion->EG1Sustain,                      (pNote && pNote->Override.Sustain.Final) ?
525                      RTMath::Max(pRegion->EG1Release * velrelease, 0.014) * egInfo.Release,                          uint(pNote->Override.Sustain.Value * 1000.f) :
526                            pRegion->EG1Sustain * (pNote ? pNote->Override.Sustain.Value : 1.f),
527                        (pNote && pNote->Override.Release.isFinal()) ?
528                            pNote->Override.Release.Value :
529                            RTMath::Max(pRegion->EG1Release * velrelease, 0.014) * egInfo.Release,
530                      velocityAttenuation,                      velocityAttenuation,
531                      sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);                      sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
532      }      }
533    
534      void Voice::TriggerEG2(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) {      void Voice::TriggerEG2(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) {
535            EG2.setStateOptions(
536                pRegion->EG2Options.AttackCancel,
537                pRegion->EG2Options.AttackHoldCancel,
538                pRegion->EG2Options.Decay1Cancel,
539                pRegion->EG2Options.Decay2Cancel,
540                pRegion->EG2Options.ReleaseCancel
541            );
542          EG2.trigger(uint(RgnInfo.EG2PreAttack),          EG2.trigger(uint(RgnInfo.EG2PreAttack),
543                      RgnInfo.EG2Attack * egInfo.Attack,                      (pNote && pNote->Override.CutoffAttack.isFinal()) ?
544                            pNote->Override.CutoffAttack.Value :
545                            RgnInfo.EG2Attack * egInfo.Attack,
546                      false,                      false,
547                      RgnInfo.EG2Decay1 * egInfo.Decay * velrelease,                      (pNote && pNote->Override.CutoffDecay.isFinal()) ?
548                      RgnInfo.EG2Decay2 * egInfo.Decay * velrelease,                          pNote->Override.CutoffDecay.Value :
549                            RgnInfo.EG2Decay1 * egInfo.Decay * velrelease,
550                        (pNote && pNote->Override.CutoffDecay.isFinal()) ?
551                            pNote->Override.CutoffDecay.Value :
552                            RgnInfo.EG2Decay2 * egInfo.Decay * velrelease,
553                      RgnInfo.EG2InfiniteSustain,                      RgnInfo.EG2InfiniteSustain,
554                      uint(RgnInfo.EG2Sustain),                      (pNote && pNote->Override.CutoffSustain.Final) ?
555                      RgnInfo.EG2Release * egInfo.Release * velrelease,                          uint(pNote->Override.CutoffSustain.Value * 1000.f) :
556                            uint(RgnInfo.EG2Sustain),
557                        (pNote && pNote->Override.CutoffRelease.isFinal()) ?
558                            pNote->Override.CutoffRelease.Value :
559                            RgnInfo.EG2Release * egInfo.Release * velrelease,
560                      velocityAttenuation,                      velocityAttenuation,
561                      sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);                      sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
562      }      }
# Line 523  namespace LinuxSampler { namespace gig { Line 598  namespace LinuxSampler { namespace gig {
598          return p;          return p;
599      }      }
600    
601        release_trigger_t Voice::GetReleaseTriggerFlags() {
602            release_trigger_t flags =
603                (pRegion->NoNoteOffReleaseTrigger) ?
604                    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
605            switch (pRegion->SustainReleaseTrigger) {
606                case ::gig::sust_rel_trg_none:
607                    break;
608                case ::gig::sust_rel_trg_maxvelocity:
609                    flags |= release_trigger_sustain_maxvelocity;
610                    break;
611                case ::gig::sust_rel_trg_keyvelocity:
612                    flags |= release_trigger_sustain_keyvelocity;
613                    break;
614            }
615            return flags;
616        }
617    
618  }} // namespace LinuxSampler::gig  }} // namespace LinuxSampler::gig

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

  ViewVC Help
Powered by ViewVC