Home Information Classes Download Usage Mail List Requirements Links Tutorial
00001 /***************************************************/ 00013 /***************************************************/ 00014 00015 #ifndef STK_STK_H 00016 #define STK_STK_H 00017 00018 #include <string> 00019 #include <iostream> 00020 #include <sstream> 00021 00022 // Most data in STK is passed and calculated with the 00023 // following user-definable floating-point type. You 00024 // can change this to "float" if you prefer or perhaps 00025 // a "long double" in the future. 00026 typedef double StkFloat; 00027 00028 // The "MY_FLOAT" type was deprecated in STK 00029 // versions higher than 4.1.3 and replaced with the variable 00030 // "StkFloat". 00031 #if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) 00032 typedef StkFloat MY_FLOAT; 00033 #pragma deprecated(MY_FLOAT) 00034 #elif defined(__GXX__) 00035 typedef StkFloat MY_FLOAT __attribute__ ((deprecated)); 00036 #else 00037 typedef StkFloat MY_FLOAT; // temporary 00038 #endif 00039 00040 00042 00047 class StkError 00048 { 00049 public: 00050 enum Type { 00051 STATUS, 00052 WARNING, 00053 DEBUG_WARNING, 00054 MEMORY_ALLOCATION, 00055 MEMORY_ACCESS, 00056 FUNCTION_ARGUMENT, 00057 FILE_NOT_FOUND, 00058 FILE_UNKNOWN_FORMAT, 00059 FILE_ERROR, 00060 PROCESS_THREAD, 00061 PROCESS_SOCKET, 00062 PROCESS_SOCKET_IPADDR, 00063 AUDIO_SYSTEM, 00064 MIDI_SYSTEM, 00065 UNSPECIFIED 00066 }; 00067 00068 protected: 00069 std::string message_; 00070 Type type_; 00071 00072 public: 00074 StkError(const std::string& message, Type type = StkError::UNSPECIFIED) 00075 : message_(message), type_(type) {} 00076 00078 virtual ~StkError(void) {}; 00079 00081 virtual void printMessage(void) { std::cerr << '\n' << message_ << "\n\n"; } 00082 00084 virtual const Type& getType(void) { return type_; } 00085 00087 virtual const std::string& getMessage(void) { return message_; } 00088 00090 virtual const char *getMessageCString(void) { return message_.c_str(); } 00091 }; 00092 00093 00094 class Stk 00095 { 00096 public: 00097 00098 typedef unsigned long StkFormat; 00099 static const StkFormat STK_SINT8; 00100 static const StkFormat STK_SINT16; 00101 static const StkFormat STK_SINT24; 00102 static const StkFormat STK_SINT32; 00103 static const StkFormat STK_FLOAT32; 00104 static const StkFormat STK_FLOAT64; 00106 00107 static StkFloat sampleRate(void) { return srate_; } 00108 00110 00118 static void setSampleRate(StkFloat rate) { if (rate > 0.0) srate_ = rate; } 00119 00121 static std::string rawwavePath(void) { return rawwavepath_; } 00122 00124 static void setRawwavePath(std::string path); 00125 00127 static void swap16(unsigned char *ptr); 00128 00130 static void swap32(unsigned char *ptr); 00131 00133 static void swap64(unsigned char *ptr); 00134 00136 static void sleep(unsigned long milliseconds); 00137 00139 static void handleError( const char *message, StkError::Type type ); 00140 00142 static void handleError( std::string message, StkError::Type type ); 00143 00145 static void showWarnings( bool status ) { showWarnings_ = status; } 00146 00148 static void printErrors( bool status ) { printErrors_ = status; } 00149 00150 private: 00151 static StkFloat srate_; 00152 static std::string rawwavepath_; 00153 static bool showWarnings_; 00154 static bool printErrors_; 00155 00156 protected: 00157 00158 std::ostringstream errorString_; 00159 00161 Stk(void); 00162 00164 virtual ~Stk(void); 00165 00167 void handleError( StkError::Type type ); 00168 }; 00169 00170 00171 /***************************************************/ 00186 /***************************************************/ 00187 00188 class StkFrames 00189 { 00190 public: 00191 00193 StkFrames( unsigned int nFrames = 0, unsigned int nChannels = 0, bool interleaved = true ); 00194 00196 StkFrames( const StkFloat& value, unsigned int nFrames, unsigned int nChannels, bool interleaved = true ); 00197 00199 ~StkFrames(); 00200 00202 00208 StkFloat& operator[] ( size_t n ); 00209 00211 00215 StkFloat operator[] ( size_t n ) const; 00216 00218 00225 StkFloat& operator() ( size_t frame, unsigned int channel ); 00226 00228 00233 StkFloat operator() ( size_t frame, unsigned int channel ) const; 00234 00236 00242 StkFloat interpolate( StkFloat frame, unsigned int channel = 0 ) const; 00243 00245 size_t size() const { return size_; }; 00246 00248 bool empty() const; 00249 00251 00258 void resize( size_t nFrames, unsigned int nChannels = 1 ); 00259 00261 00268 void resize( size_t nFrames, unsigned int nChannels, StkFloat value ); 00269 00271 unsigned int channels( void ) const { return nChannels_; }; 00272 00274 unsigned int frames( void ) const { return nFrames_; }; 00275 00277 00281 void setDataRate( StkFloat rate ) { dataRate_ = rate; }; 00282 00284 00288 StkFloat dataRate( void ) const { return dataRate_; }; 00289 00291 bool interleaved( void ) const { return interleaved_; }; 00292 00294 00299 void setInterleaved( bool isInterleaved ) { interleaved_ = isInterleaved; }; 00300 00301 private: 00302 00303 StkFloat *data_; 00304 StkFloat dataRate_; 00305 size_t nFrames_; 00306 unsigned int nChannels_; 00307 size_t size_; 00308 size_t bufferSize_; 00309 bool interleaved_; 00310 00311 }; 00312 00313 00314 // Here are a few other useful typedefs. 00315 typedef unsigned short UINT16; 00316 typedef unsigned int UINT32; 00317 typedef signed short SINT16; 00318 typedef signed int SINT32; 00319 typedef float FLOAT32; 00320 typedef double FLOAT64; 00321 00322 // The default sampling rate. 00323 const StkFloat SRATE = 44100.0; 00324 00325 // The default real-time audio input and output buffer size. If 00326 // clicks are occuring in the input and/or output sound stream, a 00327 // larger buffer size may help. Larger buffer sizes, however, produce 00328 // more latency. 00329 const unsigned int RT_BUFFER_SIZE = 512; 00330 00331 // The default rawwave path value is set with the preprocessor 00332 // definition RAWWAVE_PATH. This can be specified as an argument to 00333 // the configure script, in an integrated development environment, or 00334 // below. The global STK rawwave path variable can be dynamically set 00335 // with the Stk::setRawwavePath() function. This value is 00336 // concatenated to the beginning of all references to rawwave files in 00337 // the various STK core classes (ex. Clarinet.cpp). If you wish to 00338 // move the rawwaves directory to a different location in your file 00339 // system, you will need to set this path definition appropriately. 00340 #if !defined(RAWWAVE_PATH) 00341 #define RAWWAVE_PATH "../../rawwaves/" 00342 #endif 00343 00344 const StkFloat PI = 3.14159265358979; 00345 const StkFloat TWO_PI = 2 * PI; 00346 const StkFloat ONE_OVER_128 = 0.0078125; 00347 00348 #if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) || defined(__WINDOWS_MM__) 00349 #define __OS_WINDOWS__ 00350 #define __STK_REALTIME__ 00351 #elif defined(__LINUX_OSS__) || defined(__LINUX_ALSA__) || defined(__LINUX_JACK__) 00352 #define __OS_LINUX__ 00353 #define __STK_REALTIME__ 00354 #elif defined(__IRIX_AL__) 00355 #define __OS_IRIX__ 00356 #define __STK_REALTIME__ 00357 #elif defined(__MACOSX_CORE__) 00358 #define __OS_MACOSX__ 00359 #define __STK_REALTIME__ 00360 #endif 00361 00362 //#define _STK_DEBUG_ 00363 00364 #endif
The Synthesis ToolKit in C++ (STK) |
©1995-2005 Perry R. Cook and Gary P. Scavone. All Rights Reserved. |