[579993]: / src / StompBox.C  Maximize  Restore  History

Download this file

230 lines (173 with data), 4.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
Rakarrack Audio FX software
Stompbox.C - stompbox modeler
Modified for rakarrack by Josep Andreu
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License
as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License (version 2) for more details.
You should have received a copy of the GNU General Public License (version 2)
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "StompBox.h"
StompBox::StompBox (float * efxoutl_, float * efxoutr_)
{
efxoutl = efxoutl_;
efxoutr = efxoutr_;
//default values
Ppreset = 0;
Pvolume = 50;
//left channel filters
linput = new AnalogFilter (1, 80.0f, 1.0f, 0); // AnalogFilter (unsigned char Ftype, float Ffreq, float Fq,unsigned char Fstages);
lpre1 = new AnalogFilter (1, 630.0f, 1.0f, 0); // LPF = 0, HPF = 1
lpre2 = new AnalogFilter (1, 220.0f, 1.0f, 0);
lpost = new AnalogFilter (0, 720.0f, 1.0f, 0);
ltonehg = new AnalogFilter (1, 1500.0f, 1.0f, 0);
ltonemd = new AnalogFilter (4, 1000.0f, 1.0f, 0);
ltonelw = new AnalogFilter (0, 500.0f, 1.0, 0);
//Right channel filters
rinput = new AnalogFilter (1, 80.0f, 1.0f, 0); // AnalogFilter (unsigned char Ftype, float Ffreq, float Fq,unsigned char Fstages);
rpre1 = new AnalogFilter (1, 630.0f, 1.0f, 0); // LPF = 0, HPF = 1
rpre2 = new AnalogFilter (1, 220.0f, 1.0f, 0);
rpost = new AnalogFilter (0, 720.0f, 1.0f, 0);
rtonehg = new AnalogFilter (1, 1500.0f, 1.0f, 0);
rtonemd = new AnalogFilter (4, 1000.0f, 1.0f, 0);
rtonelw = new AnalogFilter (0, 500.0f, 1.0f, 0);
rwshape = new Waveshaper();
lwshape = new Waveshaper();
cleanup ();
setpreset (Ppreset);
};
StompBox::~StompBox ()
{
};
/*
* Cleanup the effect
*/
void
StompBox::cleanup ()
{
};
/*
* Effect output
*/
void
StompBox::out (float * smpsl, float * smpsr)
{
int i;
switch (Pmode)
{
case 0: //Odie
float hfilter; //temporary variables
float mfilter;
float lfilter;
lpre1->filterout(smpsl);
rpre1->filterout(smpsr);
rwshape->waveshapesmps (PERIOD, smpsl, 19, Pgain, 1); //compression
lwshape->waveshapesmps (PERIOD, smpsr, 19, Pgain, 1);
lpost->filterout(smpsl);
rpost->filterout(smpsr);
for (i = 0; i<PERIOD; i++)
{
//left channel
lfilter = ltonelw->filterout_s(smpsl[i]);
mfilter = ltonemd->filterout_s(smpsl[i]);
hfilter = ltonehg->filterout_s(smpsl[i]);
efxoutl[i] = 0.5f * volume * (lowb*lfilter + midb*mfilter + highb*hfilter);
//Right channel
lfilter = rtonelw->filterout_s(smpsr[i]);
mfilter = rtonemd->filterout_s(smpsr[i]);
hfilter = rtonehg->filterout_s(smpsr[i]);
efxoutr[i] = 0.5f * volume * (lowb*lfilter + midb*mfilter + highb*hfilter);
}
break;
}
};
/*
* Parameter control
*/
void
StompBox::setvolume (int value)
{
Pvolume = value;
volume = (float)Pvolume / 127.0f;
outvolume = 0.0f;
};
void
StompBox::setpreset (int npreset)
{
const int PRESET_SIZE = 6;
const int NUM_PRESETS = 1;
int presets[NUM_PRESETS][PRESET_SIZE] = {
//Trebble
{64, 127, 0, 127, 65, 0}
};
if (npreset >= NUM_PRESETS)
npreset = NUM_PRESETS - 1;
for (int n = 0; n < PRESET_SIZE; n++)
changepar (n, presets[npreset][n]);
Ppreset = npreset;
cleanup ();
};
void
StompBox::changepar (int npar, int value)
{
switch (npar)
{
case 0:
setvolume (value);
break;
case 1:
Phigh = value;
highb = ((float) value)/127.0f;
break;
case 2:
Pmid = value;
midb = ((float) value)/127.0f;
break;
case 3:
Plow = value;
lowb = ((float) value)/127.0f;
break;
case 4:
Pgain = value;
gain = 24.0f * ((float)value)/64.0f;
break;
case 5:
Pmode = value;
break;
};
};
int
StompBox::getpar (int npar)
{
switch (npar)
{
case 0:
return (Pvolume);
break;
case 1:
return (Phigh);
break;
case 2:
return (Pmid);
break;
case 3:
return (Plow);
break;
case 4:
return (Pgain);
break;
case 5:
return (Pmode);
break;
};
return (0); //in case of bogus parameter number
};