[292593]: src / Pan.C  Maximize  Restore  History

Download this file

274 lines (190 with data), 4.0 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*
rakarrack - a guitar effects software
pan.C - Auto/Pan - Extra Stereo
Copyright (C) 2008-2010 Josep Andreu
Author: 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
(version2) along with this program; if not, write to the Free Software
Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "Pan.h"
Pan::Pan (float *efxoutl_, float *efxoutr_)
{
efxoutl = efxoutl_;
efxoutr = efxoutr_;
Ppreset = 0;
setpreset (Ppreset);
lfo.effectlfoout (&lfol, &lfor);
cleanup ();
};
Pan::~Pan ()
{
};
void
Pan::cleanup ()
{
};
void
Pan::out (float *smpsl, float *smpsr)
{
int i;
float avg, ldiff, rdiff, tmp;
float pp;
float coeff_PERIOD = 1.0 / fPERIOD;
float fi,P_i;
if (PextraON)
{
for (i = 0; i < PERIOD; i++)
{
avg = (smpsl[i] + smpsr[i]) * .5f;
ldiff = smpsl[i] - avg;
rdiff = smpsr[i] - avg;
tmp = avg + ldiff * mul;
smpsl[i] = tmp*cdvalue;
tmp = avg + rdiff * mul;
smpsr[i] = tmp*sdvalue;
}
}
if (PAutoPan)
{
ll = lfol;
lr = lfor;
lfo.effectlfoout (&lfol, &lfor);
for (i = 0; i < PERIOD; i++)
{
fi = (float) i;
P_i = (float) (PERIOD - i);
pp = (ll * P_i + lfol * fi) * coeff_PERIOD;
smpsl[i] *= pp * panning;
pp = (lr * P_i + lfor * fi) * coeff_PERIOD;
smpsr[i] *= pp * (1.0f - panning);
}
}
};
void
Pan::setvolume (int Pvolume)
{
this->Pvolume = Pvolume;
outvolume = (float)Pvolume / 127.0f;
};
void
Pan::setpanning (int Ppanning)
{
this->Ppanning = Ppanning;
panning = ((float)Ppanning)/ 127.0f;
dvalue= panning*M_PI_2;
cdvalue=cosf(dvalue);
sdvalue=sinf(dvalue);
};
void
Pan::setextra (int Pextra)
{
this->Pextra = Pextra;
mul = 4.0f * (float)Pextra / 127.0f;
};
void
Pan::setpreset (int npreset)
{
const int PRESET_SIZE = 9;
const int NUM_PRESETS = 2;
int presets[NUM_PRESETS][PRESET_SIZE] = {
//AutoPan
{64, 64, 26, 0, 0, 0, 0, 1, 0},
//Extra Stereo
{64, 64, 80, 0, 0, 0, 10, 0, 1}
};
if(npreset>NUM_PRESETS-1)
{
Fpre->ReadPreset(13,npreset-NUM_PRESETS+1);
for (int n = 0; n < PRESET_SIZE; n++)
changepar (n, pdata[n]);
}
else
{
for (int n = 0; n < PRESET_SIZE; n++)
changepar (n, presets[npreset][n]);
}
Ppreset = npreset;
};
void
Pan::changepar (int npar, int value)
{
switch (npar)
{
case 0:
setvolume (value);
break;
case 1:
setpanning (value);
break;
case 2:
lfo.Pfreq = value;
lfo.updateparams ();
break;
case 3:
lfo.Prandomness = value;
lfo.updateparams ();
break;
case 4:
lfo.PLFOtype = value;
lfo.updateparams ();
break;
case 5:
lfo.Pstereo = value;
lfo.updateparams ();
break;
case 6:
setextra (value);
break;
case 7:
PAutoPan = value;
break;
case 8:
PextraON = value;
break;
}
};
int
Pan::getpar (int npar)
{
switch (npar)
{
case 0:
return (Pvolume);
break;
case 1:
return (Ppanning);
break;
case 2:
return (lfo.Pfreq);
break;
case 3:
return (lfo.Prandomness);
break;
case 4:
return (lfo.PLFOtype);
break;
case 5:
return (lfo.Pstereo);
break;
case 6:
return (Pextra);
break;
case 7:
return (PAutoPan);
break;
case 8:
return (PextraON);
break;
default:
return (0);
}
};