78typedef double StkFloat;
101 PROCESS_SOCKET_IPADDR,
108 std::string message_;
113 StkError(
const std::string& message, Type type = StkError::UNSPECIFIED)
114 : std::exception(), message_(message), type_(type) {}
120 virtual void printMessage(
void) { std::cerr <<
'\n' << message_ <<
"\n\n"; }
123 virtual const Type&
getType(
void) {
return type_; }
126 virtual const std::string&
getMessage(
void) {
return message_; }
131 virtual const char *what(
void)
const throw() {
return message_.c_str(); }
139 typedef unsigned long StkFormat;
188 static void swap16(
unsigned char *ptr );
191 static void swap32(
unsigned char *ptr );
194 static void swap64(
unsigned char *ptr );
197 static void sleep(
unsigned long milliseconds );
200 static bool inRange( StkFloat value, StkFloat min, StkFloat max ) {
201 if ( value < min )
return false;
202 else if ( value > max )
return false;
207 static void handleError(
const char *message, StkError::Type type );
210 static void handleError( std::string message, StkError::Type type );
219 static StkFloat srate_;
220 static std::string rawwavepath_;
221 static bool showWarnings_;
222 static bool printErrors_;
223 static std::vector<Stk *> alertList_;
227 static std::ostringstream oStream_;
228 bool ignoreSampleRateChange_;
283 StkFrames(
unsigned int nFrames = 0,
unsigned int nChannels = 0 );
286 StkFrames(
const StkFloat& value,
unsigned int nFrames,
unsigned int nChannels );
354 StkFloat&
operator() (
size_t frame,
unsigned int channel );
362 StkFloat
operator() (
size_t frame,
unsigned int channel )
const;
371 StkFloat
interpolate( StkFloat frame,
unsigned int channel = 0 )
const;
374 size_t size()
const {
return size_; };
387 virtual void resize(
size_t nFrames,
unsigned int nChannels = 1 );
397 virtual void resize(
size_t nFrames,
unsigned int nChannels, StkFloat value );
416 unsigned int channels(
void )
const {
return nChannels_; };
419 unsigned int frames(
void )
const {
return (
unsigned int)nFrames_; };
433 StkFloat
dataRate(
void )
const {
return dataRate_; };
440 unsigned int nChannels_;
446inline bool StkFrames :: empty()
const
448 if ( size_ > 0 )
return false;
452inline StkFloat& StkFrames :: operator[] (
size_t n )
454#if defined(_STK_DEBUG_)
456 std::ostringstream error;
457 error <<
"StkFrames::operator[]: invalid index (" << n <<
") value!";
465inline StkFloat StkFrames :: operator[] (
size_t n )
const
467#if defined(_STK_DEBUG_)
469 std::ostringstream error;
470 error <<
"StkFrames::operator[]: invalid index (" << n <<
") value!";
478inline StkFloat& StkFrames :: operator() (
size_t frame,
unsigned int channel )
480#if defined(_STK_DEBUG_)
481 if ( frame >= nFrames_ || channel >= nChannels_ ) {
482 std::ostringstream error;
483 error <<
"StkFrames::operator(): invalid frame (" << frame <<
") or channel (" << channel <<
") value!";
488 return data_[ frame * nChannels_ + channel ];
491inline StkFloat StkFrames :: operator() (
size_t frame,
unsigned int channel )
const
493#if defined(_STK_DEBUG_)
494 if ( frame >= nFrames_ || channel >= nChannels_ ) {
495 std::ostringstream error;
496 error <<
"StkFrames::operator(): invalid frame (" << frame <<
") or channel (" << channel <<
") value!";
501 return data_[ frame * nChannels_ + channel ];
506#if defined(_STK_DEBUG_)
508 std::ostringstream error;
509 error <<
"StkFrames::operator+: frames argument must be of equal dimensions!";
513 StkFrames sum((
unsigned int)nFrames_,nChannels_);
514 StkFloat *sumPtr = &sum[0];
515 const StkFloat *fptr = f.data_;
516 const StkFloat *dPtr = data_;
517 for (
unsigned int i = 0; i < size_; i++) {
518 *sumPtr++ = *fptr++ + *dPtr++;
525#if defined(_STK_DEBUG_)
527 std::ostringstream error;
528 error <<
"StkFrames::operator+=: frames argument must be of equal dimensions!";
533 StkFloat *fptr = &f[0];
534 StkFloat *dptr = data_;
535 for (
unsigned int i=0; i<size_; i++ )
542#if defined(_STK_DEBUG_)
544 std::ostringstream error;
545 error <<
"StkFrames::operator*=: frames argument must be of equal dimensions!";
550 StkFloat *fptr = &f[0];
551 StkFloat *dptr = data_;
552 for (
unsigned int i=0; i<size_; i++ )
559 StkFrames res((
unsigned int)nFrames_, nChannels_);
560 StkFloat *resPtr = &res[0];
561 const StkFloat *dPtr = data_;
562 for (
unsigned int i = 0; i < size_; i++) {
563 *resPtr++ = v * *dPtr++;
570 StkFrames res((
unsigned int)f.nFrames_, f.nChannels_);
571 StkFloat *resPtr = &res[0];
572 StkFloat *dPtr = f.data_;
573 for (
unsigned int i = 0; i < f.size_; i++) {
574 *resPtr++ = v * *dPtr++;
581 StkFloat *dptr = data_;
582 for (
unsigned int i=0; i<size_; i++ )
589typedef unsigned short UINT16;
590typedef unsigned int UINT32;
591typedef signed short SINT16;
592typedef signed int SINT32;
593typedef float FLOAT32;
594typedef double FLOAT64;
597const StkFloat SRATE = 44100.0;
603const unsigned int RT_BUFFER_SIZE = 512;
614#if !defined(RAWWAVE_PATH)
615 #define RAWWAVE_PATH "../../rawwaves/"
618const StkFloat PI = 3.14159265358979;
619const StkFloat TWO_PI = 2 * PI;
620const StkFloat ONE_OVER_128 = 0.0078125;
622#if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) || defined(__WINDOWS_MM__)
623 #define __OS_WINDOWS__
624 #define __STK_REALTIME__
625#elif defined(__LINUX_OSS__) || defined(__LINUX_ALSA__) || defined(__UNIX_JACK__) || defined(__LINUX_PULSE__)
627 #define __STK_REALTIME__
628#elif defined(__IRIX_AL__)
630#elif defined(__MACOSX_CORE__) || defined(__UNIX_JACK__)
631 #define __OS_MACOSX__
632 #define __STK_REALTIME__
STK error handling class.
Definition Stk.h:87
virtual void printMessage(void)
Prints thrown error message to stderr.
Definition Stk.h:120
virtual const std::string & getMessage(void)
Returns the thrown error message string.
Definition Stk.h:126
virtual const char * getMessageCString(void)
Returns the thrown error message as a C string.
Definition Stk.h:129
virtual const Type & getType(void)
Returns the thrown error message type.
Definition Stk.h:123
virtual ~StkError(void)
The destructor.
Definition Stk.h:117
StkError(const std::string &message, Type type=StkError::UNSPECIFIED)
The constructor.
Definition Stk.h:113
An STK class to handle vectorized audio data.
Definition Stk.h:279
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition Stk.h:416
StkFrames & operator+=(StkFrames &f)
Assignment by sum operator into self.
Definition Stk.h:523
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition Stk.h:419
size_t size() const
Returns the total number of audio samples represented by the object.
Definition Stk.h:374
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:504
virtual void resize(size_t nFrames, unsigned int nChannels=1)
Resize self to represent the specified number of channels and frames.
StkFloat dataRate(void) const
Return the sample rate associated with the StkFrames data.
Definition Stk.h:433
StkFrames & getChannel(unsigned int channel, StkFrames &destinationFrames, unsigned int destinationChannel) const
Retrieves a single channel.
bool empty() const
Returns true if the object size is zero and false otherwise.
Definition Stk.h:446
StkFloat & operator()(size_t frame, unsigned int channel)
Channel / frame subscript operator that returns a reference.
Definition Stk.h:478
StkFloat & operator[](size_t n)
Subscript operator that returns a reference to element n of self.
Definition Stk.h:452
virtual ~StkFrames()
The destructor.
StkFrames(unsigned int nFrames=0, unsigned int nChannels=0)
The default constructor initializes the frame data structure to size zero.
StkFrames & operator*=(StkFrames &f)
Assignment by product operator into self.
Definition Stk.h:540
virtual 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...
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:426
friend StkFrames operator*(StkFloat v, const StkFrames &f)
Scaling operator (StkFloat * StkFrame)
Definition Stk.h:568
STK base class.
Definition Stk.h:136
static const StkFormat STK_FLOAT32
Definition Stk.h:144
static void showWarnings(bool status)
Toggle display of WARNING and STATUS messages.
Definition Stk.h:213
static void clear_alertList()
Static method that frees memory from alertList_.
Definition Stk.h:179
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:145
static const StkFormat STK_SINT16
Definition Stk.h:141
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:182
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:148
static const StkFormat STK_SINT32
Definition Stk.h:143
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:200
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:176
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:140
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:142
static void printErrors(bool status)
Toggle display of error messages before throwing exceptions.
Definition Stk.h:216
The STK namespace.
Definition ADSR.h:6