*** empty log message ***
[chuck-blob.git] / v2 / chuck_def.h
blob3750787d74dbc6bba8e776703d7ea1c9d12c8378
1 /*----------------------------------------------------------------------------
2 ChucK Concurrent, On-the-fly Audio Programming Language
3 Compiler and Virtual Machine
5 Copyright (c) 2004 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.cs.princeton.edu/
7 http://soundlab.cs.princeton.edu/
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 U.S.A.
23 -----------------------------------------------------------------------------*/
25 //-----------------------------------------------------------------------------
26 // file: chuck_def.h
27 // desc: ...
29 // author: Ge Wang (gewang@cs.princeton.edu)
30 // Perry R. Cook (prc@cs.princeton.edu)
31 // date: Autumn 2002
32 //-----------------------------------------------------------------------------
33 #ifndef __CHUCK_DEF_H__
34 #define __CHUCK_DEF_H__
36 #include <stdlib.h>
37 #include <memory.h>
38 #include <assert.h>
41 // types
42 #define t_CKTIME double
43 #define t_CKDUR double
44 #define t_CKFLOAT double
45 #define t_CKDOUBLE double
46 #define t_CKSINGLE float
47 #define t_CKINT long
48 #define t_CKDWORD unsigned long
49 #define t_CKUINT t_CKDWORD
50 #define t_CKBOOL t_CKDWORD
51 #define t_CKBYTE unsigned char
52 #define t_CKVOID void
53 #define t_CKVOIDPTR void *
55 // complex type
56 typedef struct { t_CKFLOAT re ; t_CKFLOAT im ; } t_CKCOMPLEX;
57 // polar type
58 typedef struct { t_CKFLOAT modulus ; t_CKFLOAT phase ; } t_CKPOLAR;
60 // size
61 #define sz_TIME sizeof(double)
62 #define sz_DUR sizeof(double)
63 #define sz_FLOAT sizeof(double)
64 #define sz_DOUBLE sizeof(double)
65 #define sz_SINGLE sizeof(float)
66 #define sz_INT sizeof(long)
67 #define sz_DWORD sizeof(unsigned long)
68 #define sz_UINT sizeof(t_CKDWORD)
69 #define sz_BOOL sizeof(t_CKDWORD)
70 #define sz_BYTE sizeof(unsigned char)
71 #define sz_VOID 0
72 #define sz_VOIDPTR sizeof(void *)
73 #define sz_COMPLEX sizeof(t_CKCOMPLEX)
74 #define sz_POLAR sizeof(t_CKPOLAR)
76 typedef char * c_str;
77 typedef const char * c_constr;
79 // double
80 // #define CK_S_DOUBLE
82 // sample
83 #ifdef CK_S_DOUBLE
84 #define SAMPLE double
85 #define SILENCE 0.0
86 #define CK_DDN CK_DDN_DOUBLE
87 #else
88 #define SAMPLE float
89 #define SILENCE 0.0f
90 #define CK_DDN CK_DDN_SINGLE
91 #endif
93 // sample complex
94 typedef struct { SAMPLE re ; SAMPLE im ; } t_CKCOMPLEX_SAMPLE;
96 // bool
97 #ifndef TRUE
98 #define TRUE 1
99 #define FALSE 0
100 #endif
102 // 3.1415926535897932384626433832795028841971693993751058209749445...
103 #define ONE_PI (3.14159265358979323846)
104 #define TWO_PI (2.0 * ONE_PI)
105 #define SQRT2 (1.41421356237309504880)
107 #ifndef SAFE_DELETE
108 #define SAFE_DELETE(x) do { if(x){ delete x; x = NULL; } } while(0)
109 #define SAFE_DELETE_ARRAY(x) do { if(x){ delete [] x; x = NULL; } } while(0)
110 #define SAFE_RELEASE(x) do { if(x){ x->release(); x = NULL; } } while(0)
111 #define SAFE_ADD_REF(x) do { if(x){ x->add_ref(); } } while(0)
112 #define SAFE_REF_ASSIGN(lhs,rhs) do { SAFE_RELEASE(lhs); (lhs) = (rhs); SAFE_ADD_REF(lhs); } while(0)
113 #endif
115 // max + min
116 #define ck_max(x,y) ( (x) >= (y) ? (x) : (y) )
117 #define ck_min(x,y) ( (x) <= (y) ? (x) : (y) )
119 // dedenormal
120 #define CK_DDN_SINGLE(f) f = ( f >= 0 ? \
121 ( ( f > (t_CKSINGLE)1e-15 && f < (t_CKSINGLE)1e15 ) ? f : (t_CKSINGLE)0.0 ) : \
122 ( ( f < (t_CKSINGLE)-1e-15 && f > (t_CKSINGLE)-1e15 ) ? f : (t_CKSINGLE)0.0 ) )
123 #define CK_DDN_DOUBLE(f) f = ( f >= 0 ? \
124 ( ( f > (t_CKDOUBLE)1e-15 && f < (t_CKDOUBLE)1e15 ) ? f : 0.0 ) : \
125 ( ( f < (t_CKDOUBLE)-1e-15 && f > (t_CKDOUBLE)-1e15 ) ? f : 0.0 ) )
128 // tracking
129 #if defined(__CHUCK_STAT_TRACK__)
130 #define CK_TRACK( stmt ) stmt
131 #else
132 #define CK_TRACK( stmt )
133 #endif
135 #ifdef __MACOSX_CORE__
136 #define __PLATFORM_MACOSX__
137 #endif
139 #if defined(__LINUX_ALSA__) || defined(__LINUX_JACK__) || defined(__LINUX_OSS__)
140 #define __PLATFORM_LINUX__
141 #endif
143 #ifdef __PLATFORM_WIN32__
144 #ifndef usleep
145 #define usleep(x) Sleep( (x / 1000 <= 0 ? 1 : x / 1000) )
146 #endif
147 #pragma warning (disable : 4996) // stdio deprecation
148 #pragma warning (disable : 4786) // stl debug info
149 #pragma warning (disable : 4312) // type casts from void*
150 #pragma warning (disable : 4311) // type casts to void*
151 #pragma warning (disable : 4244) // truncation
152 #pragma warning (disable : 4068) // unknown pragma
153 #endif
155 #ifdef __CHIP_MODE__
156 #define __DISABLE_MIDI__
157 #define __DISABLE_SNDBUF__
158 #define __DISABLE_WATCHDOG__
159 #define __DISABLE_RAW__
160 #define __DISABLE_KBHIT__
161 #define __DISABLE_PROMPTER__
162 #define __DISABLE_RTAUDIO__
163 #define __ALTER_HID__
164 #define __ALTER_ENTRY_POINT__
165 #define __STK_USE_SINGLE_PRECISION__
166 #endif
171 #endif