Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial
00001 /***************************************************/ 00037 /***************************************************/ 00038 00039 #ifndef STK_STK_H 00040 #define STK_STK_H 00041 00042 #include <string> 00043 #include <iostream> 00044 #include <sstream> 00045 #include <vector> 00046 00047 // Most data in STK is passed and calculated with the 00048 // following user-definable floating-point type. You 00049 // can change this to "float" if you prefer or perhaps 00050 // a "long double" in the future. 00051 typedef double StkFloat; 00052 00054 00059 class StkError 00060 { 00061 public: 00062 enum Type { 00063 STATUS, 00064 WARNING, 00065 DEBUG_WARNING, 00066 MEMORY_ALLOCATION, 00067 MEMORY_ACCESS, 00068 FUNCTION_ARGUMENT, 00069 FILE_NOT_FOUND, 00070 FILE_UNKNOWN_FORMAT, 00071 FILE_ERROR, 00072 PROCESS_THREAD, 00073 PROCESS_SOCKET, 00074 PROCESS_SOCKET_IPADDR, 00075 AUDIO_SYSTEM, 00076 MIDI_SYSTEM, 00077 UNSPECIFIED 00078 }; 00079 00080 protected: 00081 std::string message_; 00082 Type type_; 00083 00084 public: 00086 StkError(const std::string& message, Type type = StkError::UNSPECIFIED) 00087 : message_(message), type_(type) {} 00088 00090 virtual ~StkError(void) {}; 00091 00093 virtual void printMessage(void) { std::cerr << '\n' << message_ << "\n\n"; } 00094 00096 virtual const Type& getType(void) { return type_; } 00097 00099 virtual const std::string& getMessage(void) { return message_; } 00100 00102 virtual const char *getMessageCString(void) { return message_.c_str(); } 00103 }; 00104 00105 00106 class Stk 00107 { 00108 public: 00109 00110 typedef unsigned long StkFormat; 00111 static const StkFormat STK_SINT8; 00112 static const StkFormat STK_SINT16; 00113 static const StkFormat STK_SINT24; 00114 static const StkFormat STK_SINT32; 00115 static const StkFormat STK_FLOAT32; 00116 static const StkFormat STK_FLOAT64; 00118 00119 static StkFloat sampleRate( void ) { return srate_; } 00120 00122 00139 static void setSampleRate( StkFloat rate ); 00140 00142 00147 void ignoreSampleRateChange( bool ignore = true ) { ignoreSampleRateChange_ = ignore; }; 00148 00150 static std::string rawwavePath(void) { return rawwavepath_; } 00151 00153 static void setRawwavePath( std::string path ); 00154 00156 static void swap16( unsigned char *ptr ); 00157 00159 static void swap32( unsigned char *ptr ); 00160 00162 static void swap64( unsigned char *ptr ); 00163 00165 static void sleep( unsigned long milliseconds ); 00166 00168 static void handleError( const char *message, StkError::Type type ); 00169 00171 static void handleError( std::string message, StkError::Type type ); 00172 00174 static void showWarnings( bool status ) { showWarnings_ = status; } 00175 00177 static void printErrors( bool status ) { printErrors_ = status; } 00178 00179 private: 00180 static StkFloat srate_; 00181 static std::string rawwavepath_; 00182 static bool showWarnings_; 00183 static bool printErrors_; 00184 static std::vector<Stk *> alertList_; 00185 00186 protected: 00187 00188 std::ostringstream errorString_; 00189 bool ignoreSampleRateChange_; 00190 00192 Stk( void ); 00193 00195 virtual ~Stk( void ); 00196 00198 virtual void sampleRateChanged( StkFloat newRate, StkFloat oldRate ); 00199 00201 void addSampleRateAlert( Stk *ptr ); 00202 00204 void removeSampleRateAlert( Stk *ptr ); 00205 00207 void handleError( StkError::Type type ); 00208 }; 00209 00210 00211 /***************************************************/ 00226 /***************************************************/ 00227 00228 class StkFrames 00229 { 00230 public: 00231 00233 StkFrames( unsigned int nFrames = 0, unsigned int nChannels = 0, bool interleaved = true ); 00234 00236 StkFrames( const StkFloat& value, unsigned int nFrames, unsigned int nChannels, bool interleaved = true ); 00237 00239 ~StkFrames(); 00240 00242 00248 StkFloat& operator[] ( size_t n ); 00249 00251 00255 StkFloat operator[] ( size_t n ) const; 00256 00258 00265 StkFloat& operator() ( size_t frame, unsigned int channel ); 00266 00268 00273 StkFloat operator() ( size_t frame, unsigned int channel ) const; 00274 00276 00282 StkFloat interpolate( StkFloat frame, unsigned int channel = 0 ) const; 00283 00285 size_t size() const { return size_; }; 00286 00288 bool empty() const; 00289 00291 00298 void resize( size_t nFrames, unsigned int nChannels = 1 ); 00299 00301 00308 void resize( size_t nFrames, unsigned int nChannels, StkFloat value ); 00309 00311 unsigned int channels( void ) const { return nChannels_; }; 00312 00314 unsigned int frames( void ) const { return nFrames_; }; 00315 00317 00321 void setDataRate( StkFloat rate ) { dataRate_ = rate; }; 00322 00324 00328 StkFloat dataRate( void ) const { return dataRate_; }; 00329 00331 bool interleaved( void ) const { return interleaved_; }; 00332 00334 00339 void setInterleaved( bool isInterleaved ) { interleaved_ = isInterleaved; }; 00340 00341 private: 00342 00343 StkFloat *data_; 00344 StkFloat dataRate_; 00345 size_t nFrames_; 00346 unsigned int nChannels_; 00347 size_t size_; 00348 size_t bufferSize_; 00349 bool interleaved_; 00350 00351 }; 00352 00353 00354 // Here are a few other useful typedefs. 00355 typedef unsigned short UINT16; 00356 typedef unsigned int UINT32; 00357 typedef signed short SINT16; 00358 typedef signed int SINT32; 00359 typedef float FLOAT32; 00360 typedef double FLOAT64; 00361 00362 // The default sampling rate. 00363 const StkFloat SRATE = 44100.0; 00364 00365 // The default real-time audio input and output buffer size. If 00366 // clicks are occuring in the input and/or output sound stream, a 00367 // larger buffer size may help. Larger buffer sizes, however, produce 00368 // more latency. 00369 const unsigned int RT_BUFFER_SIZE = 512; 00370 00371 // The default rawwave path value is set with the preprocessor 00372 // definition RAWWAVE_PATH. This can be specified as an argument to 00373 // the configure script, in an integrated development environment, or 00374 // below. The global STK rawwave path variable can be dynamically set 00375 // with the Stk::setRawwavePath() function. This value is 00376 // concatenated to the beginning of all references to rawwave files in 00377 // the various STK core classes (ex. Clarinet.cpp). If you wish to 00378 // move the rawwaves directory to a different location in your file 00379 // system, you will need to set this path definition appropriately. 00380 #if !defined(RAWWAVE_PATH) 00381 #define RAWWAVE_PATH "../../rawwaves/" 00382 #endif 00383 00384 const StkFloat PI = 3.14159265358979; 00385 const StkFloat TWO_PI = 2 * PI; 00386 const StkFloat ONE_OVER_128 = 0.0078125; 00387 00388 #if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) || defined(__WINDOWS_MM__) 00389 #define __OS_WINDOWS__ 00390 #define __STK_REALTIME__ 00391 #elif defined(__LINUX_OSS__) || defined(__LINUX_ALSA__) || defined(__UNIX_JACK__) 00392 #define __OS_LINUX__ 00393 #define __STK_REALTIME__ 00394 #elif defined(__IRIX_AL__) 00395 #define __OS_IRIX__ 00396 #elif defined(__MACOSX_CORE__) || defined(__UNIX_JACK__) 00397 #define __OS_MACOSX__ 00398 #define __STK_REALTIME__ 00399 #endif 00400 00401 //#define _STK_DEBUG_ 00402 00403 #endif
The Synthesis ToolKit in C++ (STK) |
©1995-2007 Perry R. Cook and Gary P. Scavone. All Rights Reserved. |