DSPLIB User Guide
DSPLIB_fltoq15_cn.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 **+--------------------------------------------------------------------------+**
3 **| **** |**
4 **| **** |**
5 **| ******o*** |**
6 **| ********_///_**** |**
7 **| ***** /_//_/ **** |**
8 **| ** ** (__/ **** |**
9 **| ********* |**
10 **| **** |**
11 **| *** |**
12 **| |**
13 **| Copyright (c) 2016 Texas Instruments Incorporated |**
14 **| ALL RIGHTS RESERVED |**
15 **| |**
16 **| Permission to use, copy, modify, or distribute this software, |**
17 **| whether in part or in whole, for any purpose is forbidden without |**
18 **| a signed licensing agreement and NDA from Texas Instruments |**
19 **| Incorporated (TI). |**
20 **| |**
21 **| TI makes no representation or warranties with respect to the |**
22 **| performance of this computer program, and specifically disclaims |**
23 **| any responsibility for any damages, special or consequential, |**
24 **| connected with the use of this program. |**
25 **| |**
26 **+--------------------------------------------------------------------------+**
27 *******************************************************************************/
28 
29 #include "DSPLIB_fltoq15_priv.h"
30 
32  DSPLIB_bufParams1D_t *bufParamsIn,
33  DSPLIB_bufParams1D_t *bufParamsOut,
34  const DSPLIB_fltoq15_InitArgs *pKerInitArgs)
35 {
36  return DSPLIB_SUCCESS;
37 }
38 
39 template <typename dataTypeIn>
40 DSPLIB_STATUS DSPLIB_fltoq15_exec_cn(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
41 {
42  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering function");
43 
45 
46  DSPLIB_fltoq15_PrivArgs *pKerPrivArgs = (DSPLIB_fltoq15_PrivArgs *) handle;
47  uint32_t blockSize = pKerPrivArgs->blockSize;
48 
49  dataTypeIn *pInLocal = (dataTypeIn *) pIn;
50  int16_t *pOutLocal = (int16_t *) pOut;
51 
52  DSPLIB_DEBUGPRINTFN(0, "pInLocal: %p pOutLocal: %p blockSize: %d\n", pInLocal, pOutLocal, blockSize);
53 
54  dataTypeIn a;
55  dataTypeIn mulFactor = 32768.00;
56  int32_t aInt = 0;
57  int16_t out = 0;
58 
59  for (int32_t counter = 0; counter < (int32_t) blockSize; counter++) {
60  a = *pInLocal++;
61  dataTypeIn mulVal = a * mulFactor;
62 
63  int32_t intPart = (int32_t) mulVal;
64  dataTypeIn fracPart = mulVal - intPart;
65 
66  if ((intPart % 2 == 0) && (abs(fracPart) == 0.5)) {
67  aInt = intPart;
68  }
69  else if (a < 0) {
70  aInt = (int32_t) (mulVal - 0.5f);
71  }
72  else {
73  aInt = (int32_t) (mulVal + 0.5f);
74  }
75 
76  /* saturate to 16-bit */
77  if (aInt > 32767) {
78  aInt = 32767;
79  }
80  if (aInt < -32768) {
81  aInt = -32768;
82  }
83 
84  out = (short) aInt;
85  *pOutLocal++ = out;
86  }
87 
88  DSPLIB_DEBUGPRINTFN(0, "Exiting function with return status: %d\n", status);
89 
90  return (status);
91 }
92 
93 // explicit instantiation for the different data type versions
94 template DSPLIB_STATUS
95 DSPLIB_fltoq15_exec_cn<float>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
96 template DSPLIB_STATUS
97 DSPLIB_fltoq15_exec_cn<double>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
DSPLIB_STATUS DSPLIB_fltoq15_exec_cn(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
This function is the main execution function for the natural C implementation of the kernel....
template DSPLIB_STATUS DSPLIB_fltoq15_exec_cn< float >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_fltoq15_init_cn(DSPLIB_kernelHandle handle, DSPLIB_bufParams1D_t *bufParamsIn, DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_fltoq15_InitArgs *pKerInitArgs)
This function is the initialization function for the natural C implementation of the kernel....
template DSPLIB_STATUS DSPLIB_fltoq15_exec_cn< double >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
Header file for kernel's internal use. For the kernel's interface, please see DSPLIB_fltoq15.
#define DSPLIB_DEBUGPRINTFN(N, fmt,...)
Definition: DSPLIB_types.h:83
DSPLIB_STATUS_NAME
The enumeration of all status codes.
Definition: DSPLIB_types.h:151
void * DSPLIB_kernelHandle
Handle type for DSPLIB operations.
Definition: DSPLIB_types.h:172
@ DSPLIB_SUCCESS
Definition: DSPLIB_types.h:152
A structure for a 1 dimensional buffer descriptor.
Structure containing the parameters to initialize the kernel.
Structure that is reserved for internal use by the kernel.
int32_t blockSize
Size of input buffer for different batches DSPLIB_fltoq15_init that will be retrieved and used by DSP...