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

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

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

revision 668 by schoenebeck, Mon Jun 20 15:30:47 2005 UTC revision 705 by schoenebeck, Wed Jul 20 21:43:23 2005 UTC
# Line 240  namespace LinuxSampler { namespace gig { Line 240  namespace LinuxSampler { namespace gig {
240    
241          // FIXME: audio drivers with varying fragment sizes might be a problem here          // FIXME: audio drivers with varying fragment sizes might be a problem here
242          MaxFadeOutPos = MaxSamplesPerCycle - int(double(SampleRate) * CONFIG_EG_MIN_RELEASE_TIME) - 1;          MaxFadeOutPos = MaxSamplesPerCycle - int(double(SampleRate) * CONFIG_EG_MIN_RELEASE_TIME) - 1;
243          if (MaxFadeOutPos < 0)          if (MaxFadeOutPos < 0) {
244              throw LinuxSamplerException("CONFIG_EG_MIN_RELEASE_TIME too big for current audio fragment size / sampling rate!");              std::cerr << "gig::Engine: WARNING, CONFIG_EG_MIN_RELEASE_TIME "
245                          << "too big for current audio fragment size & sampling rate! "
246                          << "May lead to click sounds if voice stealing chimes in!\n" << std::flush;
247                // force volume ramp downs at the beginning of each fragment
248                MaxFadeOutPos = 0;
249                // lower minimum release time
250                const float minReleaseTime = (float) MaxSamplesPerCycle / (float) SampleRate;
251                for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) {
252                    iterVoice->pEG1->CalculateFadeOutCoeff(minReleaseTime, SampleRate);
253                }
254                pVoicePool->clear();
255            }
256    
257          // (re)create disk thread          // (re)create disk thread
258          if (this->pDiskThread) {          if (this->pDiskThread) {
# Line 481  namespace LinuxSampler { namespace gig { Line 492  namespace LinuxSampler { namespace gig {
492       *                         this audio fragment cycle       *                         this audio fragment cycle
493       */       */
494      void Engine::RenderActiveVoices(EngineChannel* pEngineChannel, uint Samples) {      void Engine::RenderActiveVoices(EngineChannel* pEngineChannel, uint Samples) {
495            if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted
496    
497          RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();          RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();
498          RTList<uint>::Iterator end    = pEngineChannel->pActiveKeys->end();          RTList<uint>::Iterator end    = pEngineChannel->pActiveKeys->end();
499          while (iuiKey != end) { // iterate through all active keys          while (iuiKey != end) { // iterate through all active keys
# Line 609  namespace LinuxSampler { namespace gig { Line 622  namespace LinuxSampler { namespace gig {
622       *  @param itNoteOnEvent - key, velocity and time stamp of the event       *  @param itNoteOnEvent - key, velocity and time stamp of the event
623       */       */
624      void Engine::ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) {      void Engine::ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) {
625           if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted
626    
627          const int key = itNoteOnEvent->Param.Note.Key;          const int key = itNoteOnEvent->Param.Note.Key;
628    
# Line 668  namespace LinuxSampler { namespace gig { Line 682  namespace LinuxSampler { namespace gig {
682       *  @param itNoteOffEvent - key, velocity and time stamp of the event       *  @param itNoteOffEvent - key, velocity and time stamp of the event
683       */       */
684      void Engine::ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) {      void Engine::ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) {
685          midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[itNoteOffEvent->Param.Note.Key];          if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted
686    
687            midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[itNoteOffEvent->Param.Note.Key];
688          pKey->KeyPressed = false; // the MIDI key was now released          pKey->KeyPressed = false; // the MIDI key was now released
689    
690          // release voices on this key if needed          // release voices on this key if needed
# Line 735  namespace LinuxSampler { namespace gig { Line 750  namespace LinuxSampler { namespace gig {
750       *           defined for the given key).       *           defined for the given key).
751       */       */
752      Pool<Voice>::Iterator Engine::LaunchVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent, int iLayer, bool ReleaseTriggerVoice, bool VoiceStealing, bool HandleKeyGroupConflicts) {      Pool<Voice>::Iterator Engine::LaunchVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent, int iLayer, bool ReleaseTriggerVoice, bool VoiceStealing, bool HandleKeyGroupConflicts) {
753          midi_key_info_t* pKey  = &pEngineChannel->pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key];          int MIDIKey            = itNoteOnEvent->Param.Note.Key;
754          ::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(itNoteOnEvent->Param.Note.Key);          midi_key_info_t* pKey  = &pEngineChannel->pMIDIKeyInfo[MIDIKey];
755            ::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(MIDIKey);
756    
757          // if nothing defined for this key          // if nothing defined for this key
758          if (!pRegion) return Pool<Voice>::Iterator(); // nothing to do          if (!pRegion) return Pool<Voice>::Iterator(); // nothing to do
759    
760            // only mark the first voice of a layered voice (group) to be in a
761            // key group, so the layered voices won't kill each other
762            int iKeyGroup = (iLayer == 0 && !ReleaseTriggerVoice) ? pRegion->KeyGroup : 0;
763    
764          // handle key group (a.k.a. exclusive group) conflicts          // handle key group (a.k.a. exclusive group) conflicts
765          if (HandleKeyGroupConflicts) {          if (HandleKeyGroupConflicts) {
             // only mark the first voice of a layered voice (group) to be in a  
             // key group, so the layered voices won't kill each other  
             int iKeyGroup = (iLayer == 0 && !ReleaseTriggerVoice) ? pRegion->KeyGroup : 0;  
766              if (iKeyGroup) { // if this voice / key belongs to a key group              if (iKeyGroup) { // if this voice / key belongs to a key group
767                  uint** ppKeyGroup = &pEngineChannel->ActiveKeyGroups[iKeyGroup];                  uint** ppKeyGroup = &pEngineChannel->ActiveKeyGroups[iKeyGroup];
768                  if (*ppKeyGroup) { // if there's already an active key in that key group                  if (*ppKeyGroup) { // if there's already an active key in that key group
# Line 763  namespace LinuxSampler { namespace gig { Line 780  namespace LinuxSampler { namespace gig {
780              }              }
781          }          }
782    
783            Voice::type_t VoiceType = Voice::type_normal;
784    
785            // get current dimension values to select the right dimension region
786            //TODO: for stolen voices this dimension region selection block is processed twice, this should be changed
787            //FIXME: controller values for selecting the dimension region here are currently not sample accurate
788            uint DimValues[8] = { 0 };
789            for (int i = pRegion->Dimensions - 1; i >= 0; i--) {
790                switch (pRegion->pDimensionDefinitions[i].dimension) {
791                    case ::gig::dimension_samplechannel:
792                        DimValues[i] = 0; //TODO: we currently ignore this dimension
793                        break;
794                    case ::gig::dimension_layer:
795                        DimValues[i] = iLayer;
796                        break;
797                    case ::gig::dimension_velocity:
798                        DimValues[i] = itNoteOnEvent->Param.Note.Velocity;
799                        break;
800                    case ::gig::dimension_channelaftertouch:
801                        DimValues[i] = 0; //TODO: we currently ignore this dimension
802                        break;
803                    case ::gig::dimension_releasetrigger:
804                        VoiceType = (ReleaseTriggerVoice) ? Voice::type_release_trigger : (!iLayer) ? Voice::type_release_trigger_required : Voice::type_normal;
805                        DimValues[i] = (uint) ReleaseTriggerVoice;
806                        break;
807                    case ::gig::dimension_keyboard:
808                        DimValues[i] = (uint) pEngineChannel->CurrentKeyDimension;
809                        break;
810                    case ::gig::dimension_roundrobin:
811                        DimValues[i] = (uint) pEngineChannel->pMIDIKeyInfo[MIDIKey].RoundRobinIndex; // incremented for each note on
812                        break;
813                    case ::gig::dimension_random:
814                        RandomSeed   = RandomSeed * 1103515245 + 12345; // classic pseudo random number generator
815                        DimValues[i] = (uint) RandomSeed >> (32 - pRegion->pDimensionDefinitions[i].bits); // highest bits are most random
816                        break;
817                    case ::gig::dimension_modwheel:
818                        DimValues[i] = pEngineChannel->ControllerTable[1];
819                        break;
820                    case ::gig::dimension_breath:
821                        DimValues[i] = pEngineChannel->ControllerTable[2];
822                        break;
823                    case ::gig::dimension_foot:
824                        DimValues[i] = pEngineChannel->ControllerTable[4];
825                        break;
826                    case ::gig::dimension_portamentotime:
827                        DimValues[i] = pEngineChannel->ControllerTable[5];
828                        break;
829                    case ::gig::dimension_effect1:
830                        DimValues[i] = pEngineChannel->ControllerTable[12];
831                        break;
832                    case ::gig::dimension_effect2:
833                        DimValues[i] = pEngineChannel->ControllerTable[13];
834                        break;
835                    case ::gig::dimension_genpurpose1:
836                        DimValues[i] = pEngineChannel->ControllerTable[16];
837                        break;
838                    case ::gig::dimension_genpurpose2:
839                        DimValues[i] = pEngineChannel->ControllerTable[17];
840                        break;
841                    case ::gig::dimension_genpurpose3:
842                        DimValues[i] = pEngineChannel->ControllerTable[18];
843                        break;
844                    case ::gig::dimension_genpurpose4:
845                        DimValues[i] = pEngineChannel->ControllerTable[19];
846                        break;
847                    case ::gig::dimension_sustainpedal:
848                        DimValues[i] = pEngineChannel->ControllerTable[64];
849                        break;
850                    case ::gig::dimension_portamento:
851                        DimValues[i] = pEngineChannel->ControllerTable[65];
852                        break;
853                    case ::gig::dimension_sostenutopedal:
854                        DimValues[i] = pEngineChannel->ControllerTable[66];
855                        break;
856                    case ::gig::dimension_softpedal:
857                        DimValues[i] = pEngineChannel->ControllerTable[67];
858                        break;
859                    case ::gig::dimension_genpurpose5:
860                        DimValues[i] = pEngineChannel->ControllerTable[80];
861                        break;
862                    case ::gig::dimension_genpurpose6:
863                        DimValues[i] = pEngineChannel->ControllerTable[81];
864                        break;
865                    case ::gig::dimension_genpurpose7:
866                        DimValues[i] = pEngineChannel->ControllerTable[82];
867                        break;
868                    case ::gig::dimension_genpurpose8:
869                        DimValues[i] = pEngineChannel->ControllerTable[83];
870                        break;
871                    case ::gig::dimension_effect1depth:
872                        DimValues[i] = pEngineChannel->ControllerTable[91];
873                        break;
874                    case ::gig::dimension_effect2depth:
875                        DimValues[i] = pEngineChannel->ControllerTable[92];
876                        break;
877                    case ::gig::dimension_effect3depth:
878                        DimValues[i] = pEngineChannel->ControllerTable[93];
879                        break;
880                    case ::gig::dimension_effect4depth:
881                        DimValues[i] = pEngineChannel->ControllerTable[94];
882                        break;
883                    case ::gig::dimension_effect5depth:
884                        DimValues[i] = pEngineChannel->ControllerTable[95];
885                        break;
886                    case ::gig::dimension_none:
887                        std::cerr << "gig::Engine::LaunchVoice() Error: dimension=none\n" << std::flush;
888                        break;
889                    default:
890                        std::cerr << "gig::Engine::LaunchVoice() Error: Unknown dimension\n" << std::flush;
891                }
892            }
893            ::gig::DimensionRegion* pDimRgn = pRegion->GetDimensionRegionByValue(DimValues);
894    
895            // no need to continue if sample is silent
896            if (!pDimRgn->pSample || !pDimRgn->pSample->SamplesTotal) return Pool<Voice>::Iterator();
897    
898          // allocate a new voice for the key          // allocate a new voice for the key
899          Pool<Voice>::Iterator itNewVoice = pKey->pActiveVoices->allocAppend();          Pool<Voice>::Iterator itNewVoice = pKey->pActiveVoices->allocAppend();
900          if (itNewVoice) {          if (itNewVoice) {
901              // launch the new voice              // launch the new voice
902              if (itNewVoice->Trigger(pEngineChannel, itNoteOnEvent, pEngineChannel->Pitch, pEngineChannel->pInstrument, iLayer, ReleaseTriggerVoice, VoiceStealing) < 0) {              if (itNewVoice->Trigger(pEngineChannel, itNoteOnEvent, pEngineChannel->Pitch, pDimRgn, VoiceType, iKeyGroup) < 0) {
903                  dmsg(4,("Voice not triggered\n"));                  dmsg(4,("Voice not triggered\n"));
904                  pKey->pActiveVoices->free(itNewVoice);                  pKey->pActiveVoices->free(itNewVoice);
905              }              }
# Line 1053  namespace LinuxSampler { namespace gig { Line 1185  namespace LinuxSampler { namespace gig {
1185                      dmsg(4,("PEDAL DOWN\n"));                      dmsg(4,("PEDAL DOWN\n"));
1186                      pEngineChannel->SustainPedal = true;                      pEngineChannel->SustainPedal = true;
1187    
1188                        if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted
1189    
1190                      // cancel release process of voices if necessary                      // cancel release process of voices if necessary
1191                      RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();                      RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();
1192                      for (; iuiKey; ++iuiKey) {                      for (; iuiKey; ++iuiKey) {
# Line 1071  namespace LinuxSampler { namespace gig { Line 1205  namespace LinuxSampler { namespace gig {
1205                      dmsg(4,("PEDAL UP\n"));                      dmsg(4,("PEDAL UP\n"));
1206                      pEngineChannel->SustainPedal = false;                      pEngineChannel->SustainPedal = false;
1207    
1208                        if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted
1209    
1210                      // release voices if their respective key is not pressed                      // release voices if their respective key is not pressed
1211                      RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();                      RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();
1212                      for (; iuiKey; ++iuiKey) {                      for (; iuiKey; ++iuiKey) {
# Line 1295  namespace LinuxSampler { namespace gig { Line 1431  namespace LinuxSampler { namespace gig {
1431      }      }
1432    
1433      String Engine::Version() {      String Engine::Version() {
1434          String s = "$Revision: 1.46 $";          String s = "$Revision: 1.50 $";
1435          return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword          return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword
1436      }      }
1437    

Legend:
Removed from v.668  
changed lines
  Added in v.705

  ViewVC Help
Powered by ViewVC