Texas Instruments TMS320C64X User Manual

Page 113

Advertising
background image

DSP_fltoq15

4-85

C64x+ DSPLIB Reference

Float to Q15 Conversion

DSP_fltoq15

Function

void DSP_fltoq15 (float *x, short *r, short nx)

Arguments

x[nx]

Pointer to floating-point input vector of size nx. x should contain
the numbers normalized between [−1,1).

r[nx]

Pointer to output data vector of size nx containing the Q.15
equivalent of vector x.

nx

Length of input and output data vectors. Must be multiple of 2.

Description

Convert the IEEE floating point numbers stored in vector x[ ] into Q.15 format
numbers stored in vector r[ ]. Results are truncated toward zero. Values that
exceed the size limit will be saturated to 0x7fff if value is positive and 0x8000
if value is negative. All values too small to be correctly represented will be
truncated to 0.

Algorithm

This is the C equivalent of the assembly code without restrictions. Note that the
assembly code is hand optimized and restrictions may apply.

void fltoq15(float x[], short r[], short nx)

{

int i, a;

for(i = 0; i < nx; i++)

{

a = 32768 * x[i];

// saturate to 16−bit //

if (a>32767) a = 32767;

if (a<−32768) a = −32768;

r[i] = (short) a;

}

}

Special Requirements nx must be a multiple of 2.

Advertising