From 2c5bfa64e10af3998a728957ea794c065db3a554 Mon Sep 17 00:00:00 2001 From: Arend Lammertink Date: Sat, 5 May 2018 20:17:10 +0200 Subject: [PATCH] moved python generator headers to separate python file --- src/examples/test2d/test2d.ino | 5 +- src/gen_spec1D.py | 25 +- src/gen_spec2D.py | 25 +- src/interpol1d_spec.h | 15 +- src/interpol2d_spec.h | 763 +++++++++++++++++++++++---------- src/utils.py | 39 ++ 6 files changed, 605 insertions(+), 267 deletions(-) create mode 100644 src/utils.py diff --git a/src/examples/test2d/test2d.ino b/src/examples/test2d/test2d.ino index 0073b91..69b12ae 100644 --- a/src/examples/test2d/test2d.ino +++ b/src/examples/test2d/test2d.ino @@ -29,7 +29,7 @@ using namespace std; -#define BAUDRATE 9600 +#define BAUDRATE 115200 // Stuff needed for printing FILE serial_stdout; @@ -103,8 +103,11 @@ void setup() Map2D<8, int16_t, int8_t> testInt8; testInt8.setXs_P(xs); testInt8.setYs_P(ys8); + testInt8.printTo( Serial ); testInt8.updateEeprom(0); + testInt8.printTo( Serial ); testInt8.readEeprom(0); + testInt8.printTo( Serial ); Map2D<8, int16_t, Fix16> testFix16; testFix16.setXs_P(xs); diff --git a/src/gen_spec1D.py b/src/gen_spec1D.py index 67fa8ec..b6a5ca8 100755 --- a/src/gen_spec1D.py +++ b/src/gen_spec1D.py @@ -1,25 +1,12 @@ #!/usr/bin/python -print "//-----------------------------------------------------------------------------" -print "//" -print "// Copyright (C) 2018 Arend Lammertink" -print "//" -print "// This program is free software; you can redistribute it and/or modify it" -print "// under the terms of the GNU General Public License as published by the Free" -print "// Software Foundation, version 3." -print "//" -print "// This program is distributed in the hope that it will be useful, but WITHOUT" -print "// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or" -print "// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for" -print "// more details." -print "//" -print "// You should have received a copy of the GNU Lesser General Public License" -print "// along with this program. If not, see ." -print "//-----------------------------------------------------------------------------" -print -print"//-----------------------------------------------------------------------------" +from utils import * + +print inc_header + +print sep print"// 1D specialization for integers by casting to Fix16, generated by script " -print"//-----------------------------------------------------------------------------" +print sep print print diff --git a/src/gen_spec2D.py b/src/gen_spec2D.py index 60b3540..9f3da3c 100755 --- a/src/gen_spec2D.py +++ b/src/gen_spec2D.py @@ -1,25 +1,12 @@ #!/usr/bin/python -print "//-----------------------------------------------------------------------------" -print "//" -print "// Copyright (C) 2018 Arend Lammertink" -print "//" -print "// This program is free software; you can redistribute it and/or modify it" -print "// under the terms of the GNU General Public License as published by the Free" -print "// Software Foundation, version 3." -print "//" -print "// This program is distributed in the hope that it will be useful, but WITHOUT" -print "// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or" -print "// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for" -print "// more details." -print "//" -print "// You should have received a copy of the GNU Lesser General Public License" -print "// along with this program. If not, see ." -print "//-----------------------------------------------------------------------------" -print -print"//-----------------------------------------------------------------------------" +from utils import * + +print inc_header + +print sep print"// 2D specialization for integers by casting to Fix16, generated by script." -print"//-----------------------------------------------------------------------------" +print sep print print diff --git a/src/interpol1d_spec.h b/src/interpol1d_spec.h index 796243c..8f98b38 100644 --- a/src/interpol1d_spec.h +++ b/src/interpol1d_spec.h @@ -2,17 +2,18 @@ // // Copyright (C) 2018 Arend Lammertink // -// This program 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, version 3. +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, version 3. // -// This program is distributed in the hope that it will be useful, but WITHOUT +// This library 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. +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License +// for more details. // // You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see . +// along with this library. If not, see . +// //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --git a/src/interpol2d_spec.h b/src/interpol2d_spec.h index be660b6..1eb7a64 100644 --- a/src/interpol2d_spec.h +++ b/src/interpol2d_spec.h @@ -2,17 +2,18 @@ // // Copyright (C) 2018 Arend Lammertink // -// This program 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, version 3. +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, version 3. // -// This program is distributed in the hope that it will be useful, but WITHOUT +// This library 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. +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License +// for more details. // // You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see . +// along with this library. If not, see . +// //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -23,299 +24,464 @@ #ifndef _interpol2d_spec_h #define _interpol2d_spec_h +template<> inline int8_t interpolate( int8_t x1, int8_t x2, int8_t x_1, int8_t x_2, int8_t x_3, int8_t x_4, int8_t y_1, int8_t y_2, int8_t y_3, int8_t y_4 ) { - return static_cast< int16_t >( - interpolate( static_cast(x1), - static_cast(x2), - static_cast(x_1), - static_cast(x_2), - static_cast(x_3), - static_cast(x_4), - static_cast(y_1), - static_cast(y_2), - static_cast(y_3), - static_cast(y_4) )); +#ifdef DEBUG + Fix16 retval = ( +#else + return static_cast(static_cast( +#endif + interpolate( static_cast(static_cast(x1)), + static_cast(static_cast(x2)), + static_cast(static_cast(x_1)), + static_cast(static_cast(x_2)), + static_cast(static_cast(x_3)), + static_cast(static_cast(x_4)), + static_cast(static_cast(y_1)), + static_cast(static_cast(y_2)), + static_cast(static_cast(y_3)), + static_cast(static_cast(y_4)) ) +#ifndef DEBUG + )); +#else + return static_cast(static_cast(retval)); +#endif } +template<> inline uint8_t interpolate( int8_t x1, int8_t x2, int8_t x_1, int8_t x_2, int8_t x_3, int8_t x_4, uint8_t y_1, uint8_t y_2, uint8_t y_3, uint8_t y_4 ) { - return static_cast< int16_t >( - interpolate( static_cast(x1), - static_cast(x2), - static_cast(x_1), - static_cast(x_2), - static_cast(x_3), - static_cast(x_4), - static_cast(y_1), - static_cast(y_2), - static_cast(y_3), - static_cast(y_4) )); +#ifdef DEBUG + Fix16 retval = ( +#else + return static_cast(static_cast( +#endif + interpolate( static_cast(static_cast(x1)), + static_cast(static_cast(x2)), + static_cast(static_cast(x_1)), + static_cast(static_cast(x_2)), + static_cast(static_cast(x_3)), + static_cast(static_cast(x_4)), + static_cast(static_cast(y_1)), + static_cast(static_cast(y_2)), + static_cast(static_cast(y_3)), + static_cast(static_cast(y_4)) ) +#ifndef DEBUG + )); +#else + return static_cast(static_cast(retval)); +#endif } +template<> inline int16_t interpolate( int8_t x1, int8_t x2, int8_t x_1, int8_t x_2, int8_t x_3, int8_t x_4, int16_t y_1, int16_t y_2, int16_t y_3, int16_t y_4 ) { - return static_cast< int16_t >( - interpolate( static_cast(x1), - static_cast(x2), - static_cast(x_1), - static_cast(x_2), - static_cast(x_3), - static_cast(x_4), +#ifdef DEBUG + Fix16 retval = ( +#else + return static_cast( +#endif + interpolate( static_cast(static_cast(x1)), + static_cast(static_cast(x2)), + static_cast(static_cast(x_1)), + static_cast(static_cast(x_2)), + static_cast(static_cast(x_3)), + static_cast(static_cast(x_4)), static_cast(y_1), static_cast(y_2), static_cast(y_3), - static_cast(y_4) )); + static_cast(y_4) ) +#ifndef DEBUG + ); +#else + return static_cast(retval); +#endif } +template<> inline uint16_t interpolate( int8_t x1, int8_t x2, int8_t x_1, int8_t x_2, int8_t x_3, int8_t x_4, uint16_t y_1, uint16_t y_2, uint16_t y_3, uint16_t y_4 ) { - return static_cast< int32_t >( - interpolate( static_cast(x1), - static_cast(x2), - static_cast(x_1), - static_cast(x_2), - static_cast(x_3), - static_cast(x_4), +#ifdef DEBUG + Fix16 retval = ( +#else + return static_cast(static_cast( +#endif + interpolate( static_cast(static_cast(x1)), + static_cast(static_cast(x2)), + static_cast(static_cast(x_1)), + static_cast(static_cast(x_2)), + static_cast(static_cast(x_3)), + static_cast(static_cast(x_4)), static_cast(static_cast(y_1)), static_cast(static_cast(y_2)), static_cast(static_cast(y_3)), - static_cast(static_cast(y_4)) )); + static_cast(static_cast(y_4)) ) +#ifndef DEBUG + )); +#else + return static_cast(static_cast(retval)); +#endif } +template<> inline Fix16 interpolate( int8_t x1, int8_t x2, int8_t x_1, int8_t x_2, int8_t x_3, int8_t x_4, Fix16 y_1, Fix16 y_2, Fix16 y_3, Fix16 y_4 ) { - return static_cast< Fix16 >( - interpolate( static_cast(x1), - static_cast(x2), - static_cast(x_1), - static_cast(x_2), - static_cast(x_3), - static_cast(x_4), - static_cast(y_1), - static_cast(y_2), - static_cast(y_3), - static_cast(y_4) )); +#ifdef DEBUG + Fix16 retval = ( +#else + return +#endif + interpolate( static_cast(static_cast(x1)), + static_cast(static_cast(x2)), + static_cast(static_cast(x_1)), + static_cast(static_cast(x_2)), + static_cast(static_cast(x_3)), + static_cast(static_cast(x_4)), + y_1, + y_2, + y_3, + y_4 ) +#ifndef DEBUG + ; +#else + return retval; +#endif } +template<> inline float interpolate( int8_t x1, int8_t x2, int8_t x_1, int8_t x_2, int8_t x_3, int8_t x_4, float y_1, float y_2, float y_3, float y_4 ) { - return static_cast< float >( +#ifdef DEBUG + float retval = ( +#else + return +#endif interpolate( static_cast(x1), static_cast(x2), static_cast(x_1), static_cast(x_2), static_cast(x_3), static_cast(x_4), - static_cast(y_1), - static_cast(y_2), - static_cast(y_3), - static_cast(y_4) )); + y_1, + y_2, + y_3, + y_4 ) +#ifndef DEBUG + ; +#else + return retval; +#endif } +template<> inline double interpolate( int8_t x1, int8_t x2, int8_t x_1, int8_t x_2, int8_t x_3, int8_t x_4, double y_1, double y_2, double y_3, double y_4 ) { - return static_cast< double >( +#ifdef DEBUG + double retval = ( +#else + return +#endif interpolate( static_cast(x1), static_cast(x2), static_cast(x_1), static_cast(x_2), static_cast(x_3), static_cast(x_4), - static_cast(y_1), - static_cast(y_2), - static_cast(y_3), - static_cast(y_4) )); + y_1, + y_2, + y_3, + y_4 ) +#ifndef DEBUG + ; +#else + return retval; +#endif } +template<> inline int8_t interpolate( uint8_t x1, uint8_t x2, uint8_t x_1, uint8_t x_2, uint8_t x_3, uint8_t x_4, int8_t y_1, int8_t y_2, int8_t y_3, int8_t y_4 ) { - return static_cast< int16_t >( - interpolate( static_cast(x1), - static_cast(x2), - static_cast(x_1), - static_cast(x_2), - static_cast(x_3), - static_cast(x_4), - static_cast(y_1), - static_cast(y_2), - static_cast(y_3), - static_cast(y_4) )); +#ifdef DEBUG + Fix16 retval = ( +#else + return static_cast(static_cast( +#endif + interpolate( static_cast(static_cast(x1)), + static_cast(static_cast(x2)), + static_cast(static_cast(x_1)), + static_cast(static_cast(x_2)), + static_cast(static_cast(x_3)), + static_cast(static_cast(x_4)), + static_cast(static_cast(y_1)), + static_cast(static_cast(y_2)), + static_cast(static_cast(y_3)), + static_cast(static_cast(y_4)) ) +#ifndef DEBUG + )); +#else + return static_cast(static_cast(retval)); +#endif } +template<> inline uint8_t interpolate( uint8_t x1, uint8_t x2, uint8_t x_1, uint8_t x_2, uint8_t x_3, uint8_t x_4, uint8_t y_1, uint8_t y_2, uint8_t y_3, uint8_t y_4 ) { - return static_cast< int16_t >( - interpolate( static_cast(x1), - static_cast(x2), - static_cast(x_1), - static_cast(x_2), - static_cast(x_3), - static_cast(x_4), - static_cast(y_1), - static_cast(y_2), - static_cast(y_3), - static_cast(y_4) )); +#ifdef DEBUG + Fix16 retval = ( +#else + return static_cast(static_cast( +#endif + interpolate( static_cast(static_cast(x1)), + static_cast(static_cast(x2)), + static_cast(static_cast(x_1)), + static_cast(static_cast(x_2)), + static_cast(static_cast(x_3)), + static_cast(static_cast(x_4)), + static_cast(static_cast(y_1)), + static_cast(static_cast(y_2)), + static_cast(static_cast(y_3)), + static_cast(static_cast(y_4)) ) +#ifndef DEBUG + )); +#else + return static_cast(static_cast(retval)); +#endif } +template<> inline int16_t interpolate( uint8_t x1, uint8_t x2, uint8_t x_1, uint8_t x_2, uint8_t x_3, uint8_t x_4, int16_t y_1, int16_t y_2, int16_t y_3, int16_t y_4 ) { - return static_cast< int16_t >( - interpolate( static_cast(x1), - static_cast(x2), - static_cast(x_1), - static_cast(x_2), - static_cast(x_3), - static_cast(x_4), +#ifdef DEBUG + Fix16 retval = ( +#else + return static_cast( +#endif + interpolate( static_cast(static_cast(x1)), + static_cast(static_cast(x2)), + static_cast(static_cast(x_1)), + static_cast(static_cast(x_2)), + static_cast(static_cast(x_3)), + static_cast(static_cast(x_4)), static_cast(y_1), static_cast(y_2), static_cast(y_3), - static_cast(y_4) )); + static_cast(y_4) ) +#ifndef DEBUG + ); +#else + return static_cast(retval); +#endif } +template<> inline uint16_t interpolate( uint8_t x1, uint8_t x2, uint8_t x_1, uint8_t x_2, uint8_t x_3, uint8_t x_4, uint16_t y_1, uint16_t y_2, uint16_t y_3, uint16_t y_4 ) { - return static_cast< int32_t >( - interpolate( static_cast(x1), - static_cast(x2), - static_cast(x_1), - static_cast(x_2), - static_cast(x_3), - static_cast(x_4), +#ifdef DEBUG + Fix16 retval = ( +#else + return static_cast(static_cast( +#endif + interpolate( static_cast(static_cast(x1)), + static_cast(static_cast(x2)), + static_cast(static_cast(x_1)), + static_cast(static_cast(x_2)), + static_cast(static_cast(x_3)), + static_cast(static_cast(x_4)), static_cast(static_cast(y_1)), static_cast(static_cast(y_2)), static_cast(static_cast(y_3)), - static_cast(static_cast(y_4)) )); + static_cast(static_cast(y_4)) ) +#ifndef DEBUG + )); +#else + return static_cast(static_cast(retval)); +#endif } +template<> inline Fix16 interpolate( uint8_t x1, uint8_t x2, uint8_t x_1, uint8_t x_2, uint8_t x_3, uint8_t x_4, Fix16 y_1, Fix16 y_2, Fix16 y_3, Fix16 y_4 ) { - return static_cast< Fix16 >( - interpolate( static_cast(x1), - static_cast(x2), - static_cast(x_1), - static_cast(x_2), - static_cast(x_3), - static_cast(x_4), - static_cast(y_1), - static_cast(y_2), - static_cast(y_3), - static_cast(y_4) )); +#ifdef DEBUG + Fix16 retval = ( +#else + return +#endif + interpolate( static_cast(static_cast(x1)), + static_cast(static_cast(x2)), + static_cast(static_cast(x_1)), + static_cast(static_cast(x_2)), + static_cast(static_cast(x_3)), + static_cast(static_cast(x_4)), + y_1, + y_2, + y_3, + y_4 ) +#ifndef DEBUG + ; +#else + return retval; +#endif } +template<> inline float interpolate( uint8_t x1, uint8_t x2, uint8_t x_1, uint8_t x_2, uint8_t x_3, uint8_t x_4, float y_1, float y_2, float y_3, float y_4 ) { - return static_cast< float >( +#ifdef DEBUG + float retval = ( +#else + return +#endif interpolate( static_cast(x1), static_cast(x2), static_cast(x_1), static_cast(x_2), static_cast(x_3), static_cast(x_4), - static_cast(y_1), - static_cast(y_2), - static_cast(y_3), - static_cast(y_4) )); + y_1, + y_2, + y_3, + y_4 ) +#ifndef DEBUG + ; +#else + return retval; +#endif } +template<> inline double interpolate( uint8_t x1, uint8_t x2, uint8_t x_1, uint8_t x_2, uint8_t x_3, uint8_t x_4, double y_1, double y_2, double y_3, double y_4 ) { - return static_cast< double >( +#ifdef DEBUG + double retval = ( +#else + return +#endif interpolate( static_cast(x1), static_cast(x2), static_cast(x_1), static_cast(x_2), static_cast(x_3), static_cast(x_4), - static_cast(y_1), - static_cast(y_2), - static_cast(y_3), - static_cast(y_4) )); + y_1, + y_2, + y_3, + y_4 ) +#ifndef DEBUG + ; +#else + return retval; +#endif } +template<> inline int8_t interpolate( int16_t x1, int16_t x2, int16_t x_1, int16_t x_2, int16_t x_3, int16_t x_4, int8_t y_1, int8_t y_2, int8_t y_3, int8_t y_4 ) { - return static_cast< int16_t >( +#ifdef DEBUG + Fix16 retval = ( +#else + return static_cast(static_cast( +#endif interpolate( static_cast(x1), static_cast(x2), static_cast(x_1), static_cast(x_2), static_cast(x_3), static_cast(x_4), - static_cast(y_1), - static_cast(y_2), - static_cast(y_3), - static_cast(y_4) )); + static_cast(static_cast(y_1)), + static_cast(static_cast(y_2)), + static_cast(static_cast(y_3)), + static_cast(static_cast(y_4)) ) +#ifndef DEBUG + )); +#else + return static_cast(static_cast(retval)); +#endif } +template<> inline uint8_t interpolate( int16_t x1, int16_t x2, int16_t x_1, int16_t x_2, int16_t x_3, int16_t x_4, uint8_t y_1, uint8_t y_2, uint8_t y_3, uint8_t y_4 ) { - return static_cast< int16_t >( +#ifdef DEBUG + Fix16 retval = ( +#else + return static_cast(static_cast( +#endif interpolate( static_cast(x1), static_cast(x2), static_cast(x_1), static_cast(x_2), static_cast(x_3), static_cast(x_4), - static_cast(y_1), - static_cast(y_2), - static_cast(y_3), - static_cast(y_4) )); + static_cast(static_cast(y_1)), + static_cast(static_cast(y_2)), + static_cast(static_cast(y_3)), + static_cast(static_cast(y_4)) ) +#ifndef DEBUG + )); +#else + return static_cast(static_cast(retval)); +#endif } +template<> inline int16_t interpolate( int16_t x1, int16_t x2, int16_t x_1, int16_t x_2, int16_t x_3, int16_t x_4, int16_t y_1, int16_t y_2, int16_t y_3, int16_t y_4 ) { - return static_cast< int16_t >( +#ifdef DEBUG + Fix16 retval = ( +#else + return static_cast( +#endif interpolate( static_cast(x1), static_cast(x2), static_cast(x_1), @@ -325,15 +491,25 @@ inline int16_t interpolate( int16_t x1, int16_t x2, static_cast(y_1), static_cast(y_2), static_cast(y_3), - static_cast(y_4) )); + static_cast(y_4) ) +#ifndef DEBUG + ); +#else + return static_cast(retval); +#endif } +template<> inline uint16_t interpolate( int16_t x1, int16_t x2, int16_t x_1, int16_t x_2, int16_t x_3, int16_t x_4, uint16_t y_1, uint16_t y_2, uint16_t y_3, uint16_t y_4 ) { - return static_cast< int32_t >( +#ifdef DEBUG + Fix16 retval = ( +#else + return static_cast(static_cast( +#endif interpolate( static_cast(x1), static_cast(x2), static_cast(x_1), @@ -343,105 +519,165 @@ inline uint16_t interpolate( int16_t x1, int16_t x2, static_cast(static_cast(y_1)), static_cast(static_cast(y_2)), static_cast(static_cast(y_3)), - static_cast(static_cast(y_4)) )); + static_cast(static_cast(y_4)) ) +#ifndef DEBUG + )); +#else + return static_cast(static_cast(retval)); +#endif } +template<> inline Fix16 interpolate( int16_t x1, int16_t x2, int16_t x_1, int16_t x_2, int16_t x_3, int16_t x_4, Fix16 y_1, Fix16 y_2, Fix16 y_3, Fix16 y_4 ) { - return static_cast< Fix16 >( +#ifdef DEBUG + Fix16 retval = ( +#else + return +#endif interpolate( static_cast(x1), static_cast(x2), static_cast(x_1), static_cast(x_2), static_cast(x_3), static_cast(x_4), - static_cast(y_1), - static_cast(y_2), - static_cast(y_3), - static_cast(y_4) )); + y_1, + y_2, + y_3, + y_4 ) +#ifndef DEBUG + ; +#else + return retval; +#endif } +template<> inline float interpolate( int16_t x1, int16_t x2, int16_t x_1, int16_t x_2, int16_t x_3, int16_t x_4, float y_1, float y_2, float y_3, float y_4 ) { - return static_cast< float >( +#ifdef DEBUG + float retval = ( +#else + return +#endif interpolate( static_cast(x1), static_cast(x2), static_cast(x_1), static_cast(x_2), static_cast(x_3), static_cast(x_4), - static_cast(y_1), - static_cast(y_2), - static_cast(y_3), - static_cast(y_4) )); + y_1, + y_2, + y_3, + y_4 ) +#ifndef DEBUG + ; +#else + return retval; +#endif } +template<> inline double interpolate( int16_t x1, int16_t x2, int16_t x_1, int16_t x_2, int16_t x_3, int16_t x_4, double y_1, double y_2, double y_3, double y_4 ) { - return static_cast< double >( +#ifdef DEBUG + double retval = ( +#else + return +#endif interpolate( static_cast(x1), static_cast(x2), static_cast(x_1), static_cast(x_2), static_cast(x_3), static_cast(x_4), - static_cast(y_1), - static_cast(y_2), - static_cast(y_3), - static_cast(y_4) )); + y_1, + y_2, + y_3, + y_4 ) +#ifndef DEBUG + ; +#else + return retval; +#endif } +template<> inline int8_t interpolate( uint16_t x1, uint16_t x2, uint16_t x_1, uint16_t x_2, uint16_t x_3, uint16_t x_4, int8_t y_1, int8_t y_2, int8_t y_3, int8_t y_4 ) { - return static_cast< int16_t >( +#ifdef DEBUG + Fix16 retval = ( +#else + return static_cast(static_cast( +#endif interpolate( static_cast(static_cast(x1)), static_cast(static_cast(x2)), static_cast(static_cast(x_1)), static_cast(static_cast(x_2)), static_cast(static_cast(x_3)), static_cast(static_cast(x_4)), - static_cast(y_1), - static_cast(y_2), - static_cast(y_3), - static_cast(y_4) )); + static_cast(static_cast(y_1)), + static_cast(static_cast(y_2)), + static_cast(static_cast(y_3)), + static_cast(static_cast(y_4)) ) +#ifndef DEBUG + )); +#else + return static_cast(static_cast(retval)); +#endif } +template<> inline uint8_t interpolate( uint16_t x1, uint16_t x2, uint16_t x_1, uint16_t x_2, uint16_t x_3, uint16_t x_4, uint8_t y_1, uint8_t y_2, uint8_t y_3, uint8_t y_4 ) { - return static_cast< int16_t >( +#ifdef DEBUG + Fix16 retval = ( +#else + return static_cast(static_cast( +#endif interpolate( static_cast(static_cast(x1)), static_cast(static_cast(x2)), static_cast(static_cast(x_1)), static_cast(static_cast(x_2)), static_cast(static_cast(x_3)), static_cast(static_cast(x_4)), - static_cast(y_1), - static_cast(y_2), - static_cast(y_3), - static_cast(y_4) )); + static_cast(static_cast(y_1)), + static_cast(static_cast(y_2)), + static_cast(static_cast(y_3)), + static_cast(static_cast(y_4)) ) +#ifndef DEBUG + )); +#else + return static_cast(static_cast(retval)); +#endif } +template<> inline int16_t interpolate( uint16_t x1, uint16_t x2, uint16_t x_1, uint16_t x_2, uint16_t x_3, uint16_t x_4, int16_t y_1, int16_t y_2, int16_t y_3, int16_t y_4 ) { - return static_cast< int16_t >( +#ifdef DEBUG + Fix16 retval = ( +#else + return static_cast( +#endif interpolate( static_cast(static_cast(x1)), static_cast(static_cast(x2)), static_cast(static_cast(x_1)), @@ -451,15 +687,25 @@ inline int16_t interpolate( uint16_t x1, uint16_t x2, static_cast(y_1), static_cast(y_2), static_cast(y_3), - static_cast(y_4) )); + static_cast(y_4) ) +#ifndef DEBUG + ); +#else + return static_cast(retval); +#endif } +template<> inline uint16_t interpolate( uint16_t x1, uint16_t x2, uint16_t x_1, uint16_t x_2, uint16_t x_3, uint16_t x_4, uint16_t y_1, uint16_t y_2, uint16_t y_3, uint16_t y_4 ) { - return static_cast< int32_t >( +#ifdef DEBUG + Fix16 retval = ( +#else + return static_cast(static_cast( +#endif interpolate( static_cast(static_cast(x1)), static_cast(static_cast(x2)), static_cast(static_cast(x_1)), @@ -469,133 +715,208 @@ inline uint16_t interpolate( uint16_t x1, uint16_t x2, static_cast(static_cast(y_1)), static_cast(static_cast(y_2)), static_cast(static_cast(y_3)), - static_cast(static_cast(y_4)) )); + static_cast(static_cast(y_4)) ) +#ifndef DEBUG + )); +#else + return static_cast(static_cast(retval)); +#endif } +template<> inline Fix16 interpolate( uint16_t x1, uint16_t x2, uint16_t x_1, uint16_t x_2, uint16_t x_3, uint16_t x_4, Fix16 y_1, Fix16 y_2, Fix16 y_3, Fix16 y_4 ) { - return static_cast< Fix16 >( +#ifdef DEBUG + Fix16 retval = ( +#else + return +#endif interpolate( static_cast(static_cast(x1)), static_cast(static_cast(x2)), static_cast(static_cast(x_1)), static_cast(static_cast(x_2)), static_cast(static_cast(x_3)), static_cast(static_cast(x_4)), - static_cast(y_1), - static_cast(y_2), - static_cast(y_3), - static_cast(y_4) )); + y_1, + y_2, + y_3, + y_4 ) +#ifndef DEBUG + ; +#else + return retval; +#endif } +template<> inline float interpolate( uint16_t x1, uint16_t x2, uint16_t x_1, uint16_t x_2, uint16_t x_3, uint16_t x_4, float y_1, float y_2, float y_3, float y_4 ) { - return static_cast< float >( +#ifdef DEBUG + float retval = ( +#else + return +#endif interpolate( static_cast(x1), static_cast(x2), static_cast(x_1), static_cast(x_2), static_cast(x_3), static_cast(x_4), - static_cast(y_1), - static_cast(y_2), - static_cast(y_3), - static_cast(y_4) )); + y_1, + y_2, + y_3, + y_4 ) +#ifndef DEBUG + ; +#else + return retval; +#endif } +template<> inline double interpolate( uint16_t x1, uint16_t x2, uint16_t x_1, uint16_t x_2, uint16_t x_3, uint16_t x_4, double y_1, double y_2, double y_3, double y_4 ) { - return static_cast< double >( +#ifdef DEBUG + double retval = ( +#else + return +#endif interpolate( static_cast(x1), static_cast(x2), static_cast(x_1), static_cast(x_2), static_cast(x_3), static_cast(x_4), - static_cast(y_1), - static_cast(y_2), - static_cast(y_3), - static_cast(y_4) )); + y_1, + y_2, + y_3, + y_4 ) +#ifndef DEBUG + ; +#else + return retval; +#endif } +template<> inline int8_t interpolate( Fix16 x1, Fix16 x2, Fix16 x_1, Fix16 x_2, Fix16 x_3, Fix16 x_4, int8_t y_1, int8_t y_2, int8_t y_3, int8_t y_4 ) { - return static_cast< int16_t >( - interpolate( static_cast(x1), - static_cast(x2), - static_cast(x_1), - static_cast(x_2), - static_cast(x_3), - static_cast(x_4), - static_cast(y_1), - static_cast(y_2), - static_cast(y_3), - static_cast(y_4) )); +#ifdef DEBUG + Fix16 retval = ( +#else + return static_cast(static_cast( +#endif + interpolate( x1, + x2, + x_1, + x_2, + x_3, + x_4, + static_cast(static_cast(y_1)), + static_cast(static_cast(y_2)), + static_cast(static_cast(y_3)), + static_cast(static_cast(y_4)) ) +#ifndef DEBUG + )); +#else + return static_cast(static_cast(retval)); +#endif } +template<> inline uint8_t interpolate( Fix16 x1, Fix16 x2, Fix16 x_1, Fix16 x_2, Fix16 x_3, Fix16 x_4, uint8_t y_1, uint8_t y_2, uint8_t y_3, uint8_t y_4 ) { - return static_cast< int16_t >( - interpolate( static_cast(x1), - static_cast(x2), - static_cast(x_1), - static_cast(x_2), - static_cast(x_3), - static_cast(x_4), - static_cast(y_1), - static_cast(y_2), - static_cast(y_3), - static_cast(y_4) )); +#ifdef DEBUG + Fix16 retval = ( +#else + return static_cast(static_cast( +#endif + interpolate( x1, + x2, + x_1, + x_2, + x_3, + x_4, + static_cast(static_cast(y_1)), + static_cast(static_cast(y_2)), + static_cast(static_cast(y_3)), + static_cast(static_cast(y_4)) ) +#ifndef DEBUG + )); +#else + return static_cast(static_cast(retval)); +#endif } +template<> inline int16_t interpolate( Fix16 x1, Fix16 x2, Fix16 x_1, Fix16 x_2, Fix16 x_3, Fix16 x_4, int16_t y_1, int16_t y_2, int16_t y_3, int16_t y_4 ) { - return static_cast< int16_t >( - interpolate( static_cast(x1), - static_cast(x2), - static_cast(x_1), - static_cast(x_2), - static_cast(x_3), - static_cast(x_4), +#ifdef DEBUG + Fix16 retval = ( +#else + return static_cast( +#endif + interpolate( x1, + x2, + x_1, + x_2, + x_3, + x_4, static_cast(y_1), static_cast(y_2), static_cast(y_3), - static_cast(y_4) )); + static_cast(y_4) ) +#ifndef DEBUG + ); +#else + return static_cast(retval); +#endif } +template<> inline uint16_t interpolate( Fix16 x1, Fix16 x2, Fix16 x_1, Fix16 x_2, Fix16 x_3, Fix16 x_4, uint16_t y_1, uint16_t y_2, uint16_t y_3, uint16_t y_4 ) { - return static_cast< int32_t >( - interpolate( static_cast(x1), - static_cast(x2), - static_cast(x_1), - static_cast(x_2), - static_cast(x_3), - static_cast(x_4), +#ifdef DEBUG + Fix16 retval = ( +#else + return static_cast(static_cast( +#endif + interpolate( x1, + x2, + x_1, + x_2, + x_3, + x_4, static_cast(static_cast(y_1)), static_cast(static_cast(y_2)), static_cast(static_cast(y_3)), - static_cast(static_cast(y_4)) )); + static_cast(static_cast(y_4)) ) +#ifndef DEBUG + )); +#else + return static_cast(static_cast(retval)); +#endif } diff --git a/src/utils.py b/src/utils.py new file mode 100644 index 0000000..ab65b1f --- /dev/null +++ b/src/utils.py @@ -0,0 +1,39 @@ + +sep = '//-----------------------------------------------------------------------------' + +prog_header = sep + '''\n// +// Copyright (C) 2018 Arend Lammertink +// +// This program 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, version 3. +// +// This program 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 Lesser General Public License +// along with this program. If not, see . +//----------------------------------------------------------------------------- +''' + +inc_header = sep + '''\n// +// Copyright (C) 2018 Arend Lammertink +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, version 3. +// +// This library 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 Lesser General Public License +// for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library. If not, see . +// +//----------------------------------------------------------------------------- +''' + +