CSL 5.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

CSL_Types.h
Go to the documentation of this file.
1 ///
2 /// CSL_Types.h -- the top-most include file for CSL 5.0 (September, 2009).
3 ///
4 /// Central typedefs and platform-specific macros, also includes the model & observer classes.
5 /// This is normally included via CSL_Core.h or CSL_Includes.h.
6 ///
7 /// See the copyright notice and acknowledgment of authors in the file COPYRIGHT
8 ///
9 /// CSL Coding Conventions
10 /// Naming
11 /// Class, member, and method names are written in "camelCase" as in "UnitGenerator."
12 /// Class names are capitalized, but members and methods are written lower-camel-case.
13 /// Data members (instance variables) are written with initial "m" then camelCase as in "mOffset."
14 /// Enumeration constants are written with initial "k" followed by embedded caps as in "kDone."
15 /// Compiler flags and #defines are generally written all-upperr-case as in "USE_CASND."
16 /// Privacy
17 /// In general data members are protected and have accessor functions where appropriate.
18 /// The one exception is Buffer which is considered a record class and has public members.
19 ///
20 /// Compile-time options
21 /// (These are not set in this file so that different applications can share the source tree.)
22 ///
23 /// SoundFile type:
24 /// USE_JSND - use the JUCE-based sound file class (requires only JUCE)
25 /// USE_LSND - use libSndFile-based sound file class (supports many file types)
26 /// USE_CASND - use the CoreAudio version (runs on iPhone)
27 ///
28 /// FFT implementation
29 /// USE_FFTW - use FFTW 3 (faster but complicated to build)
30 /// USE_FFTREAL - use FFTReal (smaller and simpler)
31 /// USE_KISSFFT - use KISS FFT (smaller, untested)
32 ///
33 /// Thread implementation
34 /// USE_JTHREADS - use the JUCE thread classes (otherwise use pthreads)
35 ///
36 /// MIDI API
37 /// USE_JMIDI - use JUCE's MIDI I/O
38 ///
39 /// OSC API
40 /// USE_LOSC - use LibLo for OSC (assumes liblio 0.26 is installed)
41 /// USR_KOSC - use OSCKit for OSC (not implemented yet)
42 ///
43 /// CORE CSL Types
44 /// sample(float), Sample, SampleBuffer, SampleBufferVector, SampleComplex, SampleComplexVector
45 /// PortMap, UGenVector, UGenMap, IODeviceVector, Timestamp, VoidFcnPtr
46 ///
47 /// Constants
48 /// CSL_PI, CSL_TWOPI, CSL_PIHALF, CSL_SQRT_TWO, CSL_SPEED_OF_SOUND,
49 /// CSL_EXP_PER_DB, CSL_SAMPS_PER_METER, CSL_DEGS_PER_RAD
50 ///
51 /// Many useful macros below
52 ///
53
54 #ifndef CSL_Types_H // All CSL header files can be included only once.
55 #define CSL_Types_H // That's what these flags are for.
56
57 //// Platform macros -- check for these (e.g., CSL_WINDOWS rather than WIN32) in your code
58
59 #ifdef Linux // Linux
60 #define CSL_LINUX
61 #endif
62
63 #ifdef WIN32 // M$_Windows
64 #define CSL_WINDOWS
65 #endif
66
67 #if defined (__APPLE__) // Mac OSX
68 #define CSL_MACOSX
69 #endif
70
71 //// Global definitions
72
73 #define CSL_ENUMS // define this to use the various enumerations (which are problematic with SWIG)
74 // #define CSL_DEBUG // define this for very verbose debugging of constructors and call-backs
75 // #define CSL_DSP_BUFFER // define this for Buffer Sample Processing (feature extraction)
76 // #define USE_JUCE // use JUCE for all IO (now set as a compile-time flag)
77
78 ////
79 //// Major System Defaults (used in CGestalt to set static constants)
80 ////
81
82 #define CSL_mFrameRate 44100 ///< default sample rate (tested up to 96000)
83
84 #ifdef IPHONE
85 #define CSL_mBlockSize 256 ///< I/O block size (set to 64-2048 in typical usage)
86 #define CSL_mMaxBufferFrames 256 ///< max block size
87 #define CSL_mSndFileFrames 2000000 ///< default file cache size = 2 MB
88 #define CSL_mMaxSndFileFrames 2000000 ///< max file cache size = 2 MB
89 #else /// normal hosts
90 #define CSL_mBlockSize 2048 ///< I/O block size (set to 64-2048 in typical usage)
91 #define CSL_mMaxBufferFrames 8192 ///< max block size (set large for zooming scopes)
92 #define CSL_mSndFileFrames 20480000 ///< default file cache size = 20 MFrames (~ 2 min)
93 #define CSL_mMaxSndFileFrames 64000000 ///< max file cache size = 64 MB (set to a large value)
94 #endif
95
96 //#define READ_IO_PROPS ///< overwrite the system frame rate and block size from the
97 /// selected hardware interface at startup time
98
99 #define DEFAULT_WTABLE_SIZE CGestalt::maxBufferFrames() ///< size of wavetables, or use blockSize?
100
101 #define CSL_mVerbosity 3 ///< very verbose logging
102 #define CSL_mLoggingPeriod 10 ///< log CPU usage every N sec
103
104 #define CSL_LOG_PREFIX "-- " ///< prefix for log msgs (may be empty)
105 // #define CSL_LOG_PREFIX "\nCSL: " ///< verbose logging tags
106
107 #define CSL_mOutPort 57123 ///< RFS output port
108 #define CSL_mOSCPort 54321 ///< OSC input port
109
110 #define CSL_WORD_LEN 32 ///< default short string length
111 #define CSL_DEF_LEN 128 ///< default medium string length
112 #define CSL_NAME_LEN 256 ///< default string length
113 #define CSL_LINE_LEN 512 ///< default line length
114 #define CSL_STR_LEN 1024 ///< default long string length
115
116 #define SAMPS_TO_WRITE (44100 * 30) ///< record 30 seconds by default
117 #define OUT_SFILE_NAME "XX_csl.aiff" ///< csl output file name temlpate
118 //#define OUT_SFILE_NAME "CSLXX.aiff" ///< csl output file name temlpate
119
120 #ifdef CSL_WINDOWS
121 #define CSL_DATA_DIR "..\\..\\..\\CSL_Data\\" ///< folder where the CSL data can be found
122 #define CSL_INIT_FILE "..\\..\\..\\csl.ini" ///< where to store the CSL init file
123 #else
124 #define CSL_DATA_DIR "~/Code/CSL/CSL_Data/" ///< folder where the CSL data can be found
125 #define CSL_INIT_FILE "~/.cslrc" ///< where to store the CSL init file
126 // #define DO_TIMING ///< Gather performance timing (not on Windows)
127 #endif
128
129 //// Which Soundfile class to use? (choose with a compiler option, e.g., -DUSE_LSND)
130
131 #ifdef USE_JSND
132 #define SoundFile JSoundFile // JUCE snd file class
133 #endif
134 #ifdef USE_LSND
135 #define SoundFile LSoundFile // libSndFile
136 #endif
137 #ifdef USE_CASND
138 #define SoundFile CASoundFile // CoreAudio
139 #endif
140
141 #define USE_SNDFILEBUFFER // add snd file buffer class
142
143 //// Which MIDI IO port class to use?
144 //// (define here or choose with a compiler option, e.g., -DUSE_PMIDI)
145
146 //#define USE_JMIDI
147 #define DEFAULT_MIDI_IN 0
148 #define DEFAULT_MIDI_OUT 0
149
150 //// Use an OSC API?
151
152 #ifndef CSL_WINDOWS // works on Mac & Linux
153 #define USE_LOSC // liblo for OSC
154 #endif
155
156 //// Which default "Osc" class to use -- WavetableOscillator (table-lookup) or Sine (computed)?
157
158 #define Osc WavetableOscillator // default "Osc" -- or use Sine?
159
160
161 // Which FFT wrapper class to use? (choose with a compiler option, -DUSE_FFTREAL)
162
163 //#define USE_FFTW // use FFTW (faster but complicated to build)
164 //#define USE_FFTREAL // use FFTReal (smaller and simpler)
165
166
167 ////////////////////////// Core CSL Types //////////////////////////////////////////////
168
169 #include <vector> ///< we use the STL vector, map, and string classes
170 #include <string>
171 #include <map>
172 //#include <juce.h>
173
174 namespace csl { ///< All of CSL takes place within the "csl" namespace
175
176
177 //// CSL base audio and geometrical data type declarations - PAY ATTENTION
178
179 ///< short-hand for the base sample type
180 typedef float sample; /// (could be changed to int)
181 typedef float Sample; ///< the same, written upper-case
182
183 typedef sample* SampleBuffer; ///< 1-channel buffer data type, vector of (sample)
184 typedef SampleBuffer* SampleBufferVector; ///< Multi-channel buffer data type, vector of (SampleBuffer)
185 typedef SampleBuffer* SampleBufferArray; ///< Multi-channel buffer data type
186
187 typedef sample SampleComplex[2]; ///< array-of-2 complex # type (like FFTW)
188 #define cx_r(val) val[0] /// complex # accesor macros
189 #define cx_i(val) val[1]
190 #define ComplexPtr SampleBuffer ///< shorthand
191
192 //typedef struct { sample re; sample im; } SampleComplex; ///< alternate Complex # struct
193 //#define cx_r(val) val.re /// complex # accesor macros
194 //#define cx_i(val) val.im
195 //#define ComplexPtr SampleComplex ///< shorthand
196
197 typedef SampleComplex* SampleComplexVector; ///< complex vector
198 typedef SampleComplex* SampleComplexPtr; ///< complex pointer
199
200 class CPoint; ///< Forward declaration
201 typedef std::vector <CPoint *> PointVector; ///< A vector of points
202
203 typedef std::vector<unsigned> UnsignedVector; ///< A vector of unsigneds
204
205 typedef void * VoidFcnPtr(void * arg); ///< the generic void fcn pointer
206 typedef void VoidFcnPtrN(void); ///< the truly void fcn pointer
207
208 //// I/O and control port map types
209
210 class Buffer; ///< Forward declaration to Buffer (in CSL_Core.h)
211 class UnitGenerator; ///< Forward declaration to UnitGenerator (in CSL_Core.h)
212 class Port; ///< Forward declaration to Port
213 class IODevice; ///< Forward declaration to IO Device model
214 class Instrument; ///< Forward declaration to Instrument
215 class Observer; ///< Forward declaration
216
217 typedef unsigned CSL_MAP_KEY; ///< the type I use for map keys (could also be a string)
218 /// PortMap: a map between a name/key and a port object
219 /// (used for control and audio inputs)
220 typedef std::map <CSL_MAP_KEY, Port *> PortMap;
221 /// Buffer/UGenVector: unit generator pointers (used for outputs)
222 typedef std::vector <Buffer *> BufferVector;
223 typedef std::vector <UnitGenerator *> UGenVector;
224 /// UGenMap: a named map of unit generators (used for GUIs)
225 typedef std::map <std::string, UnitGenerator *> UGenMap;
226 // these are used in mixers
227 typedef std::map <unsigned, UnitGenerator *> UGenIMap;
228 typedef std::map <unsigned, float> FloatMap;
229 typedef std::vector <float> FloatVector;
230 /// IOs hold onto device vectors
231 typedef std::vector <IODevice *> IODeviceVector;
232 /// Players hold onto Instrument vectors/maps
233 typedef std::vector <Instrument *> InstrumentVector;
234 typedef std::map <int, InstrumentVector> InstrumentLibrary;
235 typedef std::map <std::string, Instrument *> InstrumentMap;
236
237 typedef std::map <std::string, std::string> StringMap;
238
239 /// Timestamp type: we assume that we can get the host's best guess at the IO word clock
240 /// (normally passed into the audio IO callback function). call timeNow() to get the time
241 /// We also support float-time in fTimeNow()
242
243 typedef unsigned long Timestamp;
244
245 //// struct used for the JUCE pop-up menu of tests (see the test files)
246
247 typedef struct {
248 char * name; // test name (menu item)
249 VoidFcnPtrN * fcn; // test void fcn ptr
250 char * comment; // test comment
251 } testStruct;
252
253
254 //// Hashmap keys for the default I/O ports (could be strings or int indeces)
255
256 #define CSL_SCALE 1
257 #define CSL_OFFSET 2
258 #define CSL_INPUT 3
259 #define CSL_OPERAND 4
260 #define CSL_OPERAND2 5
261 #define CSL_FREQUENCY 6
262 #define CSL_POSITION 7
263 #define CSL_POSITIONX 7
264 #define CSL_POSITIONY 8
265 #define CSL_POSITIONZ 9
266 #define CSL_FILTER_FREQUENCY 10
267 #define CSL_FILTER_AMOUNT 11
268 #define CSL_RATE 12
269
270
271 ////
272 //// Min/max, Boolean, statistics macros
273 ////
274
275 #ifndef csl_min // csl_min(a, b)
276 #define csl_min(a, b) (((a) < (b)) ? (a) : (b))
277 #endif
278
279 #ifndef csl_max // csl_max(a, b)
280 #define csl_max(a, b) (((a) > (b)) ? (a) : (b))
281 #endif
282
283 // inclusive between-ness
284
285 #define csl_between(a, b, c) (((a) >= (b)) && ((a) <= (c)))
286
287 // max/min ratio macros
288
289 #define csl_max_r(a) (((a) > 1.0f) ? (a) : (1.0f/a))
290 #define csl_min_r(a) (((a) < 1.0f) ? (a) : (1.0f/a))
291
292 #define csl_abs(a) (((a) >= 0) ? (a) : (-a))
293
294 // min/max ratio of 2 values
295
296 #define csl_max_d(a, b) ((a > b) ? (a / b) : (b / a))
297 #define csl_min_d(a, b) ((a < b) ? (a / b) : (b / a))
298
299 // ratio/remainder -- is v1 ~= N * v2?
300
301 #define csl_ratio_rem(val1, val2, remainder) \
302 remainder = csl_max_d(val1, val2); \
303 remainder -= (int) remainder; \
304 if (remainder > 0.5f) { \
305 remainder = csl_max_r(rem); \
306 remainder -= 1.0f; \
307 }
308
309 //// TRUE/FALSE
310
311 #ifndef TRUE
312 #define TRUE 1
313 #define FALSE 0
314 #endif
315
316 //// Numerical constants (for convenience, all floats)
317
318 #define CSL_PI 3.1415926535897933f
319 // #define CSL_PI 3.141592653589793238462643383279502884197169399375108209749445923ld
320 #define CSL_TWOPI 6.2831853071795865f
321 #define CSL_PIHALF 1.570796326795f
322 #define CSL_SQRT_TWO 1.414213562f
323 #define CSL_SPEED_OF_SOUND 330.0f
324 #define CSL_EXP_PER_DB 0.11512925464970228f
325 #define CSL_SAMPS_PER_METER 133.63636363636364f
326 #define CSL_DEGS_PER_RAD 57.295779513082321f
327
328 ///
329 /// Typedefs for basic types that differ across platforms
330 ///
331
332 #ifdef CSL_WINDOWS // Microsoft is explicit
333 //#include "stdafx.h"
334 // Hypotenuse = complex-to-real-magnitude
335 #define hypotf(av, bv) sqrtf((av * av) + (bv * bv))
336
337 #ifdef MSVS6 // ignore pragmas not understood by Microsoft Visual C++
338 #pragma warning(once:4068 4244 4305 4355)
339 #pragma warning(once:4290)
340 #endif
341
342 //#else
343 // // GCC long long is 64 bits on both 32 and 64 bit operating systems (long is only 64 on 64)
344 // typedef signed long long INT64;
345 // typedef unsigned long long UINT64;
346
347 #endif // CSL_WINDOWS
348
349 } // end of namespace
350
351 #endif // _CSLTypes_H