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
|
/*---------------------------------------------------------------
© 2001, Marcberg Soft und Hard GmbH, All Rights Perversed
---------------------------------------------------------------*/
#ifndef __polarizer
#include "polarizer.hpp"
#endif
#include <stdio.h>
//-----------------------------------------------------------------------------
// initializations & such
polarizer::polarizer(int argc, t_atom *argv) {
fSkip = 0.0f;
fAmount = 0.5f;
fImplode = 0.0f;
state = polarized; // the first sample is polarized
post("_ ____polarize~ ");
AddInSignal();
AddInFloat(3);
AddOutSignal();
SetupInOut();
FLEXT_ADDMETHOD( 1,setSkip);
FLEXT_ADDMETHOD( 2,setAmount);
FLEXT_ADDMETHOD( 3,setImplode);
post("_ ____ ____ _");
}
// GIMME class:
FLEXT_NEW_TILDE_G("polarizer~", polarizer)
//-----------------------------------------------------------------------------------------
void polarizer::processReplacing(float **inputs, float **outputs, long sampleFrames) {
float amp;
for (long samplecount=0; (samplecount < sampleFrames); samplecount++)
{
amp = processSampleAmp();
outputs[0][samplecount] = processOutValue(amp, inputs[0][samplecount]);
}
}
void polarizer::m_signal(int n, float *const *in, float *const *out) {
// directly move everything to the vst part
processReplacing((float **)in, (float **)out,(long)n);
} // end m_signal
//-----------------------------------------------------------------------------------------
// titles of each parameter
void polarizer::m_help() {
post(" inlet --- uno ----> ___ _ leap [ ranging from about 1 to 81 ] samples");
post(" inlet -- due -- >>>>> ___ _ _ polarize :: 0~1 __ ------ _ amount");
post(" inlet ------- >> implode << ------- | triggered madness | burn the speakers");
}
//-----------------------------------------------------------------------------------------
// this is for getting the scalar value amp for the current sample
float polarizer::processSampleAmp() {
switch (state)
{
case unaffected: // nothing much happens in this section
if (--unaffectedSamples <= 0) // go to polarized when the leap is done
state = polarized;
return 1.0f;
break;
// end unaffected
case polarized:
state = unaffected; // go right back to unaffected
// but first figure out how long unaffected will last this time
unaffectedSamples = leapScaled(fSkip);
return (0.5f - fAmount) * 2.0f; // this is the polarization scalar
break;
// end polarized
default : return 1.0f;
}
}
//-----------------------------------------------------------------------------------------
// this is for calculating & sending the current sample output value to the output stream
float polarizer::processOutValue(float amp, float in) {
float out = (in * amp); // if implode is off, just do the regular polarizing thing
if (fImplode >= 1.0f) // if it's on, then implode the audio signal
{
if (out > 0.0f) // invert the sample between 1 & 0
out = 1.0f - out;
else // invert the sample between -1 & 0
out = -1.0f - out;
}
return out;
}
|