/[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 53 by schoenebeck, Mon Apr 26 17:15:51 2004 UTC revision 225 by schoenebeck, Sun Aug 22 14:46:47 2004 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003 by Benno Senoner and Christian Schoenebeck         *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *                                                                         *   *                                                                         *
7   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
8   *   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 59  namespace LinuxSampler { namespace gig { Line 59  namespace LinuxSampler { namespace gig {
59          pVoicePool->clear();          pVoicePool->clear();
60    
61          pSynthesisParameters[0] = NULL; // we allocate when an audio device is connected          pSynthesisParameters[0] = NULL; // we allocate when an audio device is connected
62            pBasicFilterParameters  = NULL;
63            pMainFilterParameters   = NULL;
64    
65            InstrumentIdx = -1;
66            InstrumentStat = -1;
67    
68            AudioDeviceChannelLeft  = -1;
69            AudioDeviceChannelRight = -1;
70    
71          ResetInternal();          ResetInternal();
72      }      }
# Line 85  namespace LinuxSampler { namespace gig { Line 93  namespace LinuxSampler { namespace gig {
93          if (pVoicePool)  delete pVoicePool;          if (pVoicePool)  delete pVoicePool;
94          if (pActiveKeys) delete pActiveKeys;          if (pActiveKeys) delete pActiveKeys;
95          if (pEventGenerator) delete pEventGenerator;          if (pEventGenerator) delete pEventGenerator;
96            if (pMainFilterParameters) delete[] pMainFilterParameters;
97            if (pBasicFilterParameters) delete[] pBasicFilterParameters;
98          if (pSynthesisParameters[0]) delete[] pSynthesisParameters[0];          if (pSynthesisParameters[0]) delete[] pSynthesisParameters[0];
99      }      }
100    
101      void Engine::Enable() {      void Engine::Enable() {
102          dmsg(3,("gig::Engine: enabling\n"));          dmsg(3,("gig::Engine: enabling\n"));
103          EngineDisabled.PushAndUnlock(false, 2); // set condition object 'EngineDisabled' to false (wait max. 2s)          EngineDisabled.PushAndUnlock(false, 2); // set condition object 'EngineDisabled' to false (wait max. 2s)
104          dmsg(1,("gig::Engine: enabled (val=%d)\n", EngineDisabled.GetUnsafe()));          dmsg(3,("gig::Engine: enabled (val=%d)\n", EngineDisabled.GetUnsafe()));
105      }      }
106    
107      void Engine::Disable() {      void Engine::Disable() {
# Line 142  namespace LinuxSampler { namespace gig { Line 152  namespace LinuxSampler { namespace gig {
152          SustainPedal        = false;          SustainPedal        = false;
153          ActiveVoiceCount    = 0;          ActiveVoiceCount    = 0;
154          ActiveVoiceCountMax = 0;          ActiveVoiceCountMax = 0;
155            GlobalVolume        = 1.0;
156    
157          // set all MIDI controller values to zero          // set all MIDI controller values to zero
158          memset(ControllerTable, 0x00, 128);          memset(ControllerTable, 0x00, 128);
# Line 191  namespace LinuxSampler { namespace gig { Line 202  namespace LinuxSampler { namespace gig {
202              Instruments.HandBack(pInstrument, this);              Instruments.HandBack(pInstrument, this);
203          }          }
204    
205            InstrumentFile = FileName;
206            InstrumentIdx = Instrument;
207            InstrumentStat = 0;
208    
209          // request gig instrument from instrument manager          // request gig instrument from instrument manager
210          try {          try {
211              instrument_id_t instrid;              instrument_id_t instrid;
# Line 198  namespace LinuxSampler { namespace gig { Line 213  namespace LinuxSampler { namespace gig {
213              instrid.iInstrument = Instrument;              instrid.iInstrument = Instrument;
214              pInstrument = Instruments.Borrow(instrid, this);              pInstrument = Instruments.Borrow(instrid, this);
215              if (!pInstrument) {              if (!pInstrument) {
216                    InstrumentStat = -1;
217                  dmsg(1,("no instrument loaded!!!\n"));                  dmsg(1,("no instrument loaded!!!\n"));
218                  exit(EXIT_FAILURE);                  exit(EXIT_FAILURE);
219              }              }
220          }          }
221          catch (RIFF::Exception e) {          catch (RIFF::Exception e) {
222                InstrumentStat = -2;
223              String msg = "gig::Engine error: Failed to load instrument, cause: " + e.Message;              String msg = "gig::Engine error: Failed to load instrument, cause: " + e.Message;
224              throw LinuxSamplerException(msg);              throw LinuxSamplerException(msg);
225          }          }
226          catch (InstrumentResourceManagerException e) {          catch (InstrumentResourceManagerException e) {
227                InstrumentStat = -3;
228              String msg = "gig::Engine error: Failed to load instrument, cause: " + e.Message();              String msg = "gig::Engine error: Failed to load instrument, cause: " + e.Message();
229              throw LinuxSamplerException(msg);              throw LinuxSamplerException(msg);
230          }          }
231          catch (...) {          catch (...) {
232                InstrumentStat = -4;
233              throw LinuxSamplerException("gig::Engine error: Failed to load instrument, cause: Unknown exception while trying to parse gig file.");              throw LinuxSamplerException("gig::Engine error: Failed to load instrument, cause: Unknown exception while trying to parse gig file.");
234          }          }
235    
236            InstrumentStat = 100;
237    
238          // inform audio driver for the need of two channels          // inform audio driver for the need of two channels
239          try {          try {
240              if (pAudioOutputDevice) pAudioOutputDevice->AcquireChannels(2); // gig Engine only stereo              if (pAudioOutputDevice) pAudioOutputDevice->AcquireChannels(2); // gig Engine only stereo
# Line 261  namespace LinuxSampler { namespace gig { Line 282  namespace LinuxSampler { namespace gig {
282              throw LinuxSamplerException(msg);              throw LinuxSamplerException(msg);
283          }          }
284    
285            this->AudioDeviceChannelLeft  = 0;
286            this->AudioDeviceChannelRight = 1;
287            this->pOutputLeft             = pAudioOutputDevice->Channel(0)->Buffer();
288            this->pOutputRight            = pAudioOutputDevice->Channel(1)->Buffer();
289            this->MaxSamplesPerCycle      = pAudioOutputDevice->MaxSamplesPerCycle();
290            this->SampleRate              = pAudioOutputDevice->SampleRate();
291    
292          // (re)create disk thread          // (re)create disk thread
293          if (this->pDiskThread) {          if (this->pDiskThread) {
294              this->pDiskThread->StopThread();              this->pDiskThread->StopThread();
# Line 274  namespace LinuxSampler { namespace gig { Line 302  namespace LinuxSampler { namespace gig {
302    
303          for (Voice* pVoice = pVoicePool->alloc(); pVoice; pVoice = pVoicePool->alloc()) {          for (Voice* pVoice = pVoicePool->alloc(); pVoice; pVoice = pVoicePool->alloc()) {
304              pVoice->pDiskThread = this->pDiskThread;              pVoice->pDiskThread = this->pDiskThread;
             pVoice->SetOutput(pAudioOut);  
305              dmsg(3,("d"));              dmsg(3,("d"));
306          }          }
307          pVoicePool->clear();          pVoicePool->clear();
# Line 289  namespace LinuxSampler { namespace gig { Line 316  namespace LinuxSampler { namespace gig {
316          for (int dst = 1; dst < Event::destination_count; dst++)          for (int dst = 1; dst < Event::destination_count; dst++)
317              pSynthesisParameters[dst] = pSynthesisParameters[dst - 1] + pAudioOut->MaxSamplesPerCycle();              pSynthesisParameters[dst] = pSynthesisParameters[dst - 1] + pAudioOut->MaxSamplesPerCycle();
318    
319            // (re)allocate biquad filter parameter sequence
320            if (pBasicFilterParameters) delete[] pBasicFilterParameters;
321            if (pMainFilterParameters)  delete[] pMainFilterParameters;
322            pBasicFilterParameters = new biquad_param_t[pAudioOut->MaxSamplesPerCycle()];
323            pMainFilterParameters  = new biquad_param_t[pAudioOut->MaxSamplesPerCycle()];
324    
325          dmsg(1,("Starting disk thread..."));          dmsg(1,("Starting disk thread..."));
326          pDiskThread->StartThread();          pDiskThread->StartThread();
327          dmsg(1,("OK\n"));          dmsg(1,("OK\n"));
# Line 306  namespace LinuxSampler { namespace gig { Line 339  namespace LinuxSampler { namespace gig {
339              AudioOutputDevice* olddevice = pAudioOutputDevice;              AudioOutputDevice* olddevice = pAudioOutputDevice;
340              pAudioOutputDevice = NULL;              pAudioOutputDevice = NULL;
341              olddevice->Disconnect(this);              olddevice->Disconnect(this);
342                AudioDeviceChannelLeft  = -1;
343                AudioDeviceChannelRight = -1;
344          }          }
345      }      }
346    
# Line 635  namespace LinuxSampler { namespace gig { Line 670  namespace LinuxSampler { namespace gig {
670       */       */
671      void Engine::ResetSynthesisParameters(Event::destination_t dst, float val) {      void Engine::ResetSynthesisParameters(Event::destination_t dst, float val) {
672          int maxsamples = pAudioOutputDevice->MaxSamplesPerCycle();          int maxsamples = pAudioOutputDevice->MaxSamplesPerCycle();
673          for (int i = 0; i < maxsamples; i++) pSynthesisParameters[dst][i] = val;          float* m = &pSynthesisParameters[dst][0];
674            for (int i = 0; i < maxsamples; i += 4) {
675               m[i]   = val;
676               m[i+1] = val;
677               m[i+2] = val;
678               m[i+3] = val;
679            }
680      }      }
681    
682      float Engine::Volume() {      float Engine::Volume() {
# Line 646  namespace LinuxSampler { namespace gig { Line 687  namespace LinuxSampler { namespace gig {
687          GlobalVolume = f;          GlobalVolume = f;
688      }      }
689    
690        uint Engine::Channels() {
691            return 2;
692        }
693    
694        void Engine::SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel) {
695            AudioChannel* pChannel = pAudioOutputDevice->Channel(AudioDeviceChannel);
696            if (!pChannel) throw AudioOutputException("Invalid audio output device channel " + ToString(AudioDeviceChannel));
697            switch (EngineAudioChannel) {
698                case 0: // left output channel
699                    pOutputLeft = pChannel->Buffer();
700                    AudioDeviceChannelLeft = AudioDeviceChannel;
701                    break;
702                case 1: // right output channel
703                    pOutputRight = pChannel->Buffer();
704                    AudioDeviceChannelRight = AudioDeviceChannel;
705                    break;
706                default:
707                    throw AudioOutputException("Invalid engine audio channel " + ToString(EngineAudioChannel));
708            }
709        }
710    
711        int Engine::OutputChannel(uint EngineAudioChannel) {
712            switch (EngineAudioChannel) {
713                case 0: // left channel
714                    return AudioDeviceChannelLeft;
715                case 1: // right channel
716                    return AudioDeviceChannelRight;
717                default:
718                    throw AudioOutputException("Invalid engine audio channel " + ToString(EngineAudioChannel));
719            }
720        }
721    
722      uint Engine::VoiceCount() {      uint Engine::VoiceCount() {
723          return ActiveVoiceCount;          return ActiveVoiceCount;
724      }      }
# Line 674  namespace LinuxSampler { namespace gig { Line 747  namespace LinuxSampler { namespace gig {
747          return pDiskThread->GetBufferFillPercentage();          return pDiskThread->GetBufferFillPercentage();
748      }      }
749    
750        String Engine::EngineName() {
751            return "GigEngine";
752        }
753    
754        String Engine::InstrumentFileName() {
755            return InstrumentFile;
756        }
757    
758        int Engine::InstrumentIndex() {
759            return InstrumentIdx;
760        }
761    
762        int Engine::InstrumentStatus() {
763            return InstrumentStat;
764        }
765    
766      String Engine::Description() {      String Engine::Description() {
767          return "Gigasampler Engine";          return "Gigasampler Engine";
768      }      }
769    
770      String Engine::Version() {      String Engine::Version() {
771          return "0.0.1-0cvs20040423";          String s = "$Revision: 1.8 $";
772            return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword
773      }      }
774    
775  }} // namespace LinuxSampler::gig  }} // namespace LinuxSampler::gig

Legend:
Removed from v.53  
changed lines
  Added in v.225

  ViewVC Help
Powered by ViewVC