summaryrefslogtreecommitdiff
path: root/objects/faust/phaser_stereo_optimised.axo
blob: c16ac7d3e887331704c9010eb3effcd22219ffe5 (about) (plain)
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
<objdefs>
   <obj.normal id="phaser_stereo_optimised" uuid="38e0908ef72eddcefe1acb06ecfdeff201ddf1a9" sha="ae1df574629a5ec71ab34078f5084f686f786742">
   <sDescription>Phaser Stereo (from Faust) hand-optimised</sDescription>
      <author>Ricardo Wurmus</author>
      <license>GPL</license>
      <helpPatch/>
      <inlets>
         <frac32buffer name="in" description="in"/>
      </inlets>
      <outlets>
         <frac32buffer.bipolar name="left" description="left output"/>
         <frac32buffer.bipolar name="right" description="right output"/>
      </outlets>
      <params>
         <bool32.tgl name="fcheckbox0" description="VibratoMode: direct/vibrato"/>
         <bool32.tgl name="fcheckbox1" description="linear/invert"/>
         <!-- values are given as: default, min, max, increment? -->
         <!-- They all need to be remapped to the -64.0..0..64.0 range -->

         <!-- 1.0f, 0.0f, 1.0f, 0.01f -->
         <frac32.u.map description="Depth" name="fslider0"/>

         <!-- 0.0f, 0.0f, 1.0f, 0.01f -->
         <frac32.u.map description="feedback gain" name="fslider1"/>

         <!-- 1e+03f, 1e+01f, 5e+03f, 1.0f -->
         <frac32.s.map.pitch description="Notch width (Hz)" name="fslider3"/>

         <!-- 0.5f, 0.0f, 1e+01f, 0.01f -->
         <frac32.u.map description="Speed (Hz)" name="fslider4"/>
        
         <!-- 1e+02f, 2e+01f, 5e+03f, 1.0f -->
         <frac32.s.map.pitch description="MinNotch1Freq (Hz)" name="fslider5"/>

         <!-- 8e+02f, 2e+01f, 1e+04f, 1.0f -->
         <frac32.s.map.pitch description="MaxNotch1Freq (Hz)" name="fslider6"/>
        
         <!-- 1.5f, 1.1f, 4.0f, 0.01f -->
         <frac32.u.map description="NotchFreq (Hz)" name="fslider7"/>
      </params>
      <displays/>
      <attribs/>
      <code.declaration><![CDATA[
	int 	iVec0[2];
  	int32_t 	fConst1;
	int32_t 	fConst2;
	int32_t 	fRec0[2];
    int32_t 	fRec1[3];
	int32_t 	fRec2[3];
	int32_t 	fRec3[3];
	int32_t 	fRec4[3];
	int32_t 	fRec5[2];
	int32_t 	fRec6[2];
	int32_t 	fRec7[2];
	int32_t 	fRec8[3];
    int32_t 	fRec9[3];
	int32_t 	fRec10[3];
	int32_t 	fRec11[3];
    // only valid for positive values!
    #define MAX(a, b) ((a) > (b) ? (a) : (b))
    #define cosf arm_cos_q31
    #define intTAU 0x00c90fdb
    /*"6.283185307179586f"*/
]]></code.declaration>
      <code.init><![CDATA[
      int32_t intPI  = 0x006487ed /*"3.141592653589793f"*/;


      // SAMPLERATE is 48000
      fConst1 = 0x0000002c /*"2.0833333333333333e-5"*/; //1.0f / SAMPLERATE; 
      fConst2 = 0x00000113 /*"1.308996938995747e-4"*/; // TAU / SAMPLERATE;

      for (int i=0; i<2; i++) iVec0[i] = 0;
      for (int i=0; i<2; i++) fRec0[i] = 0;
      for (int i=0; i<3; i++) fRec1[i] = 0;
      for (int i=0; i<3; i++) fRec2[i] = 0;
      for (int i=0; i<3; i++) fRec3[i] = 0;
      for (int i=0; i<3; i++) fRec4[i] = 0;
      for (int i=0; i<2; i++) fRec5[i] = 0;
      for (int i=0; i<2; i++) fRec6[i] = 0;
      for (int i=0; i<2; i++) fRec7[i] = 0;
      for (int i=0; i<3; i++) fRec8[i] = 0;
      for (int i=0; i<3; i++) fRec9[i] = 0;
      for (int i=0; i<3; i++) fRec10[i] = 0;
      for (int i=0; i<3; i++) fRec11[i] = 0;
]]></code.init>
      <code.krate><![CDATA[
      // TODO: find replacements for: expf, cosf, sinf
      // values must be scaled to fit into the range expected by arm_{cos,sin}_q31
      // they all take radians!
      // cosf --> arm_cos_q31
      // sinf --> arm_sin_q31
      
      int32_t 	fSlow0 = param_fcheckbox0 ? 0x00200000 /*"1"*/ : (param_fslider0>>1);
      int32_t 	fSlow1 = param_fcheckbox1 ? __QSUB(0, fSlow0) : fSlow0;
      // TODO: find replacement for expf
      // e ^ -1 * const1 * pi * slider3
      // It's a value between 0.72 and 1.0, but for now we pretend it's just the value of fslider3.
      // float 	fSlow4 = expf((fConst1 * (0 - (3.141592653589793f * float(fslider3)))));
      int32_t 	fSlow4 = 0x00200000; //param_fslider3;
		int32_t 	fSlow5 = ___SMMUL(fSlow4, fSlow4);
		int32_t 	fSlow6 = ___SMMUL(fConst2, param_fslider4);
		int32_t 	fSlow7 = arm_cos_q31(fSlow6);
		int32_t 	fSlow8 = arm_sin_q31(fSlow6);
		int32_t 	fSlow9 = __QSUB(0, fSlow8);

        int32_t minFreq;
        MTOF(param_fslider5, minFreq);
        int32_t maxFreq;
        MTOF(param_fslider6, maxFreq);

		int32_t 	fSlow11 = ___SMMUL(intTAU, minFreq);
		int32_t 	fSlow12 = __QSUB(___SMMUL(intTAU, MAX(minFreq, maxFreq)), fSlow11) >>1;
        int32_t 	fSlow15 = __QSUB(0, fSlow4<<1);
		int32_t 	fSlow14 = ___SMMUL(fConst1, param_fslider7);
		int32_t 	fSlow16 = ___SMMUL(fSlow14, param_fslider7);
		int32_t 	fSlow17 = ___SMMUL(fSlow16, param_fslider7);
        int32_t 	fSlow18 = ___SMMUL(fSlow17, param_fslider7);
		int32_t 	fSlow19 = __QSUB(0x00200000 /*"1.0"*/, fSlow0);

		const int32_t* input0 = inlet_in;
		const int32_t* input1 = inlet_in;
		int32_t* output0 = outlet_left;
		int32_t* output1 = outlet_right;

		for (int i=0; i<BUFSIZE; i++) {
			iVec0[0] = 0x00200000 /*"1.0"*/;
            fRec5[0] = ___SMMUL(fSlow8, fRec6[1]) + ___SMMUL(fSlow7, fRec5[1]);
            fRec6[0] = __QSUB((1 + (___SMMUL(fSlow7, fRec6[1]) + ___SMMUL(fSlow9, fRec5[1]))), iVec0[1]);

            {
            int32_t fTemp0 = input0[i];
            int32_t fTemp1 = fSlow11 + ___SMMUL(fSlow12, __QSUB(0x00200000 /*"1.0"*/, fRec5[0]));
			int32_t fTemp2 = ___SMMUL(fRec4[1], cosf(___SMMUL(fSlow14, fTemp1)));
			fRec4[0] = __QSUB(0, __QSUB((___SMMUL(fSlow15, fTemp2) + ___SMMUL(fSlow5, fRec4[2])), (fTemp0 + ___SMMUL(param_fslider1, fRec0[1]))));
			int32_t fTemp3 = ___SMMUL(fRec3[1], cosf(___SMMUL(fSlow16, fTemp1)));
			fRec3[0] = ___SMMUL(fSlow15, __QSUB(fTemp2, fTemp3)) + (fRec4[2] + ___SMMUL(fSlow5, __QSUB(fRec4[0], fRec3[2])));
			int32_t fTemp4 = ___SMMUL(fRec2[1], cosf(___SMMUL(fSlow17, fTemp1)));
			fRec2[0] = ___SMMUL(fSlow15, __QSUB(fTemp3, fTemp4)) + (fRec3[2] + ___SMMUL(fSlow5, __QSUB(fRec3[0], fRec2[2])));
			int32_t fTemp5 = ___SMMUL(fRec1[1], cosf(___SMMUL(fSlow18, fTemp1)));
			fRec1[0] = ___SMMUL(fSlow15, __QSUB(fTemp4, fTemp5)) + (fRec2[2] + ___SMMUL(fSlow5, __QSUB(fRec2[0], fRec1[2])));
			fRec0[0] = ___SMMUL(fSlow5, fRec1[0]) + (___SMMUL(fSlow15, fTemp5) + fRec1[2]);
            // TODO: add outlet to see if fRec0 is at all correct
			output0[i] = ___SMMUL(fTemp0, fSlow19) + ___SMMUL(fRec0[0], fSlow1);
            }

            {
			int32_t fTemp6 = input1[i];
			int32_t fTemp7 = fSlow11 + ___SMMUL(fSlow12, __QSUB(0x00200000 /*"1.0"*/, fRec6[0]));
			int32_t fTemp8 = ___SMMUL(fRec11[1], cosf(___SMMUL(fSlow14, fTemp7)));
			fRec11[0] = __QSUB(0, (___SMMUL(fSlow15, fTemp8) + ___SMMUL(fSlow5, fRec11[2]) - (fTemp6 + ___SMMUL(param_fslider1, fRec7[1]))));
			int32_t fTemp9 = ___SMMUL(fRec10[1], cosf(___SMMUL(fSlow16, fTemp7)));
			fRec10[0] = (___SMMUL(fSlow15, __QSUB(fTemp8, fTemp9)) + (fRec11[2] + ___SMMUL(fSlow5, __QSUB(fRec11[0], fRec10[2]))));
			int32_t fTemp10 = ___SMMUL(fRec9[1], cosf(___SMMUL(fSlow17, fTemp7)));
			fRec9[0] = (___SMMUL(fSlow15, __QSUB(fTemp9, fTemp10)) + (fRec10[2] + ___SMMUL(fSlow5, __QSUB(fRec10[0], fRec9[2]))));
			int32_t fTemp11 = ___SMMUL(fRec8[1], cosf(___SMMUL(fSlow18, fTemp7)));
			fRec8[0] = (___SMMUL(fSlow15, __QSUB(fTemp10, fTemp11)) + (fRec9[2] + ___SMMUL(fSlow5, __QSUB(fRec9[0], fRec8[2]))));
			fRec7[0] = (___SMMUL(fSlow5, fRec8[0]) + (___SMMUL(fSlow15, fTemp11) + fRec8[2]));
            // TODO: add outlet to see if fRec7 is at all correct
			output1[i] = ___SMMUL(fTemp6, fSlow19) + ___SMMUL(fRec7[0], fSlow1);
            }

			// post processing
			fRec7[1] = fRec7[0];
			fRec8[2] = fRec8[1]; fRec8[1] = fRec8[0];
			fRec9[2] = fRec9[1]; fRec9[1] = fRec9[0];
			fRec10[2] = fRec10[1]; fRec10[1] = fRec10[0];
			fRec11[2] = fRec11[1]; fRec11[1] = fRec11[0];
			fRec0[1] = fRec0[0];
			fRec1[2] = fRec1[1]; fRec1[1] = fRec1[0];
			fRec2[2] = fRec2[1]; fRec2[1] = fRec2[0];
			fRec3[2] = fRec3[1]; fRec3[1] = fRec3[0];
			fRec4[2] = fRec4[1]; fRec4[1] = fRec4[0];
			fRec6[1] = fRec6[0];
			fRec5[1] = fRec5[0];
			iVec0[1] = iVec0[0];
		}
]]></code.krate>
   </obj.normal>
</objdefs>