00001 /***************************************************************************
00002 qwavdefines.h - description
00003 -------------------
00004 begin : Mon Nov 18 2002
00005 copyright : (C) 2002 by Peter Eschler
00006 email : eschler@users.sourceforge.net
00007 ***************************************************************************/
00008
00009 /***************************************************************************
00010 * *
00011 * This program is free software; you can redistribute it and/or modify *
00012 * it under the terms of the GNU Library General Public License as *
00013 * published by the Free Software Foundation; either version 2 of the *
00014 * License, or (at your option) any later version. *
00015 * *
00016 ***************************************************************************/
00017
00018 #ifndef Qwav_DEFINES_H
00019 #define Qwav_DEFINES_H
00020
00021 //---------------------------------------------------------------------------
00022 // Includes: system
00023 //---------------------------------------------------------------------------
00024
00025 #include <math.h>
00026
00027 //---------------------------------------------------------------------------
00028 // Typedefs:
00029 //---------------------------------------------------------------------------
00030
00031 #ifdef Qwav_USE_DOUBLE
00032 typedef double Float;
00033 #else
00034 typedef float Float;
00035 #endif
00036
00037 //---------------------------------------------------------------------------
00038 // Namespace:
00039 //---------------------------------------------------------------------------
00040
00041 #ifndef Qwav_NO_NAMESPACE
00042 #define Qwav_BEGIN_NAMESPACE namespace qwav {
00043 #define Qwav_END_NAMESPACE }
00044 #define Qwav_USING_NAMESPACE using namespace qwav;
00045 #else
00046 #define Qwav_BEGIN_NAMESPACE
00047 #define Qwav_END_NAMESPACE
00048 #define Qwav_USING_NAMESPACE
00049 #endif
00050
00051 //---------------------------------------------------------------------------
00052 // Linkage: windows
00053 //---------------------------------------------------------------------------
00054
00055 /*
00056 * @brief
00057 * Macro for Windows DLL linkage
00058 *
00059 */
00060
00061 #if defined(_WIN32)
00062 # ifdef QWAV_COMPILELIBQWAV
00063 # define QWAV_EXPORTIMPORT __declspec(dllexport)
00064 # else
00065 # define QWAV_EXPORTIMPORT __declspec(dllimport)
00066 # endif
00067 #else
00068 # define QWAV_EXPORTIMPORT
00069 #endif
00070
00071 Qwav_BEGIN_NAMESPACE
00072
00073 //---------------------------------------------------------------------------
00074 // Method: mapInterval
00075 //---------------------------------------------------------------------------
00076
00088 template <typename T>
00089 T mapInterval(const T& val,
00090 const T& srcMin, const T& srcMax,
00091 const T& dstMin, const T& dstMax)
00092 {
00093 return (val-srcMin) / ((srcMax-srcMin)/(dstMax-dstMin)) + dstMin;
00094 }
00095
00096
00097 //---------------------------------------------------------------------------
00098 // Method: pixel2Sample
00099 //---------------------------------------------------------------------------
00100
00108 inline long pixel2Sample(int pixel,
00109 long firstSample,
00110 double zoomFac )
00111 {
00112 long sample = long( rint(firstSample + double(pixel) * zoomFac) );
00113 return sample;
00114 }
00115
00116
00117
00118 //---------------------------------------------------------------------------
00119 // Method: sample2Pixel
00120 //---------------------------------------------------------------------------
00121
00128 inline int sample2Pixel(long sample,
00129 long firstSample,
00130 double zoomFac)
00131 {
00132 if( sample - firstSample == 0 ) return 0;
00133 int result = int( rint(double(sample - firstSample) / zoomFac) );
00134
00135 return result;
00136 }
00137
00138
00139 //---------------------------------------------------------------------------
00140 // Method: clamp
00141 //---------------------------------------------------------------------------
00142
00149 template <class T>
00150 void clamp(T& val, T min, T max)
00151 {
00152 assert( min < max );
00153
00154 if( val < min )
00155 {
00156 val = min;
00157 return;
00158 }
00159 if( val > max )
00160 val = max;
00161 }
00162
00163 //---------------------------------------------------------------------------
00164 // Method: valToPixelY
00165 //---------------------------------------------------------------------------
00166
00167 inline int valToPixelY( double val,
00168 int height,
00169 double zoomY,
00170 unsigned int topBorderDist=0,
00171 unsigned int bottomBorderDist=0 )
00172 {
00173 return int( rint( mapInterval(-val*zoomY,
00174 -1.0, 1.0,
00175 0.0+topBorderDist,
00176 double(height-1)-bottomBorderDist )) );
00177 }
00178
00179 Qwav_END_NAMESPACE
00180
00181
00182 #endif //Qwav_DEFINES_H
00183
1.2.16