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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 250 - (hide annotations) (download) (as text)
Mon Sep 20 00:31:13 2004 UTC (19 years, 6 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 11293 byte(s)
* added first two experimental voice stealing algorithms ('oldestkey' -
which just steals the oldest voice on the oldest key and 'keymask' - which
tries to pick the oldest voice on the same key where the new voice should
be spawned, if it fails it behaves like 'oldestkey'), the desired algorithm
can be selected at compile time (see Engine.h) will be configurable via
LSCP soon though

1 schoenebeck 53 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5 schoenebeck 56 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 53 * *
7     * 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 *
9     * the Free Software Foundation; either version 2 of the License, or *
10     * (at your option) any later version. *
11     * *
12     * This program is distributed in the hope that it will be useful, *
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15     * GNU General Public License for more details. *
16     * *
17     * You should have received a copy of the GNU General Public License *
18     * along with this program; if not, write to the Free Software *
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
20     * MA 02111-1307 USA *
21     ***************************************************************************/
22    
23     #ifndef __LS_GIG_ENGINE_H__
24     #define __LS_GIG_ENGINE_H__
25    
26     #include "../../common/global.h"
27    
28     #if DEBUG_HEADERS
29     # warning Engine.h included
30     #endif // DEBUG_HEADERS
31    
32 schoenebeck 239 #include <map>
33    
34 schoenebeck 53 #include "../../common/RingBuffer.h"
35     #include "../../common/RTELMemoryPool.h"
36     #include "../../common/ConditionServer.h"
37     #include "../common/Engine.h"
38     #include "../common/Event.h"
39 schoenebeck 80 #include "../common/BiquadFilter.h"
40 schoenebeck 53 #include "../../lib/fileloader/libgig/gig.h"
41     #include "InstrumentResourceManager.h"
42     #include "../../network/lscp.h"
43    
44     #define PITCHBEND_SEMITONES 12
45 schoenebeck 80 #define MAX_AUDIO_VOICES 128
46 schoenebeck 244 #define SYSEX_BUFFER_SIZE 2048 // 2kB
47 schoenebeck 250 #define VOICE_STEAL_ALGORITHM voice_steal_algo_oldestkey ///< @see voice_steal_algo_t for available voice stealing algorithms
48 schoenebeck 53
49     namespace LinuxSampler { namespace gig {
50    
51 schoenebeck 239 using std::map;
52    
53 schoenebeck 53 // just symbol prototyping
54     class Voice;
55     class DiskThread;
56     class InstrumentResourceManager;
57    
58     /**
59     * Sampler engine for the Gigasampler format.
60     */
61     class gig::Engine : public LinuxSampler::Engine, public InstrumentConsumer {
62     public:
63 schoenebeck 250 // 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 schoenebeck 53 // methods
71     Engine();
72     ~Engine();
73    
74     // abstract methods derived from class 'LinuxSampler::Engine'
75     virtual void LoadInstrument(const char* FileName, uint Instrument);
76     virtual void Reset();
77     virtual void Enable();
78     virtual void Disable();
79     virtual void SendNoteOn(uint8_t Key, uint8_t Velocity);
80     virtual void SendNoteOff(uint8_t Key, uint8_t Velocity);
81     virtual void SendPitchbend(int Pitch);
82     virtual void SendControlChange(uint8_t Controller, uint8_t Value);
83 schoenebeck 244 virtual void SendSysex(void* pData, uint Size);
84 schoenebeck 53 virtual float Volume();
85     virtual void Volume(float f);
86 schoenebeck 225 virtual uint Channels();
87 schoenebeck 53 virtual void Connect(AudioOutputDevice* pAudioOut);
88     virtual void DisconnectAudioOutputDevice();
89 schoenebeck 225 virtual void SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel);
90     virtual int OutputChannel(uint EngineAudioChannel);
91 schoenebeck 53 virtual int RenderAudio(uint Samples);
92     virtual uint VoiceCount();
93     virtual uint VoiceCountMax();
94     virtual bool DiskStreamSupported();
95     virtual uint DiskStreamCount();
96     virtual uint DiskStreamCountMax();
97     virtual String DiskStreamBufferFillBytes();
98     virtual String DiskStreamBufferFillPercentage();
99     virtual String Description();
100     virtual String Version();
101 senkov 112 virtual String EngineName();
102     virtual String InstrumentFileName();
103     virtual int InstrumentIndex();
104 capela 133 virtual int InstrumentStatus();
105 schoenebeck 53
106     // abstract methods derived from interface class 'InstrumentConsumer'
107     virtual void ResourceToBeUpdated(::gig::Instrument* pResource, void*& pUpdateArg);
108     virtual void ResourceUpdated(::gig::Instrument* pOldResource, ::gig::Instrument* pNewResource, void* pUpdateArg);
109     protected:
110     struct midi_key_info_t {
111 schoenebeck 242 RTEList<Voice>* pActiveVoices; ///< Contains the active voices associated with the MIDI key.
112     bool KeyPressed; ///< Is true if the respective MIDI key is currently pressed.
113     bool Active; ///< If the key contains active voices.
114     bool ReleaseTrigger; ///< If we have to launch release triggered voice(s) when the key is released
115     uint* pSelf; ///< hack to allow fast deallocation of the key from the list of active keys
116     RTEList<Event>* pEvents; ///< Key specific events (only Note-on, Note-off and sustain pedal currently)
117 schoenebeck 53 };
118    
119     static InstrumentResourceManager Instruments;
120    
121     AudioOutputDevice* pAudioOutputDevice;
122 schoenebeck 225 float* pOutputLeft; ///< Audio output channel buffer (left)
123     float* pOutputRight; ///< Audio output channel buffer (right)
124     int AudioDeviceChannelLeft; ///< audio device channel number to which the left channel is connected to
125     int AudioDeviceChannelRight; ///< audio device channel number to which the right channel is connected to
126     uint SampleRate; ///< Sample rate of the engines output audio signal (in Hz)
127     uint MaxSamplesPerCycle; ///< Size of each audio output buffer
128 schoenebeck 53 DiskThread* pDiskThread;
129     uint8_t ControllerTable[128]; ///< Reflects the current values (0-127) of all MIDI controllers for this engine / sampler channel.
130     RingBuffer<Event>* pEventQueue; ///< Input event queue.
131 schoenebeck 244 RingBuffer<uint8_t>* pSysexBuffer; ///< Input buffer for MIDI system exclusive messages.
132 schoenebeck 53 midi_key_info_t pMIDIKeyInfo[128]; ///< Contains all active voices sorted by MIDI key number and other informations to the respective MIDI key
133     RTELMemoryPool<Voice>* pVoicePool; ///< Contains all voices that can be activated.
134     RTELMemoryPool<uint>* pActiveKeys; ///< Holds all keys in it's allocation list with active voices.
135     RTELMemoryPool<Event>* pEventPool; ///< Contains all Event objects that can be used.
136     EventGenerator* pEventGenerator;
137 schoenebeck 250 RTEList<Event>* pVoiceStealingQueue; ///< All voice-launching events which had to be postponed due to free voice shortage.
138 schoenebeck 53 RTEList<Event>* pEvents; ///< All events for the current audio fragment.
139     RTEList<Event>* pCCEvents; ///< All control change events for the current audio fragment.
140     RTEList<Event>* pSynthesisEvents[Event::destination_count]; ///< Events directly affecting synthesis parameter (like pitch, volume and filter).
141     float* pSynthesisParameters[Event::destination_count]; ///< Matrix with final synthesis parameters for the current audio fragment which will be used in the main synthesis loop.
142 schoenebeck 80 biquad_param_t* pBasicFilterParameters; ///< Biquad parameters of the basic bandpass filter.
143     biquad_param_t* pMainFilterParameters; ///< Main biquad parameters of the individual filter (lowpass / bandpass / highpass).
144 schoenebeck 239 map<uint,uint*> ActiveKeyGroups; ///< Contains active keys (in case they belong to a key group) ordered by key group ID.
145 schoenebeck 53 RIFF::File* pRIFF;
146     ::gig::File* pGig;
147     ::gig::Instrument* pInstrument;
148     bool SustainPedal; ///< true if sustain pedal is down
149     double GlobalVolume; ///< overall volume (a value < 1.0 means attenuation, a value > 1.0 means amplification)
150     int Pitch; ///< Current (absolute) MIDI pitch value.
151     int ActiveVoiceCount; ///< number of currently active voices
152     int ActiveVoiceCountMax; ///< the maximum voice usage since application start
153     bool SuspensionRequested;
154     ConditionServer EngineDisabled;
155 senkov 112 String InstrumentFile;
156     int InstrumentIdx;
157 capela 133 int InstrumentStat;
158 schoenebeck 244 int8_t ScaleTuning[12]; ///< contains optional detune factors (-64..+63 cents) for all 12 semitones of an octave
159 schoenebeck 250 Voice* pLastStolenVoice; ///< Only for voice stealing: points to the last voice which was theft in current audio fragment, NULL otherwise.
160     uint* puiLastStolenKey; ///< Only for voice stealing: key number of last key on which the last voice was theft in current audio fragment, NULL otherwise.
161 schoenebeck 53
162     void ProcessNoteOn(Event* pNoteOnEvent);
163     void ProcessNoteOff(Event* pNoteOffEvent);
164     void ProcessPitchbend(Event* pPitchbendEvent);
165     void ProcessControlChange(Event* pControlChangeEvent);
166 schoenebeck 244 void ProcessSysex(Event* pSysexEvent);
167 schoenebeck 250 Voice* LaunchVoice(Event* pNoteOnEvent, int iLayer = 0, bool ReleaseTriggerVoice = false, bool VoiceStealing = true);
168     void StealVoice(Event* pNoteOnEvent, int iLayer, bool ReleaseTriggerVoice);
169 schoenebeck 239 void KillVoiceImmediately(Voice* pVoice);
170 schoenebeck 53 void ResetSynthesisParameters(Event::destination_t dst, float val);
171     void ResetInternal();
172    
173     friend class Voice;
174     friend class EGADSR;
175     friend class EGDecay;
176     friend class VCAManipulator;
177     friend class VCFCManipulator;
178     friend class VCOManipulator;
179     friend class InstrumentResourceManager;
180     private:
181 schoenebeck 244 void DisableAndLock();
182     uint8_t GSCheckSum(const RingBuffer<uint8_t>::NonVolatileReader AddrReader, uint DataSize);
183     void AdjustScale(int8_t ScaleTunes[12]);
184 schoenebeck 53 };
185    
186     }} // namespace LinuxSampler::gig
187    
188     #endif // __LS_GIG_ENGINE_H__

  ViewVC Help
Powered by ViewVC