pl-nk v0.4.5
Plonk|Plink|Plank are a set of cross-platform C/C++ frameworks for audio software development
plonk_StandardHeader.h
00001 /*
00002  -------------------------------------------------------------------------------
00003  This file is part of the Plink, Plonk, Plank libraries
00004   by Martin Robinson
00005  
00006  http://code.google.com/p/pl-nk/
00007  
00008  Copyright University of the West of England, Bristol 2011-14
00009  All rights reserved.
00010  
00011  Redistribution and use in source and binary forms, with or without
00012  modification, are permitted provided that the following conditions are met:
00013  
00014  * Redistributions of source code must retain the above copyright
00015    notice, this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright
00017    notice, this list of conditions and the following disclaimer in the
00018    documentation and/or other materials provided with the distribution.
00019  * Neither the name of University of the West of England, Bristol nor 
00020    the names of its contributors may be used to endorse or promote products
00021    derived from this software without specific prior written permission.
00022  
00023  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00024  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00025  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00026  DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF THE WEST OF ENGLAND, BRISTOL BE 
00027  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00028  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
00029  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
00030  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
00031  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
00032  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00033  
00034  This software makes use of third party libraries. For more information see:
00035  doc/license.txt included in the distribution.
00036  -------------------------------------------------------------------------------
00037  */
00038 
00039 #ifndef PLONK_STANDARDHEADER_H
00040 #define PLONK_STANDARDHEADER_H
00041 
00042 #include "../../plank/plank.h"
00043 
00044 #define PLONK_EMPTYDEFINE
00045 
00046 #define PLONK_BIGENDIAN     PLANK_BIGENDIAN
00047 #define PLONK_LITTLEENDIAN  PLANK_LITTLEENDIAN
00048 
00049 #if PLANK_WIN
00050     #define PLONK_WIN 1
00051 #endif
00052 
00053 #if PLANK_APPLE
00054     #define PLONK_APPLE 1
00055 #endif
00056 
00057 #if PLANK_MAC
00058     #define PLONK_MAC 1
00059 #endif
00060 
00061 #if PLANK_IOS
00062     #define PLONK_IOS 1
00063 #endif
00064 
00065 #if PLANK_LINUX
00066     #define PLONK_LINUX 1
00067 #endif
00068 
00069 #if PLANK_ANDROID
00070     #define PLONK_ANDROID 1
00071 #endif
00072 
00073 #if PLANK_GCC
00074     #define PLONK_GCC 1
00075 #endif
00076 
00077 #if PLANK_LLVM
00078     #define PLONK_LLVM 1
00079 #endif
00080 
00081 #if PLANK_APPLE_LLVM
00082     #define PLONK_APPLE_LLVM 1
00083 #endif
00084 
00085 #if PLANK_ARM
00086     #define PLONK_ARM 1
00087 #endif
00088 
00089 #if PLANK_X86
00090     #define PLONK_X86 1
00091 #endif
00092 
00093 #if PLANK_PPC
00094     #define PLONK_PPC 1
00095 #endif
00096 
00097 #if PLANK_32BIT
00098     #define PLONK_32BIT 1
00099     #define PLONK_WORDBITS 32
00100     #define PLONK_HALFWORDBITS 16
00101     #define PLONK_WORDSIZE 4
00102         #define PLONK_WIDESIZE 8
00103 #endif
00104 
00105 #if PLANK_64BIT
00106     #define PLONK_64BIT 1
00107     #define PLONK_WORDBITS 64
00108     #define PLONK_HALFWORDBITS 32
00109     #define PLONK_WORDSIZE 8
00110         #define PLONK_WIDESIZE 16
00111 #endif
00112 
00113 #define PLONK_ALIGN(X) PLANK_ALIGN(X)
00114 
00115 #ifdef PLONK_USEPLINK
00116     #include "../../plink/plink.h"
00117 #endif
00118 
00119 #define PLONK_NAMESPACE plonk
00120 
00121 #if defined(PLONK_NAMESPACE) || DOXYGEN
00122     #define BEGIN_PLONK_NAMESPACE    namespace PLONK_NAMESPACE {
00123     #define END_PLONK_NAMESPACE      }
00124 #else
00125     #define BEGIN_PLONK_NAMESPACE 
00126     #define END_PLONK_NAMESPACE   
00127 #endif
00128 
00129 #if !defined(_NDEBUG) && !defined(NDEBUG) && !defined(_DEBUG) && !defined(DEBUG)
00130     #warning You should define appropriate preprocessor macros in Debug (_DEBUG=1 DEBUG=1) and Release (_NDEBUG=1 NDEBUG=1)
00131 #endif
00132 
00133 #ifndef PLONK_DEBUG
00134     #if !defined(NDEBUG) || defined(_DEBUG)
00135         #define PLONK_DEBUG 1
00136     #endif
00137 #else
00138     #if !PLONK_DEBUG
00139         #undef PLONK_DEBUG
00140     #endif
00141 #endif
00142 
00143 /* If you get a compiler error here you need to make sure you're using a C++
00144  compiler. If you're using Objective C then use Objective C++ by using .mm files
00145  instead of .m as an extension. */
00146 #include <cstdlib>
00147 
00148 //#if PLONK_ANDROID
00149 #include <stdarg.h>
00150 //#else
00151 //    #include <cstdarg>
00152 //#endif
00153 
00154 #include <climits>
00155 #include <cfloat>
00156 #include <cmath>
00157 #include <cwchar>
00158 
00159 //#if !PLONK_ANDROID
00160 //#include <stdexcept>
00161 //#endif
00162 
00163 #include <typeinfo>
00164 #include <cstring>
00165 #include <cstdio>
00166 
00167 #if !PLONK_ANDROID
00168 #include <iostream>
00169 #endif
00170 
00171 #define PLONK_MAJOR_VERSION      0
00172 #define PLONK_MINOR_VERSION      4
00173 #define PLONK_BUILDNUMBER        5
00174 #define PLONK_VERSION           "v" PLANK_PRESTRING(PLONK_MAJOR_VERSION) "." PLANK_PRESTRING(PLONK_MINOR_VERSION) "." PLANK_PRESTRING(PLONK_BUILDNUMBER)
00175 
00176 
00177 #ifdef PLONK_DEBUG
00178     #include <cassert>
00179     #define plonk_assert        assert
00180         #define plonk_assertfalse       (assert (false))
00181 #else
00182         #define plonk_assert(x)     { }
00183         #define plonk_assertfalse       { }
00184 #endif
00185 
00186 
00187 /* if you're getting your first compile error here on iOS
00188  it's probably because the file your compiling which includes
00189  plonk headers is not a C++ file. To make an Obj-C file (.m) 
00190  an Obj-C++ file use .mm as the file extension. */
00191 BEGIN_PLONK_NAMESPACE
00192 template <bool x> struct PlonkStaticAssertUtility;
00193 template <> struct PlonkStaticAssertUtility<true> { static inline void plonkStaticAssertionFailure() {} };
00194 
00195 #ifdef PLONK_DEBUG
00196     #define plonk_staticassert(x) plonk::PlonkStaticAssertUtility<x>::plonkStaticAssertionFailure();
00197 #else
00198     #define plonk_staticassert(x) { }
00199 #endif
00200 
00201 typedef PlankResult ResultCode;
00202 
00203 typedef PlankF Float;
00204 typedef PlankD Double;
00205 
00206 typedef PlankC Char;
00207 typedef PlankI Int; 
00208 typedef PlankS Short;
00209 typedef PlankL Long;
00210 typedef PlankLL LongLong;
00211 
00212 typedef PlankUC UnsignedChar;
00213 typedef PlankUI UnsignedInt; 
00214 typedef PlankUS UnsignedShort;
00215 typedef PlankUL UnsignedLong;
00216 typedef PlankULL UnsignedLongLong;
00217 
00218 typedef bool Bool;
00219 typedef PlankP Pointer;
00220 typedef PlankM Method;
00221 typedef PlankFourCharCode FourCharCode;
00222 
00223 struct VoidReturn { enum Type { Pass = 1 }; };
00224 
00225 //#if defined (__clang__) && defined (__has_feature)
00226 //    #if !__has_feature (cxx_noexcept)
00227 //        #define PLONK_USING_NEWCXXFEATURES 1
00228 //    #endif
00229 //#endif
00230 //
00231 //#if PLONK_USING_NEWCXXFEATURES
00232 //    #define noexcept throw()
00233 //    const                           // this is a const object...
00234 //    class {
00235 //    public:
00236 //        template<class T>           // convertible to any type
00237 //        operator T*() const         // of null non-member
00238 //        { return 0; }               // pointer...
00239 //        template<class C, class T>  // or any type of null
00240 //        operator T C::*() const     // member pointer...
00241 //        { return 0; }
00242 //    private:
00243 //        void operator&() const;     // whose address can't be taken
00244 //    } nullptr = {};                 // and whose name is nullptr
00245 //#endif
00246 
00247 #define PLONK_INT24_MAX PLANK_INT24_MAX
00248 
00249 #if PLONK_WIN
00250         #pragma warning(disable : 4244) // loss of precision
00251         #pragma warning(disable : 4996) // security of snprintf etc
00252         #pragma warning(disable : 4800) // bool performance warning
00253         #pragma warning(disable : 4290) // exceptions re: std::bad_alloc
00254         #define _CRT_SECURE_NO_WARNINGS
00255 #endif
00256 
00257 
00263 struct ForceErrorStruct { int dummy; };
00264 #define FORCE_COMPILER_ERROR_FUNCTION_PROTOTYPE_CHANGED ForceErrorStruct
00265 
00266 
00267 #ifdef PLONK_USEPLINK
00268     template<class SampleType = float>
00269     struct PlinkBuffer
00270     {
00271         int bufferSize;
00272         const SampleType* buffer;
00273     };
00274 
00275     template<int N, class SampleType = float>
00276     struct PlinkProcess
00277     {        
00278         PlinkProcessBase base;
00279         PlinkBuffer<SampleType> buffers[N];
00280         
00281         static void init (PlinkProcess* pp, void* userData, int numOutputs, int numInputs)
00282         {
00283             plonk_assert (N >= (numInputs + numOutputs));
00284             
00285             pp->base.userData   = userData;
00286             pp->base.numOutputs = numOutputs;
00287             pp->base.numInputs  = numInputs;
00288             pp->base.numBuffers = N;        
00289         }
00290     };
00291 #endif
00292 
00293 #include "plonk_Memory.h"
00294 
00295 #define PLONK_UNARYOPFUNCTION(TYPE,NAME)        TYPE (*NAME)(TYPE const&)
00296 #define PLONK_BINARYOPFUNCTION(TYPE,NAME)       TYPE (*NAME)(TYPE const&, TYPE const&)
00297 #define PLONK_BINARYOPFUNCTION_TYPE(TYPE)       TYPE (TYPE const&, TYPE const&)
00298 #define PLONK_TERNARYOPFUNCTION(TYPE,NAME)      TYPE (*NAME)(TYPE const&, TYPE const&, TYPE const&)
00299 #define PLONK_QUATERNARYOPFUNCTION(TYPE,NAME)   TYPE (*NAME)(TYPE const&, TYPE const&, TYPE const&, TYPE const&)
00300 #define PLONK_QUINARYOPFUNCTION(TYPE,NAME)      TYPE (*NAME)(TYPE const&, TYPE const&, TYPE const&, TYPE const&, TYPE const&)
00301 
00302 template<class TypeA, class TypeB>
00303 class BinaryOpTypeUtility
00304 {
00305 public:
00306     typedef double CalcType;
00307 };
00308 
00309 #define PLONK_BINARYOPTYPEUTILITY_DEFINE(TYPEA,TYPEB,CALCTYPE)\
00310     template<> class BinaryOpTypeUtility<TYPEA,TYPEB>\
00311     {\
00312     public:\
00313         typedef CALCTYPE CalcType;\
00314     }
00315 
00316 PLONK_BINARYOPTYPEUTILITY_DEFINE(float,float,float);
00317 PLONK_BINARYOPTYPEUTILITY_DEFINE(float,int,float);
00318 PLONK_BINARYOPTYPEUTILITY_DEFINE(int,float,float);
00319 PLONK_BINARYOPTYPEUTILITY_DEFINE(float,short,float);
00320 PLONK_BINARYOPTYPEUTILITY_DEFINE(short,float,float);
00321 PLONK_BINARYOPTYPEUTILITY_DEFINE(float,char,float);
00322 PLONK_BINARYOPTYPEUTILITY_DEFINE(char,float,float);
00323 PLONK_BINARYOPTYPEUTILITY_DEFINE(float,LongLong,float);
00324 PLONK_BINARYOPTYPEUTILITY_DEFINE(LongLong,float,float);
00325 
00326 PLONK_BINARYOPTYPEUTILITY_DEFINE(double,double,double);
00327 PLONK_BINARYOPTYPEUTILITY_DEFINE(double,int,double);
00328 PLONK_BINARYOPTYPEUTILITY_DEFINE(int,double,double);
00329 PLONK_BINARYOPTYPEUTILITY_DEFINE(double,short,double);
00330 PLONK_BINARYOPTYPEUTILITY_DEFINE(short,double,double);
00331 PLONK_BINARYOPTYPEUTILITY_DEFINE(double,char,double);
00332 PLONK_BINARYOPTYPEUTILITY_DEFINE(char,double,double);
00333 PLONK_BINARYOPTYPEUTILITY_DEFINE(double,LongLong,double);
00334 PLONK_BINARYOPTYPEUTILITY_DEFINE(LongLong,double,double);
00335 
00336 PLONK_BINARYOPTYPEUTILITY_DEFINE(char,char,short);
00337 PLONK_BINARYOPTYPEUTILITY_DEFINE(char,short,int);
00338 PLONK_BINARYOPTYPEUTILITY_DEFINE(short,char,int);
00339 PLONK_BINARYOPTYPEUTILITY_DEFINE(char,int,LongLong);
00340 PLONK_BINARYOPTYPEUTILITY_DEFINE(int,char,LongLong);
00341 
00342 PLONK_BINARYOPTYPEUTILITY_DEFINE(short,short,int);
00343 PLONK_BINARYOPTYPEUTILITY_DEFINE(short,int,LongLong);
00344 PLONK_BINARYOPTYPEUTILITY_DEFINE(int,short,LongLong);
00345 
00346 PLONK_BINARYOPTYPEUTILITY_DEFINE(int,int,LongLong);
00347 PLONK_BINARYOPTYPEUTILITY_DEFINE(int,LongLong,LongLong);
00348 PLONK_BINARYOPTYPEUTILITY_DEFINE(LongLong,int,LongLong);
00349 
00350 
00351 
00352 // getting the calc type for ternary ops (or two chained binary ops)
00353 template<class TypeA, class TypeB, class TypeC>
00354 class TernaryOpTypeUtility
00355 {
00356 public:
00357     typedef typename BinaryOpTypeUtility<TypeA,TypeB>::CalcType TypeD;
00358     typedef typename BinaryOpTypeUtility<TypeD,TypeC>::CalcType CalcType;
00359 };
00360 
00361 // getting the calc type for quaternary ops (or three chained binary ops)
00362 template<class TypeA, class TypeB, class TypeC, class TypeD>
00363 class QuaternaryOpTypeUtility
00364 {
00365 public:
00366     typedef typename BinaryOpTypeUtility<TypeA,TypeB>::CalcType TypeE;
00367     typedef typename BinaryOpTypeUtility<TypeE,TypeC>::CalcType TypeF;
00368     typedef typename BinaryOpTypeUtility<TypeF,TypeD>::CalcType CalcType;
00369 };
00370 
00371 // getting the calc type for quinary ops (or four chained binary ops)
00372 template<class TypeA, class TypeB, class TypeC, class TypeD, class TypeE>
00373 class QuinaryOpTypeUtility
00374 {
00375 public:
00376     typedef typename BinaryOpTypeUtility<TypeA,TypeB>::CalcType TypeF;
00377     typedef typename BinaryOpTypeUtility<TypeF,TypeC>::CalcType TypeG;
00378     typedef typename BinaryOpTypeUtility<TypeG,TypeD>::CalcType TypeH;
00379     typedef typename BinaryOpTypeUtility<TypeH,TypeE>::CalcType CalcType;
00380 };
00381 
00382 
00383 
00384 #define PLONK_INFINITY PLANK_INFINITY
00385 
00386 //inline int quantiseUp(const int a, const int q) 
00387 //{ 
00388 //      if(a % q)
00389 //              return a / q * q + q;
00390 //      else
00391 //              return a / q * q;
00392 //}
00393 //
00394 //inline int quantiseDown(const int a, const int q) 
00395 //{ 
00396 //      return a / q * q; 
00397 //}
00398 
00399 //#ifndef numElementsInArray
00400 //      #define numElementsInArray(a)   ((int) (sizeof (a) / sizeof ((a)[0])))
00401 //#endif
00402 
00403 
00404 #ifndef PLONK_ALIGN
00405     #define PLONK_ALIGN PLANK_ALIGN
00406 #endif
00407 
00408 #ifndef PLONK_TYPE_DEFAULT
00409     #define PLONK_TYPE_DEFAULT Float
00410 #endif
00411 
00412 typedef PLONK_TYPE_DEFAULT TypeDefault;
00413 
00414 #ifndef LONG_LONG_MAX
00415         #define LONG_LONG_MAX LLONG_MAX
00416 #endif
00417 
00418 // unreference a variable in an inner scope to help prevent accidental usage
00419 struct ShadowType { };
00420 
00421 #define PLONK_SHADOW(VAR) ShadowType* VAR; (void)VAR;
00422 
00423 #if PLONK_APPLE && defined(__OBJC__)
00424 
00443 #define PLONK_OBJC_PROPERTY_MEMBER(Type,Name)\
00444     Variable<Type> Name
00445 
00464 #define PLONK_OBJC_PROPERTY_DECLARE(Type,Name)\
00465     @property (nonatomic,getter=get##Name,setter=set##Name:) Type Name
00466 
00483 #define PLONK_OBJC_PROPERTY_SYNTH(Type,Name)\
00484     - (Type)get##Name {\
00485     return Name.getValue();\
00486     }\
00487     - (void)set##Name:(Type)value {\
00488         Name.setValue (value);\
00489     }
00490 
00491 
00492 #define PLONK_OBJC_PROPERTY_MEMBER_UNIT(Type,Name)\
00493     Variable< UnitBase<Type>& > Name
00494 
00495 #define PLONK_OBJC_PROPERTY_DECLARE_UNIT(Type,Name)\
00496     @property (nonatomic,getter=get##Name,setter=set##Name:) UnitBase<Type> Name
00497 
00498 #define PLONK_OBJC_PROPERTY_SYNTH_UNIT(Type,Name)\
00499     - (UnitBase<Type>)get##Name {\
00500     return Name.getValue();\
00501     }\
00502     - (void)set##Name:(UnitBase<Type>)value {\
00503         Name.setValue (value);\
00504     }
00505 
00506 
00507 #endif // PLONK_APPLE && __OBJC__
00508 
00509 
00510 END_PLONK_NAMESPACE
00511 
00512 
00513 #endif // PLONK_STANDARDHEADER_H
 All Classes Functions Typedefs Enumerations Enumerator Properties