Home   Information   Classes   Download   Usage   Mail List   Requirements   Tutorial


Stk.h

00001 /***************************************************/
00013 /***************************************************/
00014 
00015 #if !defined(__STK_H)
00016 #define __STK_H
00017 
00018 // Most data in STK is passed and calculated with the following
00019 // user-definable floating-point type.  You can change this to "float"
00020 // if you prefer or perhaps a "long double" in the future.
00021 typedef double MY_FLOAT;
00022 
00024 
00029 class StkError
00030 {
00031 public:
00032   enum TYPE { 
00033     WARNING,
00034     DEBUG_WARNING,
00035     FUNCTION_ARGUMENT,
00036     FILE_NOT_FOUND,
00037     FILE_UNKNOWN_FORMAT,
00038     FILE_ERROR,
00039     PROCESS_THREAD,
00040     PROCESS_SOCKET,
00041     PROCESS_SOCKET_IPADDR,
00042     AUDIO_SYSTEM,
00043     MIDI_SYSTEM,
00044     UNSPECIFIED
00045   };
00046 
00047 protected:
00048   char message[256];
00049   TYPE type;
00050 
00051 public:
00053   StkError(const char *p, TYPE tipe = StkError::UNSPECIFIED);
00054 
00056   virtual ~StkError(void);
00057 
00059   virtual void printMessage(void);
00060 
00062   virtual const TYPE& getType(void) { return type; }
00063 
00065   virtual const char *getMessage(void) const { return message; }
00066 };
00067 
00068 
00069 class Stk
00070 {
00071  public:
00072 
00073   typedef unsigned long STK_FORMAT;
00074   static const STK_FORMAT STK_SINT8;   
00075   static const STK_FORMAT STK_SINT16;  
00076   static const STK_FORMAT STK_SINT32;  
00077   static const STK_FORMAT STK_FLOAT32; 
00078   static const STK_FORMAT STK_FLOAT64; 
00079 
00081   static MY_FLOAT sampleRate(void);
00082 
00084 
00092   static void setSampleRate(MY_FLOAT newRate);
00093 
00095   static void swap16(unsigned char *ptr);
00096 
00098   static void swap32(unsigned char *ptr);
00099 
00101   static void swap64(unsigned char *ptr);
00102 
00104   static void sleep(unsigned long milliseconds);
00105 
00106  private:
00107   static MY_FLOAT srate;
00108 
00109  protected:
00110 
00112   Stk(void);
00113 
00115   virtual ~Stk(void);
00116 
00118   static void handleError( const char *message, StkError::TYPE type );
00119 
00120 };
00121 
00122 // Here are a few other useful typedefs.
00123 typedef signed short SINT16;
00124 typedef signed int SINT32;
00125 typedef float FLOAT32;
00126 typedef double FLOAT64;
00127 
00128 // Boolean values
00129 #define FALSE 0
00130 #define TRUE 1
00131 
00132 // The default sampling rate.
00133 #define SRATE (MY_FLOAT) 22050.0
00134 
00135 // Real-time audio input and output buffer size.  If clicks are
00136 // occuring in the input and/or output sound stream, a larger buffer
00137 // size may help.  Larger buffer sizes, however, produce more latency.
00138 
00139 #define RT_BUFFER_SIZE 512
00140 
00141 // The RAWWAVE_PATH definition is concatenated to the beginning of all
00142 // references to rawwave files in the various STK core classes
00143 // (ex. Clarinet.cpp).  If you wish to move the rawwaves directory to
00144 // a different location in your file system, you will need to set this
00145 // path definition appropriately.  The current definition is a
00146 // relative reference that will work "out of the box" for the STK
00147 // distribution.
00148 #define RAWWAVE_PATH "../../"
00149 
00150 #define PI (MY_FLOAT) 3.14159265359
00151 #define TWO_PI (MY_FLOAT) (MY_FLOAT) (2 * PI)
00152 
00153 #define ONE_OVER_128 (MY_FLOAT) 0.0078125
00154 
00155 #if defined(__WINDOWS_DS__)
00156   #define __OS_WINDOWS__
00157   #define __STK_REALTIME__
00158 #elif defined(__LINUX_OSS__) || defined(__LINUX_ALSA__)
00159   #define __OS_LINUX__
00160   #define __STK_REALTIME__
00161 #elif defined(__IRIX_AL__)
00162   #define __OS_IRIX__
00163   #define __STK_REALTIME__
00164 #endif
00165 
00166 //#define _STK_DEBUG_
00167 
00168 #endif

The Synthesis ToolKit in C++ (STK)
©1995-2002 Perry R. Cook and Gary P. Scavone. All Rights Reserved.