/[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 1799 by iliev, Sat Nov 1 19:01:27 2008 UTC revision 1800 by schoenebeck, Sun Dec 7 01:26:46 2008 UTC
# Line 107  namespace LinuxSampler { namespace gig { Line 107  namespace LinuxSampler { namespace gig {
107          pSysexBuffer       = new RingBuffer<uint8_t,false>(CONFIG_SYSEX_BUFFER_SIZE, 0);          pSysexBuffer       = new RingBuffer<uint8_t,false>(CONFIG_SYSEX_BUFFER_SIZE, 0);
108          pEventQueue        = new RingBuffer<Event,false>(CONFIG_MAX_EVENTS_PER_FRAGMENT, 0);          pEventQueue        = new RingBuffer<Event,false>(CONFIG_MAX_EVENTS_PER_FRAGMENT, 0);
109          pEventPool         = new Pool<Event>(CONFIG_MAX_EVENTS_PER_FRAGMENT);          pEventPool         = new Pool<Event>(CONFIG_MAX_EVENTS_PER_FRAGMENT);
110          pVoicePool         = new Pool<Voice>(CONFIG_MAX_VOICES);          pVoicePool         = new Pool<Voice>(GLOBAL_MAX_VOICES);
111          pDimRegionPool[0]  = new Pool< ::gig::DimensionRegion*>(CONFIG_MAX_VOICES);          pDimRegionPool[0]  = new Pool< ::gig::DimensionRegion*>(GLOBAL_MAX_VOICES);
112          pDimRegionPool[1]  = new Pool< ::gig::DimensionRegion*>(CONFIG_MAX_VOICES);          pDimRegionPool[1]  = new Pool< ::gig::DimensionRegion*>(GLOBAL_MAX_VOICES);
113          pVoiceStealingQueue = new RTList<Event>(pEventPool);          pVoiceStealingQueue = new RTList<Event>(pEventPool);
114          pGlobalEvents      = new RTList<Event>(pEventPool);          pGlobalEvents      = new RTList<Event>(pEventPool);
115            iMaxDiskStreams    = GLOBAL_MAX_STREAMS;
116    
117          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()) {
118              iterVoice->SetEngine(this);              iterVoice->SetEngine(this);
# Line 342  namespace LinuxSampler { namespace gig { Line 343  namespace LinuxSampler { namespace gig {
343       * @param pAudioOut - audio output device to connect to       * @param pAudioOut - audio output device to connect to
344       */       */
345      void Engine::Connect(AudioOutputDevice* pAudioOut) {      void Engine::Connect(AudioOutputDevice* pAudioOut) {
346            // caution: don't ignore if connecting to the same device here,
347            // because otherwise SetMaxDiskStreams() implementation won't work anymore!
348    
349          pAudioOutputDevice = pAudioOut;          pAudioOutputDevice = pAudioOut;
350    
351          ResetInternal();          ResetInternal();
# Line 380  namespace LinuxSampler { namespace gig { Line 384  namespace LinuxSampler { namespace gig {
384              delete this->pDiskThread;              delete this->pDiskThread;
385              dmsg(1,("OK\n"));              dmsg(1,("OK\n"));
386          }          }
387          this->pDiskThread = new DiskThread(((pAudioOut->MaxSamplesPerCycle() << CONFIG_MAX_PITCH) << 1) + 6, //FIXME: assuming stereo          this->pDiskThread =
388                                             &instruments);              new DiskThread(
389                    iMaxDiskStreams,
390                    ((pAudioOut->MaxSamplesPerCycle() << CONFIG_MAX_PITCH) << 1) + 6, //FIXME: assuming stereo
391                    &instruments
392                );
393    
394          if (!pDiskThread) {          if (!pDiskThread) {
395              dmsg(0,("gig::Engine  new diskthread = NULL\n"));              dmsg(0,("gig::Engine  new diskthread = NULL\n"));
396              exit(EXIT_FAILURE);              exit(EXIT_FAILURE);
# Line 407  namespace LinuxSampler { namespace gig { Line 416  namespace LinuxSampler { namespace gig {
416                  exit(EXIT_FAILURE);                  exit(EXIT_FAILURE);
417              }              }
418          }          }
419            pVoicePool->clear();
420      }      }
421    
422      /**      /**
# Line 584  namespace LinuxSampler { namespace gig { Line 594  namespace LinuxSampler { namespace gig {
594          // update time of start and end of this audio fragment (as events' time stamps relate to this)          // update time of start and end of this audio fragment (as events' time stamps relate to this)
595          pEventGenerator->UpdateFragmentTime(Samples);          pEventGenerator->UpdateFragmentTime(Samples);
596    
597          // We only allow a maximum of CONFIG_MAX_VOICES voices to be spawned          // We only allow the given maximum number of voices to be spawned
598          // in each audio fragment. All subsequent request for spawning new          // in each audio fragment. All subsequent request for spawning new
599          // voices in the same audio fragment will be ignored.          // voices in the same audio fragment will be ignored.
600          VoiceSpawnsLeft = CONFIG_MAX_VOICES;          VoiceSpawnsLeft = MaxVoices();
601    
602          // get all events from the engine's global input event queue which belong to the current fragment          // get all events from the engine's global input event queue which belong to the current fragment
603          // (these are usually just SysEx messages)          // (these are usually just SysEx messages)
# Line 2111  namespace LinuxSampler { namespace gig { Line 2121  namespace LinuxSampler { namespace gig {
2121          return ActiveVoiceCountMax;          return ActiveVoiceCountMax;
2122      }      }
2123    
2124        int Engine::MaxVoices() {
2125            return pVoicePool->poolSize();
2126        }
2127    
2128        void Engine::SetMaxVoices(int iVoices) throw (Exception) {
2129            if (iVoices < 1)
2130                throw Exception("Maximum voices for an engine cannot be set lower than 1");
2131    
2132            SuspendAll();
2133    
2134            if (pDimRegionPool[0]) delete pDimRegionPool[0];
2135            if (pDimRegionPool[1]) delete pDimRegionPool[1];
2136    
2137            pDimRegionPool[0] = new Pool< ::gig::DimensionRegion*>(iVoices);
2138            pDimRegionPool[1] = new Pool< ::gig::DimensionRegion*>(iVoices);
2139    
2140            try {
2141                pVoicePool->resizePool(iVoices);
2142            } catch (...) {
2143                throw Exception("FATAL: Could not resize voice pool!");
2144            }
2145    
2146            for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) {
2147                iterVoice->SetEngine(this);
2148                iterVoice->pDiskThread = this->pDiskThread;
2149            }
2150            pVoicePool->clear();
2151    
2152            ResumeAll();
2153        }
2154    
2155      bool Engine::DiskStreamSupported() {      bool Engine::DiskStreamSupported() {
2156          return true;          return true;
2157      }      }
# Line 2123  namespace LinuxSampler { namespace gig { Line 2164  namespace LinuxSampler { namespace gig {
2164          return (pDiskThread) ? pDiskThread->ActiveStreamCountMax : 0;          return (pDiskThread) ? pDiskThread->ActiveStreamCountMax : 0;
2165      }      }
2166    
2167        int Engine::MaxDiskStreams() {
2168            return iMaxDiskStreams;
2169        }
2170    
2171        void Engine::SetMaxDiskStreams(int iStreams) throw (Exception) {
2172            if (iStreams < 0)
2173                throw Exception("Maximum disk streams for an engine cannot be set lower than 0");
2174    
2175            SuspendAll();
2176    
2177            iMaxDiskStreams = iStreams;
2178    
2179            // reconnect to audio output device, because that will automatically
2180            // recreate the disk thread with the required amount of streams
2181            if (pAudioOutputDevice) Connect(pAudioOutputDevice);
2182    
2183            ResumeAll();
2184        }
2185    
2186      String Engine::DiskStreamBufferFillBytes() {      String Engine::DiskStreamBufferFillBytes() {
2187          return pDiskThread->GetBufferFillBytes();          return pDiskThread->GetBufferFillBytes();
2188      }      }
# Line 2140  namespace LinuxSampler { namespace gig { Line 2200  namespace LinuxSampler { namespace gig {
2200      }      }
2201    
2202      String Engine::Version() {      String Engine::Version() {
2203          String s = "$Revision: 1.98 $";          String s = "$Revision: 1.99 $";
2204          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
2205      }      }
2206    

Legend:
Removed from v.1799  
changed lines
  Added in v.1800

  ViewVC Help
Powered by ViewVC