Version 4.2.1

This commit is contained in:
Gary Scavone
2009-03-24 23:02:14 -04:00
committed by Stephen Sinclair
parent a6381b9d38
commit 2cbce2d8bd
275 changed files with 8949 additions and 6906 deletions

View File

@@ -11,7 +11,7 @@
envelope value reaches 0.0 in the
ADSR::RELEASE state.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -60,7 +60,7 @@ class ADSR : public Envelope
//! Set the release rate based on a time duration.
void setReleaseTime(StkFloat time);
//! Set sustain level and attach, decay, and release time durations.
//! Set sustain level and attack, decay, and release time durations.
void setAllTimes(StkFloat aTime, StkFloat dTime, StkFloat sLevel, StkFloat rTime);
//! Set the target value.
@@ -72,22 +72,10 @@ class ADSR : public Envelope
//! Set to state = ADSR::SUSTAIN with current and target values of \e aValue.
void setValue(StkFloat value);
//! Return one envelope output value.
StkFloat tick(void);
//! Compute \e vectorSize outputs and return them in \e vector.
StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
protected:
StkFloat computeSample( void );
StkFloat attackRate_;
StkFloat decayRate_;
StkFloat sustainLevel_;

View File

@@ -19,7 +19,7 @@
to \e keyOn and \e keyOff messages by ramping to
1.0 on keyOn and to 0.0 on keyOff.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -61,22 +61,10 @@ class Asymp : public Envelope
//! Set the target value.
void setTarget(StkFloat target);
//! Return one envelope output value.
StkFloat tick(void);
//! Compute \e vectorSize outputs and return them in \e vector.
StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
protected:
StkFloat computeSample( void );
StkFloat factor_;
StkFloat constant_;
};

View File

@@ -76,26 +76,13 @@ class BandedWG : public Instrmnt
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
//! Compute one output sample.
StkFloat tick();
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
protected:
StkFloat computeSample( void );
bool doPluck_;
bool trackVelocity_;
int nModes_;

View File

@@ -28,7 +28,7 @@
type who should worry about this (making
money) worry away.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -52,20 +52,9 @@ class BeeThree : public FM
//! Start a note with the given frequency and amplitude.
void noteOn(StkFloat frequency, StkFloat amplitude);
//! Compute one output sample.
StkFloat tick();
protected:
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
StkFloat computeSample( void );
};
#endif

View File

@@ -8,7 +8,7 @@
frequency response while maintaining a constant
filter gain.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -93,17 +93,20 @@ public:
//! Input one sample to the filter and return one output.
virtual StkFloat tick(StkFloat sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
virtual StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
The \c channel argument should be zero or greater (the first
channel is specified by 0). An StkError will be thrown if the \c
channel argument is equal to or greater than the number of
channels in the StkFrames object.
*/
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
protected:
// This function must be implemented in all subclasses. It is used
// to get around a C++ problem with overloaded virtual functions.
virtual StkFloat computeSample( StkFloat input );
};
#endif

84
include/Blit.h Normal file
View File

@@ -0,0 +1,84 @@
/***************************************************/
/*! \class Blit
\brief STK band-limited impulse train class.
This class generates a band-limited impulse train using a
closed-form algorithm reported by Stilson and Smith in "Alias-Free
Digital Synthesis of Classic Analog Waveforms", 1996. The user
can specify both the fundamental frequency of the impulse train
and the number of harmonics contained in the resulting signal.
The signal is normalized so that the peak value is +/-1.0.
If nHarmonics is 0, then the signal will contain all harmonics up
to half the sample rate. Note, however, that this setting may
produce aliasing in the signal when the frequency is changing (no
automatic modification of the number of harmonics is performed by
the setFrequency() function).
Original code by Robin Davies, 2005.
Revisions by Gary Scavone for STK, 2005.
*/
/***************************************************/
#ifndef STK_BLIT_H
#define STK_BLIT_H
#include "Generator.h"
class Blit: public Generator
{
public:
//! Default constructor that initializes BLIT frequency to 220 Hz.
Blit( StkFloat frequency = 220.0 );
//! Class destructor.
~Blit();
//! Resets the oscillator state and phase to 0.
void reset();
//! Set the phase of the signal.
/*!
Set the phase of the signal, in the range 0 to 1.
*/
void setPhase( StkFloat phase ) { phase_ = PI * phase; };
//! Get the current phase of the signal.
/*!
Get the phase of the signal, in the range [0 to 1.0).
*/
StkFloat getPhase() const { return phase_ / PI; };
//! Set the impulse train rate in terms of a frequency in Hz.
void setFrequency( StkFloat frequency );
//! Set the number of harmonics generated in the signal.
/*!
This function sets the number of harmonics contained in the
resulting signal. It is equivalent to (2 * M) + 1 in the BLIT
algorithm. The default value of 0 sets the algorithm for maximum
harmonic content (harmonics up to half the sample rate). This
parameter is not checked against the current sample rate and
fundamental frequency. Thus, aliasing can result if one or more
harmonics for a given fundamental frequency exceeds fs / 2. This
behavior was chosen over the potentially more problematic solution
of automatically modifying the M parameter, which can produce
audible clicks in the signal.
*/
void setHarmonics( unsigned int nHarmonics = 0 );
protected:
void updateHarmonics( void );
StkFloat computeSample( void );
unsigned int nHarmonics_;
unsigned int m_;
StkFloat rate_;
StkFloat phase_;
StkFloat p_;
};
#endif

73
include/BlitSaw.h Normal file
View File

@@ -0,0 +1,73 @@
/***************************************************/
/*! \class BlitSaw
\brief STK band-limited sawtooth wave class.
This class generates a band-limited sawtooth waveform using a
closed-form algorithm reported by Stilson and Smith in "Alias-Free
Digital Synthesis of Classic Analog Waveforms", 1996. The user
can specify both the fundamental frequency of the sawtooth and the
number of harmonics contained in the resulting signal.
If nHarmonics is 0, then the signal will contain all harmonics up
to half the sample rate. Note, however, that this setting may
produce aliasing in the signal when the frequency is changing (no
automatic modification of the number of harmonics is performed by
the setFrequency() function).
Based on initial code of Robin Davies, 2005.
Modified algorithm code by Gary Scavone, 2005.
*/
/***************************************************/
#ifndef STK_BLITSAW_H
#define STK_BLITSAW_H
#include "Generator.h"
class BlitSaw: public Generator
{
public:
//! Class constructor.
BlitSaw( StkFloat frequency = 220.0 );
//! Class destructor.
~BlitSaw();
//! Resets the oscillator state and phase to 0.
void reset();
//! Set the sawtooth oscillator rate in terms of a frequency in Hz.
void setFrequency( StkFloat frequency );
//! Set the number of harmonics generated in the signal.
/*!
This function sets the number of harmonics contained in the
resulting signal. It is equivalent to (2 * M) + 1 in the BLIT
algorithm. The default value of 0 sets the algorithm for maximum
harmonic content (harmonics up to half the sample rate). This
parameter is not checked against the current sample rate and
fundamental frequency. Thus, aliasing can result if one or more
harmonics for a given fundamental frequency exceeds fs / 2. This
behavior was chosen over the potentially more problematic solution
of automatically modifying the M parameter, which can produce
audible clicks in the signal.
*/
void setHarmonics( unsigned int nHarmonics = 0 );
protected:
void updateHarmonics( void );
StkFloat computeSample( void );
unsigned int nHarmonics_;
unsigned int m_;
StkFloat rate_;
StkFloat phase_;
StkFloat p_;
StkFloat C2_;
StkFloat a_;
StkFloat state_;
};
#endif

89
include/BlitSquare.h Normal file
View File

@@ -0,0 +1,89 @@
/***************************************************/
/*! \class BlitSquare
\brief STK band-limited square wave class.
This class generates a band-limited square wave signal. It is
derived in part from the approach reported by Stilson and Smith in
"Alias-Free Digital Synthesis of Classic Analog Waveforms", 1996.
The algorithm implemented in this class uses a SincM function with
an even M value to achieve a bipolar bandlimited impulse train.
This signal is then integrated to achieve a square waveform. The
integration process has an associated DC offset but that is
subtracted off the output signal.
The user can specify both the fundamental frequency of the
waveform and the number of harmonics contained in the resulting
signal.
If nHarmonics is 0, then the signal will contain all harmonics up
to half the sample rate. Note, however, that this setting may
produce aliasing in the signal when the frequency is changing (no
automatic modification of the number of harmonics is performed by
the setFrequency() function).
Based on initial code of Robin Davies, 2005.
Modified algorithm code by Gary Scavone, 2005.
*/
/***************************************************/
#ifndef STK_BLITSQUARE_H
#define STK_BLITSQUARE_H
#include "Generator.h"
class BlitSquare: public Generator
{
public:
//! Default constructor that initializes BLIT frequency to 220 Hz.
BlitSquare( StkFloat frequency = 220.0 );
//! Class destructor.
~BlitSquare();
//! Resets the oscillator state and phase to 0.
void reset();
//! Set the phase of the signal.
/*!
Set the phase of the signal, in the range 0 to 1.
*/
void setPhase( StkFloat phase ) { phase_ = PI * phase; };
//! Get the current phase of the signal.
/*!
Get the phase of the signal, in the range [0 to 1.0).
*/
StkFloat getPhase() const { return phase_ / PI; };
//! Set the impulse train rate in terms of a frequency in Hz.
void setFrequency( StkFloat frequency );
//! Set the number of harmonics generated in the signal.
/*!
This function sets the number of harmonics contained in the
resulting signal. It is equivalent to (2 * M) + 1 in the BLIT
algorithm. The default value of 0 sets the algorithm for maximum
harmonic content (harmonics up to half the sample rate). This
parameter is not checked against the current sample rate and
fundamental frequency. Thus, aliasing can result if one or more
harmonics for a given fundamental frequency exceeds fs / 2. This
behavior was chosen over the potentially more problematic solution
of automatically modifying the M parameter, which can produce
audible clicks in the signal.
*/
void setHarmonics( unsigned int nHarmonics = 0 );
protected:
void updateHarmonics( void );
StkFloat computeSample( void );
unsigned int nHarmonics_;
unsigned int m_;
StkFloat rate_;
StkFloat phase_;
StkFloat p_;
StkFloat offset_;
};
#endif

View File

@@ -12,7 +12,7 @@
- Vibrato Gain = 1
- Volume = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -25,7 +25,7 @@
#include "PoleZero.h"
#include "Noise.h"
#include "ADSR.h"
#include "WaveLoop.h"
#include "SineWave.h"
class BlowBotl : public Instrmnt
{
@@ -57,31 +57,19 @@ class BlowBotl : public Instrmnt
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
//! Compute one output sample.
StkFloat tick();
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
protected:
protected:
StkFloat computeSample( void );
JetTable jetTable_;
BiQuad resonator_;
PoleZero dcBlock_;
Noise noise_;
ADSR adsr_;
WaveLoop *vibrato_;
SineWave vibrato_;
StkFloat maxPressure_;
StkFloat noiseGain_;
StkFloat vibratoGain_;

View File

@@ -29,7 +29,7 @@
- Register State = 1
- Breath Pressure = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -43,7 +43,7 @@
#include "PoleZero.h"
#include "Envelope.h"
#include "Noise.h"
#include "WaveLoop.h"
#include "SineWave.h"
class BlowHole : public Instrmnt
{
@@ -81,25 +81,13 @@ class BlowHole : public Instrmnt
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
//! Compute one output sample.
StkFloat tick();
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
protected:
protected:
StkFloat computeSample( void );
DelayL delays_[3];
ReedTable reedTable_;
OneZero filter_;
@@ -107,7 +95,7 @@ class BlowHole : public Instrmnt
PoleZero vent_;
Envelope envelope_;
Noise noise_;
WaveLoop *vibrato_;
SineWave vibrato_;
unsigned long length_;
StkFloat scatter_;
StkFloat thCoeff_;

View File

@@ -5,7 +5,7 @@
This class implements a simple bowed string
non-linear function, as described by Smith (1986).
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -39,26 +39,10 @@ public:
*/
void setSlope(StkFloat slope);
//! Return the function value for \e input.
/*!
The function input represents differential
string-to-bow velocity.
*/
StkFloat tick( StkFloat input);
protected:
//! Take \e vectorSize inputs from \e vector and replace them with corresponding outputs.
StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
StkFloat computeSample( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the function and replace with corresponding outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
protected:
StkFloat offset_;
StkFloat slope_;

View File

@@ -17,7 +17,7 @@
- Vibrato Gain = 1
- Volume = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -29,7 +29,7 @@
#include "BowTable.h"
#include "OnePole.h"
#include "BiQuad.h"
#include "WaveLoop.h"
#include "SineWave.h"
#include "ADSR.h"
class Bowed : public Instrmnt
@@ -62,31 +62,19 @@ class Bowed : public Instrmnt
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
//! Compute one output sample.
StkFloat tick();
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
protected:
protected:
StkFloat computeSample( void );
DelayL neckDelay_;
DelayL bridgeDelay_;
BowTable bowTable_;
OnePole stringFilter_;
BiQuad bodyFilter_;
WaveLoop *vibrato_;
SineWave vibrato_;
ADSR adsr_;
StkFloat maxVelocity_;
StkFloat baseDelay_;

View File

@@ -16,7 +16,7 @@
- Vibrato Gain = 1
- Volume = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -28,7 +28,7 @@
#include "BiQuad.h"
#include "PoleZero.h"
#include "ADSR.h"
#include "WaveLoop.h"
#include "SineWave.h"
class Brass: public Instrmnt
{
@@ -63,30 +63,18 @@ class Brass: public Instrmnt
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
//! Compute one output sample.
StkFloat tick();
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
protected:
protected:
StkFloat computeSample( void );
DelayA delayLine_;
BiQuad lipFilter_;
PoleZero dcBlock_;
ADSR adsr_;
WaveLoop *vibrato_;
SineWave vibrato_;
unsigned long length_;
StkFloat lipTarget_;
StkFloat slideTarget_;

View File

@@ -4,7 +4,7 @@
This class implements a chorus effect.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -13,7 +13,7 @@
#include "Effect.h"
#include "DelayL.h"
#include "WaveLoop.h"
#include "SineWave.h"
class Chorus : public Effect
{
@@ -36,24 +36,12 @@ class Chorus : public Effect
//! Set modulation frequency.
void setModFrequency(StkFloat frequency);
//! Compute one output sample.
StkFloat tick(StkFloat input);
protected:
//! Take \e vectorSize inputs, compute the same number of outputs and return them in \e vector.
StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
StkFloat computeSample( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the effect and replace with corresponding outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
protected:
DelayL delayLine_[2];
WaveLoop *mods_[2];
SineWave mods_[2];
StkFloat baseLength_;
StkFloat modDepth_;

View File

@@ -18,7 +18,7 @@
- Vibrato Gain = 1
- Breath Pressure = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -31,7 +31,7 @@
#include "OneZero.h"
#include "Envelope.h"
#include "Noise.h"
#include "WaveLoop.h"
#include "SineWave.h"
class Clarinet : public Instrmnt
{
@@ -63,31 +63,19 @@ class Clarinet : public Instrmnt
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
//! Compute one output sample.
StkFloat tick();
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
protected:
StkFloat computeSample( void );
DelayL delayLine_;
ReedTable reedTable_;
OneZero filter_;
Envelope envelope_;
Noise noise_;
WaveLoop *vibrato_;
SineWave vibrato_;
long length_;
StkFloat outputGain_;
StkFloat noiseGain_;

View File

@@ -14,7 +14,7 @@
used in fixed delay-length applications, such
as for reverberation.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -83,22 +83,24 @@ public:
*/
virtual StkFloat nextOut(void);
//! Input one sample to the delayline and return one output.
//! Input one sample to the filter and return one output.
virtual StkFloat tick(StkFloat sample);
//! Input \e vectorSize samples to the delayline and return an equal number of outputs in \e vector.
virtual StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Take a channel of the StkFrames object as inputs to the delayline and replace with corresponding outputs.
//! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
The \c channel argument should be zero or greater (the first
channel is specified by 0). An StkError will be thrown if the \c
channel argument is equal to or greater than the number of
channels in the StkFrames object.
*/
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
protected:
// This function must be implemented in all subclasses. It is used
// to get around a C++ problem with overloaded virtual functions.
virtual StkFloat computeSample( StkFloat input );
unsigned long inPoint_;
unsigned long outPoint_;
StkFloat delay_;

View File

@@ -2,23 +2,20 @@
/*! \class DelayA
\brief STK allpass interpolating delay line class.
This Delay subclass implements a fractional-
length digital delay-line using a first-order
allpass filter. A fixed maximum length
of 4095 and a delay of 0.5 is set using the
default constructor. Alternatively, the
delay and maximum length can be set during
instantiation with an overloaded constructor.
This Delay subclass implements a fractional-length digital
delay-line using a first-order allpass filter. A fixed maximum
length of 4095 and a delay of 0.5 is set using the default
constructor. Alternatively, the delay and maximum length can be
set during instantiation with an overloaded constructor.
An allpass filter has unity magnitude gain but
variable phase delay properties, making it useful
in achieving fractional delays without affecting
a signal's frequency magnitude response. In
order to achieve a maximally flat phase delay
response, the minimum delay possible in this
implementation is limited to a value of 0.5.
An allpass filter has unity magnitude gain but variable phase
delay properties, making it useful in achieving fractional delays
without affecting a signal's frequency magnitude response. In
order to achieve a maximally flat phase delay response, the
minimum delay possible in this implementation is limited to a
value of 0.5.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -55,7 +52,7 @@ public:
void setDelay(StkFloat delay);
//! Return the current delay-line length.
StkFloat getDelay(void);
StkFloat getDelay(void) const;
//! Return the value which will be output by the next call to tick().
/*!
@@ -63,22 +60,10 @@ public:
*/
StkFloat nextOut(void);
//! Input one sample to the delayline and return one output.
StkFloat tick(StkFloat sample);
//! Input \e vectorSize samples to the delayline and return an equal number of outputs in \e vector.
virtual StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Take a channel of the StkFrames object as inputs to the delayline and replace with corresponding outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
protected:
StkFloat computeSample( StkFloat input );
StkFloat alpha_;
StkFloat coeff_;
StkFloat apInput_;

View File

@@ -18,7 +18,7 @@
order Lagrange interpolators can typically
improve (minimize) this attenuation characteristic.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -60,22 +60,10 @@ public:
*/
StkFloat nextOut(void);
//! Input one sample to the delay-line and return one output.
StkFloat tick(StkFloat sample);
protected:
//! Input \e vectorSize samples to the delay-line and return an equal number of outputs in \e vector.
virtual StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
StkFloat computeSample( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the delayline and replace with corresponding outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
protected:
StkFloat alpha_;
StkFloat omAlpha_;
StkFloat nextOutput_;

View File

@@ -11,7 +11,7 @@
of simultaneous voices) via a #define in the
Drummer.h.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -19,7 +19,7 @@
#define STK_DRUMMER_H
#include "Instrmnt.h"
#include "WvIn.h"
#include "FileWvIn.h"
#include "OnePole.h"
const int DRUM_NUMWAVES = 11;
@@ -49,25 +49,14 @@ class Drummer : public Instrmnt
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
//! Compute one output sample.
StkFloat tick();
protected:
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
StkFloat computeSample( void );
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
protected:
WvIn *waves_[DRUM_POLYPHONY];
OnePole *filters_[DRUM_POLYPHONY];
int sounding_[DRUM_POLYPHONY];
FileWvIn waves_[DRUM_POLYPHONY];
OnePole filters_[DRUM_POLYPHONY];
std::vector<int> soundOrder_;
std::vector<int> soundNumber_;
int nSounding_;
};

View File

@@ -4,7 +4,7 @@
This class implements an echo effect.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -35,22 +35,10 @@ class Echo : public Effect
//! Set the delay line length in samples.
void setDelay( unsigned long delay );
//! Compute one output sample.
StkFloat tick(StkFloat input);
protected:
//! Take \e vectorSize inputs, compute the same number of outputs and return them in \e vector.
StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
StkFloat computeSample( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the effect and replace with corresponding outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
protected:
Delay delayLine_;
unsigned long length_;

View File

@@ -5,7 +5,7 @@
This class provides common functionality for
STK effects subclasses.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -38,23 +38,25 @@ class Effect : public Stk
//! Return the last right output value.
StkFloat lastOutRight() const;
//! Abstract tick function ... must be implemented in subclasses.
virtual StkFloat tick( StkFloat input ) = 0;
//! Take \e vectorSize inputs, compute the same number of outputs and return them in \e vector.
virtual StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
//! Take one sample input and compute one sample of output.
StkFloat tick( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the effect and replace with corresponding outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
The \c channel argument should be zero or greater (the first
channel is specified by 0). An StkError will be thrown if the \c
channel argument is equal to or greater than the number of
channels in the StkFrames object.
*/
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
protected:
// This abstract function must be implemented in all subclasses.
// It is used to get around a C++ problem with overloaded virtual
// functions.
virtual StkFloat computeSample( StkFloat input ) = 0;
// Returns true if argument value is prime.
bool isPrime( int number );

View File

@@ -9,7 +9,7 @@
\e keyOff messages, ramping to 1.0 on
keyOn and to 0.0 on keyOff.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -25,9 +25,15 @@ class Envelope : public Generator
//! Default constructor.
Envelope(void);
//! Copy constructor.
Envelope( const Envelope& e );
//! Class destructor.
virtual ~Envelope(void);
//! Assignment operator.
Envelope& operator= ( const Envelope& e );
//! Set target = 1.
virtual void keyOn(void);
@@ -49,22 +55,10 @@ class Envelope : public Generator
//! Return the current envelope \e state (0 = at target, 1 otherwise).
virtual int getState(void) const;
//! Return one envelope output value.
virtual StkFloat tick(void);
//! Compute \e vectorSize outputs and return them in \e vector.
virtual StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
protected:
virtual StkFloat computeSample( void );
StkFloat value_;
StkFloat target_;
StkFloat rate_;

View File

@@ -19,7 +19,7 @@
type who should worry about this (making
money) worry away.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -29,6 +29,7 @@
#include "Instrmnt.h"
#include "ADSR.h"
#include "WaveLoop.h"
#include "SineWave.h"
#include "TwoZero.h"
class FM : public Instrmnt
@@ -79,28 +80,16 @@ class FM : public Instrmnt
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
//! Pure virtual function ... must be defined in subclasses.
virtual StkFloat tick() = 0;
//! Computer \e vectorSize outputs and return them in \e vector.
virtual StkFloat *tick(StkFloat *vector, unsigned int vectorSize) = 0;
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 1 ) = 0;
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
virtual void controlChange(int number, StkFloat value);
protected:
protected:
virtual StkFloat computeSample( void ) = 0;
std::vector<ADSR *> adsr_;
std::vector<WaveLoop *> waves_;
WaveLoop *vibrato_;
SineWave vibrato_;
TwoZero twozero_;
unsigned int nOperators_;
StkFloat baseFrequency_;

View File

@@ -26,7 +26,7 @@
type who should worry about this (making
money) worry away.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -53,25 +53,13 @@ class FMVoices : public FM
//! Start a note with the given frequency and amplitude.
void noteOn(StkFloat frequency, StkFloat amplitude);
//! Compute one output sample.
StkFloat tick();
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
virtual void controlChange(int number, StkFloat value);
protected:
StkFloat computeSample( void );
int currentVowel_;
StkFloat tilt_[3];
StkFloat mods_[3];

124
include/FileRead.h Normal file
View File

@@ -0,0 +1,124 @@
/***************************************************/
/*! \class FileRead
\brief STK audio file input class.
This class provides input support for various
audio file formats. Multi-channel (>2)
soundfiles are supported. The file data is
returned via an external StkFrames object
passed to the read() function. This class
does not store its own copy of the file data,
rather the data is read directly from disk.
FileRead currently supports uncompressed WAV,
AIFF/AIFC, SND (AU), MAT-file (Matlab), and
STK RAW file formats. Signed integer (8-,
16-, and 32-bit) and floating-point (32- and
64-bit) data types are supported. Compressed
data types are not supported.
STK RAW files have no header and are assumed
to contain a monophonic stream of 16-bit
signed integers in big-endian byte order at a
sample rate of 22050 Hz. MAT-file data should
be saved in an array with each data channel
filling a matrix row. The sample rate for
MAT-files is assumed to be 44100 Hz.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
#ifndef STK_FILEREAD_H
#define STK_FILEREAD_H
#include "Stk.h"
class FileRead : public Stk
{
public:
//! Default constructor.
FileRead();
//! Overloaded constructor that opens a file during instantiation.
/*!
An StkError will be thrown if the file is not found or its
format is unknown or unsupported.
*/
FileRead( std::string fileName, bool typeRaw = false );
//! Class destructor.
~FileRead();
//! Open the specified file and determine its formatting.
/*!
An StkError will be thrown if the file is not found or its
format is unknown or unsupported. An optional parameter is
provided to specify whether the input file is of type STK RAW
(default = false).
*/
void open( std::string fileName, bool typeRaw = false );
//! If a file is open, close it.
void close( void );
//! Returns \e true if a file is currently open.
bool isOpen( void );
//! Return the file size in sample frames.
unsigned long fileSize( void ) const { return fileSize_; };
//! Return the number of audio channels in the file.
unsigned int channels( void ) const { return channels_; };
//! Return the file sample rate in Hz.
/*!
WAV, SND, and AIF formatted files specify a sample rate in
their headers. By definition, STK RAW files have a sample rate of
22050 Hz. MAT-files are assumed to have a rate of 44100 Hz.
*/
StkFloat fileRate( void ) const { return fileRate_; };
//! Read sample frames from the file into an StkFrames object.
/*!
The number of sample frames to read will be determined from the
number of frames of the StkFrames argument. If this size is
larger than the available data in the file (given the file size
and starting frame index), the extra frames will be unaffected
(the StkFrames object will not be resized). Optional parameters
are provided to specify the starting sample frame within the file
(default = 0) and whether to normalize the data with respect to
fixed-point limits (default = true). An StkError will be thrown
if a file error occurs or if the number of channels in the
StkFrames argument is not equal to that in the file.
*/
void read( StkFrames& buffer, unsigned long startFrame = 0, bool doNormalize = true );
protected:
// Get STK RAW file information.
bool getRawInfo( const char *fileName );
// Get WAV file header information.
bool getWavInfo( const char *fileName );
// Get SND (AU) file header information.
bool getSndInfo( const char *fileName );
// Get AIFF file header information.
bool getAifInfo( const char *fileName );
// Get MAT-file header information.
bool getMatInfo( const char *fileName );
FILE *fd_;
bool byteswap_;
bool wavFile_;
unsigned long fileSize_;
unsigned long dataOffset_;
unsigned int channels_;
StkFormat dataType_;
StkFloat fileRate_;
};
#endif

112
include/FileWrite.h Normal file
View File

@@ -0,0 +1,112 @@
/***************************************************/
/*! \class FileWrite
\brief STK audio file output class.
This class provides output support for various
audio file formats.
FileWrite writes samples to an audio file. It supports
multi-channel data.
FileWrite currently supports uncompressed WAV, AIFF, AIFC, SND
(AU), MAT-file (Matlab), and STK RAW file formats. Signed integer
(8-, 16-, and 32-bit) and floating- point (32- and 64-bit) data
types are supported. STK RAW files use 16-bit integers by
definition. MAT-files will always be written as 64-bit floats.
If a data type specification does not match the specified file
type, the data type will automatically be modified. Compressed
data types are not supported.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
#ifndef STK_FILEWRITE_H
#define STK_FILEWRITE_H
#include "Stk.h"
class FileWrite : public Stk
{
public:
typedef unsigned long FILE_TYPE;
static const FILE_TYPE FILE_RAW; /*!< STK RAW file type. */
static const FILE_TYPE FILE_WAV; /*!< WAV file type. */
static const FILE_TYPE FILE_SND; /*!< SND (AU) file type. */
static const FILE_TYPE FILE_AIF; /*!< AIFF file type. */
static const FILE_TYPE FILE_MAT; /*!< Matlab MAT-file type. */
//! Default constructor.
FileWrite();
//! Overloaded constructor used to specify a file name, type, and data format with this object.
/*!
An StkError is thrown for invalid argument values or if an error occurs when initializing the output file.
*/
FileWrite( std::string fileName, unsigned int nChannels = 1, FILE_TYPE type = FILE_WAV, Stk::StkFormat format = STK_SINT16 );
//! Class destructor.
virtual ~FileWrite();
//! Create a file of the specified type and name and output samples to it in the given data format.
/*!
An StkError is thrown for invalid argument values or if an error occurs when initializing the output file.
*/
void open( std::string fileName, unsigned int nChannels = 1,
FileWrite::FILE_TYPE type = FILE_WAV, Stk::StkFormat format = STK_SINT16 );
//! If a file is open, write out samples in the queue and then close it.
void close( void );
//! Returns \e true if a file is currently open.
bool isOpen( void );
//! Write sample frames from the StkFrames object to the file.
/*!
An StkError will be thrown if the number of channels in the
StkFrames argument does not agree with the number of channels
specified when opening the file.
*/
void write( StkFrames& buffer );
protected:
// Write STK RAW file header.
bool setRawFile( const char *fileName );
// Write WAV file header.
bool setWavFile( const char *fileName );
// Close WAV file, updating the header.
void closeWavFile( void );
// Write SND (AU) file header.
bool setSndFile( const char *fileName );
// Close SND file, updating the header.
void closeSndFile( void );
// Write AIFF file header.
bool setAifFile( const char *fileName );
// Close AIFF file, updating the header.
void closeAifFile( void );
// Write MAT-file header.
bool setMatFile( const char *fileName );
// Close MAT-file, updating the header.
void closeMatFile( void );
FILE *fd_;
FILE_TYPE fileType_;
StkFormat dataType_;
unsigned int channels_;
unsigned long frameCounter_;
bool byteswap_;
};
#endif

143
include/FileWvIn.h Normal file
View File

@@ -0,0 +1,143 @@
/***************************************************/
/*! \class FileWvIn
\brief STK audio file input class.
This class inherits from WvIn. It provides a "tick-level"
interface to the FileRead class. It also provides variable-rate
"playback" functionality. Audio file support is provided by the
FileRead class. Linear interpolation is used for fractional "read
rates".
FileWvIn supports multi-channel data. It is important to distinguish
the tick() methods, which return samples produced by averaging
across sample frames, from the tickFrame() methods, which return
references to multi-channel sample frames.
FileWvIn will either load the entire content of an audio file into
local memory or incrementally read file data from disk in chunks.
This behavior is controlled by the optional constructor arguments
\e chunkThreshold and \e chunkSize. File sizes greater than \e
chunkThreshold (in sample frames) will be read incrementally in
chunks of \e chunkSize each (also in sample frames).
When the file end is reached, subsequent calls to the tick()
functions return zero-valued data and isFinished() returns \e
true.
See the FileRead class for a description of the supported audio
file formats.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
#ifndef STK_FILEWVIN_H
#define STK_FILEWVIN_H
#include "WvIn.h"
#include "FileRead.h"
class FileWvIn : public WvIn
{
public:
//! Default constructor.
FileWvIn( unsigned long chunkThreshold = 1000000, unsigned long chunkSize = 1024 );
//! Overloaded constructor for file input.
/*!
An StkError will be thrown if the file is not found, its format is
unknown, or a read error occurs.
*/
FileWvIn( std::string fileName, bool raw = false, bool doNormalize = true,
unsigned long chunkThreshold = 1000000, unsigned long chunkSize = 1024 );
//! Class destructor.
virtual ~FileWvIn();
//! Open the specified file and load its data.
/*!
Data from a previously opened file will be overwritten by this
function. An StkError will be thrown if the file is not found,
its format is unknown, or a read error occurs. If the file data
is to be loaded incrementally from disk and normalization is
specified, a scaling will be applied with respect to fixed-point
limits. If the data format is floating-point, no scaling is
performed.
*/
void openFile( std::string fileName, bool raw = false, bool doNormalize = true );
//! Close a file if one is open.
void closeFile( void );
//! Clear outputs and reset time (file) pointer to zero.
void reset( void );
//! Normalize data to a maximum of +-1.0.
/*!
This function has no effect when data is incrementally loaded
from disk.
*/
void normalize( void );
//! Normalize data to a maximum of \e +-peak.
/*!
This function has no effect when data is incrementally loaded
from disk.
*/
void normalize( StkFloat peak );
//! Return the file size in sample frames.
unsigned long getSize( void ) const { return data_.frames(); };
//! Return the input file sample rate in Hz (not the data read rate).
/*!
WAV, SND, and AIF formatted files specify a sample rate in
their headers. STK RAW files have a sample rate of 22050 Hz
by definition. MAT-files are assumed to have a rate of 44100 Hz.
*/
StkFloat getFileRate( void ) const { return data_.dataRate(); };
//! Query whether reading is complete.
bool isFinished( void ) const { return finished_; };
//! Set the data read rate in samples. The rate can be negative.
/*!
If the rate value is negative, the data is read in reverse order.
*/
void setRate( StkFloat rate );
//! Increment the read pointer by \e time samples.
/*!
Note that this function will not modify the interpolation flag status.
*/
virtual void addTime( StkFloat time );
//! Turn linear interpolation on/off.
/*!
Interpolation is automatically off when the read rate is
an integer value. If interpolation is turned off for a
fractional rate, the time index is truncated to an integer
value.
*/
void setInterpolate( bool doInterpolate ) { interpolate_ = doInterpolate; };
StkFloat lastOut( void ) const;
protected:
virtual void computeFrame( void );
FileRead file_;
bool finished_;
bool interpolate_;
bool normalizing_;
bool chunking_;
StkFloat time_;
StkFloat rate_;
unsigned long chunkThreshold_;
unsigned long chunkSize_;
long chunkPointer_;
};
#endif

87
include/FileWvOut.h Normal file
View File

@@ -0,0 +1,87 @@
/***************************************************/
/*! \class FileWvOut
\brief STK audio file output class.
This class inherits from WvOut. It provides a "tick-level"
interface to the FileWrite class.
FileWvOut writes samples to an audio file and supports
multi-channel data. It is important to distinguish the tick()
methods, which output single samples to all channels in a sample
frame, from the tickFrame() methods, which take a pointer or
reference to multi-channel sample frame data.
See the FileWrite class for a description of the supported audio
file formats.
Currently, FileWvOut is non-interpolating and the output rate is
always Stk::sampleRate().
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
#ifndef STK_FILEWVOUT_H
#define STK_FILEWVOUT_H
#include "WvOut.h"
#include "FileWrite.h"
class FileWvOut : public WvOut
{
public:
//! Default constructor with optional output buffer size argument.
/*!
The output buffer size defines the number of frames that are
accumulated between writes to disk.
*/
FileWvOut( unsigned int bufferFrames = 1024 );
//! Overloaded constructor used to specify a file name, type, and data format with this object.
/*!
An StkError is thrown for invalid argument values or if an error occurs when initializing the output file.
*/
FileWvOut( std::string fileName,
unsigned int nChannels = 1,
FileWrite::FILE_TYPE type = FileWrite::FILE_WAV,
Stk::StkFormat format = STK_SINT16,
unsigned int bufferFrames = 1024 );
//! Class destructor.
virtual ~FileWvOut();
//! Open a new file with the specified parameters.
/*!
If a file was previously open, it will be closed. An StkError
will be thrown if any of the specified arguments are invalid or a
file error occurs during opening.
*/
void openFile( std::string fileName,
unsigned int nChannels,
FileWrite::FILE_TYPE type,
Stk::StkFormat format );
//! Close a file if one is open.
/*!
Any data remaining in the internal buffer will be written to
the file before closing.
*/
void closeFile( void );
protected:
void computeSample( const StkFloat sample );
void computeFrames( const StkFrames& frames );
void incrementFrame( void );
FileWrite file_;
unsigned int bufferFrames_;
unsigned int bufferIndex_;
unsigned int iData_;
};
#endif

View File

@@ -2,7 +2,7 @@
/*! \class Filter
\brief STK filter class.
This class implements a generic structure which
This class implements a generic structure that
can be used to create a wide range of filters.
It can function independently or be subclassed
to provide more specific controls based on a
@@ -23,7 +23,7 @@
results in one extra multiply per computed sample,
but allows easy control of the overall filter gain.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -32,7 +32,6 @@
#include "Stk.h"
#include <vector>
#include <valarray>
class Filter : public Stk
{
@@ -58,19 +57,20 @@ public:
An StkError can be thrown if either of the coefficient vector
sizes is zero, or if the a[0] coefficient is equal to zero. If
a[0] is not equal to 1, the filter coeffcients are normalized by
a[0]. The internal state of the filter is cleared.
a[0]. The internal state of the filter is not cleared unless the
\e clearState flag is \c true.
*/
void setCoefficients( std::vector<StkFloat> &bCoefficients, std::vector<StkFloat> &aCoefficients );
void setCoefficients( std::vector<StkFloat> &bCoefficients, std::vector<StkFloat> &aCoefficients, bool clearState = false );
//! Set numerator coefficients.
/*!
An StkError can be thrown if coefficient vector is empty. Any
previously set denominator coefficients are left unaffected. Note
that the default constructor sets the single denominator
coefficient a[0] to 1.0. The internal state of the filter is
cleared.
coefficient a[0] to 1.0. The internal state of the filter is not
cleared unless the \e clearState flag is \c true.
*/
void setNumerator( std::vector<StkFloat> &bCoefficients );
void setNumerator( std::vector<StkFloat> &bCoefficients, bool clearState = false );
//! Set denominator coefficients.
/*!
@@ -79,9 +79,10 @@ public:
numerator coefficients are unaffected unless a[0] is not equal to
1, in which case all coeffcients are normalized by a[0]. Note
that the default constructor sets the single numerator coefficient
b[0] to 1.0. The internal state of the filter is cleared.
b[0] to 1.0. The internal state of the filter is not cleared
unless the \e clearState flag is \c true.
*/
void setDenominator( std::vector<StkFloat> &aCoefficients );
void setDenominator( std::vector<StkFloat> &aCoefficients, bool clearState = false );
//! Set the filter gain.
/*!
@@ -97,21 +98,19 @@ public:
virtual StkFloat lastOut(void) const;
//! Input one sample to the filter and return one output.
virtual StkFloat tick(StkFloat sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
virtual StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
virtual StkFloat tick( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
The \c channel argument should be zero or greater (the first
channel is specified by 0). An StkError will be thrown if the \c
channel argument is equal to or greater than the number of
channels in the StkFrames object.
*/
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
protected:
StkFloat gain_;
std::vector<StkFloat> b_;
std::vector<StkFloat> a_;

View File

@@ -18,7 +18,7 @@
- Vibrato Gain = 1
- Breath Pressure = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -32,7 +32,7 @@
#include "PoleZero.h"
#include "Noise.h"
#include "ADSR.h"
#include "WaveLoop.h"
#include "SineWave.h"
class Flute : public Instrmnt
{
@@ -73,25 +73,13 @@ class Flute : public Instrmnt
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
//! Compute one output sample.
StkFloat tick();
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
protected:
protected:
StkFloat computeSample( void );
DelayL jetDelay_;
DelayL boreDelay_;
JetTable jetTable_;
@@ -99,7 +87,7 @@ class Flute : public Instrmnt
PoleZero dcBlock_;
Noise noise_;
ADSR adsr_;
WaveLoop *vibrato_;
SineWave vibrato_;
unsigned long length_;
StkFloat lastFrequency_;
StkFloat maxPressure_;

View File

@@ -8,7 +8,7 @@
It provides methods for controlling the sweep
rate and target frequency.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -56,7 +56,7 @@ class FormSwep : public BiQuad
target values. A sweep rate of 0.0 will produce no
change in resonance parameters.
*/
void setSweepRate(StkFloat rate);
void setSweepRate(StkFloat rate);
//! Set the sweep rate in terms of a time value in seconds.
/*!
@@ -64,24 +64,12 @@ class FormSwep : public BiQuad
given time for the formant parameters to reach
their target values.
*/
void setSweepTime(StkFloat time);
void setSweepTime(StkFloat time);
//! Input one sample to the filter and return one output.
StkFloat tick(StkFloat sample);
protected:
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
StkFloat computeSample( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
protected:
bool dirty_;
StkFloat frequency_;
StkFloat radius_;

View File

@@ -6,7 +6,7 @@
implement tables or other types of input to output function
mappings.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -27,23 +27,25 @@ class Function : public Stk
//! Return the last output value.
virtual StkFloat lastOut() const { return lastOutput_; };
//! Abstract tick function ... must be implemented in subclasses.
virtual StkFloat tick( StkFloat input ) = 0;
//! Take \e vectorSize inputs from \e vector and replace them with corresponding outputs.
virtual StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
//! Take one sample input and compute one sample of output.
StkFloat tick( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the function and replace with corresponding outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
The \c channel argument should be zero or greater (the first
channel is specified by 0). An StkError will be thrown if the \c
channel argument is equal to or greater than the number of
channels in the StkFrames object.
*/
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
protected:
// This abstract function must be implemented in all subclasses.
// It is used to get around a C++ problem with overloaded virtual
// functions.
virtual StkFloat computeSample( StkFloat input ) = 0;
StkFloat lastOutput_;
};

View File

@@ -3,9 +3,9 @@
\brief STK abstract unit generator parent class.
This class provides common functionality for
STK unit generator source subclasses.
STK unit generator sample-source subclasses.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -18,31 +18,33 @@ class Generator : public Stk
{
public:
//! Class constructor.
Generator();
Generator( void );
//! Class destructor.
virtual ~Generator();
virtual ~Generator( void );
//! Return the last output value.
virtual StkFloat lastOut() const { return lastOutput_; };
virtual StkFloat lastOut( void ) const { return lastOutput_; };
//! Abstract tick function ... must be implemented in subclasses.
virtual StkFloat tick( void ) = 0;
//! Compute \e vectorSize outputs and return them in \e vector.
virtual StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
//! Compute one sample and output.
StkFloat tick( void );
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
The \c channel argument should be zero or greater (the first
channel is specified by 0). An StkError will be thrown if the \c
channel argument is equal to or greater than the number of
channels in the StkFrames object.
*/
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
protected:
// This abstract function must be implemented in all subclasses.
// It is used to get around a C++ problem with overloaded virtual
// functions.
virtual StkFloat computeSample( void ) = 0;
StkFloat lastOutput_;
};

145
include/Granulate.h Normal file
View File

@@ -0,0 +1,145 @@
/***************************************************/
/*! \class Granulate
\brief STK granular synthesis class.
This class implements a real-time granular synthesis algorithm
that operates on an input soundfile. Currently, only monophonic
files are supported. Various functions are provided to allow
control over voice and grain parameters.
The functionality of this class is based on the program MacPod by
Chris Rolfe and Damian Keller, though there are likely to be a
number of differences in the actual implementation.
by Gary Scavone, 2005.
*/
/***************************************************/
#ifndef STK_GRANULATE_H
#define STK_GRANULATE_H
#include <vector>
#include "Generator.h"
#include "Envelope.h"
#include "Noise.h"
class Granulate: public Generator
{
public:
//! Default constructor.
Granulate( void );
//! Constructor taking input audio file and number of voices arguments.
Granulate( unsigned int nVoices, std::string fileName, bool typeRaw = false );
//! Class destructor.
~Granulate();
//! Load a monophonic soundfile to be "granulated".
/*!
An StkError will be thrown if the file is not found, its format
is unknown or unsupported, or the file has more than one channel.
*/
void openFile( std::string fileName, bool typeRaw = false );
//! Reset the file pointer and all existing grains to the file start.
/*!
Multiple grains are offset from one another in time by grain
duration / nVoices.
*/
void reset();
//! Set the number of simultaneous grain "voices" to use.
/*!
Multiple grains are offset from one another in time by grain
duration / nVoices. For this reason, it is best to set the grain
parameters before calling this function (during initialization).
*/
void setVoices( unsigned int nVoices = 1 );
//! Set the stretch factor used for grain playback (1 - 1000).
/*!
Granular synthesis allows for time-stetching without affecting
the original pitch of a sound. A stretch factor of 4 will produce
a resulting sound of length 4 times the orignal sound. The
default parameter of 1 produces no stretching.
*/
void setStretch( unsigned int stretchFactor = 1 );
//! Set global grain parameters used to determine individual grain settings.
/*!
Each grain is defined as having a length of \e duration
milliseconds which must be greater than zero. For values of \e
rampPercent (0 - 100) greater than zero, a linear envelope will be
applied to each grain. If \e rampPercent = 100, the resultant
grain "window" is triangular while \e rampPercent = 50 produces a
trapezoidal window. In addition, each grain can have a time delay
of length \e delay and a grain pointer increment of length \e
offset, which can be negative, before the next ramp onset (in
milliseconds). The actual values calculated for each grain will
be randomized by a factor set using the setRandomFactor()
function.
*/
void setGrainParameters( unsigned int duration = 30, unsigned int rampPercent = 50,
int offset = 0, unsigned int delay = 0 );
//! This factor is used when setting individual grain parameters (0.0 - 1.0).
/*!
This random factor is applied when all grain state durations
are calculated. If set to 0.0, no randomness occurs. When
randomness = 1.0, a grain segment of length \e duration will be
randomly augmented by up to +- \e duration seconds (i.e., a 30
millisecond length will be augmented by an extra length of up to
+30 or -30 milliseconds).
*/
void setRandomFactor( StkFloat randomness = 0.1 );
enum GrainState {
GRAIN_STOPPED,
GRAIN_FADEIN,
GRAIN_SUSTAIN,
GRAIN_FADEOUT
};
protected:
struct Grain {
StkFloat eScaler;
StkFloat eRate;
unsigned long attackCount;
unsigned long sustainCount;
unsigned long decayCount;
unsigned long delayCount;
unsigned long counter;
unsigned long pointer;
unsigned long startPointer;
unsigned int repeats;
GrainState state;
// Default constructor.
Grain()
:eScaler(0.0), eRate(0.0), attackCount(0), sustainCount(0), decayCount(0),
delayCount(0), counter(0), pointer(0), startPointer(0), repeats(0), state(GRAIN_STOPPED) {}
};
StkFloat computeSample( void );
void calculateGrain( Granulate::Grain& grain );
StkFrames data_;
std::vector<Grain> grains_;
Noise noise;
long gPointer_;
// Global grain parameters.
unsigned int gDuration_;
unsigned int gRampPercent_;
unsigned int gDelay_;
unsigned int gStretch_;
unsigned int stretchCounter_;
int gOffset_;
StkFloat gRandomFactor_;
StkFloat gain_;
};
#endif

View File

@@ -24,7 +24,7 @@
type who should worry about this (making
money) worry away.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -48,20 +48,9 @@ class HevyMetl : public FM
//! Start a note with the given frequency and amplitude.
void noteOn(StkFloat frequency, StkFloat amplitude);
//! Compute one output sample.
StkFloat tick();
protected:
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
StkFloat computeSample( void );
};
#endif

103
include/InetWvIn.h Normal file
View File

@@ -0,0 +1,103 @@
/***************************************************/
/*! \class InetWvIn
\brief STK internet streaming input class.
This Wvin subclass reads streamed audio data over a network via a
TCP or UDP socket connection. The data is assumed in big-endian,
or network, byte order. Only a single socket connection is
supported.
InetWvIn supports multi-channel data. It is important to
distinguish the tick() methods, which return samples produced by
averaging across sample frames, from the tickFrame() methods,
which return references or pointers to multi-channel sample
frames.
This class implements a socket server. When using the TCP
protocol, the server "listens" for a single remote connection
within the InetWvIn::start() function. For the UDP protocol, no
attempt is made to verify packet delivery or order. The default
data type for the incoming stream is signed 16-bit integers,
though any of the defined StkFormats are permissible.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
#ifndef STK_INETWVIN_H
#define STK_INETWVIN_H
#include "WvIn.h"
#include "TcpServer.h"
#include "UdpSocket.h"
#include "Thread.h"
#include "Mutex.h"
typedef struct {
bool finished;
void *object;
} ThreadInfo;
class InetWvIn : public WvIn
{
public:
//! Default constructor.
/*!
An StkError will be thrown if an error occurs while initializing the input thread.
*/
InetWvIn( unsigned long bufferFrames = 1024, unsigned int nBuffers = 8 );
//! Class destructor.
~InetWvIn();
//! Wait for a (new) socket connection with specified protocol, port, data channels and format.
/*!
For the UDP protocol, this function will create a socket
instance and return. For the TCP protocol, this function will
block until a connection is established. An StkError will be
thrown if a socket error occurs or an invalid function argument is
provided.
*/
void listen( int port = 2006, unsigned int nChannels = 1,
Stk::StkFormat format = STK_SINT16,
Socket::ProtocolType protocol = Socket::PROTO_TCP );
//! Returns true is an input connection exists or input data remains in the queue.
/*!
This method will not return false after an input connection has been closed until
all buffered input data has been read out.
*/
bool isConnected( void );
// Called by the thread routine to receive data via the socket connection
// and fill the socket buffer. This is not intended for general use but
// had to be made public for access from the thread.
void receive( void );
protected:
// Read buffered socket data into the data buffer ... will block if none available.
int readData( void );
void computeFrame( void );
Socket *soket_;
Thread thread_;
Mutex mutex_;
char *buffer_;
unsigned long bufferFrames_;
unsigned long bufferBytes_;
unsigned long bytesFilled_;
unsigned int nBuffers_;
unsigned long writePoint_;
unsigned long readPoint_;
long bufferCounter_;
int dataBytes_;
bool connected_;
int fd_;
ThreadInfo threadInfo_;
Stk::StkFormat dataType_;
};
#endif

77
include/InetWvOut.h Normal file
View File

@@ -0,0 +1,77 @@
/***************************************************/
/*! \class InetWvOut
\brief STK internet streaming output class.
This WvOut subclass can stream data over a network via a TCP or
UDP socket connection. The data is converted to big-endian byte
order, if necessary, before being transmitted.
InetWvOut supports multi-channel data. It is important to
distinguish the tick() methods, which output single samples to all
channels in a sample frame, from the tickFrame() method, which
takes a reference to multi-channel sample frame data.
This class connects to a socket server, the port and IP address of
which must be specified as constructor arguments. The default
data type is signed 16-bit integers but any of the defined
StkFormats are permissible.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
#ifndef STK_INETWVOUT_H
#define STK_INETWVOUT_H
#include "WvOut.h"
#include "Socket.h"
class InetWvOut : public WvOut
{
public:
//! Default constructor ... the socket is not instantiated.
InetWvOut( unsigned long packetFrames = 1024 );
//! Overloaded constructor which opens a network connection during instantiation.
/*!
An StkError is thrown if a socket error occurs or an invalid argument is specified.
*/
InetWvOut( int port, Socket::ProtocolType protocol = Socket::PROTO_TCP,
std::string hostname = "localhost", unsigned int nChannels = 1, Stk::StkFormat format = STK_SINT16,
unsigned long packetFrames = 1024 );
//! Class destructor.
~InetWvOut();
//! Connect to the specified host and port and prepare to stream \e nChannels of data in the given data format.
/*!
An StkError is thrown if a socket error occurs or an invalid argument is specified.
*/
void connect( int port, Socket::ProtocolType protocol = Socket::PROTO_TCP,
std::string hostname = "localhost", unsigned int nChannels = 1, Stk::StkFormat format = STK_SINT16 );
//! If a connection is open, write out remaining samples in the queue and then disconnect.
void disconnect(void);
protected:
void computeSample( const StkFloat sample );
void computeFrames( const StkFrames& frames );
void incrementFrame( void );
// Write a buffer of length frames via the socket connection.
void writeData( unsigned long frames );
char *buffer_;
Socket *soket_;
unsigned long bufferFrames_;
unsigned long bufferBytes_;
unsigned long bufferIndex_;
unsigned long iData_;
unsigned int dataBytes_;
Stk::StkFormat dataType_;
};
#endif

View File

@@ -5,7 +5,7 @@
This class provides a common interface for
all STK instruments.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -41,26 +41,29 @@ class Instrmnt : public Stk
//! Return the last right output value.
StkFloat lastOutRight() const;
//! Compute one output sample.
virtual StkFloat tick() = 0;
//! Computer \e vectorSize outputs and return them in \e vector.
virtual StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Compute one sample and output.
StkFloat tick( void );
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
The \c channel argument should be zero or greater (the first
channel is specified by 0). An StkError will be thrown if the \c
channel argument is equal to or greater than the number of
channels in the StkFrames object.
*/
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
virtual void controlChange(int number, StkFloat value);
protected:
StkFloat lastOutput_;
protected:
// This abstract function must be implemented in all subclasses.
// It is used to get around a C++ problem with overloaded virtual
// functions.
virtual StkFloat computeSample( void ) = 0;
StkFloat lastOutput_;
};

View File

@@ -10,7 +10,7 @@
filters, and two decorrelation delay lines in
parallel at the output.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -35,22 +35,10 @@ class JCRev : public Effect
//! Set the reverberation T60 decay time.
void setT60( StkFloat T60 );
//! Compute one output sample.
StkFloat tick(StkFloat input);
//! Take \e vectorSize inputs, compute the same number of outputs and return them in \e vector.
StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
//! Take a channel of the StkFrames object as inputs to the effect and replace with corresponding outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
protected:
StkFloat computeSample( StkFloat input );
Delay allpassDelays_[3];
Delay combDelays_[4];
Delay outLeftDelay_;

View File

@@ -9,7 +9,7 @@
Consult Fletcher and Rossing, Karjalainen,
Cook, and others for more information.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -27,22 +27,9 @@ public:
//! Class destructor.
~JetTable();
//! Return the function value for \e input.
StkFloat tick(StkFloat input);
protected:
//! Take \e vectorSize inputs from \e vector and replace them with corresponding outputs.
StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
//! Take a channel of the StkFrames object as inputs to the function and replace with corresponding outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
protected:
StkFloat computeSample( StkFloat input );
};

View File

@@ -23,7 +23,7 @@
- String Detuning = 1
- Microphone Position = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -31,7 +31,7 @@
#define STK_MANDOLIN_H
#include "PluckTwo.h"
#include "WvIn.h"
#include "FileWvIn.h"
class Mandolin : public PluckTwo
{
@@ -54,29 +54,17 @@ class Mandolin : public PluckTwo
//! Set the body size (a value of 1.0 produces the "default" size).
void setBodySize(StkFloat size);
//! Compute one output sample.
StkFloat tick();
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
protected:
WvIn *soundfile_[12];
int mic_;
long dampTime_;
bool waveDone_;
protected:
StkFloat computeSample( void );
FileWvIn *soundfile_[12];
int mic_;
long dampTime_;
bool waveDone_;
};
#endif

View File

@@ -66,29 +66,16 @@ class Mesh2D : public Instrmnt
//! Calculate and return the signal energy stored in the mesh.
StkFloat energy();
//! Compute one output sample, without adding energy to the mesh.
StkFloat tick();
//! Input a sample to the mesh and compute one output sample.
StkFloat tick(StkFloat input);
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
StkFloat inputTick( StkFloat input );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
protected:
StkFloat computeSample( void );
StkFloat tick0();
StkFloat tick1();
void clearMesh();

View File

@@ -28,7 +28,7 @@
This class is primarily for use in STK example programs but it is
generic enough to work in many other contexts.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -45,7 +45,7 @@ const int DEFAULT_QUEUE_LIMIT = 200;
#include "Mutex.h"
#include "Thread.h"
#include "Socket.h"
#include "TcpServer.h"
#include "RtMidi.h"
extern "C" THREAD_RETURN THREAD_TYPE stdinHandler(void * ptr);
@@ -69,7 +69,7 @@ class Messager : public Stk
#if defined(__STK_REALTIME__)
Mutex mutex;
RtMidiIn *midi;
Socket *socket;
TcpServer *socket;
std::vector<int> fd;
fd_set mask;
#endif

View File

@@ -7,7 +7,7 @@
(non-sweeping BiQuad filters), where N is set
during instantiation.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -17,6 +17,7 @@
#include "Instrmnt.h"
#include "Envelope.h"
#include "WaveLoop.h"
#include "SineWave.h"
#include "BiQuad.h"
#include "OnePole.h"
@@ -62,30 +63,18 @@ public:
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
//! Compute one output sample.
virtual StkFloat tick();
//! Computer \e vectorSize outputs and return them in \e vector.
virtual StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
virtual void controlChange(int number, StkFloat value) = 0;
protected:
protected:
StkFloat computeSample( void );
Envelope envelope_;
WvIn *wave_;
FileWvIn *wave_;
BiQuad **filters_;
OnePole onepole_;
WaveLoop *vibrato_;
SineWave vibrato_;
unsigned int nModes_;
std::vector<StkFloat> ratios_;

View File

@@ -24,7 +24,7 @@
- Two Fixed = 7
- Clump = 8
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/

View File

@@ -6,7 +6,7 @@
modulations to give a nice, natural human
modulation function.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -14,7 +14,7 @@
#define STK_MODULATE_H
#include "Generator.h"
#include "WaveLoop.h"
#include "SineWave.h"
#include "SubNoise.h"
#include "OnePole.h"
@@ -42,23 +42,11 @@ class Modulate : public Generator
//! Set the random modulation gain.
void setRandomGain(StkFloat gain);
//! Compute one output sample.
StkFloat tick();
//! Compute \e vectorSize outputs and return them in \e vector.
StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
protected:
WaveLoop *vibrato_;
StkFloat computeSample( void );
SineWave vibrato_;
SubNoise noise_;
OnePole filter_;
StkFloat vibratoGain_;

View File

@@ -14,7 +14,7 @@
- Vibrato Gain = 1
- Gain = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -48,25 +48,13 @@ class Moog : public Sampler
//! Set the modulation (vibrato) depth.
void setModulationDepth(StkFloat mDepth);
//! Compute one output sample.
StkFloat tick();
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
protected:
StkFloat computeSample( void );
FormSwep filters_[2];
StkFloat modDepth_;
StkFloat filterQ_;

View File

@@ -7,7 +7,7 @@
systems, the pthread library is used. Under
Windows, critical sections are used.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/

View File

@@ -12,7 +12,7 @@
filters in parallel with corresponding right
and left outputs.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -37,22 +37,10 @@ class NRev : public Effect
//! Set the reverberation T60 decay time.
void setT60( StkFloat T60 );
//! Compute one output sample.
StkFloat tick(StkFloat input);
protected:
//! Take \e vectorSize inputs, compute the same number of outputs and return them in \e vector.
StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
StkFloat computeSample( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the effect and replace with corresponding outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
protected:
Delay allpassDelays_[8];
Delay combDelays_[6];
StkFloat allpassCoefficient_;

View File

@@ -6,7 +6,7 @@
C rand() function. The quality of the rand()
function varies from one OS to another.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -39,23 +39,10 @@ public:
*/
void setSeed( unsigned int seed = 0 );
//! Return a random number between -1.0 and 1.0 using rand().
virtual StkFloat tick();
//! Compute \e vectorSize outputs and return them in \e vector.
virtual StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
protected:
virtual StkFloat computeSample( void );
};
#endif

View File

@@ -8,7 +8,7 @@
the real axis of the z-plane while maintaining
a constant peak filter gain.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -25,7 +25,7 @@ public:
OnePole();
//! Overloaded constructor which sets the pole position during instantiation.
OnePole(StkFloat thePole);
OnePole( StkFloat thePole );
//! Class destructor.
~OnePole();
@@ -65,17 +65,14 @@ public:
//! Input one sample to the filter and return one output.
StkFloat tick(StkFloat sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
The \c channel argument should be zero or greater (the first
channel is specified by 0). An StkError will be thrown if the \c
channel argument is equal to or greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
};

View File

@@ -8,7 +8,7 @@
along the real axis of the z-plane while
maintaining a constant filter gain.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -65,17 +65,14 @@ class OneZero : protected Filter
//! Input one sample to the filter and return one output.
StkFloat tick(StkFloat sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
The \c channel argument should be zero or greater (the first
channel is specified by 0). An StkError will be thrown if the \c
channel argument is equal to or greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
};

View File

@@ -10,7 +10,7 @@
two series allpass units and two parallel comb
filters.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -35,22 +35,10 @@ public:
//! Set the reverberation T60 decay time.
void setT60( StkFloat T60 );
//! Compute one output sample.
StkFloat tick(StkFloat input);
protected:
//! Take \e vectorSize inputs, compute the same number of outputs and return them in \e vector.
StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
StkFloat computeSample( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the effect and replace with corresponding outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
protected:
Delay allpassDelays_[2];
Delay combDelays_[2];
StkFloat allpassCoefficient_;

View File

@@ -22,7 +22,7 @@
type who should worry about this (making
money) worry away.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -49,20 +49,9 @@ class PercFlut : public FM
//! Start a note with the given frequency and amplitude.
void noteOn(StkFloat frequency, StkFloat amplitude);
//! Compute one output sample.
StkFloat tick();
protected:
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
StkFloat computeSample( void );
};
#endif

View File

@@ -6,7 +6,7 @@
set of 32 static phoneme formant parameters
and provide access to those values.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/

View File

@@ -5,7 +5,7 @@
This class implements a simple pitch shifter
using delay lines.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -30,22 +30,10 @@ class PitShift : public Effect
//! Set the pitch shift factor (1.0 produces no shift).
void setShift(StkFloat shift);
//! Compute one output sample.
StkFloat tick(StkFloat input);
protected:
//! Take \e vectorSize inputs, compute the same number of outputs and return them in \e vector.
StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
StkFloat computeSample( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the effect and replace with corresponding outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
protected:
DelayL delayLine_[2];
StkFloat delay_[2];
StkFloat env_[2];

View File

@@ -14,7 +14,7 @@
use possibly subject to patents held by
Stanford University, Yamaha, and others.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -61,36 +61,24 @@ class PluckTwo : public Instrmnt
//! Stop a note with the given amplitude (speed of decay).
virtual void noteOff(StkFloat amplitude);
//! Virtual (abstract) tick function is implemented by subclasses.
virtual StkFloat tick() = 0;
protected:
//! Computer \e vectorSize outputs and return them in \e vector.
virtual StkFloat *tick(StkFloat *vector, unsigned int vectorSize) = 0;
virtual StkFloat computeSample( void ) = 0;
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 1 ) = 0;
DelayA delayLine_;
DelayA delayLine2_;
DelayL combDelay_;
OneZero filter_;
OneZero filter2_;
protected:
DelayA delayLine_;
DelayA delayLine2_;
DelayL combDelay_;
OneZero filter_;
OneZero filter2_;
unsigned long length_;
StkFloat loopGain_;
StkFloat baseLoopGain_;
StkFloat lastFrequency_;
StkFloat lastLength_;
StkFloat detuning_;
StkFloat pluckAmplitude_;
StkFloat pluckPosition_;
unsigned long length_;
StkFloat loopGain_;
StkFloat baseLoopGain_;
StkFloat lastFrequency_;
StkFloat lastLength_;
StkFloat detuning_;
StkFloat pluckAmplitude_;
StkFloat pluckPosition_;
};

View File

@@ -13,7 +13,7 @@
Stanford, bearing the names of Karplus and/or
Strong.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -50,22 +50,10 @@ class Plucked : public Instrmnt
//! Stop a note with the given amplitude (speed of decay).
virtual void noteOff(StkFloat amplitude);
//! Compute one output sample.
virtual StkFloat tick();
//! Computer \e vectorSize outputs and return them in \e vector.
virtual StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
protected:
StkFloat computeSample( void );
DelayA delayLine_;
OneZero loopFilter_;
OnePole pickFilter_;

View File

@@ -8,7 +8,7 @@
filter with a given coefficient. Another
method is provided to create a DC blocking filter.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -61,28 +61,25 @@ class PoleZero : protected Filter
The gain is applied at the filter input and does not affect the
coefficient values. The default gain value is 1.0.
*/
void setGain(StkFloat gain);
void setGain( StkFloat gain );
//! Return the current filter gain.
StkFloat getGain(void) const;
StkFloat getGain( void ) const;
//! Return the last computed output value.
StkFloat lastOut(void) const;
StkFloat lastOut( void ) const;
//! Input one sample to the filter and return one output.
StkFloat tick(StkFloat sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
StkFloat tick( StkFloat sample );
//! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
The \c channel argument should be zero or greater (the first
channel is specified by 0). An StkError will be thrown if the \c
channel argument is equal to or greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
};

View File

@@ -13,7 +13,7 @@
Smith (1986), Hirschman, Cook, Scavone, and
others for more information.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -47,26 +47,10 @@ public:
*/
void setSlope(StkFloat slope);
//! Return the function value for \e input.
/*!
The function input represents the differential
pressure across the reeds.
*/
StkFloat tick(StkFloat input);
protected:
//! Take \e vectorSize inputs from \e vector and replace them with corresponding outputs.
StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
StkFloat computeSample( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the function and replace with corresponding outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
protected:
StkFloat offset_;
StkFloat slope_;

View File

@@ -13,7 +13,7 @@
- Zero Radii = 1
- Envelope Gain = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -58,25 +58,13 @@ class Resonate : public Instrmnt
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
//! Compute one output sample.
StkFloat tick();
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
protected:
protected:
StkFloat computeSample( void );
ADSR adsr_;
BiQuad filter_;
Noise noise_;

View File

@@ -26,7 +26,7 @@
type who should worry about this (making
money) worry away.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -53,20 +53,9 @@ class Rhodey : public FM
//! Start a note with the given frequency and amplitude.
void noteOn(StkFloat frequency, StkFloat amplitude);
//! Compute one output sample.
StkFloat tick();
protected:
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
StkFloat computeSample( void );
};
#endif

View File

@@ -10,7 +10,7 @@
RtAudio WWW site: http://music.mcgill.ca/~gary/rtaudio/
RtAudio: realtime audio i/o C++ classes
Copyright (c) 2001-2004 Gary P. Scavone
Copyright (c) 2001-2005 Gary P. Scavone
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
@@ -37,7 +37,7 @@
*/
/************************************************************************/
// RtAudio: Version 3.0.2, pre-release for STK 4.2.0
// RtAudio: Version 3.0.2 (14 October 2005)
#ifndef __RTAUDIO_H
#define __RTAUDIO_H
@@ -676,6 +676,53 @@ public:
void setStreamCallback( RtAudioCallback callback, void *userData );
void cancelStreamCallback();
public:
// \brief Internal structure that provide debug information on the state of a running DSound device.
struct RtDsStatistics {
// \brief Sample Rate.
long sampleRate;
// \brief The size of one sample * number of channels on the input device.
int inputFrameSize;
// \brief The size of one sample * number of channels on the output device.
int outputFrameSize;
/* \brief The number of times the read pointer had to be adjusted to avoid reading from an unsafe buffer position.
*
* This field is only used when running in DUPLEX mode. INPUT mode devices just wait until the data is
* available.
*/
int numberOfReadOverruns;
// \brief The number of times the write pointer had to be adjusted to avoid writing in an unsafe buffer position.
int numberOfWriteUnderruns;
// \brief Number of bytes by attribute to buffer configuration by which writing must lead the current write pointer.
int writeDeviceBufferLeadBytes;
// \brief Number of bytes by attributable to the device driver by which writing must lead the current write pointer on this output device.
unsigned long writeDeviceSafeLeadBytes;
// \brief Number of bytes by which reading must trail the current read pointer on this input device.
unsigned long readDeviceSafeLeadBytes;
/* \brief Estimated latency in seconds.
*
* For INPUT mode devices, based the latency of the device's safe read pointer, plus one buffer's
* worth of additional latency.
*
* For OUTPUT mode devices, the latency of the device's safe write pointer, plus N buffers of
* additional buffer latency.
*
* For DUPLEX devices, the sum of latencies for both input and output devices. DUPLEX devices
* also back off the read pointers an additional amount in order to maintain synchronization
* between out-of-phase read and write pointers. This time is also included.
*
* Note that most software packages report latency between the safe write pointer
* and the software lead pointer, excluding the hardware device's safe write pointer
* latency. Figures of 1 or 2ms of latency on Windows audio devices are invariably of this type.
* The reality is that hardware devices often have latencies of 30ms or more (often much
* higher for duplex operation).
*/
double latency;
};
// \brief Report on the current state of a running DSound device.
static RtDsStatistics getDsStatistics();
private:
void initialize(void);
@@ -683,6 +730,12 @@ public:
bool probeDeviceOpen( int device, StreamMode mode, int channels,
int sampleRate, RtAudioFormat format,
int *bufferSize, int numberOfBuffers );
bool coInitialized;
bool buffersRolling;
long duplexPrerollBytes;
static RtDsStatistics statistics;
};
#endif
@@ -716,6 +769,9 @@ public:
bool probeDeviceOpen( int device, StreamMode mode, int channels,
int sampleRate, RtAudioFormat format,
int *bufferSize, int numberOfBuffers );
bool coInitialized;
};
#endif

View File

@@ -24,7 +24,7 @@
methods, which take/return pointers to
multi-channel sample frames.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/

View File

@@ -8,7 +8,7 @@
RtMidi WWW site: http://music.mcgill.ca/~gary/rtmidi/
RtMidi: realtime MIDI i/o C++ classes
Copyright (c) 2003-2004 Gary P. Scavone
Copyright (c) 2003-2005 Gary P. Scavone
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
@@ -35,7 +35,7 @@
*/
/**********************************************************************/
// RtMidi: Version 1.0.2, 21 September 2004
// RtMidi: Version 1.0.4, 14 October 2005
#ifndef RTMIDI_H
#define RTMIDI_H
@@ -45,10 +45,26 @@
class RtMidi
{
public:
//! Pure virtual openPort() function.
virtual void openPort( unsigned int portNumber = 0 ) = 0;
//! Pure virtual openVirtualPort() function.
virtual void openVirtualPort() = 0;
//! Pure virtual getPortCount() function.
virtual unsigned int getPortCount() = 0;
//! Pure virtual getPortName() function.
virtual std::string getPortName( unsigned int portNumber = 0 ) = 0;
//! Pure virtual closePort() function.
virtual void closePort( void ) = 0;
protected:
RtMidi();
virtual ~RtMidi() {};
// A basic error reporting function for internal use in the RtMidi
@@ -56,8 +72,6 @@ class RtMidi
// suit specific needs.
void error( RtError::Type type );
virtual void openPort( unsigned int portNumber = 0 ) = 0;
void *apiData_;
bool connected_;
std::string errorString_;

View File

@@ -2,24 +2,19 @@
/*! \class RtWvIn
\brief STK realtime audio (blocking) input class.
This class provides a simplified interface to
RtAudio for realtime audio input. It is a
protected subclass of WvIn. Because this
class makes use of RtAudio's blocking output
routines, its performance is less robust on
systems where the audio API is callback-based
(Macintosh CoreAudio and Windows ASIO).
This class provides a simplified interface to RtAudio for realtime
audio input. It is a subclass of WvIn. Because this class makes
use of RtAudio's blocking output routines, its performance is less
robust on systems where the audio API is callback-based (Macintosh
CoreAudio and Windows ASIO).
RtWvIn supports multi-channel data in
interleaved format. It is important to
distinguish the tick() methods, which return
samples produced by averaging across sample
frames, from the tickFrame() methods, which
return pointers to multi-channel sample frames.
For single-channel data, these methods return
equivalent values.
RtWvIn supports multi-channel data in interleaved format. It is
important to distinguish the tick() methods, which return samples
produced by averaging across sample frames, from the tickFrame()
methods, which return references or pointers to multi-channel
sample frames.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -29,7 +24,7 @@
#include "WvIn.h"
#include "RtAudio.h"
class RtWvIn : protected WvIn
class RtWvIn : public WvIn
{
public:
//! Default constructor.
@@ -44,75 +39,35 @@ public:
is defined in Stk.h. An StkError will be thrown if an error
occurs duing instantiation.
*/
RtWvIn(int nChannels = 1, StkFloat sampleRate = Stk::sampleRate(), int device = 0, int bufferFrames = RT_BUFFER_SIZE, int nBuffers = 2);
RtWvIn( unsigned int nChannels = 1, StkFloat sampleRate = Stk::sampleRate(),
int device = 0, int bufferFrames = RT_BUFFER_SIZE, int nBuffers = 4 );
//! Class destructor.
~RtWvIn();
//! Start the audio input stream.
/*!
The stream is started automatically, if necessary, when a tick() or tickFrame method is called.
The stream is started automatically, if necessary, when a
tick() or tickFrame() method is called.
*/
void start(void);
void start( void );
//! Stop the audio input stream.
/*!
It may be necessary to use this method to avoid audio underflow problems if you wish to temporarily stop audio input.
It may be necessary to use this method to avoid audio underflow
problems if you wish to temporarily stop audio input.
*/
void stop(void);
//! Return the average across the last output sample frame.
StkFloat lastOut(void) const;
//! Read out the average across one sample frame of data.
/*!
An StkError will be thrown if an error occurs during input.
*/
StkFloat tick(void);
//! Read out vectorSize averaged sample frames of data in \e vector.
/*!
An StkError will be thrown if an error occurs during input.
*/
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with averaged sample frames.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if an
error occurs during input or the \c channel argument is zero or it
is greater than the number of channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
//! Return a pointer to the last output sample frame.
const StkFloat *lastFrame(void) const;
//! Return a pointer to the next sample frame of data.
/*!
An StkError will be thrown if an error occurs during input.
*/
const StkFloat *tickFrame(void);
//! Read out sample \e frames of data to \e frameVector.
/*!
An StkError will be thrown if an error occurs during input.
*/
StkFloat *tickFrame(StkFloat *frameVector, unsigned int frames);
//! Fill the StkFrames object with sample frames of data and return the same reference.
/*!
An StkError will be thrown if an error occurs during input or
there is an incompatability between the number of channels in the
RtWvIn object and that in the StkFrames object.
*/
StkFrames& tickFrame( StkFrames& frames );
void stop( void );
protected:
RtAudio *audio_;
void computeFrame( void );
RtAudio *adc_;
StkFloat *buffer_;
bool stopped_;
long counter_;
unsigned int bufferFrames_;
unsigned int bufferIndex_;
};

View File

@@ -2,23 +2,19 @@
/*! \class RtWvOut
\brief STK realtime audio (blocking) output class.
This class provides a simplified interface to
RtAudio for realtime audio output. It is a
protected subclass of WvOut. Because this
class makes use of RtAudio's blocking output
routines, its performance is less robust on
systems where the audio API is callback-based
This class provides a simplified interface to RtAudio for realtime
audio output. It is a subclass of WvOut. Because this class
makes use of RtAudio's blocking output routines, its performance
is less robust on systems where the audio API is callback-based
(Macintosh CoreAudio and Windows ASIO).
RtWvOut supports multi-channel data in
interleaved format. It is important to
distinguish the tick() methods, which output
single samples to all channels in a sample
frame, from the tickFrame() method, which
takes a pointer to multi-channel sample
RtWvOut supports multi-channel data in interleaved format. It is
important to distinguish the tick() methods, which output single
samples to all channels in a sample frame, from the tickFrame()
method, which take a pointer or reference to multi-channel sample
frame data.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -28,7 +24,7 @@
#include "WvOut.h"
#include "RtAudio.h"
class RtWvOut : protected WvOut
class RtWvOut : public WvOut
{
public:
@@ -44,70 +40,41 @@ class RtWvOut : protected WvOut
is defined in Stk.h. An StkError will be thrown if an error
occurs duing instantiation.
*/
RtWvOut(unsigned int nChannels = 1, StkFloat sampleRate = Stk::sampleRate(), int device = 0, int bufferFrames = RT_BUFFER_SIZE, int nBuffers = 4 );
RtWvOut( unsigned int nChannels = 1, StkFloat sampleRate = Stk::sampleRate(),
int device = 0, int bufferFrames = RT_BUFFER_SIZE, int nBuffers = 4 );
//! Class destructor.
~RtWvOut();
//! Start the audio output stream.
/*!
The stream is started automatically, if necessary, when a tick() or tickFrame method is called.
The stream is started automatically, if necessary, when a
tick() or tickFrame method is called.
*/
void start(void);
//! Stop the audio output stream.
/*!
It may be necessary to use this method to avoid undesireable audio buffer cycling if you wish to temporarily stop audio output.
It may be necessary to use this method to avoid undesireable
audio buffer cycling if you wish to temporarily stop audio output.
*/
void stop(void);
//! Return the number of sample frames output.
unsigned long getFrames( void ) const;
//! Return the number of seconds of data output.
StkFloat getTime( void ) const;
//! Output a single sample to all channels in a sample frame.
/*!
An StkError will be thrown if an error occurs during output.
*/
void tick( const StkFloat sample );
//! Output each sample in \e vector to all channels in \e vectorSize sample frames.
/*!
An StkError will be thrown if an error occurs during output.
*/
void tick( const StkFloat *vector, unsigned int vectorSize );
//! Output a channel of the StkFrames object to all channels of the RtWvOut object.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if an
error occurs during output or the \c channel argument is zero or
it is greater than the number of channels in the StkFrames object.
*/
void tick( const StkFrames& frames, unsigned int channel = 1 );
//! Output the \e frameVector of sample frames of the given length.
/*!
An StkError will be thrown if an error occurs during output.
*/
void tickFrame( const StkFloat *frameVector, unsigned int frames = 1 );
//! Output the StkFrames data to the RtWvOut object.
/*!
An StkError will be thrown if an error occurs during output or
if there is an incompatability between the number of channels in
the WvOut object and that in the StkFrames object.
*/
void tickFrame( const StkFrames& frames );
protected:
RtAudio *audio_;
StkFloat *dataPtr_;
void computeSample( const StkFloat sample );
void computeFrames( const StkFrames& frames );
void incrementFrame( void );
RtAudio *dac_;
StkFloat *buffer_;
bool stopped_;
int bufferSize_;
unsigned int nChannels_;
unsigned int bufferIndex_;
unsigned int iBuffer_;
unsigned int bufferFrames_;
};

View File

@@ -5,7 +5,7 @@
This instrument provides an ADSR envelope, a one-pole filter, and
structures for an arbitrary number of attack and loop waves.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -14,7 +14,6 @@
#include "Instrmnt.h"
#include "ADSR.h"
#include "WvIn.h"
#include "WaveLoop.h"
#include "OnePole.h"
@@ -42,27 +41,15 @@ class Sampler : public Instrmnt
//! Stop a note with the given amplitude (speed of decay).
virtual void noteOff(StkFloat amplitude);
//! Compute one output sample.
virtual StkFloat tick() = 0;
//! Computer \e vectorSize outputs and return them in \e vector.
virtual StkFloat *tick(StkFloat *vector, unsigned int vectorSize) = 0;
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 1 ) = 0;
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
virtual void controlChange(int number, StkFloat value) = 0;
protected:
protected:
virtual StkFloat computeSample( void ) = 0;
ADSR adsr_;
std::vector<WvIn *> attacks_;
std::vector<FileWvIn *> attacks_;
std::vector<WaveLoop *> loops_;
OnePole filter_;
StkFloat baseFrequency_;

View File

@@ -31,7 +31,7 @@
- Vibrato Gain = 1
- Breath Pressure = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -44,7 +44,7 @@
#include "OneZero.h"
#include "Envelope.h"
#include "Noise.h"
#include "WaveLoop.h"
#include "SineWave.h"
class Saxofony : public Instrmnt
{
@@ -79,31 +79,19 @@ class Saxofony : public Instrmnt
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
//! Compute one output sample.
StkFloat tick();
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
protected:
StkFloat computeSample( void );
DelayL delays_[2];
ReedTable reedTable_;
OneZero filter_;
Envelope envelope_;
Noise noise_;
WaveLoop *vibrato_;
SineWave vibrato_;
unsigned long length_;
StkFloat outputGain_;
StkFloat noiseGain_;

View File

@@ -79,26 +79,12 @@ class Shakers : public Instrmnt
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
//! Compute one output sample.
StkFloat tick();
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
protected:
StkFloat computeSample( void );
int setupName(char* instr);
int setupNum(int inst);
int setFreqAndReson(int which, StkFloat freq, StkFloat reson);

View File

@@ -13,7 +13,7 @@
- Envelope Rate = 11
- Gain = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -57,25 +57,13 @@ class Simple : public Instrmnt
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
//! Compute one output sample.
StkFloat tick();
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
protected:
protected:
StkFloat computeSample( void );
ADSR adsr_;
WaveLoop *loop_;
OnePole filter_;

80
include/SineWave.h Normal file
View File

@@ -0,0 +1,80 @@
/***************************************************/
/*! \class SineWave
\brief STK sinusoid oscillator class.
This class computes and saves a static sine "table" that can be
shared by multiple instances. It has an interface similar to the
WaveLoop class but inherits from the Generator class. Output
values are computed using linear interpolation.
The "table" length, set in SineWave.h, is 2048 samples by default.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
#ifndef STK_SINEWAVE_H
#define STK_SINEWAVE_H
const unsigned long TABLE_SIZE = 2048;
#include "Generator.h"
class SineWave : public Generator
{
public:
//! Default constructor.
SineWave( void );
//! Class destructor.
virtual ~SineWave( void );
//! Clear output and reset time pointer to zero.
void reset( void );
//! Set the data read rate in samples. The rate can be negative.
/*!
If the rate value is negative, the data is read in reverse order.
*/
void setRate( StkFloat rate ) { rate_ = rate; };
//! Set the data interpolation rate based on a looping frequency.
/*!
This function determines the interpolation rate based on the file
size and the current Stk::sampleRate. The \e frequency value
corresponds to file cycles per second. The frequency can be
negative, in which case the loop is read in reverse order.
*/
void setFrequency( StkFloat frequency );
//! Increment the read pointer by \e time samples, modulo file size.
void addTime( StkFloat time );
//! Increment current read pointer by \e angle, relative to a looping frequency.
/*!
This function increments the read pointer based on the file
size and the current Stk::sampleRate. The \e anAngle value
is a multiple of file size.
*/
void addPhase( StkFloat angle );
//! Add a phase offset to the current read pointer.
/*!
This function determines a time offset based on the file
size and the current Stk::sampleRate. The \e angle value
is a multiple of file size.
*/
void addPhaseOffset( StkFloat angle );
protected:
StkFloat computeSample( void );
static StkFrames table_;
StkFloat time_;
StkFloat rate_;
StkFloat phaseOffset_;
};
#endif

View File

@@ -9,7 +9,7 @@
from pitch shifting. It will be used as an
excitation source for other instruments.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -28,7 +28,7 @@ class SingWave : public Generator
An StkError will be thrown if the file is not found, its format is
unknown, a read error occurs, or the rawwave path is incorrectly set.
*/
SingWave( std::string fileName, bool raw=false);
SingWave( std::string fileName, bool raw = false);
//! Class destructor.
~SingWave();
@@ -69,25 +69,12 @@ class SingWave : public Generator
//! Stop a note.
void noteOff();
//! Compute one output sample.
StkFloat tick();
//! Compute \e vectorSize outputs and return them in \e vector.
StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
protected:
StkFloat computeSample( void );
WaveLoop *wave_;
Modulate *modulator_;
Modulate modulator_;
Envelope envelope_;
Envelope pitchEnvelope_;
StkFloat rate_;

View File

@@ -13,7 +13,7 @@
Stanford, bearing the names of Karplus and/or
Strong.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -50,22 +50,10 @@ class Sitar : public Instrmnt
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
//! Compute one output sample.
StkFloat tick();
protected:
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
StkFloat computeSample( void );
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
protected:
DelayA delayLine_;
OneZero loopFilter_;
Noise noise_;

View File

@@ -21,7 +21,7 @@
\sa \ref skini
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/

View File

@@ -1,20 +1,13 @@
/***************************************************/
/*! \class Socket
\brief STK TCP socket client/server class.
\brief STK internet socket abstract base class.
This class provides a uniform cross-platform
TCP socket client or socket server interface.
Methods are provided for reading or writing
data buffers to/from connections. This class
also provides a number of static functions for
use with external socket descriptors.
This class provides common functionality for TCP and UDP internet
socket server and client subclasses. This class also provides a
number of static functions for use with external socket
descriptors.
The user is responsible for checking the values
returned by the read/write methods. Values
less than or equal to zero indicate a closed
or lost connection or the occurence of an error.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -23,71 +16,62 @@
#include "Stk.h"
#if (defined(__OS_IRIX__) || defined(__OS_LINUX__) || defined(__OS_MACOSX__))
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#elif defined(__OS_WINDOWS__)
#include <winsock.h>
#endif
class Socket : public Stk
{
public:
//! Default constructor which creates a local socket server on port 2006 (or the specified port number).
/*!
An StkError will be thrown if a socket error occurs during instantiation.
*/
Socket( int port = 2006 );
//! Class constructor which creates a socket client connection to the specified host and port.
/*!
An StkError will be thrown if a socket error occurs during instantiation.
*/
Socket( int port, const char *hostname );
enum ProtocolType {
PROTO_TCP,
PROTO_UDP
};
//! The class destructor closes the socket instance, breaking any existing connections.
~Socket();
//! Class constructor
Socket();
//! Connect a socket client to the specified host and port and returns the resulting socket descriptor.
/*!
This method is valid for socket clients only. If it is called for
a socket server, -1 is returned. If the socket client is already
connected, that connection is terminated and a new connection is
attempted. Server connections are made using the accept() method.
An StkError will be thrown if a socket error occurs during
instantiation. \sa accept
*/
int connect( int port, const char *hostname = "localhost" );
//! Class destructor.
virtual ~Socket();
//! Close this socket.
void close( void );
//! Close the socket.
static void close( int socket );
//! Return the server/client socket descriptor.
//! Return the socket descriptor.
int id( void ) const;
//! Return the server/client port number.
//! Return the socket port number.
int port( void ) const;
//! If this is a socket server, extract the first pending connection request from the queue and create a new connection, returning the descriptor for the accepted socket.
/*!
If no connection requests are pending and the socket has not
been set non-blocking, this function will block until a connection
is present. If an error occurs or this is a socket client, -1 is
returned.
*/
int accept( void );
//! If enable = false, the socket is set to non-blocking mode. When first created, sockets are by default in blocking mode.
static void setBlocking( int socket, bool enable );
//! Close the socket with the given descriptor.
static void close( int socket );
//! Returns true if the socket descriptor is valid.
static bool isValid( int socket );
//! If enable = false, the socket is set to non-blocking mode. When first created, sockets are by default in blocking mode.
static void setBlocking( int socket, bool enable );
//! Write a buffer over the socket connection. Returns the number of bytes written or -1 if an error occurs.
int writeBuffer(const void *buffer, long bufferSize, int flags = 0);
virtual int writeBuffer(const void *buffer, long bufferSize, int flags = 0) = 0;
//! Read an input buffer, up to length \e bufferSize. Returns the number of bytes read or -1 if an error occurs.
virtual int readBuffer(void *buffer, long bufferSize, int flags = 0) = 0;
//! Write a buffer via the specified socket. Returns the number of bytes written or -1 if an error occurs.
static int writeBuffer(int socket, const void *buffer, long bufferSize, int flags );
//! Read a buffer from the socket connection, up to length \e bufferSize. Returns the number of bytes read or -1 if an error occurs.
int readBuffer(void *buffer, long bufferSize, int flags = 0);
//! Read a buffer via the specified socket. Returns the number of bytes read or -1 if an error occurs.
static int readBuffer(int socket, void *buffer, long bufferSize, int flags );
@@ -95,7 +79,6 @@ class Socket : public Stk
int soket_;
int port_;
bool server_;
};

View File

@@ -17,7 +17,7 @@
- String Sustain = 11
- String Stretch = 1
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -69,39 +69,27 @@ class StifKarp : public Instrmnt
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
//! Compute one output sample.
StkFloat tick();
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
protected:
DelayA delayLine_;
DelayL combDelay_;
OneZero filter_;
Noise noise_;
BiQuad biquad_[4];
protected:
unsigned long length_;
StkFloat loopGain_;
StkFloat baseLoopGain_;
StkFloat lastFrequency_;
StkFloat lastLength_;
StkFloat stretching_;
StkFloat pluckAmplitude_;
StkFloat pickupPosition_;
StkFloat computeSample( void );
DelayA delayLine_;
DelayL combDelay_;
OneZero filter_;
Noise noise_;
BiQuad biquad_[4];
unsigned long length_;
StkFloat loopGain_;
StkFloat baseLoopGain_;
StkFloat lastFrequency_;
StkFloat lastLength_;
StkFloat stretching_;
StkFloat pluckAmplitude_;
StkFloat pickupPosition_;
};

View File

@@ -8,7 +8,7 @@
this class provides error handling and
byte-swapping functions.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -18,7 +18,6 @@
#include <string>
#include <iostream>
#include <sstream>
#include <valarray>
// Most data in STK is passed and calculated with the
// following user-definable floating-point type. You
@@ -52,6 +51,8 @@ public:
STATUS,
WARNING,
DEBUG_WARNING,
MEMORY_ALLOCATION,
MEMORY_ACCESS,
FUNCTION_ARGUMENT,
FILE_NOT_FOUND,
FILE_UNKNOWN_FORMAT,
@@ -70,7 +71,8 @@ protected:
public:
//! The constructor.
StkError(const std::string& message, Type type = StkError::UNSPECIFIED) : message_(message), type_(type) {}
StkError(const std::string& message, Type type = StkError::UNSPECIFIED)
: message_(message), type_(type) {}
//! The destructor.
virtual ~StkError(void) {};
@@ -139,9 +141,17 @@ public:
//! Static function for error reporting and handling using c++ strings.
static void handleError( std::string message, StkError::Type type );
//! Toggle display of WARNING and STATUS messages.
static void showWarnings( bool status ) { showWarnings_ = status; }
//! Toggle display of error messages before throwing exceptions.
static void printErrors( bool status ) { printErrors_ = status; }
private:
static StkFloat srate_;
static std::string rawwavepath_;
static bool showWarnings_;
static bool printErrors_;
protected:
@@ -164,13 +174,14 @@ protected:
This class can hold single- or multi-channel audio data in either
interleaved or non-interleaved formats. The data type is always
StkFloat.
StkFloat. In an effort to maintain efficiency, no out-of-bounds
checks are performed in this class.
Possible future improvements in this class could include static
functions to inter- or de-interleave the data and to convert to
and return other data types.
Possible future improvements in this class could include functions
to inter- or de-interleave the data and to convert to and return
other data types.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -179,36 +190,82 @@ class StkFrames
public:
//! The default constructor initializes the frame data structure to size zero.
StkFrames( unsigned int nFrames = 0, unsigned int nChannels = 1, bool interleaved = true );
StkFrames( unsigned int nFrames = 0, unsigned int nChannels = 0, bool interleaved = true );
//! Overloaded constructor which initializes the frame data to the specified size with \c value.
//! Overloaded constructor that initializes the frame data to the specified size with \c value.
StkFrames( const StkFloat& value, unsigned int nFrames, unsigned int nChannels, bool interleaved = true );
//! The destructor.
~StkFrames();
//! Subscript operator which returns a reference to element \c n of self.
/*!
The result can be used as an lvalue . This reference is valid
until the resize function is called or the array is destroyed. The
index \c n must be between 0 and size less one. No range checking
is performed.
is performed unless _STK_DEBUG_ is defined.
*/
StkFloat& operator[]( size_t n ) { return data_[n]; };
StkFloat& operator[] ( size_t n );
//! Subscript operator which returns the value at element \c n of self.
//! Subscript operator that returns the value at element \c n of self.
/*!
The index \c n must be between 0 and size less one. No range
checking is performed.
checking is performed unless _STK_DEBUG_ is defined.
*/
StkFloat operator[]( size_t n ) const { return data_[n]; };
StkFloat operator[] ( size_t n ) const;
//! Channel / frame subscript operator that returns a reference.
/*!
The result can be used as an lvalue. This reference is valid
until the resize function is called or the array is destroyed. The
\c frame index must be between 0 and frames() - 1. The \c channel
index must be between 0 and channels() - 1. No range checking is
performed unless _STK_DEBUG_ is defined.
*/
StkFloat& operator() ( size_t frame, unsigned int channel );
//! Channel / frame subscript operator that returns a value.
/*!
The \c frame index must be between 0 and frames() - 1. The \c
channel index must be between 0 and channels() - 1. No range checking
is performed unless _STK_DEBUG_ is defined.
*/
StkFloat operator() ( size_t frame, unsigned int channel ) const;
//! Return an interpolated value at the fractional frame index and channel.
/*!
This function performs linear interpolation. The \c frame
index must be between 0.0 and frames() - 1. The \c channel index
must be between 0 and channels() - 1. No range checking is
performed unless _STK_DEBUG_ is defined.
*/
StkFloat interpolate( StkFloat frame, unsigned int channel = 0 ) const;
//! Returns the total number of audio samples represented by the object.
size_t size() const { return size_; };
//! Returns \e true if the object size is zero and \e false otherwise.
bool empty() const;
//! Resize self to represent the specified number of channels and frames.
/*!
Changes the size of self based on the number of frames and
channels, and assigns \c value to every element.
channels. No element assignment is performed. No memory
deallocation occurs if the new size is smaller than the previous
size. Further, no new memory is allocated when the new size is
smaller or equal to a previously allocated size.
*/
void resize( unsigned int nFrames, unsigned int nChannels = 1, StkFloat value = 0.0 );
void resize( size_t nFrames, unsigned int nChannels = 1 );
//! Resize self to represent the specified number of channels and frames and perform element initialization.
/*!
Changes the size of self based on the number of frames and
channels, and assigns \c value to every element. No memory
deallocation occurs if the new size is smaller than the previous
size. Further, no new memory is allocated when the new size is
smaller or equal to a previously allocated size.
*/
void resize( size_t nFrames, unsigned int nChannels, StkFloat value );
//! Return the number of channels represented by the data.
unsigned int channels( void ) const { return nChannels_; };
@@ -216,23 +273,47 @@ public:
//! Return the number of sample frames represented by the data.
unsigned int frames( void ) const { return nFrames_; };
//! Set the sample rate associated with the StkFrames data.
/*!
By default, this value is set equal to the current STK sample
rate at the time of instantiation.
*/
void setDataRate( StkFloat rate ) { dataRate_ = rate; };
//! Return the sample rate associated with the StkFrames data.
/*!
By default, this value is set equal to the current STK sample
rate at the time of instantiation.
*/
StkFloat dataRate( void ) const { return dataRate_; };
//! Returns \c true if the data is in interleaved format, \c false if the data is non-interleaved.
bool interleaved( void ) const { return interleaved_; };
//! Set the flag to indicate whether the internal data is in interleaved (\c true) or non-interleaved (\c false) format.
/*!
Note that this function does not modify the internal data order
with respect to the argument value. It simply changes the
indicator flag value.
*/
void setInterleaved( bool isInterleaved ) { interleaved_ = isInterleaved; };
private:
std::valarray<StkFloat> data_;
unsigned int nFrames_;
StkFloat *data_;
StkFloat dataRate_;
size_t nFrames_;
unsigned int nChannels_;
size_t size_;
size_t bufferSize_;
bool interleaved_;
};
// Here are a few other useful typedefs.
typedef unsigned short UINT16;
typedef unsigned int UINT32;
typedef signed short SINT16;
typedef signed int SINT32;
typedef float FLOAT32;
@@ -260,11 +341,11 @@ const unsigned int RT_BUFFER_SIZE = 512;
#define RAWWAVE_PATH "../../rawwaves/"
#endif
const StkFloat PI = 3.14159265359;
const StkFloat PI = 3.14159265358979;
const StkFloat TWO_PI = 2 * PI;
const StkFloat ONE_OVER_128 = 0.0078125;
#if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__)
#if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) || defined(__WINDOWS_MM__)
#define __OS_WINDOWS__
#define __STK_REALTIME__
#elif defined(__LINUX_OSS__) || defined(__LINUX_ALSA__) || defined(__LINUX_JACK__)

View File

@@ -6,7 +6,7 @@
using the C rand() function. The quality of the
rand() function varies from one OS to another.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -20,33 +20,21 @@ class SubNoise : public Noise
public:
//! Default constructor sets sub-sample rate to 16.
SubNoise(int subRate = 16);
SubNoise( int subRate = 16 );
//! Class destructor.
~SubNoise();
//! Return the current sub-sampling rate.
int subRate(void) const;
int subRate( void ) const { return rate_; };
//! Set the sub-sampling rate.
void setRate(int subRate);
//! Return a sub-sampled random number between -1.0 and 1.0.
StkFloat tick();
//! Compute \e vectorSize outputs and return them in \e vector.
StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
void setRate( int subRate );
protected:
StkFloat computeSample( void );
int counter_;
int rate_;

View File

@@ -1,63 +0,0 @@
/***************************************************/
/*! \class Table
\brief STK table lookup class.
This class loads a table of floating-point
doubles, which are assumed to be in big-endian
format. Linear interpolation is performed for
fractional lookup indexes.
An StkError will be thrown if the table file
is not found.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
#ifndef STK_TABLE_H
#define STK_TABLE_H
#include "Function.h"
class Table : public Function
{
public:
//! The constructor loads the data from \e fileName.
/*!
An StkError will be thrown in the file cannot be found or
opened.
*/
Table( std::string fileName );
//! Class destructor.
~Table();
//! Return the number of elements in the table.
long getLength() const;
//! Return the table value at position \e index.
/*!
Linear interpolation is performed if \e index is
fractional.
*/
StkFloat tick(StkFloat index);
//! Take \e vectorSize inputs from \e vector and replace them with corresponding outputs.
StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
//! Take a channel of the StkFrames object as inputs to the function and replace with corresponding outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
protected:
long length_;
std::valarray<StkFloat> data_;
};
#endif // defined(__TABLE_H)

61
include/TcpClient.h Normal file
View File

@@ -0,0 +1,61 @@
/***************************************************/
/*! \class TcpClient
\brief STK TCP socket client class.
This class provides a uniform cross-platform TCP socket client
interface. Methods are provided for reading or writing data
buffers to/from connections.
TCP sockets are reliable and connection-oriented. A TCP socket
client must be connected to a TCP server before data can be sent
or received. Data delivery is guaranteed in order, without loss,
error, or duplication. That said, TCP transmissions tend to be
slower than those using the UDP protocol and data sent with
multiple \e write() calls can be arbitrarily combined by the
underlying system.
The user is responsible for checking the values
returned by the read/write methods. Values
less than or equal to zero indicate a closed
or lost connection or the occurence of an error.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
#ifndef STK_TCPCLIENT_H
#define STK_TCPCLIENT_H
#include "Socket.h"
class TcpClient : public Socket
{
public:
//! Default class constructor creates a socket client connection to the specified host and port.
/*!
An StkError will be thrown if a socket error occurs during instantiation.
*/
TcpClient( int port, std::string hostname = "localhost" );
//! The class destructor closes the socket instance, breaking any existing connections.
~TcpClient();
//! Connect the socket client to the specified host and port and returns the resulting socket descriptor.
/*!
If the socket client is already connected, that connection is
terminated and a new connection is attempted. An StkError will be
thrown if a socket error occurs.
*/
int connect( int port, std::string hostname = "localhost" );
//! Write a buffer over the socket connection. Returns the number of bytes written or -1 if an error occurs.
int writeBuffer(const void *buffer, long bufferSize, int flags = 0);
//! Read a buffer from the socket connection, up to length \e bufferSize. Returns the number of bytes read or -1 if an error occurs.
int readBuffer(void *buffer, long bufferSize, int flags = 0);
protected:
};
#endif // defined(STK_TCPCLIENT_H)

61
include/TcpServer.h Normal file
View File

@@ -0,0 +1,61 @@
/***************************************************/
/*! \class TcpServer
\brief STK TCP socket server class.
This class provides a uniform cross-platform TCP socket server
interface. Methods are provided for reading or writing data
buffers to/from connections.
TCP sockets are reliable and connection-oriented. A TCP socket
server must accept a connection from a TCP client before data can
be sent or received. Data delivery is guaranteed in order,
without loss, error, or duplication. That said, TCP transmissions
tend to be slower than those using the UDP protocol and data sent
with multiple \e write() calls can be arbitrarily combined by the
underlying system.
The user is responsible for checking the values
returned by the read/write methods. Values
less than or equal to zero indicate a closed
or lost connection or the occurence of an error.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
#ifndef STK_TCPSERVER_H
#define STK_TCPSERVER_H
#include "Socket.h"
class TcpServer : public Socket
{
public:
//! Default constructor creates a local socket server on port 2006 (or the specified port number).
/*!
An StkError will be thrown if a socket error occurs during instantiation.
*/
TcpServer( int port = 2006 );
//! The class destructor closes the socket instance, breaking any existing connections.
~TcpServer();
//! Extract the first pending connection request from the queue and create a new connection, returning the descriptor for the accepted socket.
/*!
If no connection requests are pending and the socket has not
been set non-blocking, this function will block until a connection
is present. If an error occurs, -1 is returned.
*/
int accept( void );
//! Write a buffer over the socket connection. Returns the number of bytes written or -1 if an error occurs.
int writeBuffer(const void *buffer, long bufferSize, int flags = 0);
//! Read a buffer from the socket connection, up to length \e bufferSize. Returns the number of bytes read or -1 if an error occurs.
int readBuffer(void *buffer, long bufferSize, int flags = 0);
protected:
};
#endif // defined(STK_TCPSERVER_H)

View File

@@ -1,131 +0,0 @@
/***************************************************/
/*! \class TcpWvIn
\brief STK internet streaming input class.
This protected Wvin subclass can read streamed
data over a network via a TCP socket connection.
The data is assumed in big-endian, or network,
byte order.
TcpWvIn supports multi-channel data in
interleaved format. It is important to
distinguish the tick() methods, which return
samples produced by averaging across sample
frames, from the tickFrame() methods, which
return pointers to multi-channel sample frames.
For single-channel data, these methods return
equivalent values.
This class starts a socket server, which waits
for a single remote connection. The default
data type for the incoming stream is signed
16-bit integers, though any of the defined
StkFormats are permissible.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
#ifndef STK_TCPWVIN_H
#define STK_TCPWVIN_H
#include "WvIn.h"
#include "Socket.h"
#include "Thread.h"
#include "Mutex.h"
typedef struct {
bool finished;
void *object;
} thread_info;
class TcpWvIn : protected WvIn
{
public:
//! Default constructor starts a socket server. If not specified, the server is associated with port 2006.
/*!
An StkError will be thrown if an error occurs while initializing the input thread or starting the socket server.
*/
TcpWvIn( int port = 2006 );
//! Class destructor.
~TcpWvIn();
//! Listen for a (new) connection with specified data channels and format.
/*!
An StkError will be thrown a socket error or an invalid function argument.
*/
void listen(unsigned int nChannels = 1, Stk::StkFormat format = STK_SINT16);
//! Returns true is an input connection exists or input data remains in the queue.
/*!
This method will not return false after an input connection has been closed until
all buffered input data has been read out.
*/
bool isConnected(void);
//! Return the average across the last output sample frame.
StkFloat lastOut(void) const;
//! Read out the average across one sample frame of data.
StkFloat tick(void);
//! Read out vectorSize averaged sample frames of data in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with averaged sample frames.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
//! Return a pointer to the last output sample frame.
const StkFloat *lastFrame(void) const;
//! Return a pointer to the next sample frame of data.
const StkFloat *tickFrame(void);
//! Read out sample \e frames of data to \e frameVector.
StkFloat *tickFrame(StkFloat *frameVector, unsigned int frames);
//! Fill the StkFrames object with sample frames of data and return the same reference.
/*!
An StkError will be thrown if there is an incompatability
between the number of channels in the TcpWvIn object and that in
the StkFrames object.
*/
StkFrames& tickFrame( StkFrames& frames );
// Called by the thread routine to receive data via the socket connection
// and fill the socket buffer. This is not intended for general use but
// had to be made public for access from the thread.
void receive(void);
protected:
// Initialize class variables.
void init( int port );
// Read buffered socket data into the data buffer ... will block if none available.
int readData( void );
Socket *soket_;
Thread *thread_;
Mutex mutex_;
char *buffer_;
long bufferBytes_;
long bytesFilled_;
long writePoint_;
long readPoint_;
long counter_;
int dataSize_;
bool connected_;
int fd_;
thread_info threadInfo_;
};
#endif

View File

@@ -1,109 +0,0 @@
/***************************************************/
/*! \class TcpWvOut
\brief STK internet streaming output class.
This protected WvOut subclass can stream
data over a network via a TCP socket connection.
The data is converted to big-endian byte order,
if necessary, before being transmitted.
TcpWvOut supports multi-channel data in
interleaved format. It is important to
distinguish the tick() methods, which output
single samples to all channels in a sample
frame, from the tickFrame() method, which
takes a pointer to multi-channel sample
frame data.
This class connects to a socket server, the
port and IP address of which must be specified
as constructor arguments. The default data
type is signed 16-bit integers but any of the
defined StkFormats are permissible.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
#ifndef STK_TCPWVOUT_H
#define STK_TCPWVOUT_H
#include "WvOut.h"
#include "Socket.h"
class TcpWvOut : protected WvOut
{
public:
//! Default constructor ... the socket is not instantiated.
TcpWvOut();
//! Overloaded constructor which opens a network connection during instantiation.
/*!
An StkError is thrown if a socket error occurs or an invalid argument is specified.
*/
TcpWvOut(int port, const char *hostname = "localhost", unsigned int nChannels = 1, Stk::StkFormat format = STK_SINT16);
//! Class destructor.
~TcpWvOut();
//! Connect to the specified host and port and prepare to stream \e nChannels of data in the given data format.
/*!
An StkError is thrown if a socket error occurs or an invalid argument is specified.
*/
void connect(int port, const char *hostname = "localhost", unsigned int nChannels = 1, Stk::StkFormat format = STK_SINT16);
//! If a connection is open, write out remaining samples in the queue and then disconnect.
void disconnect(void);
//! Return the number of sample frames output.
unsigned long getFrames( void ) const;
//! Return the number of seconds of data output.
StkFloat getTime( void ) const;
//! Output a single sample to all channels in a sample frame.
/*!
An StkError is thrown if a socket write error occurs.
*/
void tick( const StkFloat sample );
//! Output each sample in \e vector to all channels in \e vectorSize sample frames.
/*!
An StkError is thrown if a socket write error occurs.
*/
void tick( const StkFloat *vector, unsigned int vectorSize );
//! Output a channel of the StkFrames object to all channels of the TcpWvOut object.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if a
socket write error occurs or the \c channel argument is zero or it
is greater than the number of channels in the StkFrames object.
*/
void tick( const StkFrames& frames, unsigned int channel = 1 );
//! Output the \e frameVector of sample frames of the given length.
/*!
An StkError is thrown if a socket write error occurs.
*/
void tickFrame( const StkFloat *frameVector, unsigned int frames = 1 );
//! Output the StkFrames data to the TcpWvOut object.
/*!
An StkError will be thrown if a socket write error occurs or if
there is an incompatability between the number of channels in the
TcpWvOut object and that in the StkFrames object.
*/
virtual void tickFrame( const StkFrames& frames );
protected:
// Write a buffer of length \e frames via the socket connection.
void writeData( unsigned long frames );
char *buffer_;
Socket *soket_;
int dataSize_;
};
#endif

View File

@@ -16,7 +16,7 @@
THREAD_RETURN THREAD_TYPE thread_function(void *ptr)
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/

View File

@@ -26,7 +26,7 @@
type who should worry about this (making
money) worry away.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -50,20 +50,9 @@ class TubeBell : public FM
//! Start a note with the given frequency and amplitude.
void noteOn(StkFloat frequency, StkFloat amplitude);
//! Compute one output sample.
StkFloat tick();
protected:
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
StkFloat computeSample( void );
};
#endif

View File

@@ -8,7 +8,7 @@
frequency response while maintaining a nearly
constant filter gain.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -71,17 +71,14 @@ class TwoPole : protected Filter
//! Input one sample to the filter and return one output.
StkFloat tick(StkFloat sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
The \c channel argument should be zero or greater (the first
channel is specified by 0). An StkError will be thrown if the \c
channel argument is equal to or greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
};
#endif

View File

@@ -8,7 +8,7 @@
frequency response while maintaining a
constant filter gain.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -67,17 +67,14 @@ class TwoZero : protected Filter
//! Input one sample to the filter and return one output.
StkFloat tick(StkFloat sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
The \c channel argument should be zero or greater (the first
channel is specified by 0). An StkError will be thrown if the \c
channel argument is equal to or greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
};
#endif

72
include/UdpSocket.h Normal file
View File

@@ -0,0 +1,72 @@
/***************************************************/
/*! \class UdpSocket
\brief STK UDP socket server/client class.
This class provides a uniform cross-platform UDP socket
server/client interface. Methods are provided for reading or
writing data buffers. The constructor creates a UDP socket and
binds it to the specified port. Note that only one socket can be
bound to a given port on the same machine.
UDP sockets provide unreliable, connection-less service. Messages
can be lost, duplicated, or received out of order. That said,
data transmission tends to be faster than with TCP connections and
datagrams are not potentially combined by the underlying system.
The user is responsible for checking the values returned by the
read/write methods. Values less than or equal to zero indicate
the occurence of an error.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
#ifndef STK_UDPSOCKET_H
#define STK_UDPSOCKET_H
#include "Socket.h"
class UdpSocket : public Socket
{
public:
//! Default constructor creates a local UDP socket on port 2006 (or the specified port number).
/*!
An StkError will be thrown if a socket error occurs during instantiation.
*/
UdpSocket( int port = 2006 );
//! The class destructor closes the socket instance.
~UdpSocket();
//! Set the address for subsequent outgoing data sent via the \e writeBuffer() function.
/*!
An StkError will be thrown if the host is unknown.
*/
void setDestination( int port = 2006, std::string hostname = "localhost" );
//! Send a buffer to the address specified with the \e setDestination() function. Returns the number of bytes written or -1 if an error occurs.
/*!
This function will fail if the default address (set with \e setDestination()) is invalid or has not been specified.
*/
int writeBuffer(const void *buffer, long bufferSize, int flags = 0);
//! Read an input buffer, up to length \e bufferSize. Returns the number of bytes read or -1 if an error occurs.
int readBuffer(void *buffer, long bufferSize, int flags = 0);
//! Write a buffer to the specified socket. Returns the number of bytes written or -1 if an error occurs.
int writeBufferTo(const void *buffer, long bufferSize, int port, std::string hostname = "localhost", int flags = 0 );
protected:
//! A protected function for use in writing a socket address structure.
/*!
An StkError will be thrown if the host is unknown.
*/
void setAddress( struct sockaddr_in *address, int port = 2006, std::string hostname = "localhost" );
struct sockaddr_in address_;
bool validAddress_;
};
#endif // defined(STK_UDPSOCKET_H)

View File

@@ -21,7 +21,7 @@
- Vibrato Gain = 1
- Loudness (Spectral Tilt) = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -81,25 +81,13 @@ class VoicForm : public Instrmnt
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
//! Compute one output sample.
StkFloat tick();
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
protected:
StkFloat computeSample( void );
SingWave *voiced_;
Noise noise_;
Envelope noiseEnv_;

View File

@@ -25,7 +25,7 @@
an ensemble. Alternately, control changes can
be sent to all voices on a given channel.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/

View File

@@ -2,87 +2,89 @@
/*! \class WaveLoop
\brief STK waveform oscillator class.
This class inherits from WvIn and provides
audio file looping functionality.
This class inherits from FileWvIn and provides audio file looping
functionality. Any audio file that can be loaded by FileRead can
be looped using this class.
WaveLoop supports multi-channel data in
interleaved format. It is important to
distinguish the tick() methods, which return
samples produced by averaging across sample
frames, from the tickFrame() methods, which
return pointers to multi-channel sample frames.
For single-channel data, these methods return
equivalent values.
WaveLoop supports multi-channel data. It is important to
distinguish the tick() methods, which return samples produced by
averaging across sample frames, from the tickFrame() methods,
which return references or pointers to multi-channel sample
frames.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
#ifndef STK_WAVELOOP_H
#define STK_WAVELOOP_H
#include "WvIn.h"
#include "FileWvIn.h"
class WaveLoop : public WvIn
class WaveLoop : public FileWvIn
{
public:
//! Class constructor.
WaveLoop( std::string fileName, bool raw = false );
//! Default constructor.
WaveLoop( unsigned long chunkThreshold = 1000000, unsigned long chunkSize = 1024 );
//! Class constructor that opens a specified file.
WaveLoop( std::string fileName, bool raw = false, bool doNormalize = true,
unsigned long chunkThreshold = 1000000, unsigned long chunkSize = 1024 );
//! Class destructor.
virtual ~WaveLoop();
//! Open the specified file and load its data.
/*!
Data from a previously opened file will be overwritten by this
function. An StkError will be thrown if the file is not found,
its format is unknown, or a read error occurs. If the file data
is to be loaded incrementally from disk and normalization is
specified, a scaling will be applied with respect to fixed-point
limits. If the data format is floating-point, no scaling is
performed.
*/
void openFile( std::string fileName, bool raw = false, bool doNormalize = true );
//! Set the data read rate in samples. The rate can be negative.
/*!
If the rate value is negative, the data is read in reverse order.
*/
void setRate( StkFloat rate );
//! Set the data interpolation rate based on a looping frequency.
/*!
This function determines the interpolation rate based on the file
size and the current Stk::sampleRate. The \e aFrequency value
size and the current Stk::sampleRate. The \e frequency value
corresponds to file cycles per second. The frequency can be
negative, in which case the loop is read in reverse order.
*/
void setFrequency(StkFloat frequency);
void setFrequency( StkFloat frequency );
//! Increment the read pointer by \e aTime samples, modulo file size.
void addTime(StkFloat time);
//! Increment the read pointer by \e time samples, modulo file size.
void addTime( StkFloat time );
//! Increment current read pointer by \e anAngle, relative to a looping frequency.
//! Increment current read pointer by \e angle, relative to a looping frequency.
/*!
This function increments the read pointer based on the file
size and the current Stk::sampleRate. The \e anAngle value
is a multiple of file size.
*/
void addPhase(StkFloat angle);
void addPhase( StkFloat angle );
//! Add a phase offset to the current read pointer.
/*!
This function determines a time offset based on the file
size and the current Stk::sampleRate. The \e anAngle value
size and the current Stk::sampleRate. The \e angle value
is a multiple of file size.
*/
void addPhaseOffset(StkFloat angle);
//! Return a pointer to the next sample frame of data.
const StkFloat *tickFrame(void);
//! Read out sample \e frames of data to \e frameVector.
/*!
An StkError will be thrown if a file is read incrementally and a read error occurs.
*/
StkFloat *tickFrame(StkFloat *frameVector, unsigned int frames);
//! Fill the StkFrames object with sample frames of data and return the same reference.
/*!
An StkError will be thrown if a file is read incrementally and
a read error occurs or there is an incompatability between the
number of channels in the RtWvIn object and that in the StkFrames
object.
*/
StkFrames& tickFrame( StkFrames& frames );
void addPhaseOffset( StkFloat angle );
protected:
// Read file data.
void readData(unsigned long index);
virtual void computeFrame( void );
StkFrames firstFrame_;
StkFloat phaseOffset_;
};

View File

@@ -23,7 +23,7 @@
#include "Sphere.h"
#include "Vector3D.h"
#include "Noise.h"
#include "WaveLoop.h"
#include "SineWave.h"
#include "OnePole.h"
#include "Envelope.h"
@@ -57,25 +57,12 @@ public:
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
//! Compute one output sample.
StkFloat tick();
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
protected:
protected:
StkFloat computeSample( void );
Vector3D *tempVectorP_;
Vector3D tempVector_;
@@ -85,7 +72,7 @@ protected:
Sphere can_; // Declare a Spherical "can".
Sphere pea_, bumper_; // One spherical "pea", and a spherical "bumper".
WaveLoop *sine_;
SineWave sine_;
StkFloat baseFrequency_;
StkFloat noiseGain_;

View File

@@ -26,7 +26,7 @@
type who should worry about this (making
money) worry away.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -53,20 +53,9 @@ class Wurley : public FM
//! Start a note with the given frequency and amplitude.
void noteOn(StkFloat frequency, StkFloat amplitude);
//! Compute one output sample.
StkFloat tick();
protected:
//! Computer \e vectorSize outputs and return them in \e vector.
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if the \c
channel argument is zero or it is greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
StkFloat computeSample( void );
};
#endif

View File

@@ -1,58 +1,27 @@
/***************************************************/
/*! \class WvIn
\brief STK audio data input base class.
\brief STK audio input abstract base class.
This class provides input support for various
audio file formats. It also serves as a base
class for "realtime" streaming subclasses.
This class provides common functionality for a variety of audio
data input subclasses.
WvIn loads the contents of an audio file for
subsequent output. Linear interpolation is
used for fractional "read rates".
WvIn supports multi-channel data. It is important to distinguish
the tick() methods, which return samples produced by averaging
across sample frames, from the tickFrame() methods, which return
references or pointers to multi-channel sample frames.
WvIn supports multi-channel data in
interleaved format. It is important to
distinguish the tick() methods, which return
samples produced by averaging across sample
frames, from the tickFrame() methods, which
return pointers to multi-channel sample
frames. For single-channel data, these
methods return equivalent values.
Both interleaved and non-interleaved data is supported via the use
of StkFrames objects.
Small files are completely read into local
memory during instantiation. Large files are
read incrementally from disk. The file size
threshold and the increment size values are
defined in WvIn.h.
When the end of a file is reached, subsequent
calls to the tick() functions return the data
values at the end of the file.
WvIn currently supports WAV, AIFF, SND (AU),
MAT-file (Matlab), and STK RAW file formats.
Signed integer (8-, 16-, and 32-bit) and floating-
point (32- and 64-bit) data types are supported.
Compressed data types are not supported. If using
MAT-files, data should be saved in an array with
each data channel filling a matrix row. The sample
rate for MAT-files is assumed to be 44100 Hz.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
#ifndef STK_WVIN_H
#define STK_WVIN_H
// Files larger than CHUNK_THRESHOLD will be copied into memory
// in CHUNK_SIZE increments, rather than completely loaded into
// a buffer at once.
const unsigned long CHUNK_THRESHOLD = 5000000; // 5 Mb
const long CHUNK_SIZE = 1024; // sample frames
#include "Stk.h"
#include <vector>
class WvIn : public Stk
{
@@ -60,171 +29,59 @@ public:
//! Default constructor.
WvIn();
//! Overloaded constructor for file input.
/*!
An StkError will be thrown if the file is not found, its format is
unknown, or a read error occurs.
*/
WvIn( std::string fileName, bool raw = false, bool doNormalize = true );
//! Class destructor.
virtual ~WvIn();
//! Open the specified file and load its data.
/*!
An StkError will be thrown if the file is not found, its format is
unknown, or a read error occurs.
*/
void openFile( std::string fileName, bool raw = false, bool doNormalize = true );
//! If a file is open, close it.
void closeFile(void);
//! Clear outputs and reset time (file pointer) to zero.
void reset(void);
//! Normalize data to a maximum of +-1.0.
/*!
For large, incrementally loaded files with integer data types,
normalization is computed relative to the data type maximum.
No normalization is performed for incrementally loaded files
with floating-point data types.
*/
void normalize(void);
//! Normalize data to a maximum of \e +-peak.
/*!
For large, incrementally loaded files with integer data types,
normalization is computed relative to the data type maximum
(\e peak/maximum). For incrementally loaded files with floating-
point data types, direct scaling by \e peak is performed.
*/
void normalize(StkFloat peak);
//! Return the file size in sample frames.
unsigned long getSize(void) const;
//! Return the number of audio channels in the file.
unsigned int getChannels(void) const;
//! Return the input file sample rate in Hz (not the data read rate).
/*!
WAV, SND, and AIF formatted files specify a sample rate in
their headers. STK RAW files have a sample rate of 22050 Hz
by definition. MAT-files are assumed to have a rate of 44100 Hz.
*/
StkFloat getFileRate(void) const;
//! Query whether reading is complete.
bool isFinished(void) const;
//! Set the data read rate in samples. The rate can be negative.
/*!
If the rate value is negative, the data is read in reverse order.
*/
void setRate(StkFloat aRate);
//! Increment the read pointer by \e aTime samples.
virtual void addTime(StkFloat aTime);
//! Turn linear interpolation on/off.
/*!
Interpolation is automatically off when the read rate is
an integer value. If interpolation is turned off for a
fractional rate, the time index is truncated to an integer
value.
*/
void setInterpolate(bool doInterpolate);
//! Return the number of audio channels in the data.
unsigned int getChannels( void ) const { return data_.channels(); };
//! Return the average across the last output sample frame.
virtual StkFloat lastOut(void) const;
/*!
If no file data is loaded, the returned value is 0.0.
*/
StkFloat lastOut( void ) const;
//! Return an StkFrames reference to the last output sample frame.
/*!
If no file data is loaded, an empty container is returned.
*/
const StkFrames& lastFrame( void ) const { return lastOutputs_; };
//! Read out the average across one sample frame of data.
/*!
An StkError will be thrown if a file is read incrementally and a read error occurs.
If no file data is loaded, the returned value is 0.0.
*/
virtual StkFloat tick(void);
//! Read out vectorSize averaged sample frames of data in \e vector.
/*!
An StkError will be thrown if a file is read incrementally and a read error occurs.
*/
virtual StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
StkFloat tick( void );
//! Fill a channel of the StkFrames object with averaged sample frames.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if a file
is read incrementally and a read error occurs or the \c channel
argument is zero or it is greater than the number of channels in
the StkFrames object.
The \c channel argument should be zero or greater (the first
channel is specified by 0). An StkError will be thrown if the \c
channel argument is greater than or equal to the number of
channels in the StkFrames object. If no file data is loaded, the
container is filled with zeroes.
*/
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
//! Return a pointer to the last output sample frame.
virtual const StkFloat *lastFrame(void) const;
//! Return a pointer to the next sample frame of data.
//! Fill the StkFrames argument with data and return the same reference.
/*!
An StkError will be thrown if a file is read incrementally and a read error occurs.
An StkError will be thrown if there is an incompatability
between the number of channels in the loaded data and that in the
StkFrames argument. If no file data is loaded, the container is
filled with zeroes.
*/
virtual const StkFloat *tickFrame(void);
//! Read out sample \e frames of data to \e frameVector.
/*!
An StkError will be thrown if a file is read incrementally and a read error occurs.
*/
virtual StkFloat *tickFrame(StkFloat *frameVector, unsigned int frames);
//! Fill the StkFrames object with sample frames of data and return the same reference.
/*!
An StkError will be thrown if a file is read incrementally and
a read error occurs or if there is an incompatability between the
number of channels in the WvIn object and that in the StkFrames
object.
*/
virtual StkFrames& tickFrame( StkFrames& frames );
StkFrames& tickFrame( StkFrames& frames );
protected:
// Initialize class variables.
void init( void );
// This abstract function must be implemented in all subclasses.
// It is used to get around a C++ problem with overloaded virtual
// functions.
virtual void computeFrame( void ) = 0;
// Read file data.
virtual void readData(unsigned long index);
StkFrames data_;
StkFrames lastOutputs_;
// Get STK RAW file information.
bool getRawInfo( const char *fileName );
// Get WAV file header information.
bool getWavInfo( const char *fileName );
// Get SND (AU) file header information.
bool getSndInfo( const char *fileName );
// Get AIFF file header information.
bool getAifInfo( const char *fileName );
// Get MAT-file header information.
bool getMatInfo( const char *fileName );
FILE *fd_;
StkFloat *data_;
StkFloat *lastOutputs_;
bool chunking_;
bool finished_;
bool interpolate_;
bool byteswap_;
unsigned long fileSize_;
unsigned long bufferSize_;
unsigned long dataOffset_;
unsigned int channels_;
long chunkPointer_;
StkFormat dataType_;
StkFloat fileRate_;
StkFloat gain_;
StkFloat time_;
StkFloat rate_;
};
#endif

View File

@@ -1,35 +1,22 @@
/***************************************************/
/*! \class WvOut
\brief STK audio data output base class.
\brief STK audio output abstract base class.
This class provides output support for various
audio file formats. It also serves as a base
class for "realtime" streaming subclasses.
This class provides common functionality for a variety of audio
data output subclasses.
WvOut writes samples to an audio file. It
supports multi-channel data in interleaved
format. It is important to distinguish the
tick() methods, which output single samples
to all channels in a sample frame, from the
tickFrame() method, which takes a pointer
to multi-channel sample frame data.
WvOut supports multi-channel data. It is important to distinguish
the tick() methods, which output single samples to all channels in
a sample frame, from the tickFrame() methods, which take a pointer
or reference to multi-channel sample frame data.
WvOut currently supports uncompressed WAV,
AIFF, AIFC, SND (AU), MAT-file (Matlab), and
STK RAW file formats. Signed integer (8-,
16-, and 32-bit) and floating- point (32- and
64-bit) data types are supported. STK RAW
files use 16-bit integers by definition.
MAT-files will always be written as 64-bit
floats. If a data type specification does not
match the specified file type, the data type
will automatically be modified. Compressed
data types are not supported.
Both interleaved and non-interleaved data is supported via the use
of StkFrames objects.
Currently, WvOut is non-interpolating and the
output rate is always Stk::sampleRate().
Currently, WvOut is non-interpolating and the output rate is
always Stk::sampleRate().
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/
@@ -37,136 +24,67 @@
#define STK_WVOUT_H
#include "Stk.h"
const unsigned long BUFFER_SIZE = 1024; // sample frames
#include <vector>
class WvOut : public Stk
{
public:
typedef unsigned long FILE_TYPE;
static const FILE_TYPE WVOUT_RAW; /*!< STK RAW file type. */
static const FILE_TYPE WVOUT_WAV; /*!< WAV file type. */
static const FILE_TYPE WVOUT_SND; /*!< SND (AU) file type. */
static const FILE_TYPE WVOUT_AIF; /*!< AIFF file type. */
static const FILE_TYPE WVOUT_MAT; /*!< Matlab MAT-file type. */
//! Default constructor.
WvOut();
//! Overloaded constructor used to specify a file name, type, and data format with this object.
/*!
An StkError is thrown for invalid argument values or if an error occurs when initializing the output file.
*/
WvOut( const char *fileName, unsigned int nChannels = 1, FILE_TYPE type = WVOUT_WAV, Stk::StkFormat format = STK_SINT16 );
//! Class destructor.
virtual ~WvOut();
//! Create a file of the specified type and name and output samples to it in the given data format.
/*!
An StkError is thrown for invalid argument values or if an error occurs when initializing the output file.
*/
void openFile( const char *fileName, unsigned int nChannels = 1,
WvOut::FILE_TYPE type = WVOUT_WAV, Stk::StkFormat format = STK_SINT16 );
//! If a file is open, write out samples in the queue and then close it.
void closeFile( void );
//! Return the number of sample frames output.
unsigned long getFrames( void ) const;
unsigned long getFrameCount( void ) const;
//! Return the number of seconds of data output.
StkFloat getTime( void ) const;
//! Returns \c true if clipping has been detected during output since instantiation or the last reset.
bool getClipStatus( void ) { return clipping_; };
bool clipStatus( void ) { return clipping_; };
//! Reset the clipping status to \c false.
void resetClipStatus( void ) { clipping_ = false; };
//! Output a single sample to all channels in a sample frame.
/*!
An StkError is thrown if a file write error occurs.
An StkError is thrown if an output error occurs.
*/
virtual void tick(const StkFloat sample);
//! Output each sample in \e vector to all channels in \e vectorSize sample frames.
/*!
An StkError is thrown if a file write error occurs.
*/
virtual void tick( const StkFloat *vector, unsigned int vectorSize );
void tick( const StkFloat sample );
//! Output a channel of the StkFrames object to all channels of the WvOut object.
/*!
The \c channel argument should be one or greater (the first
channel is specified by 1). An StkError will be thrown if a file
write error occurs or the \c channel argument is zero or it is
The \c channel argument should be 0 or greater (the first
channel is specified by 0). An StkError will be thrown if an
output error occurs or if the \c channel argument is equal to or
greater than the number of channels in the StkFrames object.
*/
virtual void tick( const StkFrames& frames, unsigned int channel = 1 );
void tick( const StkFrames& frames, unsigned int channel = 0 );
//! Output the \e frameVector of sample frames of the given length.
//! Output the StkFrames data.
/*!
An StkError is thrown if a file write error occurs.
*/
virtual void tickFrame( const StkFloat *frameVector, unsigned int frames = 1);
//! Output the StkFrames data to the WvOut object.
/*!
An StkError will be thrown if a file write error occurs or if
An StkError will be thrown if an output error occurs or if
there is an incompatability between the number of channels in the
WvOut object and that in the StkFrames object.
*/
virtual void tickFrame( const StkFrames& frames );
void tickFrame( const StkFrames& frames );
protected:
// Initialize class variables.
void init( void );
// These abstract functions must be implemented in all subclasses.
// They are used to get around a C++ problem with overloaded virtual
// functions.
virtual void computeSample( const StkFloat sample ) = 0;
// Write data to output file;
virtual void writeData( unsigned long frames );
virtual void computeFrames( const StkFrames& frames ) = 0;
// Check for sample clipping and clamp.
void clipTest( StkFloat& sample );
StkFloat& clipTest( StkFloat& sample );
// Write STK RAW file header.
bool setRawFile( const char *fileName );
// Write WAV file header.
bool setWavFile( const char *fileName );
// Close WAV file, updating the header.
void closeWavFile( void );
// Write SND (AU) file header.
bool setSndFile( const char *fileName );
// Close SND file, updating the header.
void closeSndFile( void );
// Write AIFF file header.
bool setAifFile( const char *fileName );
// Close AIFF file, updating the header.
void closeAifFile( void );
// Write MAT-file header.
bool setMatFile( const char *fileName );
// Close MAT-file, updating the header.
void closeMatFile( void );
FILE *fd_;
std::valarray<StkFloat> data_;
FILE_TYPE fileType_;
StkFormat dataType_;
unsigned int channels_;
unsigned long counter_;
unsigned long totalCount_;
bool byteswap_;
StkFrames data_;
unsigned long frameCounter_;
bool clipping_;
};