/[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 716 by iliev, Sun Jul 24 06:57:30 2005 UTC revision 769 by schoenebeck, Sat Sep 3 11:14:30 2005 UTC
# Line 29  Line 29 
29    
30  #include "Engine.h"  #include "Engine.h"
31    
 #if defined(__APPLE__)  
 # include <stdlib.h>  
 #else  
 # include <malloc.h>  
 #endif  
   
32  namespace LinuxSampler { namespace gig {  namespace LinuxSampler { namespace gig {
33    
34      InstrumentResourceManager Engine::instruments;      InstrumentResourceManager Engine::instruments;
# Line 114  namespace LinuxSampler { namespace gig { Line 108  namespace LinuxSampler { namespace gig {
108          }          }
109          pVoicePool->clear();          pVoicePool->clear();
110    
         pSynthesisParameters[0] = NULL; // we allocate when an audio device is connected  
         pBasicFilterParameters  = NULL;  
         pMainFilterParameters   = NULL;  
   
111          ResetInternal();          ResetInternal();
112          ResetScaleTuning();          ResetScaleTuning();
113      }      }
# Line 139  namespace LinuxSampler { namespace gig { Line 129  namespace LinuxSampler { namespace gig {
129              delete pVoicePool;              delete pVoicePool;
130          }          }
131          if (pEventGenerator) delete pEventGenerator;          if (pEventGenerator) delete pEventGenerator;
         if (pMainFilterParameters) delete[] pMainFilterParameters;  
         if (pBasicFilterParameters) delete[] pBasicFilterParameters;  
         if (pSynthesisParameters[0]) free(pSynthesisParameters[0]);  
132          if (pVoiceStealingQueue) delete pVoiceStealingQueue;          if (pVoiceStealingQueue) delete pVoiceStealingQueue;
133          if (pSysexBuffer) delete pSysexBuffer;          if (pSysexBuffer) delete pSysexBuffer;
134          EngineFactory::Destroy(this);          EngineFactory::Destroy(this);
# Line 249  namespace LinuxSampler { namespace gig { Line 236  namespace LinuxSampler { namespace gig {
236              // lower minimum release time              // lower minimum release time
237              const float minReleaseTime = (float) MaxSamplesPerCycle / (float) SampleRate;              const float minReleaseTime = (float) MaxSamplesPerCycle / (float) SampleRate;
238              for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) {              for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) {
239                  iterVoice->pEG1->CalculateFadeOutCoeff(minReleaseTime, SampleRate);                  iterVoice->EG1.CalculateFadeOutCoeff(minReleaseTime, SampleRate);
240              }              }
241              pVoicePool->clear();              pVoicePool->clear();
242          }          }
# Line 277  namespace LinuxSampler { namespace gig { Line 264  namespace LinuxSampler { namespace gig {
264          if (pEventGenerator) delete pEventGenerator;          if (pEventGenerator) delete pEventGenerator;
265          pEventGenerator = new EventGenerator(pAudioOut->SampleRate());          pEventGenerator = new EventGenerator(pAudioOut->SampleRate());
266    
         // (re)allocate synthesis parameter matrix  
         if (pSynthesisParameters[0]) free(pSynthesisParameters[0]);  
   
         #if defined(__APPLE__)  
         pSynthesisParameters[0] = (float *) malloc(Event::destination_count * sizeof(float) * pAudioOut->MaxSamplesPerCycle());  
         #else  
         pSynthesisParameters[0] = (float *) memalign(16,(Event::destination_count * sizeof(float) * pAudioOut->MaxSamplesPerCycle()));  
         #endif  
         for (int dst = 1; dst < Event::destination_count; dst++)  
             pSynthesisParameters[dst] = pSynthesisParameters[dst - 1] + pAudioOut->MaxSamplesPerCycle();  
   
         // (re)allocate biquad filter parameter sequence  
         if (pBasicFilterParameters) delete[] pBasicFilterParameters;  
         if (pMainFilterParameters)  delete[] pMainFilterParameters;  
         pBasicFilterParameters = new biquad_param_t[pAudioOut->MaxSamplesPerCycle()];  
         pMainFilterParameters  = new biquad_param_t[pAudioOut->MaxSamplesPerCycle()];  
   
267          dmsg(1,("Starting disk thread..."));          dmsg(1,("Starting disk thread..."));
268          pDiskThread->StartThread();          pDiskThread->StartThread();
269          dmsg(1,("OK\n"));          dmsg(1,("OK\n"));
# Line 724  namespace LinuxSampler { namespace gig { Line 694  namespace LinuxSampler { namespace gig {
694      }      }
695    
696      /**      /**
697       *  Moves pitchbend event from the general (input) event list to the pitch       *  Moves pitchbend event from the general (input) event list to the engine
698       *  event list.       *  channel's event list. It will actually processed later by the
699         *  respective voice.
700       *       *
701       *  @param pEngineChannel - engine channel on which this event occured on       *  @param pEngineChannel - engine channel on which this event occured on
702       *  @param itPitchbendEvent - absolute pitch value and time stamp of the event       *  @param itPitchbendEvent - absolute pitch value and time stamp of the event
703       */       */
704      void Engine::ProcessPitchbend(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent) {      void Engine::ProcessPitchbend(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent) {
705          pEngineChannel->Pitch = itPitchbendEvent->Param.Pitch.Pitch; // store current pitch value          pEngineChannel->Pitch = itPitchbendEvent->Param.Pitch.Pitch; // store current pitch value
         itPitchbendEvent.moveToEndOf(pEngineChannel->pSynthesisEvents[Event::destination_vco]);  
706      }      }
707    
708      /**      /**
# Line 1169  namespace LinuxSampler { namespace gig { Line 1139  namespace LinuxSampler { namespace gig {
1139          // update controller value in the engine channel's controller table          // update controller value in the engine channel's controller table
1140          pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value;          pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value;
1141    
1142          // move event from the unsorted event list to the control change event list          switch (itControlChangeEvent->Param.CC.Controller) {
         Pool<Event>::Iterator itControlChangeEventOnCCList = itControlChangeEvent.moveToEndOf(pEngineChannel->pCCEvents);  
   
         switch (itControlChangeEventOnCCList->Param.CC.Controller) {  
1143              case 7: { // volume              case 7: { // volume
1144                  //TODO: not sample accurate yet                  //TODO: not sample accurate yet
1145                  pEngineChannel->GlobalVolume = (float) itControlChangeEventOnCCList->Param.CC.Value / 127.0f;                  pEngineChannel->GlobalVolume = (float) itControlChangeEvent->Param.CC.Value / 127.0f;
1146                  pEngineChannel->bStatusChanged = true; // engine channel status has changed, so set notify flag                  pEngineChannel->bStatusChanged = true; // engine channel status has changed, so set notify flag
1147                  break;                  break;
1148              }              }
1149              case 10: { // panpot              case 10: { // panpot
1150                  //TODO: not sample accurate yet                  //TODO: not sample accurate yet
1151                  const int pan = (int) itControlChangeEventOnCCList->Param.CC.Value - 64;                  const int pan = (int) itControlChangeEvent->Param.CC.Value - 64;
1152                  pEngineChannel->GlobalPanLeft  = 1.0f - float(RTMath::Max(pan, 0)) /  63.0f;                  pEngineChannel->GlobalPanLeft  = 1.0f - float(RTMath::Max(pan, 0)) /  63.0f;
1153                  pEngineChannel->GlobalPanRight = 1.0f - float(RTMath::Min(pan, 0)) / -64.0f;                  pEngineChannel->GlobalPanRight = 1.0f - float(RTMath::Min(pan, 0)) / -64.0f;
1154                  break;                  break;
1155              }              }
1156              case 64: { // sustain              case 64: { // sustain
1157                  if (itControlChangeEventOnCCList->Param.CC.Value >= 64 && !pEngineChannel->SustainPedal) {                  if (itControlChangeEvent->Param.CC.Value >= 64 && !pEngineChannel->SustainPedal) {
1158                      dmsg(4,("PEDAL DOWN\n"));                      dmsg(4,("PEDAL DOWN\n"));
1159                      pEngineChannel->SustainPedal = true;                      pEngineChannel->SustainPedal = true;
1160    
# Line 1202  namespace LinuxSampler { namespace gig { Line 1169  namespace LinuxSampler { namespace gig {
1169                          if (!pKey->KeyPressed) {                          if (!pKey->KeyPressed) {
1170                              RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();                              RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();
1171                              if (itNewEvent) {                              if (itNewEvent) {
1172                                  *itNewEvent = *itControlChangeEventOnCCList; // copy event to the key's own event list                                  *itNewEvent = *itControlChangeEvent; // copy event to the key's own event list
1173                                  itNewEvent->Type = Event::type_cancel_release; // transform event type                                  itNewEvent->Type = Event::type_cancel_release; // transform event type
1174                              }                              }
1175                              else dmsg(1,("Event pool emtpy!\n"));                              else dmsg(1,("Event pool emtpy!\n"));
1176                          }                          }
1177                      }                      }
1178                  }                  }
1179                  if (itControlChangeEventOnCCList->Param.CC.Value < 64 && pEngineChannel->SustainPedal) {                  if (itControlChangeEvent->Param.CC.Value < 64 && pEngineChannel->SustainPedal) {
1180                      dmsg(4,("PEDAL UP\n"));                      dmsg(4,("PEDAL UP\n"));
1181                      pEngineChannel->SustainPedal = false;                      pEngineChannel->SustainPedal = false;
1182    
# Line 1224  namespace LinuxSampler { namespace gig { Line 1191  namespace LinuxSampler { namespace gig {
1191                          if (!pKey->KeyPressed) {                          if (!pKey->KeyPressed) {
1192                              RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();                              RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();
1193                              if (itNewEvent) {                              if (itNewEvent) {
1194                                  *itNewEvent = *itControlChangeEventOnCCList; // copy event to the key's own event list                                  *itNewEvent = *itControlChangeEvent; // copy event to the key's own event list
1195                                  itNewEvent->Type = Event::type_release; // transform event type                                  itNewEvent->Type = Event::type_release; // transform event type
1196                              }                              }
1197                              else dmsg(1,("Event pool emtpy!\n"));                              else dmsg(1,("Event pool emtpy!\n"));
# Line 1238  namespace LinuxSampler { namespace gig { Line 1205  namespace LinuxSampler { namespace gig {
1205              // Channel Mode Messages              // Channel Mode Messages
1206    
1207              case 120: { // all sound off              case 120: { // all sound off
1208                  KillAllVoices(pEngineChannel, itControlChangeEventOnCCList);                  KillAllVoices(pEngineChannel, itControlChangeEvent);
1209                  break;                  break;
1210              }              }
1211              case 121: { // reset all controllers              case 121: { // reset all controllers
# Line 1246  namespace LinuxSampler { namespace gig { Line 1213  namespace LinuxSampler { namespace gig {
1213                  break;                  break;
1214              }              }
1215              case 123: { // all notes off              case 123: { // all notes off
1216                  ReleaseAllVoices(pEngineChannel, itControlChangeEventOnCCList);                  ReleaseAllVoices(pEngineChannel, itControlChangeEvent);
1217                  break;                  break;
1218              }              }
1219          }          }
# Line 1389  namespace LinuxSampler { namespace gig { Line 1356  namespace LinuxSampler { namespace gig {
1356          }          }
1357      }      }
1358    
     /**  
      * Initialize the parameter sequence for the modulation destination given by  
      * by 'dst' with the constant value given by val.  
      */  
     void Engine::ResetSynthesisParameters(Event::destination_t dst, float val) {  
         int maxsamples = pAudioOutputDevice->MaxSamplesPerCycle();  
         float* m = &pSynthesisParameters[dst][0];  
         for (int i = 0; i < maxsamples; i += 4) {  
            m[i]   = val;  
            m[i+1] = val;  
            m[i+2] = val;  
            m[i+3] = val;  
         }  
     }  
   
1359      uint Engine::VoiceCount() {      uint Engine::VoiceCount() {
1360          return ActiveVoiceCount;          return ActiveVoiceCount;
1361      }      }
# Line 1441  namespace LinuxSampler { namespace gig { Line 1393  namespace LinuxSampler { namespace gig {
1393      }      }
1394    
1395      String Engine::Version() {      String Engine::Version() {
1396          String s = "$Revision: 1.51 $";          String s = "$Revision: 1.53 $";
1397          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
1398      }      }
1399    

Legend:
Removed from v.716  
changed lines
  Added in v.769

  ViewVC Help
Powered by ViewVC