diff options
author | Tom Rondeau <trondeau@vt.edu> | 2013-03-17 18:20:59 -0400 |
---|---|---|
committer | Tom Rondeau <trondeau@vt.edu> | 2013-03-17 18:20:59 -0400 |
commit | 842db35f8e379df7f8bc8171f13bbe02f3ab0cfd (patch) | |
tree | f5e95fb5c5c7a1de6fc54af563a182e3cbcfc3e0 /gnuradio-core/src/lib/general | |
parent | cab7429540a5790d4fe0997c3fa056386ebaca5f (diff) |
core: moving core sincos functions back into core to act as deps for anything else.
Diffstat (limited to 'gnuradio-core/src/lib/general')
-rw-r--r-- | gnuradio-core/src/lib/general/CMakeLists.txt | 11 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_sincos.c | 83 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_sincos.h | 41 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/qa_general.cc | 2 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/qa_sincos.cc | 75 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/qa_sincos.h | 47 |
6 files changed, 259 insertions, 0 deletions
diff --git a/gnuradio-core/src/lib/general/CMakeLists.txt b/gnuradio-core/src/lib/general/CMakeLists.txt index 820f300f10..08e5a003c0 100644 --- a/gnuradio-core/src/lib/general/CMakeLists.txt +++ b/gnuradio-core/src/lib/general/CMakeLists.txt @@ -53,6 +53,7 @@ list(APPEND gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/gr_misc.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_random.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_reverse.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_sincos.c ${CMAKE_CURRENT_SOURCE_DIR}/gri_debugger_hook.cc ${CMAKE_CURRENT_SOURCE_DIR}/malloc16.c ) @@ -64,6 +65,7 @@ list(APPEND test_gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/qa_general.cc ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr_circular_file.cc ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr_math.cc + ${CMAKE_CURRENT_SOURCE_DIR}/qa_sincos.cc ) ######################################################################## @@ -79,6 +81,7 @@ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gr_misc.h ${CMAKE_CURRENT_SOURCE_DIR}/gr_random.h ${CMAKE_CURRENT_SOURCE_DIR}/gr_reverse.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_sincos.h ${CMAKE_CURRENT_SOURCE_DIR}/gr_test_types.h ${CMAKE_CURRENT_SOURCE_DIR}/gri_debugger_hook.h ${CMAKE_CURRENT_SOURCE_DIR}/gri_lfsr_15_1_0.h @@ -121,3 +124,11 @@ foreach(file_tt ${gr_core_general_triple_threats}) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${file_tt}.i DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig COMPONENT "core_swig") endif(ENABLE_PYTHON) endforeach(file_tt ${gr_core_general_triple_threats}) + +CHECK_CXX_SOURCE_COMPILES(" + #define _GNU_SOURCE + #include <math.h> + int main(){double x, sin, cos; sincos(x, &sin, &cos); return 0;} + " HAVE_SINCOS +) +GR_ADD_COND_DEF(HAVE_SINCOS) diff --git a/gnuradio-core/src/lib/general/gr_sincos.c b/gnuradio-core/src/lib/general/gr_sincos.c new file mode 100644 index 0000000000..a8d01b0da4 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_sincos.c @@ -0,0 +1,83 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2010 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 + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE // ask for GNU extensions if available +#endif + +#include <gr_sincos.h> +#include <math.h> + +// ---------------------------------------------------------------- + +#if defined (HAVE_SINCOS) + +void +gr_sincos (double x, double *sinx, double *cosx) +{ + sincos (x, sinx, cosx); +} + +#else + +void +gr_sincos (double x, double *sinx, double *cosx) +{ + *sinx = sin (x); + *cosx = cos (x); +} + +#endif + +// ---------------------------------------------------------------- + +#if defined (HAVE_SINCOSF) + +void +gr_sincosf (float x, float *sinx, float *cosx) +{ + sincosf (x, sinx, cosx); +} + +#elif defined (HAVE_SINF) && defined (HAVE_COSF) + +void +gr_sincosf (float x, float *sinx, float *cosx) +{ + *sinx = sinf (x); + *cosx = cosf (x); +} + +#else + +void +gr_sincosf (float x, float *sinx, float *cosx) +{ + *sinx = sin (x); + *cosx = cos (x); +} + +#endif diff --git a/gnuradio-core/src/lib/general/gr_sincos.h b/gnuradio-core/src/lib/general/gr_sincos.h new file mode 100644 index 0000000000..516f43437a --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_sincos.h @@ -0,0 +1,41 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002,2004 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_SINCOS_H +#define INCLUDED_GR_SINCOS_H + +#include <gr_core_api.h> + +#ifdef __cplusplus +extern "C" { +#endif + +// compute sine and cosine at the same time + +GR_CORE_API void gr_sincos (double x, double *sin, double *cos); +GR_CORE_API void gr_sincosf (float x, float *sin, float *cos); + +#ifdef __cplusplus +}; +#endif + +#endif /* INCLUDED_GR_SINCOS_H */ diff --git a/gnuradio-core/src/lib/general/qa_general.cc b/gnuradio-core/src/lib/general/qa_general.cc index e2328c2cb2..0fce7d2379 100644 --- a/gnuradio-core/src/lib/general/qa_general.cc +++ b/gnuradio-core/src/lib/general/qa_general.cc @@ -28,6 +28,7 @@ #include <qa_general.h> #include <qa_gr_circular_file.h> #include <qa_gr_math.h> +#include <qa_sincos.h> CppUnit::TestSuite * qa_general::suite () @@ -36,6 +37,7 @@ qa_general::suite () s->addTest (qa_gr_circular_file::suite ()); s->addTest (qa_gr_math::suite ()); + s->addTest(gr::analog::qa_sincos::suite()); return s; } diff --git a/gnuradio-core/src/lib/general/qa_sincos.cc b/gnuradio-core/src/lib/general/qa_sincos.cc new file mode 100644 index 0000000000..0066ff6b92 --- /dev/null +++ b/gnuradio-core/src/lib/general/qa_sincos.cc @@ -0,0 +1,75 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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 <qa_sincos.h> +#include <gr_sincos.h> +#include <gruel/attributes.h> +#include <cppunit/TestAssert.h> +#include <cmath> + +namespace gr { + namespace analog { + + void + qa_sincos::t1() + { + static const unsigned int N = 1000; + double c_sin, c_cos; + double gr_sin, gr_cos; + + for(unsigned i = 0; i < N; i++) { + double x = i/100.0; + c_sin = sin(x); + c_cos = cos(x); + + gr_sincos(x, &gr_sin, &gr_cos); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(c_sin, gr_sin, 0.0001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(c_cos, gr_cos, 0.0001); + } + } + + void + qa_sincos::t2() + { + static const unsigned int N = 1000; + float c_sin, c_cos; + float gr_sin, gr_cos; + + for(unsigned i = 0; i < N; i++) { + float x = i/100.0; + c_sin = sinf(x); + c_cos = cosf(x); + + gr_sincosf(x, &gr_sin, &gr_cos); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(c_sin, gr_sin, 0.0001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(c_cos, gr_cos, 0.0001); + } + } + + } /* namespace analog */ +} /* namespace gr */ diff --git a/gnuradio-core/src/lib/general/qa_sincos.h b/gnuradio-core/src/lib/general/qa_sincos.h new file mode 100644 index 0000000000..f18e879dd8 --- /dev/null +++ b/gnuradio-core/src/lib/general/qa_sincos.h @@ -0,0 +1,47 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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 _QA_ANALOG_SINCOS_H_ +#define _QA_ANALOG_SINCOS_H_ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestCase.h> + +namespace gr { + namespace analog { + + class qa_sincos : public CppUnit::TestCase + { + CPPUNIT_TEST_SUITE(qa_sincos); + CPPUNIT_TEST(t1); + CPPUNIT_TEST(t2); + CPPUNIT_TEST_SUITE_END(); + + private: + void t1(); + void t2(); + }; + + } /* namespace analog */ +} /* namespace gr */ + +#endif /* _QA_ANALOG_SINCOS_H_ */ |