1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Python Wrapper
3  * Title:        cmsismodule.h
4  * Description:  C code for the CMSIS-DSP Python wrapper
5  *
6  * $Date:        27 April 2021
7  * $Revision:    V1.0
8  *
9  * Target Processor: Cortex-M cores
10  * -------------------------------------------------------------------- */
11 /*
12  * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
13  *
14  * SPDX-License-Identifier: Apache-2.0
15  *
16  * Licensed under the Apache License, Version 2.0 (the License); you may
17  * not use this file except in compliance with the License.
18  * You may obtain a copy of the License at
19  *
20  * www.apache.org/licenses/LICENSE-2.0
21  *
22  * Unless required by applicable law or agreed to in writing, software
23  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
24  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25  * See the License for the specific language governing permissions and
26  * limitations under the License.
27  */
28 
29 #define MODNAME "cmsisdsp_complexf"
30 #define MODINITNAME cmsisdsp_complexf
31 
32 #include "cmsisdsp_module.h"
33 
34 
35 NUMPYVECTORFROMBUFFER(f32,float32_t,NPY_FLOAT);
36 
37 
typeRegistration(PyObject * module)38 void typeRegistration(PyObject *module) {
39 
40 
41 }
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 static PyObject *
cmsis_arm_cmplx_conj_f32(PyObject * obj,PyObject * args)54 cmsis_arm_cmplx_conj_f32(PyObject *obj, PyObject *args)
55 {
56 
57   PyObject *pSrc=NULL; // input
58   float32_t *pSrc_converted=NULL; // input
59   float32_t *pDst=NULL; // output
60   uint32_t numSamples; // input
61 
62   if (PyArg_ParseTuple(args,"O",&pSrc))
63   {
64 
65     GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t);
66     numSamples = arraySizepSrc ;
67     numSamples = numSamples / 2;
68 
69     pDst=PyMem_Malloc(sizeof(float32_t)*2*numSamples);
70 
71 
72     arm_cmplx_conj_f32(pSrc_converted,pDst,numSamples);
73  FLOATARRAY1(pDstOBJ,2*numSamples,pDst);
74 
75     PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
76 
77     FREEARGUMENT(pSrc_converted);
78     Py_DECREF(pDstOBJ);
79     return(pythonResult);
80 
81   }
82   return(NULL);
83 }
84 
85 
86 static PyObject *
cmsis_arm_cmplx_conj_q31(PyObject * obj,PyObject * args)87 cmsis_arm_cmplx_conj_q31(PyObject *obj, PyObject *args)
88 {
89 
90   PyObject *pSrc=NULL; // input
91   q31_t *pSrc_converted=NULL; // input
92   q31_t *pDst=NULL; // output
93   uint32_t numSamples; // input
94 
95   if (PyArg_ParseTuple(args,"O",&pSrc))
96   {
97 
98     GETARGUMENT(pSrc,NPY_INT32,int32_t,int32_t);
99     numSamples = arraySizepSrc ;
100     numSamples = numSamples / 2;
101 
102     pDst=PyMem_Malloc(sizeof(q31_t)*2*numSamples);
103 
104 
105     arm_cmplx_conj_q31(pSrc_converted,pDst,numSamples);
106  INT32ARRAY1(pDstOBJ,2*numSamples,pDst);
107 
108     PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
109 
110     FREEARGUMENT(pSrc_converted);
111     Py_DECREF(pDstOBJ);
112     return(pythonResult);
113 
114   }
115   return(NULL);
116 }
117 
118 
119 static PyObject *
cmsis_arm_cmplx_conj_q15(PyObject * obj,PyObject * args)120 cmsis_arm_cmplx_conj_q15(PyObject *obj, PyObject *args)
121 {
122 
123   PyObject *pSrc=NULL; // input
124   q15_t *pSrc_converted=NULL; // input
125   q15_t *pDst=NULL; // output
126   uint32_t numSamples; // input
127 
128   if (PyArg_ParseTuple(args,"O",&pSrc))
129   {
130 
131     GETARGUMENT(pSrc,NPY_INT16,int16_t,int16_t);
132     numSamples = arraySizepSrc ;
133     numSamples = numSamples / 2;
134 
135     pDst=PyMem_Malloc(sizeof(q15_t)*2*numSamples);
136 
137 
138     arm_cmplx_conj_q15(pSrc_converted,pDst,numSamples);
139  INT16ARRAY1(pDstOBJ,2*numSamples,pDst);
140 
141     PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
142 
143     FREEARGUMENT(pSrc_converted);
144     Py_DECREF(pDstOBJ);
145     return(pythonResult);
146 
147   }
148   return(NULL);
149 }
150 
151 
152 static PyObject *
cmsis_arm_cmplx_mag_squared_f32(PyObject * obj,PyObject * args)153 cmsis_arm_cmplx_mag_squared_f32(PyObject *obj, PyObject *args)
154 {
155 
156   PyObject *pSrc=NULL; // input
157   float32_t *pSrc_converted=NULL; // input
158   float32_t *pDst=NULL; // output
159   uint32_t numSamples; // input
160 
161   if (PyArg_ParseTuple(args,"O",&pSrc))
162   {
163 
164     GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t);
165     numSamples = arraySizepSrc ;
166     numSamples = numSamples / 2;
167 
168     pDst=PyMem_Malloc(sizeof(float32_t)*2*numSamples);
169 
170 
171     arm_cmplx_mag_squared_f32(pSrc_converted,pDst,numSamples);
172  FLOATARRAY1(pDstOBJ,numSamples,pDst);
173 
174     PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
175 
176     FREEARGUMENT(pSrc_converted);
177     Py_DECREF(pDstOBJ);
178     return(pythonResult);
179 
180   }
181   return(NULL);
182 }
183 
184 static PyObject *
cmsis_arm_cmplx_mag_squared_f64(PyObject * obj,PyObject * args)185 cmsis_arm_cmplx_mag_squared_f64(PyObject *obj, PyObject *args)
186 {
187 
188   PyObject *pSrc=NULL; // input
189   float64_t *pSrc_converted=NULL; // input
190   float64_t *pDst=NULL; // output
191   uint32_t numSamples; // input
192 
193   if (PyArg_ParseTuple(args,"O",&pSrc))
194   {
195 
196     GETARGUMENT(pSrc,NPY_DOUBLE,double,float64_t);
197     numSamples = arraySizepSrc ;
198     numSamples = numSamples / 2;
199 
200     pDst=PyMem_Malloc(sizeof(float64_t)*2*numSamples);
201 
202 
203     arm_cmplx_mag_squared_f64(pSrc_converted,pDst,numSamples);
204  FLOAT64ARRAY1(pDstOBJ,numSamples,pDst);
205 
206     PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
207 
208     FREEARGUMENT(pSrc_converted);
209     Py_DECREF(pDstOBJ);
210     return(pythonResult);
211 
212   }
213   return(NULL);
214 }
215 
216 
217 static PyObject *
cmsis_arm_cmplx_mag_squared_q31(PyObject * obj,PyObject * args)218 cmsis_arm_cmplx_mag_squared_q31(PyObject *obj, PyObject *args)
219 {
220 
221   PyObject *pSrc=NULL; // input
222   q31_t *pSrc_converted=NULL; // input
223   q31_t *pDst=NULL; // output
224   uint32_t numSamples; // input
225 
226   if (PyArg_ParseTuple(args,"O",&pSrc))
227   {
228 
229     GETARGUMENT(pSrc,NPY_INT32,int32_t,int32_t);
230     numSamples = arraySizepSrc ;
231     numSamples = numSamples / 2;
232 
233     pDst=PyMem_Malloc(sizeof(q31_t)*2*numSamples);
234 
235 
236     arm_cmplx_mag_squared_q31(pSrc_converted,pDst,numSamples);
237  INT32ARRAY1(pDstOBJ,numSamples,pDst);
238 
239     PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
240 
241     FREEARGUMENT(pSrc_converted);
242     Py_DECREF(pDstOBJ);
243     return(pythonResult);
244 
245   }
246   return(NULL);
247 }
248 
249 
250 static PyObject *
cmsis_arm_cmplx_mag_squared_q15(PyObject * obj,PyObject * args)251 cmsis_arm_cmplx_mag_squared_q15(PyObject *obj, PyObject *args)
252 {
253 
254   PyObject *pSrc=NULL; // input
255   q15_t *pSrc_converted=NULL; // input
256   q15_t *pDst=NULL; // output
257   uint32_t numSamples; // input
258 
259   if (PyArg_ParseTuple(args,"O",&pSrc))
260   {
261 
262     GETARGUMENT(pSrc,NPY_INT16,int16_t,int16_t);
263     numSamples = arraySizepSrc ;
264     numSamples = numSamples / 2;
265 
266     pDst=PyMem_Malloc(sizeof(q15_t)*2*numSamples);
267 
268 
269     arm_cmplx_mag_squared_q15(pSrc_converted,pDst,numSamples);
270  INT16ARRAY1(pDstOBJ,numSamples,pDst);
271 
272     PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
273 
274     FREEARGUMENT(pSrc_converted);
275     Py_DECREF(pDstOBJ);
276     return(pythonResult);
277 
278   }
279   return(NULL);
280 }
281 
282 
283 
284 
285 
286 
287 
288 static PyObject *
cmsis_arm_cmplx_mag_f32(PyObject * obj,PyObject * args)289 cmsis_arm_cmplx_mag_f32(PyObject *obj, PyObject *args)
290 {
291 
292   PyObject *pSrc=NULL; // input
293   float32_t *pSrc_converted=NULL; // input
294   float32_t *pDst=NULL; // output
295   uint32_t numSamples; // input
296 
297   if (PyArg_ParseTuple(args,"O",&pSrc))
298   {
299 
300     GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t);
301     numSamples = arraySizepSrc ;
302     numSamples = numSamples / 2;
303 
304     pDst=PyMem_Malloc(sizeof(float32_t)*2*numSamples);
305 
306 
307     arm_cmplx_mag_f32(pSrc_converted,pDst,numSamples);
308  FLOATARRAY1(pDstOBJ,numSamples,pDst);
309 
310     PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
311 
312     FREEARGUMENT(pSrc_converted);
313     Py_DECREF(pDstOBJ);
314     return(pythonResult);
315 
316   }
317   return(NULL);
318 }
319 
320 static PyObject *
cmsis_arm_cmplx_mag_f64(PyObject * obj,PyObject * args)321 cmsis_arm_cmplx_mag_f64(PyObject *obj, PyObject *args)
322 {
323 
324   PyObject *pSrc=NULL; // input
325   float64_t *pSrc_converted=NULL; // input
326   float64_t *pDst=NULL; // output
327   uint32_t numSamples; // input
328 
329   if (PyArg_ParseTuple(args,"O",&pSrc))
330   {
331 
332     GETARGUMENT(pSrc,NPY_DOUBLE,double,float64_t);
333     numSamples = arraySizepSrc ;
334     numSamples = numSamples / 2;
335 
336     pDst=PyMem_Malloc(sizeof(float64_t)*2*numSamples);
337 
338 
339     arm_cmplx_mag_f64(pSrc_converted,pDst,numSamples);
340  FLOAT64ARRAY1(pDstOBJ,numSamples,pDst);
341 
342     PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
343 
344     FREEARGUMENT(pSrc_converted);
345     Py_DECREF(pDstOBJ);
346     return(pythonResult);
347 
348   }
349   return(NULL);
350 }
351 
352 
353 static PyObject *
cmsis_arm_cmplx_mag_q31(PyObject * obj,PyObject * args)354 cmsis_arm_cmplx_mag_q31(PyObject *obj, PyObject *args)
355 {
356 
357   PyObject *pSrc=NULL; // input
358   q31_t *pSrc_converted=NULL; // input
359   q31_t *pDst=NULL; // output
360   uint32_t numSamples; // input
361 
362   if (PyArg_ParseTuple(args,"O",&pSrc))
363   {
364 
365     GETARGUMENT(pSrc,NPY_INT32,int32_t,int32_t);
366     numSamples = arraySizepSrc ;
367     numSamples = numSamples / 2;
368 
369     pDst=PyMem_Malloc(sizeof(q31_t)*2*numSamples);
370 
371 
372     arm_cmplx_mag_q31(pSrc_converted,pDst,numSamples);
373  INT32ARRAY1(pDstOBJ,numSamples,pDst);
374 
375     PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
376 
377     FREEARGUMENT(pSrc_converted);
378     Py_DECREF(pDstOBJ);
379     return(pythonResult);
380 
381   }
382   return(NULL);
383 }
384 
385 
386 static PyObject *
cmsis_arm_cmplx_mag_q15(PyObject * obj,PyObject * args)387 cmsis_arm_cmplx_mag_q15(PyObject *obj, PyObject *args)
388 {
389 
390   PyObject *pSrc=NULL; // input
391   q15_t *pSrc_converted=NULL; // input
392   q15_t *pDst=NULL; // output
393   uint32_t numSamples; // input
394 
395   if (PyArg_ParseTuple(args,"O",&pSrc))
396   {
397 
398     GETARGUMENT(pSrc,NPY_INT16,int16_t,int16_t);
399     numSamples = arraySizepSrc ;
400     numSamples = numSamples / 2;
401 
402     pDst=PyMem_Malloc(sizeof(q15_t)*2*numSamples);
403 
404 
405     arm_cmplx_mag_q15(pSrc_converted,pDst,numSamples);
406  INT16ARRAY1(pDstOBJ,numSamples,pDst);
407 
408     PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
409 
410     FREEARGUMENT(pSrc_converted);
411     Py_DECREF(pDstOBJ);
412     return(pythonResult);
413 
414   }
415   return(NULL);
416 }
417 
418 static PyObject *
cmsis_arm_cmplx_mag_fast_q15(PyObject * obj,PyObject * args)419 cmsis_arm_cmplx_mag_fast_q15(PyObject *obj, PyObject *args)
420 {
421 
422   PyObject *pSrc=NULL; // input
423   q15_t *pSrc_converted=NULL; // input
424   q15_t *pDst=NULL; // output
425   uint32_t numSamples; // input
426 
427   if (PyArg_ParseTuple(args,"O",&pSrc))
428   {
429 
430     GETARGUMENT(pSrc,NPY_INT16,int16_t,int16_t);
431     numSamples = arraySizepSrc ;
432     numSamples = numSamples / 2;
433 
434     pDst=PyMem_Malloc(sizeof(q15_t)*2*numSamples);
435 
436 
437     arm_cmplx_mag_fast_q15(pSrc_converted,pDst,numSamples);
438  INT16ARRAY1(pDstOBJ,numSamples,pDst);
439 
440     PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
441 
442     FREEARGUMENT(pSrc_converted);
443     Py_DECREF(pDstOBJ);
444     return(pythonResult);
445 
446   }
447   return(NULL);
448 }
449 
450 static PyObject *
cmsis_arm_cmplx_dot_prod_q15(PyObject * obj,PyObject * args)451 cmsis_arm_cmplx_dot_prod_q15(PyObject *obj, PyObject *args)
452 {
453 
454   PyObject *pSrcA=NULL; // input
455   q15_t *pSrcA_converted=NULL; // input
456   PyObject *pSrcB=NULL; // input
457   q15_t *pSrcB_converted=NULL; // input
458   uint32_t numSamples; // input
459   q31_t realResult; // output
460   q31_t imagResult; // output
461 
462   if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB))
463   {
464 
465     GETARGUMENT(pSrcA,NPY_INT16,int16_t,int16_t);
466     GETARGUMENT(pSrcB,NPY_INT16,int16_t,int16_t);
467     numSamples = arraySizepSrcA ;
468     numSamples = numSamples / 2;
469 
470 
471     arm_cmplx_dot_prod_q15(pSrcA_converted,pSrcB_converted,numSamples,&realResult,&imagResult);
472     PyObject* realResultOBJ=Py_BuildValue("i",realResult);
473     PyObject* imagResultOBJ=Py_BuildValue("i",imagResult);
474 
475     PyObject *pythonResult = Py_BuildValue("OO",realResultOBJ,imagResultOBJ);
476 
477     FREEARGUMENT(pSrcA_converted);
478     FREEARGUMENT(pSrcB_converted);
479     Py_DECREF(realResultOBJ);
480     Py_DECREF(imagResultOBJ);
481     return(pythonResult);
482 
483   }
484   return(NULL);
485 }
486 
487 
488 static PyObject *
cmsis_arm_cmplx_dot_prod_q31(PyObject * obj,PyObject * args)489 cmsis_arm_cmplx_dot_prod_q31(PyObject *obj, PyObject *args)
490 {
491 
492   PyObject *pSrcA=NULL; // input
493   q31_t *pSrcA_converted=NULL; // input
494   PyObject *pSrcB=NULL; // input
495   q31_t *pSrcB_converted=NULL; // input
496   uint32_t numSamples; // input
497   q63_t realResult; // output
498   q63_t imagResult; // output
499 
500   if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB))
501   {
502 
503     GETARGUMENT(pSrcA,NPY_INT32,int32_t,int32_t);
504     GETARGUMENT(pSrcB,NPY_INT32,int32_t,int32_t);
505     numSamples = arraySizepSrcA ;
506     numSamples = numSamples / 2;
507 
508 
509     arm_cmplx_dot_prod_q31(pSrcA_converted,pSrcB_converted,numSamples,&realResult,&imagResult);
510     PyObject* realResultOBJ=Py_BuildValue("L",realResult);
511     PyObject* imagResultOBJ=Py_BuildValue("L",imagResult);
512 
513     PyObject *pythonResult = Py_BuildValue("OO",realResultOBJ,imagResultOBJ);
514 
515     FREEARGUMENT(pSrcA_converted);
516     FREEARGUMENT(pSrcB_converted);
517     Py_DECREF(realResultOBJ);
518     Py_DECREF(imagResultOBJ);
519     return(pythonResult);
520 
521   }
522   return(NULL);
523 }
524 
525 
526 static PyObject *
cmsis_arm_cmplx_dot_prod_f32(PyObject * obj,PyObject * args)527 cmsis_arm_cmplx_dot_prod_f32(PyObject *obj, PyObject *args)
528 {
529 
530   PyObject *pSrcA=NULL; // input
531   float32_t *pSrcA_converted=NULL; // input
532   PyObject *pSrcB=NULL; // input
533   float32_t *pSrcB_converted=NULL; // input
534   uint32_t numSamples; // input
535   float32_t realResult; // output
536   float32_t imagResult; // output
537 
538   if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB))
539   {
540 
541     GETARGUMENT(pSrcA,NPY_DOUBLE,double,float32_t);
542     GETARGUMENT(pSrcB,NPY_DOUBLE,double,float32_t);
543     numSamples = arraySizepSrcA ;
544     numSamples = numSamples / 2;
545 
546 
547     arm_cmplx_dot_prod_f32(pSrcA_converted,pSrcB_converted,numSamples,&realResult,&imagResult);
548     PyObject* realResultOBJ=Py_BuildValue("f",realResult);
549     PyObject* imagResultOBJ=Py_BuildValue("f",imagResult);
550 
551     PyObject *pythonResult = Py_BuildValue("OO",realResultOBJ,imagResultOBJ);
552 
553     FREEARGUMENT(pSrcA_converted);
554     FREEARGUMENT(pSrcB_converted);
555     Py_DECREF(realResultOBJ);
556     Py_DECREF(imagResultOBJ);
557     return(pythonResult);
558 
559   }
560   return(NULL);
561 }
562 
563 
564 static PyObject *
cmsis_arm_cmplx_mult_real_q15(PyObject * obj,PyObject * args)565 cmsis_arm_cmplx_mult_real_q15(PyObject *obj, PyObject *args)
566 {
567 
568   PyObject *pSrcCmplx=NULL; // input
569   q15_t *pSrcCmplx_converted=NULL; // input
570   PyObject *pSrcReal=NULL; // input
571   q15_t *pSrcReal_converted=NULL; // input
572   q15_t *pCmplxDst=NULL; // output
573   uint32_t numSamples; // input
574 
575   if (PyArg_ParseTuple(args,"OO",&pSrcCmplx,&pSrcReal))
576   {
577 
578     GETARGUMENT(pSrcCmplx,NPY_INT16,int16_t,int16_t);
579     GETARGUMENT(pSrcReal,NPY_INT16,int16_t,int16_t);
580     numSamples = arraySizepSrcCmplx ;
581     numSamples = numSamples / 2;
582 
583     pCmplxDst=PyMem_Malloc(sizeof(q15_t)*2*numSamples);
584 
585 
586     arm_cmplx_mult_real_q15(pSrcCmplx_converted,pSrcReal_converted,pCmplxDst,numSamples);
587  INT16ARRAY1(pCmplxDstOBJ,2*numSamples,pCmplxDst);
588 
589     PyObject *pythonResult = Py_BuildValue("O",pCmplxDstOBJ);
590 
591     FREEARGUMENT(pSrcCmplx_converted);
592     FREEARGUMENT(pSrcReal_converted);
593     Py_DECREF(pCmplxDstOBJ);
594     return(pythonResult);
595 
596   }
597   return(NULL);
598 }
599 
600 
601 static PyObject *
cmsis_arm_cmplx_mult_real_q31(PyObject * obj,PyObject * args)602 cmsis_arm_cmplx_mult_real_q31(PyObject *obj, PyObject *args)
603 {
604 
605   PyObject *pSrcCmplx=NULL; // input
606   q31_t *pSrcCmplx_converted=NULL; // input
607   PyObject *pSrcReal=NULL; // input
608   q31_t *pSrcReal_converted=NULL; // input
609   q31_t *pCmplxDst=NULL; // output
610   uint32_t numSamples; // input
611 
612   if (PyArg_ParseTuple(args,"OO",&pSrcCmplx,&pSrcReal))
613   {
614 
615     GETARGUMENT(pSrcCmplx,NPY_INT32,int32_t,int32_t);
616     GETARGUMENT(pSrcReal,NPY_INT32,int32_t,int32_t);
617     numSamples = arraySizepSrcCmplx ;
618     numSamples = numSamples / 2;
619 
620     pCmplxDst=PyMem_Malloc(sizeof(q31_t)*2*numSamples);
621 
622 
623     arm_cmplx_mult_real_q31(pSrcCmplx_converted,pSrcReal_converted,pCmplxDst,numSamples);
624  INT32ARRAY1(pCmplxDstOBJ,2*numSamples,pCmplxDst);
625 
626     PyObject *pythonResult = Py_BuildValue("O",pCmplxDstOBJ);
627 
628     FREEARGUMENT(pSrcCmplx_converted);
629     FREEARGUMENT(pSrcReal_converted);
630     Py_DECREF(pCmplxDstOBJ);
631     return(pythonResult);
632 
633   }
634   return(NULL);
635 }
636 
637 
638 static PyObject *
cmsis_arm_cmplx_mult_real_f32(PyObject * obj,PyObject * args)639 cmsis_arm_cmplx_mult_real_f32(PyObject *obj, PyObject *args)
640 {
641 
642   PyObject *pSrcCmplx=NULL; // input
643   float32_t *pSrcCmplx_converted=NULL; // input
644   PyObject *pSrcReal=NULL; // input
645   float32_t *pSrcReal_converted=NULL; // input
646   float32_t *pCmplxDst=NULL; // output
647   uint32_t numSamples; // input
648 
649   if (PyArg_ParseTuple(args,"OO",&pSrcCmplx,&pSrcReal))
650   {
651 
652     GETARGUMENT(pSrcCmplx,NPY_DOUBLE,double,float32_t);
653     GETARGUMENT(pSrcReal,NPY_DOUBLE,double,float32_t);
654     numSamples = arraySizepSrcCmplx ;
655     numSamples = numSamples / 2;
656 
657     pCmplxDst=PyMem_Malloc(sizeof(float32_t)*2*numSamples);
658 
659 
660     arm_cmplx_mult_real_f32(pSrcCmplx_converted,pSrcReal_converted,pCmplxDst,numSamples);
661  FLOATARRAY1(pCmplxDstOBJ,2*numSamples,pCmplxDst);
662 
663     PyObject *pythonResult = Py_BuildValue("O",pCmplxDstOBJ);
664 
665     FREEARGUMENT(pSrcCmplx_converted);
666     FREEARGUMENT(pSrcReal_converted);
667     Py_DECREF(pCmplxDstOBJ);
668     return(pythonResult);
669 
670   }
671   return(NULL);
672 }
673 
674 
675 
676 
677 static PyObject *
cmsis_arm_cmplx_mult_cmplx_q15(PyObject * obj,PyObject * args)678 cmsis_arm_cmplx_mult_cmplx_q15(PyObject *obj, PyObject *args)
679 {
680 
681   PyObject *pSrcA=NULL; // input
682   q15_t *pSrcA_converted=NULL; // input
683   PyObject *pSrcB=NULL; // input
684   q15_t *pSrcB_converted=NULL; // input
685   q15_t *pDst=NULL; // output
686   uint32_t numSamples; // input
687 
688   if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB))
689   {
690 
691     GETARGUMENT(pSrcA,NPY_INT16,int16_t,int16_t);
692     GETARGUMENT(pSrcB,NPY_INT16,int16_t,int16_t);
693     numSamples = arraySizepSrcA ;
694     numSamples = numSamples / 2;
695 
696     pDst=PyMem_Malloc(sizeof(q15_t)*2*numSamples);
697 
698 
699     arm_cmplx_mult_cmplx_q15(pSrcA_converted,pSrcB_converted,pDst,numSamples);
700  INT16ARRAY1(pDstOBJ,2*numSamples,pDst);
701 
702     PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
703 
704     FREEARGUMENT(pSrcA_converted);
705     FREEARGUMENT(pSrcB_converted);
706     Py_DECREF(pDstOBJ);
707     return(pythonResult);
708 
709   }
710   return(NULL);
711 }
712 
713 
714 static PyObject *
cmsis_arm_cmplx_mult_cmplx_q31(PyObject * obj,PyObject * args)715 cmsis_arm_cmplx_mult_cmplx_q31(PyObject *obj, PyObject *args)
716 {
717 
718   PyObject *pSrcA=NULL; // input
719   q31_t *pSrcA_converted=NULL; // input
720   PyObject *pSrcB=NULL; // input
721   q31_t *pSrcB_converted=NULL; // input
722   q31_t *pDst=NULL; // output
723   uint32_t numSamples; // input
724 
725   if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB))
726   {
727 
728     GETARGUMENT(pSrcA,NPY_INT32,int32_t,int32_t);
729     GETARGUMENT(pSrcB,NPY_INT32,int32_t,int32_t);
730     numSamples = arraySizepSrcA ;
731     numSamples = numSamples / 2;
732 
733     pDst=PyMem_Malloc(sizeof(q31_t)*2*numSamples);
734 
735 
736     arm_cmplx_mult_cmplx_q31(pSrcA_converted,pSrcB_converted,pDst,numSamples);
737  INT32ARRAY1(pDstOBJ,2*numSamples,pDst);
738 
739     PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
740 
741     FREEARGUMENT(pSrcA_converted);
742     FREEARGUMENT(pSrcB_converted);
743     Py_DECREF(pDstOBJ);
744     return(pythonResult);
745 
746   }
747   return(NULL);
748 }
749 
750 
751 static PyObject *
cmsis_arm_cmplx_mult_cmplx_f32(PyObject * obj,PyObject * args)752 cmsis_arm_cmplx_mult_cmplx_f32(PyObject *obj, PyObject *args)
753 {
754 
755   PyObject *pSrcA=NULL; // input
756   float32_t *pSrcA_converted=NULL; // input
757   PyObject *pSrcB=NULL; // input
758   float32_t *pSrcB_converted=NULL; // input
759   float32_t *pDst=NULL; // output
760   uint32_t numSamples; // input
761 
762   if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB))
763   {
764 
765     GETARGUMENT(pSrcA,NPY_DOUBLE,double,float32_t);
766     GETARGUMENT(pSrcB,NPY_DOUBLE,double,float32_t);
767     numSamples = arraySizepSrcA ;
768     numSamples = numSamples / 2;
769 
770     pDst=PyMem_Malloc(sizeof(float32_t)*2*numSamples);
771 
772 
773     arm_cmplx_mult_cmplx_f32(pSrcA_converted,pSrcB_converted,pDst,numSamples);
774  FLOATARRAY1(pDstOBJ,2*numSamples,pDst);
775 
776     PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
777 
778     FREEARGUMENT(pSrcA_converted);
779     FREEARGUMENT(pSrcB_converted);
780     Py_DECREF(pDstOBJ);
781     return(pythonResult);
782 
783   }
784   return(NULL);
785 }
786 
787 static PyObject *
cmsis_arm_cmplx_mult_cmplx_f64(PyObject * obj,PyObject * args)788 cmsis_arm_cmplx_mult_cmplx_f64(PyObject *obj, PyObject *args)
789 {
790 
791   PyObject *pSrcA=NULL; // input
792   float64_t *pSrcA_converted=NULL; // input
793   PyObject *pSrcB=NULL; // input
794   float64_t *pSrcB_converted=NULL; // input
795   float64_t *pDst=NULL; // output
796   uint32_t numSamples; // input
797 
798   if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB))
799   {
800 
801     GETARGUMENT(pSrcA,NPY_DOUBLE,double,float64_t);
802     GETARGUMENT(pSrcB,NPY_DOUBLE,double,float64_t);
803     numSamples = arraySizepSrcA ;
804     numSamples = numSamples / 2;
805 
806     pDst=PyMem_Malloc(sizeof(float64_t)*2*numSamples);
807 
808 
809     arm_cmplx_mult_cmplx_f64(pSrcA_converted,pSrcB_converted,pDst,numSamples);
810  FLOAT64ARRAY1(pDstOBJ,2*numSamples,pDst);
811 
812     PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
813 
814     FREEARGUMENT(pSrcA_converted);
815     FREEARGUMENT(pSrcB_converted);
816     Py_DECREF(pDstOBJ);
817     return(pythonResult);
818 
819   }
820   return(NULL);
821 }
822 
823 
824 static PyMethodDef CMSISDSPMethods[] = {
825 
826 
827 {"arm_cmplx_conj_f32",  cmsis_arm_cmplx_conj_f32, METH_VARARGS,""},
828 {"arm_cmplx_conj_q31",  cmsis_arm_cmplx_conj_q31, METH_VARARGS,""},
829 {"arm_cmplx_conj_q15",  cmsis_arm_cmplx_conj_q15, METH_VARARGS,""},
830 {"arm_cmplx_mag_squared_f32",  cmsis_arm_cmplx_mag_squared_f32, METH_VARARGS,""},
831 {"arm_cmplx_mag_squared_f64",  cmsis_arm_cmplx_mag_squared_f64, METH_VARARGS,""},
832 {"arm_cmplx_mag_squared_q31",  cmsis_arm_cmplx_mag_squared_q31, METH_VARARGS,""},
833 {"arm_cmplx_mag_squared_q15",  cmsis_arm_cmplx_mag_squared_q15, METH_VARARGS,""},
834 
835 
836 {"arm_cmplx_mag_f32",  cmsis_arm_cmplx_mag_f32, METH_VARARGS,""},
837 {"arm_cmplx_mag_f64",  cmsis_arm_cmplx_mag_f64, METH_VARARGS,""},
838 {"arm_cmplx_mag_q31",  cmsis_arm_cmplx_mag_q31, METH_VARARGS,""},
839 {"arm_cmplx_mag_q15",  cmsis_arm_cmplx_mag_q15, METH_VARARGS,""},
840 {"arm_cmplx_mag_fast_q15",  cmsis_arm_cmplx_mag_fast_q15, METH_VARARGS,""},
841 {"arm_cmplx_dot_prod_q15",  cmsis_arm_cmplx_dot_prod_q15, METH_VARARGS,""},
842 {"arm_cmplx_dot_prod_q31",  cmsis_arm_cmplx_dot_prod_q31, METH_VARARGS,""},
843 {"arm_cmplx_dot_prod_f32",  cmsis_arm_cmplx_dot_prod_f32, METH_VARARGS,""},
844 {"arm_cmplx_mult_real_q15",  cmsis_arm_cmplx_mult_real_q15, METH_VARARGS,""},
845 {"arm_cmplx_mult_real_q31",  cmsis_arm_cmplx_mult_real_q31, METH_VARARGS,""},
846 {"arm_cmplx_mult_real_f32",  cmsis_arm_cmplx_mult_real_f32, METH_VARARGS,""},
847 {"arm_cmplx_mult_cmplx_q15",  cmsis_arm_cmplx_mult_cmplx_q15, METH_VARARGS,""},
848 {"arm_cmplx_mult_cmplx_q31",  cmsis_arm_cmplx_mult_cmplx_q31, METH_VARARGS,""},
849 {"arm_cmplx_mult_cmplx_f32",  cmsis_arm_cmplx_mult_cmplx_f32, METH_VARARGS,""},
850 {"arm_cmplx_mult_cmplx_f64",  cmsis_arm_cmplx_mult_cmplx_f64, METH_VARARGS,""},
851 
852     {"error_out", (PyCFunction)error_out, METH_NOARGS, NULL},
853     {NULL, NULL, 0, NULL}        /* Sentinel */
854 };
855 
856 #ifdef IS_PY3K
cmsisdsp_traverse(PyObject * m,visitproc visit,void * arg)857 static int cmsisdsp_traverse(PyObject *m, visitproc visit, void *arg) {
858     Py_VISIT(GETSTATE(m)->error);
859     return 0;
860 }
861 
cmsisdsp_clear(PyObject * m)862 static int cmsisdsp_clear(PyObject *m) {
863     Py_CLEAR(GETSTATE(m)->error);
864     return 0;
865 }
866 
867 
868 static struct PyModuleDef moduledef = {
869         PyModuleDef_HEAD_INIT,
870         MODNAME,
871         NULL,
872         sizeof(struct module_state),
873         CMSISDSPMethods,
874         NULL,
875         cmsisdsp_traverse,
876         cmsisdsp_clear,
877         NULL
878 };
879 
880 #define INITERROR return NULL
881 
882 PyMODINIT_FUNC
CAT(PyInit_,MODINITNAME)883 CAT(PyInit_,MODINITNAME)(void)
884 
885 
886 #else
887 #define INITERROR return
888 
889 void CAT(init,MODINITNAME)(void)
890 #endif
891 {
892     import_array();
893 
894   #ifdef IS_PY3K
895     PyObject *module = PyModule_Create(&moduledef);
896   #else
897     PyObject *module = Py_InitModule(MODNAME, CMSISDSPMethods);
898   #endif
899 
900   if (module == NULL)
901       INITERROR;
902   struct module_state *st = GETSTATE(module);
903 
904   st->error = PyErr_NewException(MODNAME".Error", NULL, NULL);
905   if (st->error == NULL) {
906       Py_DECREF(module);
907       INITERROR;
908   }
909 
910 
911   typeRegistration(module);
912 
913   #ifdef IS_PY3K
914     return module;
915   #endif
916 }