GNU Radio Manual and C++ API Reference  3.7.7
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
volk_32fc_s32f_deinterleave_real_16i.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2012, 2014 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 /*!
24  * \page volk_32fc_s32f_deinterleave_real_16i
25  *
26  * \b Overview
27  *
28  * Deinterleaves the complex floating point vector and return the real
29  * part (inphase) of the samples scaled to 16-bit shorts.
30  *
31  * <b>Dispatcher Prototype</b>
32  * \code
33  * void volk_32fc_s32f_deinterleave_real_16i(int16_t* iBuffer, const lv_32fc_t* complexVector, const float scalar, unsigned int num_points)
34  * \endcode
35  *
36  * \b Inputs
37  * \li complexVector: The complex input vector.
38  * \li scalar: The value to be multiplied against each of the input vectors..
39  * \li num_points: The number of complex data values to be deinterleaved.
40  *
41  * \b Outputs
42  * \li iBuffer: The I buffer output data.
43  *
44  * \b Example
45  * Generate points around the unit circle and map them to integers with
46  * magnitude 50 to preserve smallest deltas.
47  * \code
48  * int N = 10;
49  * unsigned int alignment = volk_get_alignment();
50  * lv_32fc_t* in = (lv_32fc_t*)volk_malloc(sizeof(lv_32fc_t)*N, alignment);
51  * int16_t* out = (int16_t*)volk_malloc(sizeof(int16_t)*N, alignment);
52  * float scale = 50.f;
53  *
54  * for(unsigned int ii = 0; ii < N/2; ++ii){
55  * // Generate points around the unit circle
56  * float real = -4.f * ((float)ii / (float)N) + 1.f;
57  * float imag = std::sqrt(1.f - real * real);
58  * in[ii] = lv_cmake(real, imag);
59  * in[ii+N/2] = lv_cmake(-real, -imag);
60  * }
61  *
62  * volk_32fc_s32f_deinterleave_real_16i(out, in, scale, N);
63  *
64  * for(unsigned int ii = 0; ii < N; ++ii){
65  * printf("out[%u] = %i\n", ii, out[ii]);
66  * }
67  *
68  * volk_free(in);
69  * volk_free(out);
70  * \endcode
71  */
72 
73 #ifndef INCLUDED_volk_32fc_s32f_deinterleave_real_16i_a_H
74 #define INCLUDED_volk_32fc_s32f_deinterleave_real_16i_a_H
75 
76 #include <volk/volk_common.h>
77 #include <inttypes.h>
78 #include <stdio.h>
79 
80 #ifdef LV_HAVE_SSE
81 #include <xmmintrin.h>
82 
83 static inline void
84 volk_32fc_s32f_deinterleave_real_16i_a_sse(int16_t* iBuffer, const lv_32fc_t* complexVector,
85  const float scalar, unsigned int num_points)
86 {
87  unsigned int number = 0;
88  const unsigned int quarterPoints = num_points / 4;
89 
90  const float* complexVectorPtr = (float*)complexVector;
91  int16_t* iBufferPtr = iBuffer;
92 
93  __m128 vScalar = _mm_set_ps1(scalar);
94 
95  __m128 cplxValue1, cplxValue2, iValue;
96 
97  __VOLK_ATTR_ALIGNED(16) float floatBuffer[4];
98 
99  for(;number < quarterPoints; number++){
100  cplxValue1 = _mm_load_ps(complexVectorPtr);
101  complexVectorPtr += 4;
102 
103  cplxValue2 = _mm_load_ps(complexVectorPtr);
104  complexVectorPtr += 4;
105 
106  // Arrange in i1i2i3i4 format
107  iValue = _mm_shuffle_ps(cplxValue1, cplxValue2, _MM_SHUFFLE(2,0,2,0));
108 
109  iValue = _mm_mul_ps(iValue, vScalar);
110 
111  _mm_store_ps(floatBuffer, iValue);
112  *iBufferPtr++ = (int16_t)(floatBuffer[0]);
113  *iBufferPtr++ = (int16_t)(floatBuffer[1]);
114  *iBufferPtr++ = (int16_t)(floatBuffer[2]);
115  *iBufferPtr++ = (int16_t)(floatBuffer[3]);
116  }
117 
118  number = quarterPoints * 4;
119  iBufferPtr = &iBuffer[number];
120  for(; number < num_points; number++){
121  *iBufferPtr++ = (int16_t)(*complexVectorPtr++ * scalar);
122  complexVectorPtr++;
123  }
124 }
125 
126 #endif /* LV_HAVE_SSE */
127 
128 
129 #ifdef LV_HAVE_GENERIC
130 
131 static inline void
132 volk_32fc_s32f_deinterleave_real_16i_generic(int16_t* iBuffer, const lv_32fc_t* complexVector,
133  const float scalar, unsigned int num_points)
134 {
135  const float* complexVectorPtr = (float*)complexVector;
136  int16_t* iBufferPtr = iBuffer;
137  unsigned int number = 0;
138  for(number = 0; number < num_points; number++){
139  *iBufferPtr++ = (int16_t)(*complexVectorPtr++ * scalar);
140  complexVectorPtr++;
141  }
142 }
143 
144 #endif /* LV_HAVE_GENERIC */
145 
146 #endif /* INCLUDED_volk_32fc_s32f_deinterleave_real_16i_a_H */
signed short int16_t
Definition: stdint.h:76
#define __VOLK_ATTR_ALIGNED(x)
Definition: volk_common.h:27
float complex lv_32fc_t
Definition: volk_complex.h:56