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

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

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

revision 112 by senkov, Sun Jun 6 20:57:28 2004 UTC revision 392 by schoenebeck, Sat Feb 19 02:40:24 2005 UTC
# Line 29  Line 29 
29  # warning Engine.h included  # warning Engine.h included
30  #endif // DEBUG_HEADERS  #endif // DEBUG_HEADERS
31    
32    #include <map>
33    
34  #include "../../common/RingBuffer.h"  #include "../../common/RingBuffer.h"
35  #include "../../common/RTELMemoryPool.h"  #include "../../common/Pool.h"
36  #include "../../common/ConditionServer.h"  #include "../../common/ConditionServer.h"
37  #include "../common/Engine.h"  #include "../common/Engine.h"
38  #include "../common/Event.h"  #include "../common/Event.h"
# Line 41  Line 43 
43    
44  #define PITCHBEND_SEMITONES             12  #define PITCHBEND_SEMITONES             12
45  #define MAX_AUDIO_VOICES                128  #define MAX_AUDIO_VOICES                128
46    #define SYSEX_BUFFER_SIZE               2048  // 2kB
47    #define VOICE_STEAL_ALGORITHM           voice_steal_algo_oldestkey  ///< @see voice_steal_algo_t for available voice stealing algorithms
48    
49  namespace LinuxSampler { namespace gig {  namespace LinuxSampler { namespace gig {
50    
51        using std::map;
52    
53      // just symbol prototyping      // just symbol prototyping
54      class Voice;      class Voice;
55      class DiskThread;      class DiskThread;
# Line 52  namespace LinuxSampler { namespace gig { Line 58  namespace LinuxSampler { namespace gig {
58      /**      /**
59       * Sampler engine for the Gigasampler format.       * Sampler engine for the Gigasampler format.
60       */       */
61      class gig::Engine : public LinuxSampler::Engine, public InstrumentConsumer {      class Engine : public LinuxSampler::Engine, public InstrumentConsumer {
62          public:          public:
63                // types
64                enum voice_steal_algo_t {
65                    voice_steal_algo_none,
66                    voice_steal_algo_keymask,
67                    voice_steal_algo_oldestkey
68                };
69    
70              // methods              // methods
71              Engine();              Engine();
72             ~Engine();             ~Engine();
73    
74              // abstract methods derived from class 'LinuxSampler::Engine'              // abstract methods derived from class 'LinuxSampler::Engine'
75              virtual void   LoadInstrument(const char* FileName, uint Instrument);              virtual void   PrepareLoadInstrument(const char* FileName, uint Instrument);
76                virtual void   LoadInstrument();
77              virtual void   Reset();              virtual void   Reset();
78              virtual void   Enable();              virtual void   Enable();
79              virtual void   Disable();              virtual void   Disable();
# Line 67  namespace LinuxSampler { namespace gig { Line 81  namespace LinuxSampler { namespace gig {
81              virtual void   SendNoteOff(uint8_t Key, uint8_t Velocity);              virtual void   SendNoteOff(uint8_t Key, uint8_t Velocity);
82              virtual void   SendPitchbend(int Pitch);              virtual void   SendPitchbend(int Pitch);
83              virtual void   SendControlChange(uint8_t Controller, uint8_t Value);              virtual void   SendControlChange(uint8_t Controller, uint8_t Value);
84                virtual void   SendSysex(void* pData, uint Size);
85              virtual float  Volume();              virtual float  Volume();
86              virtual void   Volume(float f);              virtual void   Volume(float f);
87                virtual uint   Channels();
88              virtual void   Connect(AudioOutputDevice* pAudioOut);              virtual void   Connect(AudioOutputDevice* pAudioOut);
89              virtual void   DisconnectAudioOutputDevice();              virtual void   DisconnectAudioOutputDevice();
90                virtual void   SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel);
91                virtual int    OutputChannel(uint EngineAudioChannel);
92              virtual int    RenderAudio(uint Samples);              virtual int    RenderAudio(uint Samples);
93              virtual uint   VoiceCount();              virtual uint   VoiceCount();
94              virtual uint   VoiceCountMax();              virtual uint   VoiceCountMax();
# Line 83  namespace LinuxSampler { namespace gig { Line 101  namespace LinuxSampler { namespace gig {
101              virtual String Version();              virtual String Version();
102              virtual String EngineName();              virtual String EngineName();
103              virtual String InstrumentFileName();              virtual String InstrumentFileName();
104                virtual String InstrumentName();
105              virtual int    InstrumentIndex();              virtual int    InstrumentIndex();
106                virtual int    InstrumentStatus();
107    
108              // abstract methods derived from interface class 'InstrumentConsumer'              // abstract methods derived from interface class 'InstrumentConsumer'
109              virtual void ResourceToBeUpdated(::gig::Instrument* pResource, void*& pUpdateArg);              virtual void ResourceToBeUpdated(::gig::Instrument* pResource, void*& pUpdateArg);
110              virtual void ResourceUpdated(::gig::Instrument* pOldResource, ::gig::Instrument* pNewResource, void* pUpdateArg);              virtual void ResourceUpdated(::gig::Instrument* pOldResource, ::gig::Instrument* pNewResource, void* pUpdateArg);
111          protected:          //protected:
112              struct midi_key_info_t {              struct midi_key_info_t {
113                  RTEList<Voice>* pActiveVoices; ///< Contains the active voices associated with the MIDI key.                  RTList<Voice>*  pActiveVoices;  ///< Contains the active voices associated with the MIDI key.
114                  bool            KeyPressed;    ///< Is true if the respective MIDI key is currently pressed.                  bool            KeyPressed;     ///< Is true if the respective MIDI key is currently pressed.
115                  bool            Active;        ///< If the key contains active voices.                  bool            Active;         ///< If the key contains active voices.
116                  uint*           pSelf;         ///< hack to allow fast deallocation of the key from the list of active keys                  bool            ReleaseTrigger; ///< If we have to launch release triggered voice(s) when the key is released
117                  RTEList<Event>* pEvents;       ///< Key specific events (only Note-on, Note-off and sustain pedal currently)                  Pool<uint>::Iterator itSelf;         ///< hack to allow fast deallocation of the key from the list of active keys
118                    RTList<Event>*  pEvents;        ///< Key specific events (only Note-on, Note-off and sustain pedal currently)
119              };              };
120    
121              static InstrumentResourceManager Instruments;              static InstrumentResourceManager Instruments;
122    
123              AudioOutputDevice*      pAudioOutputDevice;              AudioOutputDevice*      pAudioOutputDevice;
124                float*                  pOutputLeft;           ///< Audio output channel buffer (left)
125                float*                  pOutputRight;          ///< Audio output channel buffer (right)
126                int                     AudioDeviceChannelLeft;  ///< audio device channel number to which the left channel is connected to
127                int                     AudioDeviceChannelRight; ///< audio device channel number to which the right channel is connected to
128                uint                    SampleRate;            ///< Sample rate of the engines output audio signal (in Hz)
129                uint                    MaxSamplesPerCycle;    ///< Size of each audio output buffer
130              DiskThread*             pDiskThread;              DiskThread*             pDiskThread;
131              uint8_t                 ControllerTable[128];  ///< Reflects the current values (0-127) of all MIDI controllers for this engine / sampler channel.              uint8_t                 ControllerTable[128];  ///< Reflects the current values (0-127) of all MIDI controllers for this engine / sampler channel.
132              RingBuffer<Event>*      pEventQueue;           ///< Input event queue.              RingBuffer<Event>*      pEventQueue;           ///< Input event queue.
133                RingBuffer<uint8_t>*    pSysexBuffer;          ///< Input buffer for MIDI system exclusive messages.
134              midi_key_info_t         pMIDIKeyInfo[128];     ///< Contains all active voices sorted by MIDI key number and other informations to the respective MIDI key              midi_key_info_t         pMIDIKeyInfo[128];     ///< Contains all active voices sorted by MIDI key number and other informations to the respective MIDI key
135              RTELMemoryPool<Voice>*  pVoicePool;            ///< Contains all voices that can be activated.              Pool<Voice>*            pVoicePool;            ///< Contains all voices that can be activated.
136              RTELMemoryPool<uint>*   pActiveKeys;           ///< Holds all keys in it's allocation list with active voices.              Pool<uint>*             pActiveKeys;           ///< Holds all keys in it's allocation list with active voices.
137              RTELMemoryPool<Event>*  pEventPool;            ///< Contains all Event objects that can be used.              Pool<Event>*            pEventPool;            ///< Contains all Event objects that can be used.
138              EventGenerator*         pEventGenerator;              EventGenerator*         pEventGenerator;
139              RTEList<Event>*         pEvents;               ///< All events for the current audio fragment.              RTList<Event>*          pVoiceStealingQueue;   ///< All voice-launching events which had to be postponed due to free voice shortage.
140              RTEList<Event>*         pCCEvents;             ///< All control change events for the current audio fragment.              RTList<Event>*          pEvents;               ///< All events for the current audio fragment.
141              RTEList<Event>*         pSynthesisEvents[Event::destination_count];     ///< Events directly affecting synthesis parameter (like pitch, volume and filter).              RTList<Event>*          pCCEvents;             ///< All control change events for the current audio fragment.
142                RTList<Event>*          pSynthesisEvents[Event::destination_count];     ///< Events directly affecting synthesis parameter (like pitch, volume and filter).
143              float*                  pSynthesisParameters[Event::destination_count]; ///< Matrix with final synthesis parameters for the current audio fragment which will be used in the main synthesis loop.              float*                  pSynthesisParameters[Event::destination_count]; ///< Matrix with final synthesis parameters for the current audio fragment which will be used in the main synthesis loop.
144              biquad_param_t*         pBasicFilterParameters; ///< Biquad parameters of the basic bandpass filter.              biquad_param_t*         pBasicFilterParameters; ///< Biquad parameters of the basic bandpass filter.
145              biquad_param_t*         pMainFilterParameters;  ///< Main biquad parameters of the individual filter (lowpass / bandpass / highpass).              biquad_param_t*         pMainFilterParameters;  ///< Main biquad parameters of the individual filter (lowpass / bandpass / highpass).
146                map<uint,uint*>         ActiveKeyGroups;        ///< Contains active keys (in case they belong to a key group) ordered by key group ID.
147              RIFF::File*             pRIFF;              RIFF::File*             pRIFF;
148              ::gig::File*            pGig;              ::gig::File*            pGig;
149              ::gig::Instrument*      pInstrument;              ::gig::Instrument*      pInstrument;
150              bool                    SustainPedal;          ///< true if sustain pedal is down              bool                    SustainPedal;          ///< true if sustain pedal is down
151              double                  GlobalVolume;          ///< overall volume (a value < 1.0 means attenuation, a value > 1.0 means amplification)              double                  GlobalVolume;          ///< overall volume (a value < 1.0 means attenuation, a value > 1.0 means amplification)
152              int                     Pitch;                 ///< Current (absolute) MIDI pitch value.              int                     Pitch;                 ///< Current (absolute) MIDI pitch value.
153                int                     CurrentKeyDimension;   ///< Current value (0-127) for the keyboard dimension, altered by pressing a keyswitching key.
154              int                     ActiveVoiceCount;      ///< number of currently active voices              int                     ActiveVoiceCount;      ///< number of currently active voices
155              int                     ActiveVoiceCountMax;   ///< the maximum voice usage since application start              int                     ActiveVoiceCountMax;   ///< the maximum voice usage since application start
156              bool                    SuspensionRequested;              bool                    SuspensionRequested;
157              ConditionServer         EngineDisabled;              ConditionServer         EngineDisabled;
158              String                  InstrumentFile;              String                  InstrumentFile;
159              int                     InstrumentIdx;              int                     InstrumentIdx;
160                String                  InstrumentIdxName;
161              void ProcessNoteOn(Event* pNoteOnEvent);              int                     InstrumentStat;
162              void ProcessNoteOff(Event* pNoteOffEvent);              int8_t                  ScaleTuning[12];       ///< contains optional detune factors (-64..+63 cents) for all 12 semitones of an octave
163              void ProcessPitchbend(Event* pPitchbendEvent);              RTList<Voice>::Iterator itLastStolenVoice;      ///< Only for voice stealing: points to the last voice which was theft in current audio fragment, NULL otherwise.
164              void ProcessControlChange(Event* pControlChangeEvent);              RTList<uint>::Iterator  iuiLastStolenKey;      ///< Only for voice stealing: key number of last key on which the last voice was theft in current audio fragment, NULL otherwise.
165              void KillVoice(Voice* pVoice);              int                     MaxFadeOutPos;         ///< The last position in an audio fragment to allow a instant fade out (e.g. for voice stealing) without leading to clicks.
166    
167                void ProcessNoteOn(Pool<Event>::Iterator& itNoteOnEvent);
168                void ProcessNoteOff(Pool<Event>::Iterator& itNoteOffEvent);
169                void ProcessPitchbend(Pool<Event>::Iterator& itPitchbendEvent);
170                void ProcessControlChange(Pool<Event>::Iterator& itControlChangeEvent);
171                void ProcessSysex(Pool<Event>::Iterator& itSysexEvent);
172                Pool<Voice>::Iterator LaunchVoice(Pool<Event>::Iterator& itNoteOnEvent, int iLayer, bool ReleaseTriggerVoice, bool VoiceStealing);
173                void StealVoice(Pool<Event>::Iterator& itNoteOnEvent);
174                void FreeVoice(Pool<Voice>::Iterator& itVoice);
175                void FreeKey(midi_key_info_t* pKey);
176              void ResetSynthesisParameters(Event::destination_t dst, float val);              void ResetSynthesisParameters(Event::destination_t dst, float val);
177              void ResetInternal();              void ResetInternal();
178    
# Line 143  namespace LinuxSampler { namespace gig { Line 184  namespace LinuxSampler { namespace gig {
184              friend class VCOManipulator;              friend class VCOManipulator;
185              friend class InstrumentResourceManager;              friend class InstrumentResourceManager;
186          private:          private:
187              void DisableAndLock();              void    DisableAndLock();
188                uint8_t GSCheckSum(const RingBuffer<uint8_t>::NonVolatileReader AddrReader, uint DataSize);
189                void    AdjustScale(int8_t ScaleTunes[12]);
190      };      };
191    
192  }} // namespace LinuxSampler::gig  }} // namespace LinuxSampler::gig

Legend:
Removed from v.112  
changed lines
  Added in v.392

  ViewVC Help
Powered by ViewVC