/[svn]/linuxsampler/trunk/src/engines/common/ModulatorGraph.cpp
ViewVC logotype

Contents of /linuxsampler/trunk/src/engines/common/ModulatorGraph.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2296 - (show annotations) (download)
Thu Dec 8 20:03:47 2011 UTC (12 years, 4 months ago) by iliev
File size: 6167 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 #include "SignalUnitRack.h"
24 #include "../../effects/EffectFactory.h"
25
26 namespace LinuxSampler {
27
28 /**
29 * Searches for know EQ effects and create one if the search succeed.
30 */
31 EqSupport::EqSupport() {
32 pEffect = pEffect2 = NULL;
33 BandCount = 0;
34 GainIdxs = FreqIdxs = BandwidthIdxs = NULL;
35
36 Install();
37 }
38
39 void EqSupport::Install() {
40 Uninstall();
41 for (int i = 0; i < EffectFactory::AvailableEffectsCount(); i++) {
42 EffectInfo* pEffectInfo = EffectFactory::GetEffectInfo(i);
43 /*if (!pEffectInfo->Name().compare("tap_equalizer_bw")) {
44 try { pEffect = EffectFactory::Create(pEffectInfo); }
45 catch(Exception e) { std::cerr << e.Message(); continue; }
46
47 BandCount = 8;
48 GainIdxs = new int[BandCount];
49 FreqIdxs = new int[BandCount];
50 BandwidthIdxs = new int[BandCount];
51 for(int i = 0; i < BandCount; i++) {
52 GainIdxs[i] = i;
53 FreqIdxs[i] = i + 8;
54 BandwidthIdxs[i] = i + 16;
55 }
56 dmsg(1,("EQ support: %s\n", pEffectInfo->Description().c_str()));
57 break;
58 }*/
59
60 if (!pEffectInfo->Name().compare("triplePara")) {
61 try {
62 pEffect = EffectFactory::Create(pEffectInfo);
63 pEffect2 = EffectFactory::Create(pEffectInfo);
64 } catch(Exception e) { std::cerr << e.Message(); continue; }
65
66 BandCount = 3;
67 GainIdxs = new int[BandCount];
68 FreqIdxs = new int[BandCount];
69 BandwidthIdxs = new int[BandCount];
70 for(int i = 0; i < BandCount; i++) {
71 GainIdxs[i] = i*3 + 3;
72 FreqIdxs[i] = i*3 + 4;
73 BandwidthIdxs[i] = i*3 + 5;
74 }
75
76 pEffect->InputControl(0)->SetValue(0); // Low-shelving gain (0dB)
77 pEffect->InputControl(12)->SetValue(0); // High-shelving gain (0dB)
78
79 pEffect2->InputControl(0)->SetValue(0); // Low-shelving gain (0dB)
80 pEffect2->InputControl(12)->SetValue(0); // High-shelving gain (0dB)
81
82 dmsg(1,("EQ support: %s\n", pEffectInfo->Description().c_str()));
83 break;
84 }
85 }
86
87 if (pEffect == NULL) {
88 dmsg(1,("EQ support: no\n"));
89 return;
90 }
91
92 Reset();
93 }
94
95 void EqSupport::SetGain(int band, float gain) {
96 if (!HasSupport()) return;
97 if (band < 0 || band >= BandCount) throw Exception("EQ support: invalid band");
98
99 EffectControl* ctrl = pEffect->InputControl(GainIdxs[band]);
100 gain = check(ctrl->MinValue(), ctrl->MaxValue(), gain);
101 ctrl->SetValue(gain);
102 if (pEffect2 != NULL) pEffect2->InputControl(GainIdxs[band])->SetValue(gain);
103 }
104
105 void EqSupport::SetFreq(int band, float freq) {
106 if (!HasSupport()) return;
107 if (band < 0 || band >= BandCount) throw Exception("EQ support: invalid band");
108
109 EffectControl* ctrl = pEffect->InputControl(FreqIdxs[band]);
110 freq = check(ctrl->MinValue(), ctrl->MaxValue(), freq);
111 ctrl->SetValue(freq);
112 if (pEffect2 != NULL) pEffect2->InputControl(FreqIdxs[band])->SetValue(freq);
113 }
114
115 void EqSupport::SetBandwidth(int band, float octaves) {
116 if (!HasSupport()) return;
117 if (band < 0 || band >= BandCount) throw Exception("EQ support: invalid band");
118
119 EffectControl* ctrl = pEffect->InputControl(BandwidthIdxs[band]);
120 octaves = check(ctrl->MinValue(), ctrl->MaxValue(), octaves);
121 ctrl->SetValue(octaves);
122 if (pEffect2 != NULL) pEffect2->InputControl(BandwidthIdxs[band])->SetValue(octaves);
123 }
124
125 void EqSupport::Uninstall() {
126 if (pEffect != NULL) EffectFactory::Destroy(pEffect);
127 if (pEffect2 != NULL) EffectFactory::Destroy(pEffect2);
128 if (GainIdxs != NULL) delete[] GainIdxs;
129 if (FreqIdxs != NULL) delete[] FreqIdxs;
130 if (BandwidthIdxs != NULL) delete[] BandwidthIdxs;
131
132 pEffect = pEffect2 = NULL;
133 BandCount = 0;
134 GainIdxs = FreqIdxs = BandwidthIdxs = NULL;
135 }
136
137 EqSupport::~EqSupport() {
138 Uninstall();
139 }
140 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC