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;
185 static void swap16(
unsigned char *ptr );
188 static void swap32(
unsigned char *ptr );
191 static void swap64(
unsigned char *ptr );
194 static void sleep(
unsigned long milliseconds );
197 static bool inRange( StkFloat value, StkFloat min, StkFloat max ) {
198 if ( value < min )
return false;
199 else if ( value > max )
return false;
204 static void handleError(
const char *message, StkError::Type type );
207 static void handleError( std::string message, StkError::Type type );
216 static StkFloat srate_;
217 static std::string rawwavepath_;
218 static bool showWarnings_;
219 static bool printErrors_;
220 static std::vector<Stk *> alertList_;
224 static std::ostringstream oStream_;
225 bool ignoreSampleRateChange_;
280 StkFrames(
unsigned int nFrames = 0,
unsigned int nChannels = 0 );
283 StkFrames(
const StkFloat& value,
unsigned int nFrames,
unsigned int nChannels );
342 StkFloat&
operator() (
size_t frame,
unsigned int channel );
350 StkFloat
operator() (
size_t frame,
unsigned int channel )
const;
359 StkFloat
interpolate( StkFloat frame,
unsigned int channel = 0 )
const;
362 size_t size()
const {
return size_; };
375 void resize(
size_t nFrames,
unsigned int nChannels = 1 );
385 void resize(
size_t nFrames,
unsigned int nChannels, StkFloat value );
404 unsigned int channels(
void )
const {
return nChannels_; };
407 unsigned int frames(
void )
const {
return (
unsigned int)nFrames_; };
421 StkFloat
dataRate(
void )
const {
return dataRate_; };
428 unsigned int nChannels_;
436 if ( size_ > 0 )
return false;
442 #if defined(_STK_DEBUG_)
444 std::ostringstream error;
445 error <<
"StkFrames::operator[]: invalid index (" << n <<
") value!";
455 #if defined(_STK_DEBUG_)
457 std::ostringstream error;
458 error <<
"StkFrames::operator[]: invalid index (" << n <<
") value!";
468 #if defined(_STK_DEBUG_)
469 if ( frame >= nFrames_ || channel >= nChannels_ ) {
470 std::ostringstream error;
471 error <<
"StkFrames::operator(): invalid frame (" << frame <<
") or channel (" << channel <<
") value!";
476 return data_[ frame * nChannels_ + channel ];
481 #if defined(_STK_DEBUG_)
482 if ( frame >= nFrames_ || channel >= nChannels_ ) {
483 std::ostringstream error;
484 error <<
"StkFrames::operator(): invalid frame (" << frame <<
") or channel (" << channel <<
") value!";
489 return data_[ frame * nChannels_ + channel ];
494 #if defined(_STK_DEBUG_)
496 std::ostringstream error;
497 error <<
"StkFrames::operator+: frames argument must be of equal dimensions!";
501 StkFrames sum((
unsigned int)nFrames_,nChannels_);
502 StkFloat *sumPtr = &sum[0];
503 const StkFloat *fptr = f.data_;
504 const StkFloat *dPtr = data_;
505 for (
unsigned int i = 0; i < size_; i++) {
506 *sumPtr++ = *fptr++ + *dPtr++;
513 #if defined(_STK_DEBUG_)
515 std::ostringstream error;
516 error <<
"StkFrames::operator+=: frames argument must be of equal dimensions!";
521 StkFloat *fptr = &f[0];
522 StkFloat *dptr = data_;
523 for (
unsigned int i=0; i<size_; i++ )
529 #if defined(_STK_DEBUG_)
531 std::ostringstream error;
532 error <<
"StkFrames::operator*=: frames argument must be of equal dimensions!";
537 StkFloat *fptr = &f[0];
538 StkFloat *dptr = data_;
539 for (
unsigned int i=0; i<size_; i++ )
544 typedef unsigned short UINT16;
545 typedef unsigned int UINT32;
546 typedef signed short SINT16;
547 typedef signed int SINT32;
548 typedef float FLOAT32;
549 typedef double FLOAT64;
552 const StkFloat SRATE = 44100.0;
558 const unsigned int RT_BUFFER_SIZE = 512;
569 #if !defined(RAWWAVE_PATH)
570 #define RAWWAVE_PATH "../../rawwaves/"
573 const StkFloat PI = 3.14159265358979;
574 const StkFloat TWO_PI = 2 * PI;
575 const StkFloat ONE_OVER_128 = 0.0078125;
577 #if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) || defined(__WINDOWS_MM__)
578 #define __OS_WINDOWS__
579 #define __STK_REALTIME__
580 #elif defined(__LINUX_OSS__) || defined(__LINUX_ALSA__) || defined(__UNIX_JACK__)
582 #define __STK_REALTIME__
583 #elif defined(__IRIX_AL__)
585 #elif defined(__MACOSX_CORE__) || defined(__UNIX_JACK__)
586 #define __OS_MACOSX__
587 #define __STK_REALTIME__
STK error handling class.
Definition: Stk.h:86
virtual void printMessage(void)
Prints thrown error message to stderr.
Definition: Stk.h:119
virtual const Type & getType(void)
Returns the thrown error message type.
Definition: Stk.h:122
virtual ~StkError(void)
The destructor.
Definition: Stk.h:116
StkError(const std::string &message, Type type=StkError::UNSPECIFIED)
The constructor.
Definition: Stk.h:112
virtual const std::string & getMessage(void)
Returns the thrown error message string.
Definition: Stk.h:125
virtual const char * getMessageCString(void)
Returns the thrown error message as a C string.
Definition: Stk.h:128
An STK class to handle vectorized audio data.
Definition: Stk.h:276
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition: Stk.h:404
void operator*=(StkFrames &f)
Assignment by product operator into self.
Definition: Stk.h:527
void operator+=(StkFrames &f)
Assignment by sum operator into self.
Definition: Stk.h:511
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition: Stk.h:407
size_t size() const
Returns the total number of audio samples represented by the object.
Definition: Stk.h:362
void resize(size_t nFrames, unsigned int nChannels=1)
Resize self to represent the specified number of channels and frames.
~StkFrames()
The destructor.
StkFloat interpolate(StkFloat frame, unsigned int channel=0) const
Return an interpolated value at the fractional frame index and channel.
StkFrames operator+(const StkFrames &frames) const
Sum operator.
Definition: Stk.h:492
void resize(size_t nFrames, unsigned int nChannels, StkFloat value)
Resize self to represent the specified number of channels and frames and perform element initializati...
StkFloat dataRate(void) const
Return the sample rate associated with the StkFrames data.
Definition: Stk.h:421
bool empty() const
Returns true if the object size is zero and false otherwise.
Definition: Stk.h:434
StkFloat & operator()(size_t frame, unsigned int channel)
Channel / frame subscript operator that returns a reference.
Definition: Stk.h:466
StkFloat & operator[](size_t n)
Subscript operator that returns a reference to element n of self.
Definition: Stk.h:440
StkFrames & getChannel(unsigned int channel, StkFrames &destinationFrames, unsigned int destinationChannel) const
Retrieves a single channel.
StkFrames(unsigned int nFrames=0, unsigned int nChannels=0)
The default constructor initializes the frame data structure to size zero.
StkFrames(const StkFloat &value, unsigned int nFrames, unsigned int nChannels)
Overloaded constructor that initializes the frame data to the specified size with value.
void setChannel(unsigned int channel, const StkFrames &sourceFrames, unsigned int sourceChannel)
Sets a single channel.
void setDataRate(StkFloat rate)
Set the sample rate associated with the StkFrames data.
Definition: Stk.h:414
STK base class.
Definition: Stk.h:133
static const StkFormat STK_FLOAT32
Definition: Stk.h:141
static void showWarnings(bool status)
Toggle display of WARNING and STATUS messages.
Definition: Stk.h:210
static void clear_alertList()
Static method that frees memory from alertList_.
Definition: Stk.h:176
void removeSampleRateAlert(Stk *ptr)
Remove class pointer from list for sample rate change notification.
static void setSampleRate(StkFloat rate)
Static method that sets the STK sample rate.
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
static void setRawwavePath(std::string path)
Static method that sets the STK rawwave path.
static const StkFormat STK_FLOAT64
Definition: Stk.h:142
static const StkFormat STK_SINT16
Definition: Stk.h:138
void addSampleRateAlert(Stk *ptr)
Add class pointer to list for sample rate change notification.
static std::string rawwavePath(void)
Static method that returns the current rawwave path.
Definition: Stk.h:179
static void swap64(unsigned char *ptr)
Static method that byte-swaps a 64-bit data type.
static StkFloat sampleRate(void)
Static method that returns the current STK sample rate.
Definition: Stk.h:145
static const StkFormat STK_SINT32
Definition: Stk.h:140
virtual void sampleRateChanged(StkFloat newRate, StkFloat oldRate)
This function should be implemented in subclasses that depend on the sample rate.
static bool inRange(StkFloat value, StkFloat min, StkFloat max)
Static method to check whether a value is within a specified range.
Definition: Stk.h:197
static void swap32(unsigned char *ptr)
Static method that byte-swaps a 32-bit data type.
Stk(void)
Default constructor.
static void swap16(unsigned char *ptr)
Static method that byte-swaps a 16-bit data type.
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
static void handleError(std::string message, StkError::Type type)
Static function for error reporting and handling using c++ strings.
virtual ~Stk(void)
Class destructor.
static void sleep(unsigned long milliseconds)
Static cross-platform method to sleep for a number of milliseconds.
static const StkFormat STK_SINT8
Definition: Stk.h:137
void handleError(StkError::Type type) const
Internal function for error reporting that assumes message in oStream_ variable.
static const StkFormat STK_SINT24
Definition: Stk.h:139
static void printErrors(bool status)
Toggle display of error messages before throwing exceptions.
Definition: Stk.h:213
The STK namespace.
Definition: ADSR.h:6