77 typedef double StkFloat;
100 PROCESS_SOCKET_IPADDR,
107 std::string message_;
112 StkError(
const std::string& message, Type type = StkError::UNSPECIFIED)
113 : message_(message), type_(type) {}
119 virtual void printMessage(
void) { std::cerr <<
'\n' << message_ <<
"\n\n"; }
122 virtual const Type&
getType(
void) {
return type_; }
125 virtual const std::string&
getMessage(
void) {
return message_; }
136 typedef unsigned long StkFormat;
182 static void swap16(
unsigned char *ptr );
185 static void swap32(
unsigned char *ptr );
188 static void swap64(
unsigned char *ptr );
191 static void sleep(
unsigned long milliseconds );
194 static bool inRange( StkFloat value, StkFloat min, StkFloat max ) {
195 if ( value < min )
return false;
196 else if ( value > max )
return false;
201 static void handleError(
const char *message, StkError::Type type );
204 static void handleError( std::string message, StkError::Type type );
213 static StkFloat srate_;
214 static std::string rawwavepath_;
215 static bool showWarnings_;
216 static bool printErrors_;
217 static std::vector<Stk *> alertList_;
221 static std::ostringstream oStream_;
222 bool ignoreSampleRateChange_;
228 virtual ~Stk(
void );
277 StkFrames(
unsigned int nFrames = 0,
unsigned int nChannels = 0 );
280 StkFrames(
const StkFloat& value,
unsigned int nFrames,
unsigned int nChannels );
331 StkFloat&
operator() (
size_t frame,
unsigned int channel );
339 StkFloat
operator() (
size_t frame,
unsigned int channel )
const;
348 StkFloat
interpolate( StkFloat frame,
unsigned int channel = 0 )
const;
351 size_t size()
const {
return size_; };
364 void resize(
size_t nFrames,
unsigned int nChannels = 1 );
374 void resize(
size_t nFrames,
unsigned int nChannels, StkFloat value );
377 unsigned int channels(
void )
const {
return nChannels_; };
380 unsigned int frames(
void )
const {
return (
unsigned int)nFrames_; };
394 StkFloat
dataRate(
void )
const {
return dataRate_; };
401 unsigned int nChannels_;
409 if ( size_ > 0 )
return false;
415 #if defined(_STK_DEBUG_)
417 std::ostringstream error;
418 error <<
"StkFrames::operator[]: invalid index (" << n <<
") value!";
428 #if defined(_STK_DEBUG_)
430 std::ostringstream error;
431 error <<
"StkFrames::operator[]: invalid index (" << n <<
") value!";
441 #if defined(_STK_DEBUG_)
442 if ( frame >= nFrames_ || channel >= nChannels_ ) {
443 std::ostringstream error;
444 error <<
"StkFrames::operator(): invalid frame (" << frame <<
") or channel (" << channel <<
") value!";
449 return data_[ frame * nChannels_ + channel ];
454 #if defined(_STK_DEBUG_)
455 if ( frame >= nFrames_ || channel >= nChannels_ ) {
456 std::ostringstream error;
457 error <<
"StkFrames::operator(): invalid frame (" << frame <<
") or channel (" << channel <<
") value!";
462 return data_[ frame * nChannels_ + channel ];
467 #if defined(_STK_DEBUG_)
469 std::ostringstream error;
470 error <<
"StkFrames::operator+=: frames argument must be of equal dimensions!";
475 StkFloat *fptr = &f[0];
476 StkFloat *dptr = data_;
477 for (
unsigned int i=0; i<size_; i++ )
483 #if defined(_STK_DEBUG_)
485 std::ostringstream error;
486 error <<
"StkFrames::operator*=: frames argument must be of equal dimensions!";
491 StkFloat *fptr = &f[0];
492 StkFloat *dptr = data_;
493 for (
unsigned int i=0; i<size_; i++ )
498 typedef unsigned short UINT16;
499 typedef unsigned int UINT32;
500 typedef signed short SINT16;
501 typedef signed int SINT32;
502 typedef float FLOAT32;
503 typedef double FLOAT64;
506 const StkFloat SRATE = 44100.0;
512 const unsigned int RT_BUFFER_SIZE = 512;
523 #if !defined(RAWWAVE_PATH)
524 #define RAWWAVE_PATH "../../rawwaves/"
527 const StkFloat PI = 3.14159265358979;
528 const StkFloat TWO_PI = 2 * PI;
529 const StkFloat ONE_OVER_128 = 0.0078125;
531 #if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) || defined(__WINDOWS_MM__)
532 #define __OS_WINDOWS__
533 #define __STK_REALTIME__
534 #elif defined(__LINUX_OSS__) || defined(__LINUX_ALSA__) || defined(__UNIX_JACK__)
536 #define __STK_REALTIME__
537 #elif defined(__IRIX_AL__)
539 #elif defined(__MACOSX_CORE__) || defined(__UNIX_JACK__)
540 #define __OS_MACOSX__
541 #define __STK_REALTIME__
static void setRawwavePath(std::string path)
Static method that sets the STK rawwave path.
Definition: Stk.cpp:116
StkFloat interpolate(StkFloat frame, unsigned int channel=0) const
Return an interpolated value at the fractional frame index and channel.
Definition: Stk.cpp:319
void operator*=(StkFrames &f)
Assignment by product operator into self.
Definition: Stk.h:481
static void swap16(unsigned char *ptr)
Static method that byte-swaps a 16-bit data type.
Definition: Stk.cpp:126
Stk(void)
Default constructor.
Definition: Stk.cpp:71
virtual const char * getMessageCString(void)
Returns the thrown error message as a C string.
Definition: Stk.h:128
~StkFrames()
The destructor.
Definition: Stk.cpp:269
static const StkFormat STK_FLOAT64
Definition: Stk.h:142
bool empty() const
Returns true if the object size is zero and false otherwise.
Definition: Stk.h:407
static void swap32(unsigned char *ptr)
Static method that byte-swaps a 32-bit data type.
Definition: Stk.cpp:136
virtual void printMessage(void)
Prints thrown error message to stderr.
Definition: Stk.h:119
static const StkFormat STK_SINT24
Definition: Stk.h:139
StkFrames(unsigned int nFrames=0, unsigned int nChannels=0)
The default constructor initializes the frame data structure to size zero.
Definition: Stk.cpp:231
The STK namespace.
Definition: FileRead.cpp:41
virtual const Type & getType(void)
Returns the thrown error message type.
Definition: Stk.h:122
static const StkFormat STK_SINT8
Definition: Stk.h:137
static void printErrors(bool status)
Toggle display of error messages before throwing exceptions.
Definition: Stk.h:210
virtual void sampleRateChanged(StkFloat newRate, StkFloat oldRate)
This function should be implemented in subclasses that depend on the sample rate. ...
Definition: Stk.cpp:91
static bool inRange(StkFloat value, StkFloat min, StkFloat max)
Static method to check whether a value is within a specified range.
Definition: Stk.h:194
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition: Stk.h:380
static void sleep(unsigned long milliseconds)
Static cross-platform method to sleep for a number of milliseconds.
Definition: Stk.cpp:186
static const StkFormat STK_SINT32
Definition: Stk.h:140
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
Definition: Stk.cpp:201
STK error handling class.
Definition: Stk.h:85
void resize(size_t nFrames, unsigned int nChannels=1)
Resize self to represent the specified number of channels and frames.
Definition: Stk.cpp:293
static void showWarnings(bool status)
Toggle display of WARNING and STATUS messages.
Definition: Stk.h:207
virtual ~StkError(void)
The destructor.
Definition: Stk.h:116
static StkFloat sampleRate(void)
Static method that returns the current STK sample rate.
Definition: Stk.h:145
static std::string rawwavePath(void)
Static method that returns the current rawwave path.
Definition: Stk.h:176
static void setSampleRate(StkFloat rate)
Static method that sets the STK sample rate.
Definition: Stk.cpp:80
virtual ~Stk(void)
Class destructor.
Definition: Stk.cpp:76
StkFloat dataRate(void) const
Return the sample rate associated with the StkFrames data.
Definition: Stk.h:394
An STK class to handle vectorized audio data.
Definition: Stk.h:272
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition: Stk.h:377
static void swap64(unsigned char *ptr)
Static method that byte-swaps a 64-bit data type.
Definition: Stk.cpp:152
void setDataRate(StkFloat rate)
Set the sample rate associated with the StkFrames data.
Definition: Stk.h:387
static const StkFormat STK_FLOAT32
Definition: Stk.h:141
STK base class.
Definition: Stk.h:132
StkFloat & operator[](size_t n)
Subscript operator that returns a reference to element n of self.
Definition: Stk.h:413
void removeSampleRateAlert(Stk *ptr)
Remove class pointer from list for sample rate change notification.
Definition: Stk.cpp:106
void ignoreSampleRateChange(bool ignore=true)
A function to enable/disable the automatic updating of class data when the STK sample rate changes...
Definition: Stk.h:173
StkFloat & operator()(size_t frame, unsigned int channel)
Channel / frame subscript operator that returns a reference.
Definition: Stk.h:439
StkError(const std::string &message, Type type=StkError::UNSPECIFIED)
The constructor.
Definition: Stk.h:112
size_t size() const
Returns the total number of audio samples represented by the object.
Definition: Stk.h:351
static const StkFormat STK_SINT16
Definition: Stk.h:138
void addSampleRateAlert(Stk *ptr)
Add class pointer to list for sample rate change notification.
Definition: Stk.cpp:98
void operator+=(StkFrames &f)
Assignment by sum operator into self.
Definition: Stk.h:465
virtual const std::string & getMessage(void)
Returns the thrown error message string.
Definition: Stk.h:125