diff options
author | ghostop14 <ghostop14@gmail.com> | 2020-02-15 18:07:35 -0500 |
---|---|---|
committer | Michael Dickens <michael.dickens@ettus.com> | 2020-02-20 09:08:11 -0500 |
commit | 458414c7b2ab93fa1a6d130fa64d907dd9fca5f0 (patch) | |
tree | 95d0b94f17c4a5396756150558b922e0a240fb01 /gr-blocks/lib/interleaved_char_to_complex_impl.cc | |
parent | 5cd7b4cd472e9dca41f19e2cdfed4393374c9fe0 (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/interleaved_char_to_complex_impl.cc')
-rw-r--r-- | gr-blocks/lib/interleaved_char_to_complex_impl.cc | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/gr-blocks/lib/interleaved_char_to_complex_impl.cc b/gr-blocks/lib/interleaved_char_to_complex_impl.cc index 31ed942485..1b1ace671f 100644 --- a/gr-blocks/lib/interleaved_char_to_complex_impl.cc +++ b/gr-blocks/lib/interleaved_char_to_complex_impl.cc @@ -19,16 +19,21 @@ namespace gr { namespace blocks { -interleaved_char_to_complex::sptr interleaved_char_to_complex::make(bool vector_input) +interleaved_char_to_complex::sptr interleaved_char_to_complex::make(bool vector_input, + float scale_factor) { - return gnuradio::get_initial_sptr(new interleaved_char_to_complex_impl(vector_input)); + return gnuradio::get_initial_sptr( + new interleaved_char_to_complex_impl(vector_input, scale_factor)); } -interleaved_char_to_complex_impl::interleaved_char_to_complex_impl(bool vector_input) +interleaved_char_to_complex_impl::interleaved_char_to_complex_impl(bool vector_input, + float scale_factor) : sync_decimator("interleaved_char_to_complex", gr::io_signature::make(1, 1, (vector_input ? 2 : 1) * sizeof(char)), gr::io_signature::make(1, 1, sizeof(gr_complex)), - vector_input ? 1 : 2) + vector_input ? 1 : 2), + d_scalar(scale_factor), + d_vector(vector_input) { const int alignment_multiple = volk_get_alignment() / sizeof(gr_complex); set_alignment(std::max(1, alignment_multiple)); @@ -38,10 +43,11 @@ int interleaved_char_to_complex_impl::work(int noutput_items, gr_vector_const_void_star& input_items, gr_vector_void_star& output_items) { - const int8_t* in = (const int8_t*)input_items[0]; float* out = (float*)output_items[0]; + const int8_t* in = (const int8_t*)input_items[0]; - volk_8i_s32f_convert_32f_u(out, in, 1.0, 2 * noutput_items); + // This calculates in[] * 1.0 / d_scalar + volk_8i_s32f_convert_32f(out, in, d_scalar, 2 * noutput_items); return noutput_items; } |