1 /*
2 This software is part of pffft/pfdsp, a set of simple DSP routines.
3
4 Copyright (c) 2014, Andras Retzler <randras@sdr.hu>
5 Copyright (c) 2020 Hayati Ayguen <h_ayguen@web.de>
6
7 All rights reserved.
8
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
11 * Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
13 * Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
16 * Neither the name of the copyright holder nor the
17 names of its contributors may be used to endorse or promote products
18 derived from this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 DISCLAIMED. IN NO EVENT SHALL ANDRAS RETZLER BE LIABLE FOR ANY
24 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /* include own header first, to see missing includes */
33 #include "pf_carrier.h"
34 #include "fmv.h"
35
36 #include <limits.h>
37 #include <assert.h>
38
39
40 PF_TARGET_CLONES
generate_dc_f(float * output,int size)41 void generate_dc_f(float* output, int size)
42 {
43 for(int i=0;i<2*size;)
44 {
45 /* exp(i*0) = 1+i*0 */
46 output[i++]=(127.0F / 128.0F);
47 output[i++]=0.0F;
48 }
49 }
50
51 PF_TARGET_CLONES
generate_dc_s16(short * output,int size)52 void generate_dc_s16(short* output, int size)
53 {
54 for(int i=0;i<2*size;)
55 {
56 /* exp(i*0) = 1+i*0 */
57 output[i++]=SHRT_MAX;
58 output[i++]=0;
59 }
60 }
61
62 PF_TARGET_CLONES
generate_pos_fs4_f(float * output,int size)63 void generate_pos_fs4_f(float* output, int size)
64 {
65 /* size must be multiple of 4 */
66 assert(!(size&3));
67 for(int i=0;i<2*size;)
68 {
69 /* exp(i*0) = 1+i*0 */
70 output[i++]=(127.0F / 128.0F);
71 output[i++]=0.0F;
72 /* exp(i* +pi/2) = 0+i*1 */
73 output[i++]=0.0F;
74 output[i++]=(127.0F / 128.0F);
75 /* exp(i* +pi) = -1+i*0 */
76 output[i++]=(-127.0F / 128.0F);
77 output[i++]=0.0F;
78 /* exp(i* -pi/2) = 0+i*-1 */
79 output[i++]=0.0F;
80 output[i++]=(-127.0F / 128.0F);
81 }
82 }
83
84 PF_TARGET_CLONES
generate_pos_fs4_s16(short * output,int size)85 void generate_pos_fs4_s16(short* output, int size)
86 {
87 /* size must be multiple of 4 */
88 assert(!(size&3));
89 for(int i=0;i<2*size;)
90 {
91 /* exp(i*0) = 1+i*0 */
92 output[i++]=SHRT_MAX;
93 output[i++]=0;
94 /* exp(i* +pi/2) = 0+i*1 */
95 output[i++]=0;
96 output[i++]=SHRT_MAX;
97 /* exp(i* +pi) = -1+i*0 */
98 output[i++]=-SHRT_MAX;
99 output[i++]=0;
100 /* exp(i* -pi/2) = 0+i*-1 */
101 output[i++]=0;
102 output[i++]=-SHRT_MAX;
103 }
104 }
105
106 PF_TARGET_CLONES
generate_neg_fs4_f(float * output,int size)107 void generate_neg_fs4_f(float* output, int size)
108 {
109 /* size must be multiple of 4 */
110 assert(!(size&3));
111 for(int i=0;i<2*size;)
112 {
113 /* exp(i*0) = 1+i*0 */
114 output[i++]=(127.0F / 128.0F);
115 output[i++]=0.0F;
116 /* exp(i* -pi/2) = 0+i*-1 */
117 output[i++]=0.0F;
118 output[i++]=(-127.0F / 128.0F);
119 /* exp(i* +pi) = -1+i*0 */
120 output[i++]=(-127.0F / 128.0F);
121 output[i++]=0.0F;
122 /* exp(i* +pi/2) = 0+i*1 */
123 output[i++]=0.0F;
124 output[i++]=(127.0F / 128.0F);
125 }
126 }
127
128 PF_TARGET_CLONES
generate_neg_fs4_s16(short * output,int size)129 void generate_neg_fs4_s16(short* output, int size)
130 {
131 /* size must be multiple of 4 */
132 assert(!(size&3));
133 for(int i=0;i<2*size;)
134 {
135 /* exp(i*0) = 1+i*0 */
136 output[i++]=SHRT_MAX;
137 output[i++]=0;
138 /* exp(i* -pi/2) = 0+i*-1 */
139 output[i++]=0;
140 output[i++]=-SHRT_MAX;
141 /* exp(i* +pi) = -1+i*0 */
142 output[i++]=-SHRT_MAX;
143 output[i++]=0;
144 /* exp(i* +pi/2) = 0+i*1 */
145 output[i++]=0;
146 output[i++]=SHRT_MAX;
147 }
148 }
149
150 /****************************************************/
151
152 PF_TARGET_CLONES
generate_dc_pos_fs4_s16(short * output,int size)153 void generate_dc_pos_fs4_s16(short* output, int size)
154 {
155 const int m = SHRT_MAX / 2;
156 /* size must be multiple of 4 */
157 assert(!(size&3));
158 for(int i=0;i<2*size;)
159 {
160 /* exp(i*0) = 1+1+i*0 */
161 output[i++]=m+m;
162 output[i++]=0;
163 /* exp(i* +pi/2) = 1+0+i*1 */
164 output[i++]=m+0;
165 output[i++]=m;
166 /* exp(i* +pi) = 1-1+i*0 */
167 output[i++]=m-m;
168 output[i++]=0;
169 /* exp(i* -pi/2) = 1+0+i*-1 */
170 output[i++]=m;
171 output[i++]=-m;
172 }
173 }
174
175 PF_TARGET_CLONES
generate_dc_neg_fs4_s16(short * output,int size)176 void generate_dc_neg_fs4_s16(short* output, int size)
177 {
178 const int m = SHRT_MAX / 2;
179 /* size must be multiple of 4 */
180 assert(!(size&3));
181 for(int i=0;i<2*size;)
182 {
183 /* exp(i*0) = 1+1+i*0 */
184 output[i++]=m+m;
185 output[i++]=0;
186 /* exp(i* -pi/2) = 1+0+i*-1 */
187 output[i++]=m+0;
188 output[i++]=-m;
189 /* exp(i* +pi) = 1-1+i*0 */
190 output[i++]=m-m;
191 output[i++]=0;
192 /* exp(i* +pi/2) = 1+0+i*1 */
193 output[i++]=m+0;
194 output[i++]=m;
195 }
196 }
197
198 PF_TARGET_CLONES
generate_pos_neg_fs4_s16(short * output,int size)199 void generate_pos_neg_fs4_s16(short* output, int size)
200 {
201 const int m = SHRT_MAX / 2;
202 /* size must be multiple of 4 */
203 assert(!(size&3));
204 for(int i=0;i<2*size;)
205 {
206 /* pos(0) + neg(0) = exp(i* 0 ) + exp(i* 0 ) = 1 +i* 0 + 1 +i* 0 */
207 output[i++]=m;
208 output[i++]=-m;
209
210 /* pos(1) + neg(1) = exp(i* +pi/2) + exp(i* -pi/2) = 0 +i* 1 + 0 +i* -1 */
211 output[i++]=-m;
212 output[i++]=m;
213
214 /* pos(2) + neg(2) = exp(i* +pi ) + exp(i* +pi ) = -1 +i* 0 + -1 +i* 0 */
215 output[i++]=-m;
216 output[i++]=m;
217
218 /* pos(3) + neg(3) = exp(i* -pi/2) + exp(i* +pi/2) = 0 +i* -1 + 0 +i* 1 */
219 output[i++]=m;
220 output[i++]=-m;
221 }
222 }
223
224 PF_TARGET_CLONES
generate_dc_pos_neg_fs4_s16(short * output,int size)225 void generate_dc_pos_neg_fs4_s16(short* output, int size)
226 {
227 const int m = SHRT_MAX / 2;
228 /* size must be multiple of 4 */
229 assert(!(size&3));
230 for(int i=0;i<2*size;)
231 {
232 /* dc + pos(0) + neg(0) = dc + exp(i* 0 ) + exp(i* 0 ) = 1 +i* 0 + 1 +i* 0 */
233 output[i++]=m+m;
234 output[i++]=-m;
235
236 /* dc + pos(1) + neg(1) = dc + exp(i* +pi/2) + exp(i* -pi/2) = 0 +i* 1 + 0 +i* -1 */
237 output[i++]=0;
238 output[i++]=m;
239
240 /* dc + pos(2) + neg(2) = dc + exp(i* +pi ) + exp(i* +pi ) = -1 +i* 0 + -1 +i* 0 */
241 output[i++]=0;
242 output[i++]=m;
243
244 /* dc + pos(3) + neg(3) = dc + exp(i* -pi/2) + exp(i* +pi/2) = 0 +i* -1 + 0 +i* 1 */
245 output[i++]=m+m;
246 output[i++]=-m;
247 }
248 }
249
250
251 PF_TARGET_CLONES
generate_pos_neg_fs2_s16(short * output,int size)252 void generate_pos_neg_fs2_s16(short* output, int size)
253 {
254 const int m = SHRT_MAX / 2;
255 /* size must be multiple of 4 */
256 assert(!(size&3));
257 for(int i=0;i<2*size;)
258 {
259 /* dc + exp(i* 0 ) = +1 */
260 output[i++]=m;
261 output[i++]=0;
262 /* dc + exp(i* pi) = -1 */
263 output[i++]=-m;
264 output[i++]=0;
265 /* dc + exp(i* 0 ) = +1 */
266 output[i++]=m;
267 output[i++]=0;
268 /* dc + exp(i* pi) = -1 */
269 output[i++]=-m;
270 output[i++]=0;
271 }
272 }
273
274 PF_TARGET_CLONES
generate_dc_pos_neg_fs2_s16(short * output,int size)275 void generate_dc_pos_neg_fs2_s16(short* output, int size)
276 {
277 const int m = SHRT_MAX / 2;
278 /* size must be multiple of 4 */
279 assert(!(size&3));
280 for(int i=0;i<2*size;)
281 {
282 /* with dc = i*1 */
283 /* dc + exp(i* 0 ) = i*1 +1 */
284 output[i++]=m;
285 output[i++]=m;
286 /* dc + exp(i* pi) = i*1 -1 */
287 output[i++]=-m;
288 output[i++]=m;
289 /* dc + exp(i* 0 ) = i*1 +1 */
290 output[i++]=m;
291 output[i++]=m;
292 /* dc + exp(i* pi) = i*1 -1 */
293 output[i++]=-m;
294 output[i++]=m;
295 }
296 }
297
298
299