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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2296 - (show annotations) (download) (as text)
Thu Dec 8 20:03:47 2011 UTC (9 years, 7 months ago) by iliev
File MIME type: text/x-c++hdr
File size: 9047 byte(s)
* fixed crash when trying to create an effect instance with controls
  which min and/or max values depend on the sample rate
* experimental support for per voice equalization (work in progress)
* sfz engine: implemented opcodes eq1_freq, eq2_freq, eq3_freq,
  eq1_freqccN, eq2_freqccN, eq3_freqccN, eq1_bw, eq2_bw, eq3_bw,
  eq1_bwccN, eq2_bwccN, eq3_bwccN, eq1_gain, eq2_gain, eq3_gain,
  eq1_gainccN, eq2_gainccN, eq3_gainccN

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005-2008 Christian Schoenebeck *
7 * Copyright (C) 2009-2010 Christian Schoenebeck and Grigor Iliev *
8 * *
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 #include "../drivers/audio/AudioOutputDevice.h"
35 #include "common/Event.h"
36 #include "common/SignalUnitRack.h"
37
38 namespace LinuxSampler {
39
40 class AbstractEngineChannel;
41
42 class AbstractEngine: public Engine {
43
44 public:
45 enum Format { GIG = 1, SF2, SFZ };
46 static String GetFormatString(Format f);
47 static AbstractEngine* AcquireEngine(AbstractEngineChannel* pChannel, AudioOutputDevice* pDevice);
48 static void FreeEngine(AbstractEngineChannel* pChannel, AudioOutputDevice* pDevice);
49
50 AbstractEngine();
51 virtual ~AbstractEngine();
52
53 // implementation of abstract methods derived from class 'LinuxSampler::Engine'
54 virtual void SendSysex(void* pData, uint Size, MidiInputPort* pSender);
55 virtual void Reset();
56 virtual void Enable();
57 virtual void Disable();
58 virtual uint VoiceCount();
59 virtual uint VoiceCountMax();
60 virtual String EngineName();
61
62 virtual Format GetEngineFormat() = 0;
63 virtual void Connect(AudioOutputDevice* pAudioOut) = 0;
64 virtual void DisableAndLock();
65
66 void SetVoiceCount(uint Count);// Simple array wrapper just to make sure memory is freed
67 // when liblinuxsampler is unloaded
68
69 class FloatTable {
70 private:
71 const float* array;
72 public:
73 FloatTable(const float* array) : array(array) { }
74 ~FloatTable() { delete[] array; }
75 const float& operator[](int i) const { return array[i]; }
76 };
77
78 static const FloatTable VolumeCurve; ///< Table that maps volume control change values 0..127 to amplitude. Unity gain is at 90.
79 static const FloatTable PanCurve; ///< Table that maps pan control change values 0..128 to right channel amplitude. Unity gain is at 64 (center).
80 static const FloatTable CrossfadeCurve; ///< Table that maps crossfade control change values 0..127 to amplitude. Unity gain is at 127.
81
82 AudioOutputDevice* pAudioOutputDevice;
83
84 //TODO: should be protected
85 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)
86 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)
87
88 friend class AbstractVoice;
89 friend class AbstractEngineChannel;
90 template<class V, class R, class I> friend class EngineChannelBase;
91 template<class EC, class R, class S, class D> friend class VoiceBase;
92
93 protected:
94 ArrayList<EngineChannel*> engineChannels; ///< All engine channels of a Engine instance.
95 ConditionServer EngineDisabled;
96 int8_t ScaleTuning[12]; ///< contains optional detune factors (-64..+63 cents) for all 12 semitones of an octave
97 RingBuffer<Event,false>* pEventQueue; ///< Input event queue for engine global events (e.g. SysEx messages).
98 EventGenerator* pEventGenerator;
99 RTList<Event>* pGlobalEvents; ///< All engine global events for the current audio fragment (usually only SysEx messages).
100 Pool<Event>* pEventPool; ///< Contains all Event objects that can be used.
101 RingBuffer<uint8_t,false>* pSysexBuffer; ///< Input buffer for MIDI system exclusive messages.
102 uint SampleRate; ///< Sample rate of the engines output audio signal (in Hz)
103 uint MaxSamplesPerCycle; ///< Size of each audio output buffer
104 unsigned long FrameTime; ///< Time in frames of the start of the current audio fragment
105 int ActiveVoiceCountMax; ///< the maximum voice usage since application start
106 atomic_t ActiveVoiceCount; ///< number of currently active voices
107 int VoiceSpawnsLeft; ///< We only allow CONFIG_MAX_VOICES voices to be spawned per audio fragment, we use this variable to ensure this limit.
108 EqSupport* pEq; ///< Used for per voice equalization
109
110 void RouteAudio(EngineChannel* pEngineChannel, uint Samples);
111 void RouteDedicatedVoiceChannels(EngineChannel* pEngineChannel, optional<float> FxSendLevels[2], uint Samples);
112 void ClearEventLists();
113 void ImportEvents(uint Samples);
114 void ProcessSysex(Pool<Event>::Iterator& itSysexEvent);
115 void ResetScaleTuning();
116 void ProcessPitchbend(AbstractEngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent);
117
118 void ProcessFxSendControllers (
119 AbstractEngineChannel* pEngineChannel,
120 Pool<Event>::Iterator& itControlChangeEvent
121 );
122
123 uint8_t GSCheckSum(const RingBuffer<uint8_t,false>::NonVolatileReader AddrReader, uint DataSize);
124
125 float Random() {
126 RandomSeed = RandomSeed * 1103515245 + 12345; // classic pseudo random number generator
127 return RandomSeed / 4294967296.0f;
128 }
129
130 virtual void ResetInternal() = 0;
131 virtual void KillAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itKillEvent) = 0;
132 virtual void ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) = 0;
133 virtual void ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) = 0;
134 virtual void ProcessControlChange(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itControlChangeEvent) = 0;
135 virtual int GetMinFadeOutSamples() = 0;
136
137 private:
138 static std::map<Format, std::map<AudioOutputDevice*,AbstractEngine*> > engines;
139 uint32_t RandomSeed; ///< State of the random number generator used by the random dimension.
140
141 static float* InitVolumeCurve();
142 static float* InitPanCurve();
143 static float* InitCrossfadeCurve();
144 static float* InitCurve(const float* segments, int size = 128);
145
146 void AdjustScale(int8_t ScaleTunes[12]);
147 bool RouteFxSend(FxSend* pFxSend, AudioChannel* ppSource[2], float FxSendLevel, uint Samples);
148 };
149
150 } // namespace LinuxSampler
151
152 #endif /* __LS_ABSTRACTENGINE_H__ */
153

  ViewVC Help
Powered by ViewVC