Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-kde
Path: blob/main/audio/alienwah/files/patch-aw.cpp
16462 views
1
--- aw.cpp.orig 2002-01-25 17:51:03 UTC
2
+++ aw.cpp
3
@@ -62,11 +62,11 @@ The output of this effect is the real pa
4
5
/*****************************************************************************/
6
7
-#include <math.h>
8
-#include <complex.h>
9
-#include <stdlib.h>
10
-#include <string.h>
11
-#include <stdio.h>
12
+#include <cmath>
13
+#include <complex>
14
+#include <cstdlib>
15
+#include <cstring>
16
+#include <cstdio>
17
18
/*****************************************************************************/
19
20
@@ -85,6 +85,8 @@ The output of this effect is the real pa
21
#define AW_INPUT2 6
22
#define AW_OUTPUT2 7
23
24
+#define AW_NUMPORTS 8
25
+
26
/*****************************************************************************/
27
/* Make number of samples represented by 'delay' proportional to
28
* the sample rate, such that delay=1 is 1 sample buffer at
29
@@ -118,10 +120,10 @@ unsigned long t; //??
30
unsigned long t2; //??
31
unsigned long k; // index for delaybuf
32
unsigned long k2; // index for delaybuf2
33
-float_complex * delaybuf;
34
-float_complex * delaybuf2;
35
-float_complex c; //??
36
-float_complex c2; //??
37
+std::complex<float> * delaybuf;
38
+std::complex<float> * delaybuf2;
39
+std::complex<float> c; //??
40
+std::complex<float> c2; //??
41
float freq;
42
float startphase;
43
float feedback;
44
@@ -135,25 +137,61 @@ AW(const long lSampleRate) :
45
samplerate(lSampleRate),
46
t(0), t2(0),
47
k(0), k2(0),
48
- c(float_complex(0,0)),
49
- c2(float_complex(0,0)) {
50
+ c(std::complex<float>(0,0)),
51
+ c2(std::complex<float>(0,0)) {
52
}
53
54
+friend LADSPA_Handle instantiateAW(const LADSPA_Descriptor *,
55
+ unsigned long SampleRate);
56
+friend void connectPortToAW(LADSPA_Handle instance, unsigned long port,
57
+ LADSPA_Data * datalocation);
58
+friend void activateAW(void * pvHandle);
59
+friend void runAW_Mono(LADSPA_Handle instance, unsigned long samplecount);
60
+friend void runAW_Stereo(LADSPA_Handle instance, unsigned long samplecount);
61
+friend void cleanupAW(void *pvHandle);
62
+
63
/*
64
- * simply calls the constructor
65
+ * Munge some things based upon the settings passed. Set
66
+ * initial state.
67
*/
68
-friend LADSPA_Handle instantiateAW(const LADSPA_Descriptor *,
69
- unsigned long SampleRate) {
70
+void initState(int chans) {
71
+ inited = true;
72
+ freq = (float)lfreq;
73
+ feedback = ((float)lfeedback)/4 + 0.74; // whyfor?
74
+ if (feedback>0.999) feedback=0.999;
75
+ if (ldelay < 0) ldelay = 1;
76
+ // swh I think this is wrong delay = (unsigned int) (ldelay * samplerate * NORM);
77
+ delay = (unsigned int) ldelay;
78
+printf("delay %d\n", delay);
79
+ if (delay < 1) delay = 1;
80
+ if (delay > MAX_DELAY) delay = MAX_DELAY;
81
+ delaybuf = new std::complex<float>[delay];
82
+ if (chans == 2) {
83
+ delaybuf2 = new std::complex<float>[MAX_DELAY+1];
84
+ }
85
+ for (unsigned int i =0; i<delay; ++i) {
86
+ delaybuf[i] = std::complex<float>(0,0);
87
+ }
88
+}
89
+
90
+};
91
+
92
93
+/*
94
+ * simply calls the constructor
95
+ */
96
+LADSPA_Handle instantiateAW(const LADSPA_Descriptor *,
97
+ unsigned long SampleRate)
98
+{
99
return new AW(SampleRate);
100
}
101
102
/*
103
* get all the pointers to our ports data
104
*/
105
-friend void connectPortToAW(LADSPA_Handle instance, unsigned long port,
106
- LADSPA_Data * datalocation) {
107
-
108
+void connectPortToAW(LADSPA_Handle instance, unsigned long port,
109
+ LADSPA_Data * datalocation)
110
+{
111
switch (port) {
112
case AW_FREQ:
113
((AW *)instance)->lfreq = *datalocation;
114
@@ -182,41 +220,19 @@ friend void connectPortToAW(LADSPA_Handl
115
* connect_port may be called before of after here, so we
116
* cannot rely upon port data for initialization
117
*/
118
-friend void activateAW(void * pvHandle) {
119
-}
120
-
121
-/*
122
- * Munge some things based upon the settings passed. Set
123
- * initial state.
124
- */
125
-void initState(int chans) {
126
- inited = true;
127
- freq = (float)lfreq;
128
- feedback = ((float)lfeedback)/4 + 0.74; // whyfor?
129
- if (feedback>0.999) feedback=0.999;
130
- if (ldelay < 0) ldelay = 1;
131
- // swh I think this is wrong delay = (unsigned int) (ldelay * samplerate * NORM);
132
- delay = (unsigned int) ldelay;
133
-printf("delay %d\n", delay);
134
- if (delay < 1) delay = 1;
135
- if (delay > MAX_DELAY) delay = MAX_DELAY;
136
- delaybuf = new float_complex[delay];
137
- if (chans == 2) {
138
- delaybuf2 = new float_complex[MAX_DELAY+1];
139
- }
140
- for (unsigned int i =0; i<delay; ++i) {
141
- delaybuf[i] = float_complex(0,0);
142
- }
143
+void activateAW(void * pvHandle)
144
+{
145
}
146
147
/*
148
* Mono effect
149
* Do the effect. 'i_buf' is transformed into 'o_buf'
150
*/
151
-friend void runAW_Mono(LADSPA_Handle instance, unsigned long samplecount) {
152
+void runAW_Mono(LADSPA_Handle instance, unsigned long samplecount)
153
+{
154
AW * me = (AW *)instance;
155
float lfo;
156
- float_complex outc;
157
+ std::complex<float> outc;
158
float lfoskip = me->freq * 2 * PI / me->samplerate;
159
160
if (! me->inited) me->initState(1);
161
@@ -224,7 +240,7 @@ friend void runAW_Mono(LADSPA_Handle ins
162
for(unsigned int i=0; i<samplecount; ++i) {
163
if ((me->t++ % LFO_SKIPSAMPLES) == 0) {
164
lfo = 1 + cos(me->t * lfoskip + me->startphase);
165
- me->c = float_complex(cos(lfo) * me->feedback,
166
+ me->c = std::complex<float>(cos(lfo) * me->feedback,
167
sin(lfo) * me->feedback);
168
}
169
outc = me->c * me->delaybuf[me->k] + (1 - me->feedback) *
170
@@ -238,10 +254,11 @@ friend void runAW_Mono(LADSPA_Handle ins
171
/*
172
* Stereo effect?
173
*/
174
-friend void runAW_Stereo(LADSPA_Handle instance, unsigned long samplecount) {
175
+void runAW_Stereo(LADSPA_Handle instance, unsigned long samplecount)
176
+{
177
AW * me = (AW *)instance;
178
float lfo;
179
- float_complex outc;
180
+ std::complex<float> outc;
181
float lfoskip = me->freq * 2 * PI / me->samplerate;
182
183
if (! me->inited) me->initState(2);
184
@@ -249,7 +266,7 @@ friend void runAW_Stereo(LADSPA_Handle i
185
for(unsigned int i=0; i<samplecount; ++i) {
186
if ((me->t++ % LFO_SKIPSAMPLES) == 0) {
187
lfo = 1 + cos(me->t * lfoskip + me->startphase);
188
- me->c = float_complex(cos(lfo) * me->feedback,
189
+ me->c = std::complex<float>(cos(lfo) * me->feedback,
190
sin(lfo) * me->feedback);
191
}
192
outc = me->c * me->delaybuf[me->k] + (1 - me->feedback) *
193
@@ -262,7 +279,7 @@ friend void runAW_Stereo(LADSPA_Handle i
194
for(unsigned int i=0; i<samplecount; ++i) {
195
if ((me->t2++ % LFO_SKIPSAMPLES) == 0) {
196
lfo = 1 + cos(me->t2 * lfoskip);
197
- me->c2 = float_complex(cos(lfo) * me->feedback,
198
+ me->c2 = std::complex<float>(cos(lfo) * me->feedback,
199
sin(lfo) * me->feedback);
200
}
201
outc = me->c2 * me->delaybuf2[me->k2] + (1 - me->feedback) *
202
@@ -273,13 +290,11 @@ friend void runAW_Stereo(LADSPA_Handle i
203
}
204
}
205
206
-
207
-friend void cleanupAW(void *pvHandle) {
208
- delete (AW *)pvHandle;
209
+void cleanupAW(void *pvHandle)
210
+{
211
+ delete (AW *)pvHandle;
212
}
213
214
-};
215
-
216
/*****************************************************************************/
217
218
typedef char * char_ptr;
219
@@ -342,7 +357,7 @@ StartupShutdownHandler() {
220
desc[plug]->PortCount
221
= 6;
222
portdesc
223
- = new LADSPA_PortDescriptor[6];
224
+ = new LADSPA_PortDescriptor[AW_NUMPORTS];
225
desc[plug]->PortDescriptors
226
= (const LADSPA_PortDescriptor *)portdesc;
227
portdesc[AW_FREQ]
228
@@ -358,7 +373,7 @@ StartupShutdownHandler() {
229
portdesc[AW_OUTPUT1]
230
= LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
231
pnames
232
- = new char_ptr[6];
233
+ = new char_ptr[AW_NUMPORTS];
234
desc[plug]->PortNames
235
= (const char **)pnames;
236
pnames[AW_FREQ]
237
@@ -376,7 +391,7 @@ StartupShutdownHandler() {
238
239
/* range hints */
240
rangehints
241
- = new LADSPA_PortRangeHint[6];
242
+ = new LADSPA_PortRangeHint[AW_NUMPORTS];
243
desc[plug]->PortRangeHints
244
= (const LADSPA_PortRangeHint *)rangehints;
245
246
@@ -417,7 +432,7 @@ StartupShutdownHandler() {
247
desc[plug]->PortCount
248
= 8;
249
portdesc
250
- = new LADSPA_PortDescriptor[8];
251
+ = new LADSPA_PortDescriptor[AW_NUMPORTS];
252
desc[plug]->PortDescriptors
253
= (const LADSPA_PortDescriptor *)portdesc;
254
portdesc[AW_FREQ]
255
@@ -437,7 +452,7 @@ StartupShutdownHandler() {
256
portdesc[AW_OUTPUT1]
257
= LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
258
pnames
259
- = new char_ptr[8];
260
+ = new char_ptr[AW_NUMPORTS];
261
desc[plug]->PortNames
262
= (const char **)pnames;
263
pnames[AW_FREQ]
264
@@ -459,7 +474,7 @@ StartupShutdownHandler() {
265
266
/* range hints */
267
rangehints
268
- = new LADSPA_PortRangeHint[8];
269
+ = new LADSPA_PortRangeHint[AW_NUMPORTS];
270
desc[plug]->PortRangeHints
271
= (const LADSPA_PortRangeHint *)rangehints;
272
273
274