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

Annotation of /linuxsampler/trunk/src/engines/AbstractEngine.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2962 - (hide annotations) (download) (as text)
Sun Jul 17 17:54:04 2016 UTC (7 years, 9 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 10629 byte(s)
* NKSP: Fixed all change_*() built-in script functions to apply their
  synthesis parameter changes immediately in case the respective note
  was triggered at the same time, instead of scheduling the parameter
  change, especially because it would cause some parameter types's
  changes either to be ramped (i.e. change_vol()) or other types even
  to have not effect at all (i.e. change_attack()).
* Bumped version (2.0.0.svn20).

1 iliev 2012 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck *
6 persson 2072 * Copyright (C) 2005-2008 Christian Schoenebeck *
7 persson 2427 * Copyright (C) 2009-2013 Christian Schoenebeck and Grigor Iliev *
8 iliev 2012 * *
9     * This program is free software; you can redistribute it and/or modify *
10     * it under the terms of the GNU General Public License as published by *
11     * the Free Software Foundation; either version 2 of the License, or *
12     * (at your option) any later version. *
13     * *
14     * This program is distributed in the hope that it will be useful, *
15     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17     * GNU General Public License for more details. *
18     * *
19     * You should have received a copy of the GNU General Public License *
20     * along with this program; if not, write to the Free Software *
21     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
22     * MA 02111-1307 USA *
23     ***************************************************************************/
24    
25     #ifndef __LS_ABSTRACTENGINE_H__
26     #define __LS_ABSTRACTENGINE_H__
27    
28     #include "Engine.h"
29     #include "../common/ArrayList.h"
30     #include "../common/atomic.h"
31     #include "../common/ConditionServer.h"
32     #include "../common/Pool.h"
33     #include "../common/RingBuffer.h"
34 schoenebeck 2448 #include "../common/ChangeFlagRelaxed.h"
35 schoenebeck 2594 #include "../common/ResourceManager.h"
36 iliev 2012 #include "../drivers/audio/AudioOutputDevice.h"
37     #include "common/Event.h"
38 schoenebeck 2879 #include "common/Note.h"
39 iliev 2296 #include "common/SignalUnitRack.h"
40 schoenebeck 2594 #include "common/InstrumentScriptVM.h"
41 iliev 2012
42     namespace LinuxSampler {
43    
44     class AbstractEngineChannel;
45    
46     class AbstractEngine: public Engine {
47    
48     public:
49     enum Format { GIG = 1, SF2, SFZ };
50     static String GetFormatString(Format f);
51     static AbstractEngine* AcquireEngine(AbstractEngineChannel* pChannel, AudioOutputDevice* pDevice);
52     static void FreeEngine(AbstractEngineChannel* pChannel, AudioOutputDevice* pDevice);
53    
54     AbstractEngine();
55     virtual ~AbstractEngine();
56    
57     // implementation of abstract methods derived from class 'LinuxSampler::Engine'
58 schoenebeck 2434 virtual void SendSysex(void* pData, uint Size, MidiInputPort* pSender) OVERRIDE;
59     virtual void Reset() OVERRIDE;
60     virtual void Enable() OVERRIDE;
61     virtual void Disable() OVERRIDE;
62     virtual uint VoiceCount() OVERRIDE;
63     virtual uint VoiceCountMax() OVERRIDE;
64     virtual String EngineName() OVERRIDE;
65 schoenebeck 2448 virtual void AdjustScaleTuning(const int8_t ScaleTunes[12]) OVERRIDE;
66     virtual void GetScaleTuning(int8_t* pScaleTunes) OVERRIDE;
67     virtual void ResetScaleTuning() OVERRIDE;
68 iliev 2012
69     virtual Format GetEngineFormat() = 0;
70     virtual void Connect(AudioOutputDevice* pAudioOut) = 0;
71     virtual void DisableAndLock();
72    
73 persson 2427 void SetVoiceCount(uint Count);
74 iliev 2297
75 schoenebeck 2600 /**
76     * Returns event with the given event ID.
77     */
78 schoenebeck 2879 RTList<Event>::Iterator EventByID(event_id_t id) {
79 schoenebeck 2600 return pEventPool->fromID(id);
80     }
81    
82 schoenebeck 2879 virtual NoteBase* NoteByID(note_id_t id) = 0;
83    
84 iliev 2297 float Random() {
85     RandomSeed = RandomSeed * 1103515245 + 12345; // classic pseudo random number generator
86     return RandomSeed / 4294967296.0f;
87     }
88 persson 2427
89     // Simple array wrapper just to make sure memory is freed
90     // when liblinuxsampler is unloaded
91 iliev 2012 class FloatTable {
92     private:
93     const float* array;
94     public:
95     FloatTable(const float* array) : array(array) { }
96     ~FloatTable() { delete[] array; }
97     const float& operator[](int i) const { return array[i]; }
98     };
99    
100     static const FloatTable VolumeCurve; ///< Table that maps volume control change values 0..127 to amplitude. Unity gain is at 90.
101     static const FloatTable PanCurve; ///< Table that maps pan control change values 0..128 to right channel amplitude. Unity gain is at 64 (center).
102     static const FloatTable CrossfadeCurve; ///< Table that maps crossfade control change values 0..127 to amplitude. Unity gain is at 127.
103    
104 schoenebeck 2931 static float PanCurveValueNorm(float pan, int channel);
105    
106 iliev 2012 AudioOutputDevice* pAudioOutputDevice;
107 schoenebeck 2121
108     //TODO: should be protected
109     AudioChannel* pDedicatedVoiceChannelLeft; ///< encapsulates a special audio rendering buffer (left) for rendering and routing audio on a per voice basis (this is a very special case and only used for voices which lie on a note which was set with individual, dedicated FX send level)
110     AudioChannel* pDedicatedVoiceChannelRight; ///< encapsulates a special audio rendering buffer (right) for rendering and routing audio on a per voice basis (this is a very special case and only used for voices which lie on a note which was set with individual, dedicated FX send level)
111 iliev 2012
112 iliev 2015 friend class AbstractVoice;
113 iliev 2012 friend class AbstractEngineChannel;
114     template<class V, class R, class I> friend class EngineChannelBase;
115 iliev 2015 template<class EC, class R, class S, class D> friend class VoiceBase;
116 iliev 2012
117 schoenebeck 2611 //protected:
118 iliev 2012 ArrayList<EngineChannel*> engineChannels; ///< All engine channels of a Engine instance.
119     ConditionServer EngineDisabled;
120     int8_t ScaleTuning[12]; ///< contains optional detune factors (-64..+63 cents) for all 12 semitones of an octave
121 schoenebeck 2448 ChangeFlagRelaxed ScaleTuningChanged; ///< Boolean flag indicating whenever ScaleTuning has been modified by a foreign thread (i.e. by API).
122 iliev 2012 RingBuffer<Event,false>* pEventQueue; ///< Input event queue for engine global events (e.g. SysEx messages).
123     EventGenerator* pEventGenerator;
124     RTList<Event>* pGlobalEvents; ///< All engine global events for the current audio fragment (usually only SysEx messages).
125     Pool<Event>* pEventPool; ///< Contains all Event objects that can be used.
126 iliev 2027 RingBuffer<uint8_t,false>* pSysexBuffer; ///< Input buffer for MIDI system exclusive messages.
127 iliev 2012 uint SampleRate; ///< Sample rate of the engines output audio signal (in Hz)
128     uint MaxSamplesPerCycle; ///< Size of each audio output buffer
129 schoenebeck 2962 sched_time_t FrameTime; ///< Scheduler time of the 1st sample point of the current audio fragment cycle. This is a consecutive sample point counter for the engine which proceeds (beyond fragment boundaries) until the engine is explicitly reset for some reason.
130 iliev 2012 int ActiveVoiceCountMax; ///< the maximum voice usage since application start
131 iliev 2027 atomic_t ActiveVoiceCount; ///< number of currently active voices
132     int VoiceSpawnsLeft; ///< We only allow CONFIG_MAX_VOICES voices to be spawned per audio fragment, we use this variable to ensure this limit.
133 schoenebeck 2594 InstrumentScriptVM* pScriptVM; ///< Real-time instrument script virtual machine runner for this engine.
134 iliev 2012
135     void RouteAudio(EngineChannel* pEngineChannel, uint Samples);
136 schoenebeck 2121 void RouteDedicatedVoiceChannels(EngineChannel* pEngineChannel, optional<float> FxSendLevels[2], uint Samples);
137 iliev 2012 void ClearEventLists();
138     void ImportEvents(uint Samples);
139     void ProcessSysex(Pool<Event>::Iterator& itSysexEvent);
140     void ProcessPitchbend(AbstractEngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent);
141    
142     void ProcessFxSendControllers (
143     AbstractEngineChannel* pEngineChannel,
144     Pool<Event>::Iterator& itControlChangeEvent
145     );
146    
147     uint8_t GSCheckSum(const RingBuffer<uint8_t,false>::NonVolatileReader AddrReader, uint DataSize);
148    
149     virtual void ResetInternal() = 0;
150     virtual void KillAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itKillEvent) = 0;
151     virtual void ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) = 0;
152     virtual void ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) = 0;
153     virtual void ProcessControlChange(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itControlChangeEvent) = 0;
154 schoenebeck 2559 virtual void ProcessChannelPressure(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itChannelPressureEvent) = 0;
155     virtual void ProcessPolyphonicKeyPressure(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNotePressureEvent) = 0;
156 schoenebeck 2927 virtual void ProcessReleaseTrigger(EngineChannel* pEngineChannel, RTList<Event>::Iterator& itEvent) = 0;
157 iliev 2015 virtual int GetMinFadeOutSamples() = 0;
158 schoenebeck 2879 virtual note_id_t LaunchNewNote(LinuxSampler::EngineChannel* pEngineChannel, Event* pNoteOnEvent) = 0;
159 schoenebeck 2611 virtual void CreateInstrumentScriptVM();
160 iliev 2012
161     private:
162     static std::map<Format, std::map<AudioOutputDevice*,AbstractEngine*> > engines;
163 persson 2072 uint32_t RandomSeed; ///< State of the random number generator used by the random dimension.
164 iliev 2012
165     static float* InitVolumeCurve();
166     static float* InitPanCurve();
167     static float* InitCrossfadeCurve();
168     static float* InitCurve(const float* segments, int size = 128);
169    
170 schoenebeck 2121 bool RouteFxSend(FxSend* pFxSend, AudioChannel* ppSource[2], float FxSendLevel, uint Samples);
171 iliev 2012 };
172    
173     } // namespace LinuxSampler
174    
175     #endif /* __LS_ABSTRACTENGINE_H__ */
176    

  ViewVC Help
Powered by ViewVC