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

Contents of /linuxsampler/trunk/src/engines/common/SignalUnitRack.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2296 - (show annotations) (download) (as text)
Thu Dec 8 20:03:47 2011 UTC (12 years, 4 months ago) by iliev
File MIME type: text/x-c++hdr
File size: 7604 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) 2011 Grigor Iliev *
6 * *
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_SIGNALUNITRACK_H__
24 #define __LS_SIGNALUNITRACK_H__
25
26 #include "Event.h"
27 #include "SignalUnit.h"
28 #include "../../common/Pool.h"
29
30
31 namespace LinuxSampler {
32
33 class EqSupport {
34 private:
35 int BandCount;
36 int* GainIdxs; ///< the indices of the gain controls
37 int* FreqIdxs; ///< the indices of the frequency controls
38 int* BandwidthIdxs; ///< the indices of the bandwidth controls
39 Effect* pEffect;
40 Effect* pEffect2; // If the effect is mono we'll need two effects
41
42 inline float check(optional<float> minimum, optional<float> maximum, float value) {
43 if (minimum) {
44 float min = *minimum;
45 if (value < min) value = min;
46 }
47 if (maximum) {
48 float max = *maximum;
49 if (value > max) value = max;
50 }
51
52 return value;
53 }
54
55 public:
56 EqSupport();
57 ~EqSupport();
58
59 /**
60 * Searches for know EQ effects and create one if the search succeed.
61 * If the initialization is successful and EQ effect is selected,
62 * HasSupport() returns true;
63 */
64 void Install();
65
66 void Uninstall();
67
68 /** Returns true if an EQ is created and is ready for use. */
69 bool HasSupport() { return pEffect != NULL; }
70
71 /** Reset the gains of all bands to 0dB. */
72 void Reset() {
73 if (!HasSupport()) return;
74 for (int i = 0; i < BandCount; i++) {
75 pEffect->InputControl(GainIdxs[i])->SetValue(0); // 0dB
76 if (pEffect2 != NULL) pEffect2->InputControl(GainIdxs[i])->SetValue(0); // 0dB
77 }
78 }
79
80 void InitEffect(AudioOutputDevice* pDevice) {
81 if (pEffect != NULL) pEffect->InitEffect(pDevice);
82 if (pEffect2 != NULL) pEffect2->InitEffect(pDevice);
83 }
84
85 int GetBandCount() { return BandCount; }
86
87 void SetGain(int band, float gain);
88 void SetFreq(int band, float freq);
89 void SetBandwidth(int band, float octaves);
90
91 AudioChannel* GetInChannelLeft() {
92 return pEffect->InputChannel(0);
93 }
94
95 AudioChannel* GetInChannelRight() {
96 return pEffect2 != NULL ? pEffect2->InputChannel(0) : pEffect->InputChannel(1);
97 }
98
99 AudioChannel* GetOutChannelLeft() {
100 return pEffect->OutputChannel(0);
101 }
102
103 AudioChannel* GetOutChannelRight() {
104 return pEffect2 != NULL ? pEffect2->OutputChannel(0) : pEffect->OutputChannel(1);
105 }
106
107 void RenderAudio(uint Samples) {
108 pEffect->RenderAudio(Samples);
109 if (pEffect2 != NULL) pEffect2->RenderAudio(Samples);
110 }
111 };
112
113
114
115 class SignalUnitRack {
116 protected:
117 uint CurrentStep; // The current time step
118 bool bHasEq;
119
120 public:
121 FixedArray<SignalUnit*> Units; // A list of all signal units in this rack
122
123 /**
124 * @param maxUnitCount We are using fixed size array because of the real-time safe requirements.
125 */
126 SignalUnitRack(int maxUnitCount): CurrentStep(0), bHasEq(false), Units(maxUnitCount) { }
127
128 uint GetCurrentStep() { return CurrentStep; }
129
130 virtual EndpointSignalUnit* GetEndpointUnit() = 0;
131
132 virtual void EnterFadeOutStage() = 0;
133
134 /**
135 * Will be called to increment the time with one sample point.
136 * Each unit should recalculate its current level on every call of this function.
137 */
138 virtual void Increment() {
139 CurrentStep++;
140
141 for (int i = 0; i < Units.size(); i++) {
142 Units[i]->Increment();
143 }
144 }
145
146 virtual void ProcessCCEvent(RTList<Event>::Iterator& itEvent) {
147 if ( !(itEvent->Type == Event::type_control_change && itEvent->Param.CC.Controller) ) return;
148 for (int i = 0; i < Units.size(); i++) {
149 Units[i]->ProcessCCEvent(itEvent->Param.CC.Controller, itEvent->Param.CC.Value);
150 }
151 }
152
153 /** Initializes and triggers the rack. */
154 virtual void Trigger() {
155 CurrentStep = 0;
156 for (int i = 0; i < Units.size(); i++) {
157 Units[i]->Trigger();
158 }
159 }
160
161 /**
162 * When the rack belongs to a voice, this method is
163 * called when the voice enter the release stage.
164 */
165 virtual void EnterReleaseStage() {
166 for (int i = 0; i < Units.size(); i++) {
167 Units[i]->EnterReleaseStage();
168 }
169 }
170
171 /**
172 * When the rack belongs to a voice, this method is
173 * called when the voice is of type which ignore note off.
174 */
175 virtual void CancelRelease() {
176 for (int i = 0; i < Units.size(); i++) {
177 Units[i]->CancelRelease();
178 }
179 }
180
181 /**
182 * Determines whether an equalization is applied to the voice.
183 * Used for optimization.
184 */
185 bool HasEq() { return bHasEq; }
186
187 virtual void UpdateEqSettings(EqSupport* pEqSupport) = 0;
188 };
189 } // namespace LinuxSampler
190
191 #endif /* __LS_SIGNALUNITRACK_H__ */

  ViewVC Help
Powered by ViewVC