diff options
author | Tom Rondeau | 2011-10-23 17:12:32 -0400 |
---|---|---|
committer | Tom Rondeau | 2011-10-23 17:12:32 -0400 |
commit | 7112e308a6b0b84387c73460c4c8d1e8ff9f3b5a (patch) | |
tree | e96b5804d26e221ab0de2c5bbeaffd7ab88159fd /gnuradio-core/src/lib/general | |
parent | fea70a9c312ebf9cfcf8b5ddb60db3b6a3004248 (diff) | |
download | gnuradio-7112e308a6b0b84387c73460c4c8d1e8ff9f3b5a.tar.gz gnuradio-7112e308a6b0b84387c73460c4c8d1e8ff9f3b5a.tar.bz2 gnuradio-7112e308a6b0b84387c73460c4c8d1e8ff9f3b5a.zip |
core: Added type conversion int->float (issue #192). Added with a gri file and also added a gri file for float->int to perform function inside gr_float_to_int. Also added QA code for the new block.
Diffstat (limited to 'gnuradio-core/src/lib/general')
-rw-r--r-- | gnuradio-core/src/lib/general/CMakeLists.txt | 5 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/Makefile.am | 7 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/general.i | 2 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_float_to_int.cc | 58 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_float_to_int.h | 52 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_float_to_int.i | 30 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_int_to_float.cc | 5 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gri_float_to_int.cc | 46 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gri_float_to_int.h | 33 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gri_int_to_float.cc | 37 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gri_int_to_float.h | 34 |
11 files changed, 306 insertions, 3 deletions
diff --git a/gnuradio-core/src/lib/general/CMakeLists.txt b/gnuradio-core/src/lib/general/CMakeLists.txt index cd850ca30..6ecaa930a 100644 --- a/gnuradio-core/src/lib/general/CMakeLists.txt +++ b/gnuradio-core/src/lib/general/CMakeLists.txt @@ -81,10 +81,12 @@ list(APPEND gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/gri_debugger_hook.cc ${CMAKE_CURRENT_SOURCE_DIR}/gri_fft.cc ${CMAKE_CURRENT_SOURCE_DIR}/gri_float_to_char.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gri_float_to_int.cc ${CMAKE_CURRENT_SOURCE_DIR}/gri_float_to_short.cc ${CMAKE_CURRENT_SOURCE_DIR}/gri_float_to_uchar.cc ${CMAKE_CURRENT_SOURCE_DIR}/gri_glfsr.cc ${CMAKE_CURRENT_SOURCE_DIR}/gri_interleaved_short_to_complex.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gri_int_to_float.cc ${CMAKE_CURRENT_SOURCE_DIR}/gri_short_to_float.cc ${CMAKE_CURRENT_SOURCE_DIR}/gri_uchar_to_float.cc ${CMAKE_CURRENT_SOURCE_DIR}/malloc16.c @@ -137,6 +139,7 @@ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gri_debugger_hook.h ${CMAKE_CURRENT_SOURCE_DIR}/gri_fft.h ${CMAKE_CURRENT_SOURCE_DIR}/gri_float_to_char.h + ${CMAKE_CURRENT_SOURCE_DIR}/gri_float_to_int.h ${CMAKE_CURRENT_SOURCE_DIR}/gri_float_to_short.h ${CMAKE_CURRENT_SOURCE_DIR}/gri_float_to_uchar.h ${CMAKE_CURRENT_SOURCE_DIR}/gri_lfsr.h @@ -144,6 +147,7 @@ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gri_interleaved_short_to_complex.h ${CMAKE_CURRENT_SOURCE_DIR}/gri_lfsr_15_1_0.h ${CMAKE_CURRENT_SOURCE_DIR}/gri_lfsr_32k.h + ${CMAKE_CURRENT_SOURCE_DIR}/gri_int_to_float.h ${CMAKE_CURRENT_SOURCE_DIR}/gri_short_to_float.h ${CMAKE_CURRENT_SOURCE_DIR}/gri_uchar_to_float.h ${CMAKE_CURRENT_SOURCE_DIR}/malloc16.h @@ -208,6 +212,7 @@ set(gr_core_general_triple_threats gr_firdes gr_float_to_char gr_float_to_complex + gr_float_to_int gr_float_to_short gr_float_to_uchar gr_fmdet_cf diff --git a/gnuradio-core/src/lib/general/Makefile.am b/gnuradio-core/src/lib/general/Makefile.am index 260867931..0122932cf 100644 --- a/gnuradio-core/src/lib/general/Makefile.am +++ b/gnuradio-core/src/lib/general/Makefile.am @@ -75,6 +75,7 @@ libgeneral_la_SOURCES = \ gr_firdes.cc \ gr_float_to_char.cc \ gr_float_to_complex.cc \ + gr_float_to_int.cc \ gr_float_to_short.cc \ gr_float_to_uchar.cc \ gr_fmdet_cf.cc \ @@ -152,10 +153,12 @@ libgeneral_la_SOURCES = \ gri_debugger_hook.cc \ gri_fft.cc \ gri_float_to_char.cc \ + gri_float_to_int.cc \ gri_float_to_short.cc \ gri_float_to_uchar.cc \ gri_glfsr.cc \ gri_interleaved_short_to_complex.cc \ + gri_int_to_float.cc \ gri_short_to_float.cc \ gri_uchar_to_float.cc \ malloc16.c \ @@ -221,6 +224,7 @@ grinclude_HEADERS = \ gr_firdes.h \ gr_float_to_char.h \ gr_float_to_complex.h \ + gr_float_to_int.h \ gr_float_to_short.h \ gr_float_to_uchar.h \ gr_fmdet_cf.h \ @@ -310,11 +314,13 @@ grinclude_HEADERS = \ gri_debugger_hook.h \ gri_fft.h \ gri_float_to_char.h \ + gri_float_to_int.h \ gri_float_to_short.h \ gri_float_to_uchar.h \ gri_lfsr.h \ gri_glfsr.h \ gri_interleaved_short_to_complex.h \ + gri_int_to_float.h \ gri_lfsr_15_1_0.h \ gri_lfsr_32k.h \ gri_short_to_float.h \ @@ -380,6 +386,7 @@ swiginclude_HEADERS = \ gr_firdes.i \ gr_float_to_char.i \ gr_float_to_complex.i \ + gr_float_to_int.i \ gr_float_to_short.i \ gr_float_to_uchar.i \ gr_fmdet_cf.i \ diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index 0a3200741..5a701bf80 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -39,6 +39,7 @@ #include <gr_keep_one_in_n.h> #include <gr_fft_vcc.h> #include <gr_fft_vfc.h> +#include <gr_float_to_int.h> #include <gr_float_to_short.h> #include <gr_float_to_char.h> #include <gr_float_to_uchar.h> @@ -152,6 +153,7 @@ %include "gr_keep_one_in_n.i" %include "gr_fft_vcc.i" %include "gr_fft_vfc.i" +%include "gr_float_to_int.i" %include "gr_float_to_short.i" %include "gr_float_to_char.i" %include "gr_float_to_uchar.i" diff --git a/gnuradio-core/src/lib/general/gr_float_to_int.cc b/gnuradio-core/src/lib/general/gr_float_to_int.cc new file mode 100644 index 000000000..2349de8cb --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_float_to_int.cc @@ -0,0 +1,58 @@ +/* -*- c++ -*- */ +/* + * Copyright 2011 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gr_float_to_int.h> +#include <gr_io_signature.h> +#include <gri_float_to_int.h> + +gr_float_to_int_sptr +gr_make_float_to_int () +{ + return gnuradio::get_initial_sptr(new gr_float_to_int ()); +} + +gr_float_to_int::gr_float_to_int () + : gr_sync_block ("gr_float_to_int", + gr_make_io_signature (1, 1, sizeof (float)), + gr_make_io_signature (1, 1, sizeof (int))) +{ +} + +int +gr_float_to_int::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const float *in = (const float *) input_items[0]; + int *out = (int *) output_items[0]; + + gri_float_to_int (in, out, noutput_items); + + return noutput_items; +} + + + diff --git a/gnuradio-core/src/lib/general/gr_float_to_int.h b/gnuradio-core/src/lib/general/gr_float_to_int.h new file mode 100644 index 000000000..3324ed110 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_float_to_int.h @@ -0,0 +1,52 @@ +/* -*- c++ -*- */ +/* + * Copyright 2011 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_FLOAT_TO_INT_H +#define INCLUDED_GR_FLOAT_TO_INT_H + +#include <gr_core_api.h> +#include <gr_sync_block.h> + +class gr_float_to_int; +typedef boost::shared_ptr<gr_float_to_int> gr_float_to_int_sptr; + +GR_CORE_API gr_float_to_int_sptr +gr_make_float_to_int (); + +/*! + * \brief Convert stream of float to a stream of short + * \ingroup converter_blk + */ + +class GR_CORE_API gr_float_to_int : public gr_sync_block +{ + friend GR_CORE_API gr_float_to_int_sptr gr_make_float_to_int (); + gr_float_to_int (); + + public: + virtual int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + + +#endif /* INCLUDED_GR_FLOAT_TO_INT_H */ diff --git a/gnuradio-core/src/lib/general/gr_float_to_int.i b/gnuradio-core/src/lib/general/gr_float_to_int.i new file mode 100644 index 000000000..4ab04cbf2 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_float_to_int.i @@ -0,0 +1,30 @@ +/* -*- c++ -*- */ +/* + * Copyright 2011 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,float_to_int) + +gr_float_to_int_sptr gr_make_float_to_int (); + +class gr_float_to_int : public gr_sync_block +{ + gr_float_to_int (); +}; diff --git a/gnuradio-core/src/lib/general/gr_int_to_float.cc b/gnuradio-core/src/lib/general/gr_int_to_float.cc index b5a19e5c0..29ca22add 100644 --- a/gnuradio-core/src/lib/general/gr_int_to_float.cc +++ b/gnuradio-core/src/lib/general/gr_int_to_float.cc @@ -26,6 +26,7 @@ #include <gr_int_to_float.h> #include <gr_io_signature.h> +#include <gri_int_to_float.h> gr_int_to_float_sptr gr_make_int_to_float () @@ -48,9 +49,7 @@ gr_int_to_float::work (int noutput_items, const int32_t *in = (const int32_t *) input_items[0]; float *out = (float *) output_items[0]; - for(int i=0; i < noutput_items; i++) { - out[i] = (float)in[i]; - } + gri_int_to_float(in, out, noutput_items); 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 new file mode 100644 index 000000000..0b29abfd9 --- /dev/null +++ b/gnuradio-core/src/lib/general/gri_float_to_int.cc @@ -0,0 +1,46 @@ +/* -*- c++ -*- */ +/* + * Copyright 2011 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#define _ISOC9X_SOURCE +#include <gri_float_to_int.h> +#include <math.h> + +static const int MIN_INT = -2147483648; // -2^31 +static const int MAX_INT = 2147483647; // (2^31)-1 + + +void +gri_float_to_int (const float *in, int *out, int nsamples) +{ + for (int i = 0; i < nsamples; i++){ + long int r = (long int) rint (in[i]); + if (r < MIN_INT) + r = MIN_INT; + else if (r > MAX_INT) + r = MAX_INT; + out[i] = r; + } +} diff --git a/gnuradio-core/src/lib/general/gri_float_to_int.h b/gnuradio-core/src/lib/general/gri_float_to_int.h new file mode 100644 index 000000000..a2f6ea877 --- /dev/null +++ b/gnuradio-core/src/lib/general/gri_float_to_int.h @@ -0,0 +1,33 @@ +/* -*- c++ -*- */ +/* + * Copyright 2011 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GRI_FLOAT_TO_INT_H +#define INCLUDED_GRI_FLOAT_TO_INT_H + +#include <gr_core_api.h> + +/*! + * 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); + +#endif /* INCLUDED_GRI_FLOAT_TO_INT_H */ diff --git a/gnuradio-core/src/lib/general/gri_int_to_float.cc b/gnuradio-core/src/lib/general/gri_int_to_float.cc new file mode 100644 index 000000000..342c20cc4 --- /dev/null +++ b/gnuradio-core/src/lib/general/gri_int_to_float.cc @@ -0,0 +1,37 @@ +/* -*- c++ -*- */ +/* + * Copyright 2011 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#define _ISOC9X_SOURCE +#include <gri_int_to_float.h> +#include <math.h> + +void +gri_int_to_float (const int *in, float *out, int nsamples) +{ + for (int i = 0; i < nsamples; i++){ + out[i] = static_cast<float>(in[i]); + } +} diff --git a/gnuradio-core/src/lib/general/gri_int_to_float.h b/gnuradio-core/src/lib/general/gri_int_to_float.h new file mode 100644 index 000000000..29d1e3b7d --- /dev/null +++ b/gnuradio-core/src/lib/general/gri_int_to_float.h @@ -0,0 +1,34 @@ +/* -*- c++ -*- */ +/* + * Copyright 2011 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GRI_INT_TO_FLOAT_H +#define INCLUDED_GRI_INT_TO_FLOAT_H + +#include <gr_core_api.h> + +/* + * convert array of ints to floats + */ +GR_CORE_API void gri_int_to_float (const int *in, float *out, int nsamples); + + +#endif /* INCLUDED_GRI_INT_TO_FLOAT_H */ |