/[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 831 by persson, Sat Jan 28 16:55:30 2006 UTC revision 970 by schoenebeck, Wed Dec 6 22:28:17 2006 UTC
# Line 97  namespace LinuxSampler { namespace gig { Line 97  namespace LinuxSampler { namespace gig {
97          pAudioOutputDevice = NULL;          pAudioOutputDevice = NULL;
98          pDiskThread        = NULL;          pDiskThread        = NULL;
99          pEventGenerator    = NULL;          pEventGenerator    = NULL;
100          pSysexBuffer       = new RingBuffer<uint8_t>(CONFIG_SYSEX_BUFFER_SIZE, 0);          pSysexBuffer       = new RingBuffer<uint8_t,false>(CONFIG_SYSEX_BUFFER_SIZE, 0);
101          pEventQueue        = new RingBuffer<Event>(CONFIG_MAX_EVENTS_PER_FRAGMENT, 0);          pEventQueue        = new RingBuffer<Event,false>(CONFIG_MAX_EVENTS_PER_FRAGMENT, 0);
102          pEventPool         = new Pool<Event>(CONFIG_MAX_EVENTS_PER_FRAGMENT);          pEventPool         = new Pool<Event>(CONFIG_MAX_EVENTS_PER_FRAGMENT);
103          pVoicePool         = new Pool<Voice>(CONFIG_MAX_VOICES);          pVoicePool         = new Pool<Voice>(CONFIG_MAX_VOICES);
104          pVoiceStealingQueue = new RTList<Event>(pEventPool);          pVoiceStealingQueue = new RTList<Event>(pEventPool);
# Line 116  namespace LinuxSampler { namespace gig { Line 116  namespace LinuxSampler { namespace gig {
116       * Destructor       * Destructor
117       */       */
118      Engine::~Engine() {      Engine::~Engine() {
119            MidiInputPort::RemoveSysexListener(this);
120          if (pDiskThread) {          if (pDiskThread) {
121              dmsg(1,("Stopping disk thread..."));              dmsg(1,("Stopping disk thread..."));
122              pDiskThread->StopThread();              pDiskThread->StopThread();
# Line 165  namespace LinuxSampler { namespace gig { Line 166  namespace LinuxSampler { namespace gig {
166    
167      /**      /**
168       *  Reset all voices and disk thread and clear input event queue and all       *  Reset all voices and disk thread and clear input event queue and all
169       *  control and status variables. This method is not thread safe!       *  control and status variables. This method is protected by a mutex.
170       */       */
171      void Engine::ResetInternal() {      void Engine::ResetInternal() {
172            ResetInternalMutex.Lock();
173    
174            // make sure that the engine does not get any sysex messages
175            // while it's reseting
176            bool sysexDisabled = MidiInputPort::RemoveSysexListener(this);
177          ActiveVoiceCount    = 0;          ActiveVoiceCount    = 0;
178          ActiveVoiceCountMax = 0;          ActiveVoiceCountMax = 0;
179    
# Line 191  namespace LinuxSampler { namespace gig { Line 197  namespace LinuxSampler { namespace gig {
197          // delete all input events          // delete all input events
198          pEventQueue->init();          pEventQueue->init();
199          pSysexBuffer->init();          pSysexBuffer->init();
200            if (sysexDisabled) MidiInputPort::AddSysexListener(this);
201            ResetInternalMutex.Unlock();
202      }      }
203    
204      /**      /**
# Line 220  namespace LinuxSampler { namespace gig { Line 228  namespace LinuxSampler { namespace gig {
228          }          }
229          catch (AudioOutputException e) {          catch (AudioOutputException e) {
230              String msg = "Audio output device unable to provide 2 audio channels, cause: " + e.Message();              String msg = "Audio output device unable to provide 2 audio channels, cause: " + e.Message();
231              throw LinuxSamplerException(msg);              throw Exception(msg);
232          }          }
233    
234          this->MaxSamplesPerCycle = pAudioOutputDevice->MaxSamplesPerCycle();          this->MaxSamplesPerCycle = pAudioOutputDevice->MaxSamplesPerCycle();
# Line 298  namespace LinuxSampler { namespace gig { Line 306  namespace LinuxSampler { namespace gig {
306       *                  current audio cycle       *                  current audio cycle
307       */       */
308      void Engine::ImportEvents(uint Samples) {      void Engine::ImportEvents(uint Samples) {
309          RingBuffer<Event>::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader();          RingBuffer<Event,false>::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader();
310          Event* pEvent;          Event* pEvent;
311          while (true) {          while (true) {
312              // get next event from input event queue              // get next event from input event queue
# Line 321  namespace LinuxSampler { namespace gig { Line 329  namespace LinuxSampler { namespace gig {
329      }      }
330    
331      /**      /**
332       *  Let this engine proceed to render the given amount of sample points. The       * Let this engine proceed to render the given amount of sample points.
333       *  calculated audio data of all voices of this engine will be placed into       * The engine will iterate through all engine channels and render audio
334       *  the engine's audio sum buffer which has to be copied and eventually be       * for each engine channel independently. The calculated audio data of
335       *  converted to the appropriate value range by the audio output class (e.g.       * all voices of each engine channel will be placed into the audio sum
336       *  AlsaIO or JackIO) right after.       * buffers of the respective audio output device, connected to the
337         * respective engine channel.
338       *       *
339       *  @param Samples - number of sample points to be rendered       *  @param Samples - number of sample points to be rendered
340       *  @returns       0 on success       *  @returns       0 on success
341       */       */
342      int Engine::RenderAudio(uint Samples) {      int Engine::RenderAudio(uint Samples) {
343          dmsg(5,("RenderAudio(Samples=%d)\n", Samples));          dmsg(7,("RenderAudio(Samples=%d)\n", Samples));
344    
345          // return if engine disabled          // return if engine disabled
346          if (EngineDisabled.Pop()) {          if (EngineDisabled.Pop()) {
# Line 634  namespace LinuxSampler { namespace gig { Line 643  namespace LinuxSampler { namespace gig {
643          {          {
644              const ::gig::Instrument* pInstrument = pEngineChannel->pInstrument;              const ::gig::Instrument* pInstrument = pEngineChannel->pInstrument;
645              if (key >= pInstrument->DimensionKeyRange.low && key <= pInstrument->DimensionKeyRange.high)              if (key >= pInstrument->DimensionKeyRange.low && key <= pInstrument->DimensionKeyRange.high)
646                  pEngineChannel->CurrentKeyDimension = ((key - pInstrument->DimensionKeyRange.low) * 128) /                  pEngineChannel->CurrentKeyDimension = float(key - pInstrument->DimensionKeyRange.low) /
647                      (pInstrument->DimensionKeyRange.high - pInstrument->DimensionKeyRange.low + 1);                      (pInstrument->DimensionKeyRange.high - pInstrument->DimensionKeyRange.low + 1);
648          }          }
649    
# Line 862  namespace LinuxSampler { namespace gig { Line 871  namespace LinuxSampler { namespace gig {
871                      DimValues[i] = itNoteOnEvent->Param.Note.Velocity;                      DimValues[i] = itNoteOnEvent->Param.Note.Velocity;
872                      break;                      break;
873                  case ::gig::dimension_channelaftertouch:                  case ::gig::dimension_channelaftertouch:
874                      DimValues[i] = 0; //TODO: we currently ignore this dimension                      DimValues[i] = pEngineChannel->ControllerTable[128];
875                      break;                      break;
876                  case ::gig::dimension_releasetrigger:                  case ::gig::dimension_releasetrigger:
877                      VoiceType = (ReleaseTriggerVoice) ? Voice::type_release_trigger : (!iLayer) ? Voice::type_release_trigger_required : Voice::type_normal;                      VoiceType = (ReleaseTriggerVoice) ? Voice::type_release_trigger : (!iLayer) ? Voice::type_release_trigger_required : Voice::type_normal;
878                      DimValues[i] = (uint) ReleaseTriggerVoice;                      DimValues[i] = (uint) ReleaseTriggerVoice;
879                      break;                      break;
880                  case ::gig::dimension_keyboard:                  case ::gig::dimension_keyboard:
881                      DimValues[i] = (uint) pEngineChannel->CurrentKeyDimension;                      DimValues[i] = (uint) (pEngineChannel->CurrentKeyDimension * pRegion->pDimensionDefinitions[i].zones);
882                      break;                      break;
883                  case ::gig::dimension_roundrobin:                  case ::gig::dimension_roundrobin:
884                      DimValues[i] = (uint) pEngineChannel->pMIDIKeyInfo[MIDIKey].RoundRobinIndex; // incremented for each note on                      DimValues[i] = (uint) pEngineChannel->pMIDIKeyInfo[MIDIKey].RoundRobinIndex; // incremented for each note on
# Line 1234  namespace LinuxSampler { namespace gig { Line 1243  namespace LinuxSampler { namespace gig {
1243              }              }
1244              case 7: { // volume              case 7: { // volume
1245                  //TODO: not sample accurate yet                  //TODO: not sample accurate yet
1246                  pEngineChannel->GlobalVolume = VolumeCurve[itControlChangeEvent->Param.CC.Value] *  CONFIG_GLOBAL_ATTENUATION;                  pEngineChannel->MidiVolume = VolumeCurve[itControlChangeEvent->Param.CC.Value];
1247                  pEngineChannel->bStatusChanged = true; // engine channel status has changed, so set notify flag                  pEngineChannel->bStatusChanged = true; // engine channel status has changed, so set notify flag
1248                  break;                  break;
1249              }              }
# Line 1349  namespace LinuxSampler { namespace gig { Line 1358  namespace LinuxSampler { namespace gig {
1358                  break;                  break;
1359              }              }
1360              case 123: { // all notes off              case 123: { // all notes off
1361                    #if CONFIG_PROCESS_ALL_NOTES_OFF
1362                  ReleaseAllVoices(pEngineChannel, itControlChangeEvent);                  ReleaseAllVoices(pEngineChannel, itControlChangeEvent);
1363                    #endif // CONFIG_PROCESS_ALL_NOTES_OFF
1364                  break;                  break;
1365              }              }
1366              case 126: { // mono mode on              case 126: { // mono mode on
# Line 1371  namespace LinuxSampler { namespace gig { Line 1382  namespace LinuxSampler { namespace gig {
1382       *  @param itSysexEvent - sysex data size and time stamp of the sysex event       *  @param itSysexEvent - sysex data size and time stamp of the sysex event
1383       */       */
1384      void Engine::ProcessSysex(Pool<Event>::Iterator& itSysexEvent) {      void Engine::ProcessSysex(Pool<Event>::Iterator& itSysexEvent) {
1385          RingBuffer<uint8_t>::NonVolatileReader reader = pSysexBuffer->get_non_volatile_reader();          RingBuffer<uint8_t,false>::NonVolatileReader reader = pSysexBuffer->get_non_volatile_reader();
1386    
1387          uint8_t exclusive_status, id;          uint8_t exclusive_status, id;
1388          if (!reader.pop(&exclusive_status)) goto free_sysex_data;          if (!reader.pop(&exclusive_status)) goto free_sysex_data;
# Line 1390  namespace LinuxSampler { namespace gig { Line 1401  namespace LinuxSampler { namespace gig {
1401    
1402                  // command address                  // command address
1403                  uint8_t addr[3]; // 2 byte addr MSB, followed by 1 byte addr LSB)                  uint8_t addr[3]; // 2 byte addr MSB, followed by 1 byte addr LSB)
1404                  const RingBuffer<uint8_t>::NonVolatileReader checksum_reader = reader; // so we can calculate the check sum later                  const RingBuffer<uint8_t,false>::NonVolatileReader checksum_reader = reader; // so we can calculate the check sum later
1405                  if (reader.read(&addr[0], 3) != 3) goto free_sysex_data;                  if (reader.read(&addr[0], 3) != 3) goto free_sysex_data;
1406                  if (addr[0] == 0x40 && addr[1] == 0x00) { // System Parameters                  if (addr[0] == 0x40 && addr[1] == 0x00) { // System Parameters
1407                      dmsg(3,("\tSystem Parameter\n"));                      dmsg(3,("\tSystem Parameter\n"));
# Line 1437  namespace LinuxSampler { namespace gig { Line 1448  namespace LinuxSampler { namespace gig {
1448       *                     question       *                     question
1449       * @param DataSize   - size of the GS message data (in bytes)       * @param DataSize   - size of the GS message data (in bytes)
1450       */       */
1451      uint8_t Engine::GSCheckSum(const RingBuffer<uint8_t>::NonVolatileReader AddrReader, uint DataSize) {      uint8_t Engine::GSCheckSum(const RingBuffer<uint8_t,false>::NonVolatileReader AddrReader, uint DataSize) {
1452          RingBuffer<uint8_t>::NonVolatileReader reader = AddrReader;          RingBuffer<uint8_t,false>::NonVolatileReader reader = AddrReader;
1453          uint bytes = 3 /*addr*/ + DataSize;          uint bytes = 3 /*addr*/ + DataSize;
1454          uint8_t addr_and_data[bytes];          uint8_t addr_and_data[bytes];
1455          reader.read(&addr_and_data[0], bytes);          reader.read(&addr_and_data[0], bytes);
# Line 1557  namespace LinuxSampler { namespace gig { Line 1568  namespace LinuxSampler { namespace gig {
1568      }      }
1569    
1570      String Engine::Version() {      String Engine::Version() {
1571          String s = "$Revision: 1.58 $";          String s = "$Revision: 1.67 $";
1572          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
1573      }      }
1574    
1575        InstrumentManager* Engine::GetInstrumentManager() {
1576            return &instruments;
1577        }
1578    
1579      // static constant initializers      // static constant initializers
1580      const float* Engine::VolumeCurve(InitVolumeCurve());      const float* Engine::VolumeCurve(InitVolumeCurve());
1581      const float* Engine::PanCurve(InitPanCurve());      const float* Engine::PanCurve(InitPanCurve());
1582        const float* Engine::CrossfadeCurve(InitCrossfadeCurve());
1583    
1584      float* Engine::InitVolumeCurve() {      float* Engine::InitVolumeCurve() {
1585          // line-segment approximation          // line-segment approximation
# Line 1584  namespace LinuxSampler { namespace gig { Line 1600  namespace LinuxSampler { namespace gig {
1600          return InitCurve(segments, 129);          return InitCurve(segments, 129);
1601      }      }
1602    
1603        float* Engine::InitCrossfadeCurve() {
1604            // line-segment approximation
1605            const float segments[] = {
1606                0, 0, 1, 0.03, 10, 0.1, 51, 0.58, 127, 1
1607            };
1608            return InitCurve(segments);
1609        }
1610    
1611      float* Engine::InitCurve(const float* segments, int size) {      float* Engine::InitCurve(const float* segments, int size) {
1612          float* y = new float[size];          float* y = new float[size];
1613          for (int x = 0 ; x < size ; x++) {          for (int x = 0 ; x < size ; x++) {

Legend:
Removed from v.831  
changed lines
  Added in v.970

  ViewVC Help
Powered by ViewVC