summaryrefslogtreecommitdiff
path: root/gnuradio-core/src/lib
diff options
context:
space:
mode:
authorTom Rondeau2012-02-11 09:06:45 -0500
committerTom Rondeau2012-02-13 14:57:28 -0500
commitf671319ca9ccef8fb1590e676ff6bcb85d7ca5a1 (patch)
treefeb7b7ef296bcaf01138152feaf43202dc04087b /gnuradio-core/src/lib
parent84cb8f63d0d96ede1a6a10940112ae5a087029fc (diff)
downloadgnuradio-f671319ca9ccef8fb1590e676ff6bcb85d7ca5a1.tar.gz
gnuradio-f671319ca9ccef8fb1590e676ff6bcb85d7ca5a1.tar.bz2
gnuradio-f671319ca9ccef8fb1590e676ff6bcb85d7ca5a1.zip
core: reverting float_to_int to non-Volk due to precision/wrapping issues.
Using the Volk function causes too much of a change in the output values right now. Will have to relook at it for the right thing to do. Keeping the use of vlen and scale, though.
Diffstat (limited to 'gnuradio-core/src/lib')
-rw-r--r--gnuradio-core/src/lib/general/gr_float_to_int.cc18
-rw-r--r--gnuradio-core/src/lib/general/gri_float_to_int.cc4
-rw-r--r--gnuradio-core/src/lib/general/gri_float_to_int.h2
3 files changed, 17 insertions, 7 deletions
diff --git a/gnuradio-core/src/lib/general/gr_float_to_int.cc b/gnuradio-core/src/lib/general/gr_float_to_int.cc
index 28214538f..b69591043 100644
--- a/gnuradio-core/src/lib/general/gr_float_to_int.cc
+++ b/gnuradio-core/src/lib/general/gr_float_to_int.cc
@@ -26,6 +26,7 @@
#include <gr_float_to_int.h>
#include <gr_io_signature.h>
+#include <gri_float_to_int.h>
#include <volk/volk.h>
gr_float_to_int_sptr
@@ -56,12 +57,17 @@ gr_float_to_int::set_scale(float scale)
{
d_scale = scale;
}
-
int
gr_float_to_int::work (int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
+ // Disable the Volk for now. There is a problem for large 32-bit ints that
+ // are not properly represented by the precisions of a single float, which
+ // can cause wrapping from large, positive numbers to negative.
+ // In gri_float_to_int, the value is first promoted to a 64-bit
+ // value, clipped, then converted to a float.
+#if 0
const float *in = (const float *) input_items[0];
int32_t *out = (int32_t *) output_items[0];
@@ -71,9 +77,13 @@ gr_float_to_int::work (int noutput_items,
else {
volk_32f_s32f_convert_32i_a(out, in, d_scale, d_vlen*noutput_items);
}
+#else
+ const float *in = (const float *) input_items[0];
+ int *out = (int *) output_items[0];
+
+ gri_float_to_int (in, out, d_scale, d_vlen*noutput_items);
+
+#endif
return noutput_items;
}
-
-
-
diff --git a/gnuradio-core/src/lib/general/gri_float_to_int.cc b/gnuradio-core/src/lib/general/gri_float_to_int.cc
index 5271e60e2..0b0b10dfe 100644
--- a/gnuradio-core/src/lib/general/gri_float_to_int.cc
+++ b/gnuradio-core/src/lib/general/gri_float_to_int.cc
@@ -34,10 +34,10 @@ static const int64_t MIN_INT = -2147483647; // -(2^31)-1
void
-gri_float_to_int (const float *in, int *out, int nsamples)
+gri_float_to_int (const float *in, int *out, float scale, int nsamples)
{
for (int i = 0; i < nsamples; i++){
- int64_t r = llrintf(in[i]);
+ int64_t r = llrintf(scale * in[i]);
if (r < MIN_INT)
r = MIN_INT;
else if (r > MAX_INT)
diff --git a/gnuradio-core/src/lib/general/gri_float_to_int.h b/gnuradio-core/src/lib/general/gri_float_to_int.h
index a2f6ea877..d8b98efc1 100644
--- a/gnuradio-core/src/lib/general/gri_float_to_int.h
+++ b/gnuradio-core/src/lib/general/gri_float_to_int.h
@@ -28,6 +28,6 @@
/*!
* convert array of floats to int with rounding and saturation.
*/
-GR_CORE_API void gri_float_to_int (const float *in, int *out, int nsamples);
+GR_CORE_API void gri_float_to_int (const float *in, int *out, float scale, int nsamples);
#endif /* INCLUDED_GRI_FLOAT_TO_INT_H */