summaryrefslogtreecommitdiff
path: root/gr-blocks/lib/complex_to_interleaved_char_impl.cc
diff options
context:
space:
mode:
authorghostop14 <ghostop14@gmail.com>2020-02-15 18:07:35 -0500
committerMichael Dickens <michael.dickens@ettus.com>2020-02-20 09:08:11 -0500
commit458414c7b2ab93fa1a6d130fa64d907dd9fca5f0 (patch)
tree95d0b94f17c4a5396756150558b922e0a240fb01 /gr-blocks/lib/complex_to_interleaved_char_impl.cc
parent5cd7b4cd472e9dca41f19e2cdfed4393374c9fe0 (diff)
gr-blocks: Add scaling option to Complex to/from ishort and ichar
The existing block combinations of complex-to-ichar/ichar-to-complex and complex-to-ishort/ishort-to-complex was not exposing a scale factor to the UI (it was hard-coded at 1.0) which prevented the blocks from being used with voltage-based inputs and outputs, for example a -127 to 127 byte input would be mapped directly to the same value as a float. The same was true in reverse and there were notes in the code about FIX clipping. Adding the scale factor provides a mechanism for the user to appropriately fix the clipping and scale the conversion correctly. Additional documentation was added to the block yml to provide guidance to users on how to appropriately select the scale factor for their use case, and the default value was set to 1.0 for backward compatibility.
Diffstat (limited to 'gr-blocks/lib/complex_to_interleaved_char_impl.cc')
-rw-r--r--gr-blocks/lib/complex_to_interleaved_char_impl.cc24
1 files changed, 13 insertions, 11 deletions
diff --git a/gr-blocks/lib/complex_to_interleaved_char_impl.cc b/gr-blocks/lib/complex_to_interleaved_char_impl.cc
index d875ce9772..a60a3d9675 100644
--- a/gr-blocks/lib/complex_to_interleaved_char_impl.cc
+++ b/gr-blocks/lib/complex_to_interleaved_char_impl.cc
@@ -14,21 +14,26 @@
#include "complex_to_interleaved_char_impl.h"
#include <gnuradio/io_signature.h>
+#include <volk/volk.h>
namespace gr {
namespace blocks {
-complex_to_interleaved_char::sptr complex_to_interleaved_char::make(bool vector)
+complex_to_interleaved_char::sptr complex_to_interleaved_char::make(bool vector,
+ float scale_factor)
{
- return gnuradio::get_initial_sptr(new complex_to_interleaved_char_impl(vector));
+ return gnuradio::get_initial_sptr(
+ new complex_to_interleaved_char_impl(vector, scale_factor));
}
-complex_to_interleaved_char_impl::complex_to_interleaved_char_impl(bool vector)
+complex_to_interleaved_char_impl::complex_to_interleaved_char_impl(bool vector,
+ float scale_factor)
: sync_interpolator(
"complex_to_interleaved_char",
io_signature::make(1, 1, sizeof(gr_complex)),
io_signature::make(1, 1, vector ? 2 * sizeof(char) : sizeof(char)),
vector ? 1 : 2),
+ d_scalar(scale_factor),
d_vector(vector)
{
}
@@ -37,14 +42,11 @@ int complex_to_interleaved_char_impl::work(int noutput_items,
gr_vector_const_void_star& input_items,
gr_vector_void_star& output_items)
{
- const gr_complex* in = (const gr_complex*)input_items[0];
- char* out = (char*)output_items[0];
-
- int npairs = (d_vector ? noutput_items : noutput_items / 2);
- for (int i = 0; i < npairs; i++) {
- *out++ = (char)lrintf(in[i].real()); // FIXME saturate?
- *out++ = (char)lrintf(in[i].imag());
- }
+ const float* in = (const float*)input_items[0];
+ int8_t* out = (int8_t*)output_items[0];
+
+ volk_32f_s32f_convert_8i(
+ out, in, d_scalar, d_vector ? noutput_items * 2 : noutput_items);
return noutput_items;
}