Version 4.1

This commit is contained in:
Gary Scavone
2009-03-24 23:02:12 -04:00
committed by Stephen Sinclair
parent 81475b04c5
commit 2f09fcd019
279 changed files with 36223 additions and 25364 deletions

View File

@@ -1,88 +1,88 @@
/***************************************************/
/*! \class ADSR
\brief STK ADSR envelope class.
This Envelope subclass implements a
traditional ADSR (Attack, Decay,
Sustain, Release) envelope. It
responds to simple keyOn and keyOff
messages, keeping track of its state.
The \e state = ADSR::DONE after the
envelope value reaches 0.0 in the
ADSR::RELEASE state.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__ADSR_H)
#define __ADSR_H
#include "Envelope.h"
class ADSR : public Envelope
{
public:
//! Envelope states.
enum { ATTACK, DECAY, SUSTAIN, RELEASE, DONE };
//! Default constructor.
ADSR(void);
//! Class destructor.
~ADSR(void);
//! Set target = 1, state = \e ADSR::ATTACK.
void keyOn(void);
//! Set target = 0, state = \e ADSR::RELEASE.
void keyOff(void);
//! Set the attack rate.
void setAttackRate(MY_FLOAT aRate);
//! Set the decay rate.
void setDecayRate(MY_FLOAT aRate);
//! Set the sustain level.
void setSustainLevel(MY_FLOAT aLevel);
//! Set the release rate.
void setReleaseRate(MY_FLOAT aRate);
//! Set the attack rate based on a time duration.
void setAttackTime(MY_FLOAT aTime);
//! Set the decay rate based on a time duration.
void setDecayTime(MY_FLOAT aTime);
//! Set the release rate based on a time duration.
void setReleaseTime(MY_FLOAT aTime);
//! Set sustain level and attack, decay, and release state rates based on time durations.
void setAllTimes(MY_FLOAT aTime, MY_FLOAT dTime, MY_FLOAT sLevel, MY_FLOAT rTime);
//! Set the target value.
void setTarget(MY_FLOAT aTarget);
//! Return the current envelope \e state (ATTACK, DECAY, SUSTAIN, RELEASE, DONE).
int getState(void) const;
//! Set to state = ADSR::SUSTAIN with current and target values of \e aValue.
void setValue(MY_FLOAT aValue);
//! Return one envelope output value.
MY_FLOAT tick(void);
//! Return \e vectorSize envelope outputs in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
protected:
MY_FLOAT attackRate;
MY_FLOAT decayRate;
MY_FLOAT sustainLevel;
MY_FLOAT releaseRate;
};
#endif
/***************************************************/
/*! \class ADSR
\brief STK ADSR envelope class.
This Envelope subclass implements a
traditional ADSR (Attack, Decay,
Sustain, Release) envelope. It
responds to simple keyOn and keyOff
messages, keeping track of its state.
The \e state = ADSR::DONE after the
envelope value reaches 0.0 in the
ADSR::RELEASE state.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__ADSR_H)
#define __ADSR_H
#include "Envelope.h"
class ADSR : public Envelope
{
public:
//! Envelope states.
enum { ATTACK, DECAY, SUSTAIN, RELEASE, DONE };
//! Default constructor.
ADSR(void);
//! Class destructor.
~ADSR(void);
//! Set target = 1, state = \e ADSR::ATTACK.
void keyOn(void);
//! Set target = 0, state = \e ADSR::RELEASE.
void keyOff(void);
//! Set the attack rate.
void setAttackRate(MY_FLOAT aRate);
//! Set the decay rate.
void setDecayRate(MY_FLOAT aRate);
//! Set the sustain level.
void setSustainLevel(MY_FLOAT aLevel);
//! Set the release rate.
void setReleaseRate(MY_FLOAT aRate);
//! Set the attack rate based on a time duration.
void setAttackTime(MY_FLOAT aTime);
//! Set the decay rate based on a time duration.
void setDecayTime(MY_FLOAT aTime);
//! Set the release rate based on a time duration.
void setReleaseTime(MY_FLOAT aTime);
//! Set sustain level and attack, decay, and release state rates based on time durations.
void setAllTimes(MY_FLOAT aTime, MY_FLOAT dTime, MY_FLOAT sLevel, MY_FLOAT rTime);
//! Set the target value.
void setTarget(MY_FLOAT aTarget);
//! Return the current envelope \e state (ATTACK, DECAY, SUSTAIN, RELEASE, DONE).
int getState(void) const;
//! Set to state = ADSR::SUSTAIN with current and target values of \e aValue.
void setValue(MY_FLOAT aValue);
//! Return one envelope output value.
MY_FLOAT tick(void);
//! Return \e vectorSize envelope outputs in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
protected:
MY_FLOAT attackRate;
MY_FLOAT decayRate;
MY_FLOAT sustainLevel;
MY_FLOAT releaseRate;
};
#endif

View File

@@ -32,10 +32,10 @@
#if !defined(__BANDEDWG_H)
#define __BANDEDWG_H
#define MAX_BANDED_MODES 17
#define MAX_BANDED_MODES 20
#include "Instrmnt.h"
#include "Delay.h"
#include "DelayL.h"
#include "BowTabl.h"
#include "ADSR.h"
#include "BiQuad.h"
@@ -91,16 +91,20 @@ class BandedWG : public Instrmnt
BowTabl *bowTabl;
ADSR *adsr;
BiQuad *bandpass;
Delay *delay;
DelayL *delay;
MY_FLOAT maxVelocity;
MY_FLOAT modes[MAX_BANDED_MODES];
MY_FLOAT freakency;
MY_FLOAT baseGain;
MY_FLOAT gains[MAX_BANDED_MODES];
MY_FLOAT basegains[MAX_BANDED_MODES];
MY_FLOAT excitation[MAX_BANDED_MODES];
MY_FLOAT integrationConstant;
MY_FLOAT velocityInput;
MY_FLOAT bowVelocity;
MY_FLOAT bowTarget;
MY_FLOAT bowPosition;
MY_FLOAT strikeAmp;
int strikePosition;
};

View File

@@ -1,100 +1,100 @@
/***************************************************/
/*! \class BiQuad
\brief STK biquad (two-pole, two-zero) filter class.
This protected Filter subclass implements a
two-pole, two-zero digital filter. A method
is provided for creating a resonance in the
frequency response while maintaining a constant
filter gain.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__BIQUAD_H)
#define __BIQUAD_H
#include "Filter.h"
class BiQuad : protected Filter
{
public:
//! Default constructor creates a second-order pass-through filter.
BiQuad();
//! Class destructor.
virtual ~BiQuad();
//! Clears all internal states of the filter.
void clear(void);
//! Set the b[0] coefficient value.
void setB0(MY_FLOAT b0);
//! Set the b[1] coefficient value.
void setB1(MY_FLOAT b1);
//! Set the b[2] coefficient value.
void setB2(MY_FLOAT b2);
//! Set the a[1] coefficient value.
void setA1(MY_FLOAT a1);
//! Set the a[2] coefficient value.
void setA2(MY_FLOAT a2);
//! Sets the filter coefficients for a resonance at \e frequency (in Hz).
/*!
This method determines the filter coefficients corresponding to
two complex-conjugate poles with the given \e frequency (in Hz)
and \e radius from the z-plane origin. If \e normalize is true,
the filter zeros are placed at z = 1, z = -1, and the coefficients
are then normalized to produce a constant unity peak gain
(independent of the filter \e gain parameter). The resulting
filter frequency response has a resonance at the given \e
frequency. The closer the poles are to the unit-circle (\e radius
close to one), the narrower the resulting resonance width.
*/
void setResonance(MY_FLOAT frequency, MY_FLOAT radius, bool normalize = FALSE);
//! Set the filter coefficients for a notch at \e frequency (in Hz).
/*!
This method determines the filter coefficients corresponding to
two complex-conjugate zeros with the given \e frequency (in Hz)
and \e radius from the z-plane origin. No filter normalization
is attempted.
*/
void setNotch(MY_FLOAT frequency, MY_FLOAT radius);
//! Sets the filter zeroes for equal resonance gain.
/*!
When using the filter as a resonator, zeroes places at z = 1, z
= -1 will result in a constant gain at resonance of 1 / (1 - R),
where R is the pole radius setting.
*/
void setEqualGainZeroes();
//! Set the filter gain.
/*!
The gain is applied at the filter input and does not affect the
coefficient values. The default gain value is 1.0.
*/
void setGain(MY_FLOAT theGain);
//! Return the current filter gain.
MY_FLOAT getGain(void) const;
//! Return the last computed output value.
MY_FLOAT lastOut(void) const;
//! Input one sample to the filter and return one output.
MY_FLOAT tick(MY_FLOAT sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
};
#endif
/***************************************************/
/*! \class BiQuad
\brief STK biquad (two-pole, two-zero) filter class.
This protected Filter subclass implements a
two-pole, two-zero digital filter. A method
is provided for creating a resonance in the
frequency response while maintaining a constant
filter gain.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__BIQUAD_H)
#define __BIQUAD_H
#include "Filter.h"
class BiQuad : protected Filter
{
public:
//! Default constructor creates a second-order pass-through filter.
BiQuad();
//! Class destructor.
virtual ~BiQuad();
//! Clears all internal states of the filter.
void clear(void);
//! Set the b[0] coefficient value.
void setB0(MY_FLOAT b0);
//! Set the b[1] coefficient value.
void setB1(MY_FLOAT b1);
//! Set the b[2] coefficient value.
void setB2(MY_FLOAT b2);
//! Set the a[1] coefficient value.
void setA1(MY_FLOAT a1);
//! Set the a[2] coefficient value.
void setA2(MY_FLOAT a2);
//! Sets the filter coefficients for a resonance at \e frequency (in Hz).
/*!
This method determines the filter coefficients corresponding to
two complex-conjugate poles with the given \e frequency (in Hz)
and \e radius from the z-plane origin. If \e normalize is true,
the filter zeros are placed at z = 1, z = -1, and the coefficients
are then normalized to produce a constant unity peak gain
(independent of the filter \e gain parameter). The resulting
filter frequency response has a resonance at the given \e
frequency. The closer the poles are to the unit-circle (\e radius
close to one), the narrower the resulting resonance width.
*/
void setResonance(MY_FLOAT frequency, MY_FLOAT radius, bool normalize = FALSE);
//! Set the filter coefficients for a notch at \e frequency (in Hz).
/*!
This method determines the filter coefficients corresponding to
two complex-conjugate zeros with the given \e frequency (in Hz)
and \e radius from the z-plane origin. No filter normalization
is attempted.
*/
void setNotch(MY_FLOAT frequency, MY_FLOAT radius);
//! Sets the filter zeroes for equal resonance gain.
/*!
When using the filter as a resonator, zeroes places at z = 1, z
= -1 will result in a constant gain at resonance of 1 / (1 - R),
where R is the pole radius setting.
*/
void setEqualGainZeroes();
//! Set the filter gain.
/*!
The gain is applied at the filter input and does not affect the
coefficient values. The default gain value is 1.0.
*/
void setGain(MY_FLOAT theGain);
//! Return the current filter gain.
MY_FLOAT getGain(void) const;
//! Return the last computed output value.
MY_FLOAT lastOut(void) const;
//! Input one sample to the filter and return one output.
MY_FLOAT tick(MY_FLOAT sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
};
#endif

View File

@@ -1,77 +1,77 @@
/***************************************************/
/*! \class BlowBotl
\brief STK blown bottle instrument class.
This class implements a helmholtz resonator
(biquad filter) with a polynomial jet
excitation (a la Cook).
Control Change Numbers:
- Noise Gain = 4
- Vibrato Frequency = 11
- Vibrato Gain = 1
- Volume = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__BOTTLE_H)
#define __BOTTLE_H
#include "Instrmnt.h"
#include "JetTabl.h"
#include "BiQuad.h"
#include "PoleZero.h"
#include "Noise.h"
#include "ADSR.h"
#include "WaveLoop.h"
class BlowBotl : public Instrmnt
{
public:
//! Class constructor.
BlowBotl();
//! Class destructor.
~BlowBotl();
//! Reset and clear all internal state.
void clear();
//! Set instrument parameters for a particular frequency.
void setFrequency(MY_FLOAT frequency);
//! Apply breath velocity to instrument with given amplitude and rate of increase.
void startBlowing(MY_FLOAT amplitude, MY_FLOAT rate);
//! Decrease breath velocity with given rate of decrease.
void stopBlowing(MY_FLOAT rate);
//! Start a note with the given frequency and amplitude.
void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
//! Stop a note with the given amplitude (speed of decay).
void noteOff(MY_FLOAT amplitude);
//! Compute one output sample.
MY_FLOAT tick();
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, MY_FLOAT value);
protected:
JetTabl *jetTable;
BiQuad *resonator;
PoleZero *dcBlock;
Noise *noise;
ADSR *adsr;
WaveLoop *vibrato;
MY_FLOAT maxPressure;
MY_FLOAT noiseGain;
MY_FLOAT vibratoGain;
MY_FLOAT outputGain;
};
#endif
/***************************************************/
/*! \class BlowBotl
\brief STK blown bottle instrument class.
This class implements a helmholtz resonator
(biquad filter) with a polynomial jet
excitation (a la Cook).
Control Change Numbers:
- Noise Gain = 4
- Vibrato Frequency = 11
- Vibrato Gain = 1
- Volume = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__BOTTLE_H)
#define __BOTTLE_H
#include "Instrmnt.h"
#include "JetTabl.h"
#include "BiQuad.h"
#include "PoleZero.h"
#include "Noise.h"
#include "ADSR.h"
#include "WaveLoop.h"
class BlowBotl : public Instrmnt
{
public:
//! Class constructor.
BlowBotl();
//! Class destructor.
~BlowBotl();
//! Reset and clear all internal state.
void clear();
//! Set instrument parameters for a particular frequency.
void setFrequency(MY_FLOAT frequency);
//! Apply breath velocity to instrument with given amplitude and rate of increase.
void startBlowing(MY_FLOAT amplitude, MY_FLOAT rate);
//! Decrease breath velocity with given rate of decrease.
void stopBlowing(MY_FLOAT rate);
//! Start a note with the given frequency and amplitude.
void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
//! Stop a note with the given amplitude (speed of decay).
void noteOff(MY_FLOAT amplitude);
//! Compute one output sample.
MY_FLOAT tick();
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, MY_FLOAT value);
protected:
JetTabl *jetTable;
BiQuad *resonator;
PoleZero *dcBlock;
Noise *noise;
ADSR *adsr;
WaveLoop *vibrato;
MY_FLOAT maxPressure;
MY_FLOAT noiseGain;
MY_FLOAT vibratoGain;
MY_FLOAT outputGain;
};
#endif

View File

@@ -1,62 +1,62 @@
/***************************************************/
/*! \class BowTabl
\brief STK bowed string table class.
This class implements a simple bowed string
non-linear function, as described by Smith (1986).
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__BOWTABL_H)
#define __BOWTABL_H
#include "Stk.h"
class BowTabl : public Stk
{
public:
//! Default constructor.
BowTabl();
//! Class destructor.
~BowTabl();
//! Set the table offset value.
/*!
The table offset is a bias which controls the
symmetry of the friction. If you want the
friction to vary with direction, use a non-zero
value for the offset. The default value is zero.
*/
void setOffset(MY_FLOAT aValue);
//! Set the table slope value.
/*!
The table slope controls the width of the friction
pulse, which is related to bow force.
*/
void setSlope(MY_FLOAT aValue);
//! Return the last output value.
MY_FLOAT lastOut(void) const;
//! Return the function value for \e input.
/*!
The function input represents differential
string-to-bow velocity.
*/
MY_FLOAT tick(const MY_FLOAT input);
//! Take \e vectorSize inputs and return the corresponding function values in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
protected:
MY_FLOAT offSet;
MY_FLOAT slope;
MY_FLOAT lastOutput;
};
#endif
/***************************************************/
/*! \class BowTabl
\brief STK bowed string table class.
This class implements a simple bowed string
non-linear function, as described by Smith (1986).
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__BOWTABL_H)
#define __BOWTABL_H
#include "Stk.h"
class BowTabl : public Stk
{
public:
//! Default constructor.
BowTabl();
//! Class destructor.
~BowTabl();
//! Set the table offset value.
/*!
The table offset is a bias which controls the
symmetry of the friction. If you want the
friction to vary with direction, use a non-zero
value for the offset. The default value is zero.
*/
void setOffset(MY_FLOAT aValue);
//! Set the table slope value.
/*!
The table slope controls the width of the friction
pulse, which is related to bow force.
*/
void setSlope(MY_FLOAT aValue);
//! Return the last output value.
MY_FLOAT lastOut(void) const;
//! Return the function value for \e input.
/*!
The function input represents differential
string-to-bow velocity.
*/
MY_FLOAT tick(const MY_FLOAT input);
//! Take \e vectorSize inputs and return the corresponding function values in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
protected:
MY_FLOAT offSet;
MY_FLOAT slope;
MY_FLOAT lastOutput;
};
#endif

View File

@@ -1,83 +1,83 @@
/***************************************************/
/*! \class Clarinet
\brief STK clarinet physical model class.
This class implements a simple clarinet
physical model, as discussed by Smith (1986),
McIntyre, Schumacher, Woodhouse (1983), and
others.
This is a digital waveguide model, making its
use possibly subject to patents held by Stanford
University, Yamaha, and others.
Control Change Numbers:
- Reed Stiffness = 2
- Noise Gain = 4
- Vibrato Frequency = 11
- Vibrato Gain = 1
- Breath Pressure = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__CLARINET_H)
#define __CLARINET_H
#include "Instrmnt.h"
#include "DelayL.h"
#include "ReedTabl.h"
#include "OneZero.h"
#include "Envelope.h"
#include "Noise.h"
#include "WaveLoop.h"
class Clarinet : public Instrmnt
{
public:
//! Class constructor, taking the lowest desired playing frequency.
Clarinet(MY_FLOAT lowestFrequency);
//! Class destructor.
~Clarinet();
//! Reset and clear all internal state.
void clear();
//! Set instrument parameters for a particular frequency.
void setFrequency(MY_FLOAT frequency);
//! Apply breath pressure to instrument with given amplitude and rate of increase.
void startBlowing(MY_FLOAT amplitude, MY_FLOAT rate);
//! Decrease breath pressure with given rate of decrease.
void stopBlowing(MY_FLOAT rate);
//! Start a note with the given frequency and amplitude.
void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
//! Stop a note with the given amplitude (speed of decay).
void noteOff(MY_FLOAT amplitude);
//! Compute one output sample.
MY_FLOAT tick();
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, MY_FLOAT value);
protected:
DelayL *delayLine;
ReedTabl *reedTable;
OneZero *filter;
Envelope *envelope;
Noise *noise;
WaveLoop *vibrato;
long length;
MY_FLOAT outputGain;
MY_FLOAT noiseGain;
MY_FLOAT vibratoGain;
};
#endif
/***************************************************/
/*! \class Clarinet
\brief STK clarinet physical model class.
This class implements a simple clarinet
physical model, as discussed by Smith (1986),
McIntyre, Schumacher, Woodhouse (1983), and
others.
This is a digital waveguide model, making its
use possibly subject to patents held by Stanford
University, Yamaha, and others.
Control Change Numbers:
- Reed Stiffness = 2
- Noise Gain = 4
- Vibrato Frequency = 11
- Vibrato Gain = 1
- Breath Pressure = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__CLARINET_H)
#define __CLARINET_H
#include "Instrmnt.h"
#include "DelayL.h"
#include "ReedTabl.h"
#include "OneZero.h"
#include "Envelope.h"
#include "Noise.h"
#include "WaveLoop.h"
class Clarinet : public Instrmnt
{
public:
//! Class constructor, taking the lowest desired playing frequency.
Clarinet(MY_FLOAT lowestFrequency);
//! Class destructor.
~Clarinet();
//! Reset and clear all internal state.
void clear();
//! Set instrument parameters for a particular frequency.
void setFrequency(MY_FLOAT frequency);
//! Apply breath pressure to instrument with given amplitude and rate of increase.
void startBlowing(MY_FLOAT amplitude, MY_FLOAT rate);
//! Decrease breath pressure with given rate of decrease.
void stopBlowing(MY_FLOAT rate);
//! Start a note with the given frequency and amplitude.
void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
//! Stop a note with the given amplitude (speed of decay).
void noteOff(MY_FLOAT amplitude);
//! Compute one output sample.
MY_FLOAT tick();
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, MY_FLOAT value);
protected:
DelayL *delayLine;
ReedTabl *reedTable;
OneZero *filter;
Envelope *envelope;
Noise *noise;
WaveLoop *vibrato;
long length;
MY_FLOAT outputGain;
MY_FLOAT noiseGain;
MY_FLOAT vibratoGain;
};
#endif

View File

@@ -1,77 +1,83 @@
/***************************************************/
/*! \class Delay
\brief STK non-interpolating delay line class.
This protected Filter subclass implements
a non-interpolating digital delay-line.
A fixed maximum length of 4095 and a delay
of zero is set using the default constructor.
Alternatively, the delay and maximum length
can be set during instantiation with an
overloaded constructor.
A non-interpolating delay line is typically
used in fixed delay-length applications, such
as for reverberation.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__DELAY_H)
#define __DELAY_H
#include "Filter.h"
class Delay : protected Filter
{
public:
//! Default constructor creates a delay-line with maximum length of 4095 samples and zero delay.
Delay();
//! Overloaded constructor which specifies the current and maximum delay-line lengths.
Delay(long theDelay, long maxDelay);
//! Class destructor.
virtual ~Delay();
//! Clears the internal state of the delay line.
void clear();
//! Set the delay-line length.
/*!
The valid range for \e theDelay is from 0 to the maximum delay-line length.
*/
void setDelay(long theDelay);
//! Return the current delay-line length.
long getDelay(void) const;
//! Calculate and return the signal energy in the delay-line.
MY_FLOAT energy(void) const;
//! Return the value at \e tapDelay samples from the delay-line input.
/*!
The valid range for \e tapDelay is 1 to the delay-line length.
*/
MY_FLOAT contentsAt(long tapDelay) const;
//! Return the last computed output value.
MY_FLOAT lastOut(void) const;
//! Input one sample to the delay-line and return one output.
virtual MY_FLOAT tick(MY_FLOAT sample);
//! Input \e vectorSize samples to the delay-line and return an equal number of outputs in \e vector.
virtual MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
protected:
long inPoint;
long outPoint;
long length;
MY_FLOAT delay;
};
#endif
/***************************************************/
/*! \class Delay
\brief STK non-interpolating delay line class.
This protected Filter subclass implements
a non-interpolating digital delay-line.
A fixed maximum length of 4095 and a delay
of zero is set using the default constructor.
Alternatively, the delay and maximum length
can be set during instantiation with an
overloaded constructor.
A non-interpolating delay line is typically
used in fixed delay-length applications, such
as for reverberation.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__DELAY_H)
#define __DELAY_H
#include "Filter.h"
class Delay : protected Filter
{
public:
//! Default constructor creates a delay-line with maximum length of 4095 samples and zero delay.
Delay();
//! Overloaded constructor which specifies the current and maximum delay-line lengths.
Delay(long theDelay, long maxDelay);
//! Class destructor.
virtual ~Delay();
//! Clears the internal state of the delay line.
void clear();
//! Set the delay-line length.
/*!
The valid range for \e theDelay is from 0 to the maximum delay-line length.
*/
void setDelay(long theDelay);
//! Return the current delay-line length.
long getDelay(void) const;
//! Calculate and return the signal energy in the delay-line.
MY_FLOAT energy(void) const;
//! Return the value at \e tapDelay samples from the delay-line input.
/*!
The valid range for \e tapDelay is 1 to the delay-line length.
*/
MY_FLOAT contentsAt(long tapDelay) const;
//! Return the last computed output value.
MY_FLOAT lastOut(void) const;
//! Return the value which will be output by the next call to tick().
/*!
This method is valid only for delay settings greater than zero!
*/
virtual MY_FLOAT nextOut(void) const;
//! Input one sample to the delay-line and return one output.
virtual MY_FLOAT tick(MY_FLOAT sample);
//! Input \e vectorSize samples to the delay-line and return an equal number of outputs in \e vector.
virtual MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
protected:
long inPoint;
long outPoint;
long length;
MY_FLOAT delay;
};
#endif

View File

@@ -1,65 +1,73 @@
/***************************************************/
/*! \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.
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 - 2002.
*/
/***************************************************/
#if !defined(__DelayA_h)
#define __DelayA_h
#include "Delay.h"
class DelayA : public Delay
{
public:
//! Default constructor creates a delay-line with maximum length of 4095 samples and zero delay.
DelayA();
//! Overloaded constructor which specifies the current and maximum delay-line lengths.
DelayA(MY_FLOAT theDelay, long maxDelay);
//! Class destructor.
~DelayA();
//! Clears the internal state of the delay line.
void clear();
//! Set the delay-line length
/*!
The valid range for \e theDelay is from 0.5 to the maximum delay-line length.
*/
void setDelay(MY_FLOAT theDelay);
//! Return the current delay-line length.
MY_FLOAT getDelay(void);
//! Input one sample to the delay-line and return one output.
MY_FLOAT tick(MY_FLOAT sample);
protected:
MY_FLOAT alpha;
MY_FLOAT coeff;
MY_FLOAT apInput;
};
#endif
/***************************************************/
/*! \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.
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 - 2002.
*/
/***************************************************/
#if !defined(__DelayA_h)
#define __DelayA_h
#include "Delay.h"
class DelayA : public Delay
{
public:
//! Default constructor creates a delay-line with maximum length of 4095 samples and zero delay.
DelayA();
//! Overloaded constructor which specifies the current and maximum delay-line lengths.
DelayA(MY_FLOAT theDelay, long maxDelay);
//! Class destructor.
~DelayA();
//! Clears the internal state of the delay line.
void clear();
//! Set the delay-line length
/*!
The valid range for \e theDelay is from 0.5 to the maximum delay-line length.
*/
void setDelay(MY_FLOAT theDelay);
//! Return the current delay-line length.
MY_FLOAT getDelay(void);
//! Return the value which will be output by the next call to tick().
/*!
This method is valid only for delay settings greater than zero!
*/
MY_FLOAT nextOut(void);
//! Input one sample to the delay-line and return one output.
MY_FLOAT tick(MY_FLOAT sample);
protected:
MY_FLOAT alpha;
MY_FLOAT coeff;
MY_FLOAT apInput;
MY_FLOAT nextOutput;
bool doNextOut;
};
#endif

View File

@@ -1,61 +1,69 @@
/***************************************************/
/*! \class DelayL
\brief STK linear interpolating delay line class.
This Delay subclass implements a fractional-
length digital delay-line using first-order
linear interpolation. A fixed maximum length
of 4095 and a delay of zero is set using the
default constructor. Alternatively, the
delay and maximum length can be set during
instantiation with an overloaded constructor.
Linear interpolation is an efficient technique
for achieving fractional delay lengths, though
it does introduce high-frequency signal
attenuation to varying degrees depending on the
fractional delay setting. The use of higher
order Lagrange interpolators can typically
improve (minimize) this attenuation characteristic.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__DELAYL_H)
#define __DELAYL_H
#include "Delay.h"
class DelayL : public Delay
{
public:
//! Default constructor creates a delay-line with maximum length of 4095 samples and zero delay.
DelayL();
//! Overloaded constructor which specifies the current and maximum delay-line lengths.
DelayL(MY_FLOAT theDelay, long maxDelay);
//! Class destructor.
~DelayL();
//! Set the delay-line length.
/*!
The valid range for \e theDelay is from 0 to the maximum delay-line length.
*/
void setDelay(MY_FLOAT theDelay);
//! Return the current delay-line length.
MY_FLOAT getDelay(void) const;
//! Input one sample to the delay-line and return one output.
MY_FLOAT tick(MY_FLOAT sample);
protected:
MY_FLOAT alpha;
MY_FLOAT omAlpha;
};
#endif
/***************************************************/
/*! \class DelayL
\brief STK linear interpolating delay line class.
This Delay subclass implements a fractional-
length digital delay-line using first-order
linear interpolation. A fixed maximum length
of 4095 and a delay of zero is set using the
default constructor. Alternatively, the
delay and maximum length can be set during
instantiation with an overloaded constructor.
Linear interpolation is an efficient technique
for achieving fractional delay lengths, though
it does introduce high-frequency signal
attenuation to varying degrees depending on the
fractional delay setting. The use of higher
order Lagrange interpolators can typically
improve (minimize) this attenuation characteristic.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__DELAYL_H)
#define __DELAYL_H
#include "Delay.h"
class DelayL : public Delay
{
public:
//! Default constructor creates a delay-line with maximum length of 4095 samples and zero delay.
DelayL();
//! Overloaded constructor which specifies the current and maximum delay-line lengths.
DelayL(MY_FLOAT theDelay, long maxDelay);
//! Class destructor.
~DelayL();
//! Set the delay-line length.
/*!
The valid range for \e theDelay is from 0 to the maximum delay-line length.
*/
void setDelay(MY_FLOAT theDelay);
//! Return the current delay-line length.
MY_FLOAT getDelay(void) const;
//! Return the value which will be output by the next call to tick().
/*!
This method is valid only for delay settings greater than zero!
*/
MY_FLOAT nextOut(void);
//! Input one sample to the delay-line and return one output.
MY_FLOAT tick(MY_FLOAT sample);
protected:
MY_FLOAT alpha;
MY_FLOAT omAlpha;
MY_FLOAT nextOutput;
bool doNextOut;
};
#endif

View File

@@ -1,68 +1,68 @@
/***************************************************/
/*! \class Envelope
\brief STK envelope base class.
This class implements a simple envelope
generator which is capable of ramping to
a target value by a specified \e rate.
It also responds to simple \e keyOn and
\e keyOff messages, ramping to 1.0 on
keyOn and to 0.0 on keyOff.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__ENVELOPE_H)
#define __ENVELOPE_H
#include "Stk.h"
class Envelope : public Stk
{
public:
//! Default constructor.
Envelope(void);
//! Class destructor.
virtual ~Envelope(void);
//! Set target = 1.
virtual void keyOn(void);
//! Set target = 0.
virtual void keyOff(void);
//! Set the \e rate.
void setRate(MY_FLOAT aRate);
//! Set the \e rate based on a time duration.
void setTime(MY_FLOAT aTime);
//! Set the target value.
virtual void setTarget(MY_FLOAT aTarget);
//! Set current and target values to \e aValue.
virtual void setValue(MY_FLOAT aValue);
//! Return the current envelope \e state (0 = at target, 1 otherwise).
virtual int getState(void) const;
//! Return one envelope output value.
virtual MY_FLOAT tick(void);
//! Return \e vectorSize envelope outputs in \e vector.
virtual MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
//! Return the last computed output value.
MY_FLOAT lastOut(void) const;
protected:
MY_FLOAT value;
MY_FLOAT target;
MY_FLOAT rate;
int state;
};
#endif
/***************************************************/
/*! \class Envelope
\brief STK envelope base class.
This class implements a simple envelope
generator which is capable of ramping to
a target value by a specified \e rate.
It also responds to simple \e keyOn and
\e keyOff messages, ramping to 1.0 on
keyOn and to 0.0 on keyOff.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__ENVELOPE_H)
#define __ENVELOPE_H
#include "Stk.h"
class Envelope : public Stk
{
public:
//! Default constructor.
Envelope(void);
//! Class destructor.
virtual ~Envelope(void);
//! Set target = 1.
virtual void keyOn(void);
//! Set target = 0.
virtual void keyOff(void);
//! Set the \e rate.
void setRate(MY_FLOAT aRate);
//! Set the \e rate based on a time duration.
void setTime(MY_FLOAT aTime);
//! Set the target value.
virtual void setTarget(MY_FLOAT aTarget);
//! Set current and target values to \e aValue.
virtual void setValue(MY_FLOAT aValue);
//! Return the current envelope \e state (0 = at target, 1 otherwise).
virtual int getState(void) const;
//! Return one envelope output value.
virtual MY_FLOAT tick(void);
//! Return \e vectorSize envelope outputs in \e vector.
virtual MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
//! Return the last computed output value.
MY_FLOAT lastOut(void) const;
protected:
MY_FLOAT value;
MY_FLOAT target;
MY_FLOAT rate;
int state;
};
#endif

View File

@@ -1,112 +1,112 @@
/***************************************************/
/*! \class Filter
\brief STK filter class.
This class implements a generic structure which
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
particular filter type.
In particular, this class implements the standard
difference equation:
a[0]*y[n] = b[0]*x[n] + ... + b[nb]*x[n-nb] -
a[1]*y[n-1] - ... - a[na]*y[n-na]
If a[0] is not equal to 1, the filter coeffcients
are normalized by a[0].
The \e gain parameter is applied at the filter
input and does not affect the coefficient values.
The default gain value is 1.0. This structure
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 - 2002.
*/
/***************************************************/
#if !defined(__FILTER_H)
#define __FILTER_H
#include "Stk.h"
class Filter : public Stk
{
public:
//! Default constructor creates a zero-order pass-through "filter".
Filter(void);
//! Overloaded constructor which takes filter coefficients.
/*!
An StkError can be thrown if either \e nb or \e na is less than
one, or if the a[0] coefficient is equal to zero.
*/
Filter(int nb, MY_FLOAT *bCoefficients, int na, MY_FLOAT *aCoefficients);
//! Class destructor.
virtual ~Filter(void);
//! Clears all internal states of the filter.
void clear(void);
//! Set filter coefficients.
/*!
An StkError can be thrown if either \e nb or \e na is less than
one, 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].
*/
void setCoefficients(int nb, MY_FLOAT *bCoefficients, int na, MY_FLOAT *aCoefficients);
//! Set numerator coefficients.
/*!
An StkError can be thrown if \e nb is less than one. Any
previously set denominator coefficients are left unaffected.
Note that the default constructor sets the single denominator
coefficient a[0] to 1.0.
*/
void setNumerator(int nb, MY_FLOAT *bCoefficients);
//! Set denominator coefficients.
/*!
An StkError can be thrown if \e na is less than one or if the
a[0] coefficient is equal to zero. Previously set 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.
*/
void setDenominator(int na, MY_FLOAT *aCoefficients);
//! Set the filter gain.
/*!
The gain is applied at the filter input and does not affect the
coefficient values. The default gain value is 1.0.
*/
virtual void setGain(MY_FLOAT theGain);
//! Return the current filter gain.
virtual MY_FLOAT getGain(void) const;
//! Return the last computed output value.
virtual MY_FLOAT lastOut(void) const;
//! Input one sample to the filter and return one output.
virtual MY_FLOAT tick(MY_FLOAT sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
virtual MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
protected:
MY_FLOAT gain;
int nB;
int nA;
MY_FLOAT *b;
MY_FLOAT *a;
MY_FLOAT *outputs;
MY_FLOAT *inputs;
};
#endif
/***************************************************/
/*! \class Filter
\brief STK filter class.
This class implements a generic structure which
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
particular filter type.
In particular, this class implements the standard
difference equation:
a[0]*y[n] = b[0]*x[n] + ... + b[nb]*x[n-nb] -
a[1]*y[n-1] - ... - a[na]*y[n-na]
If a[0] is not equal to 1, the filter coeffcients
are normalized by a[0].
The \e gain parameter is applied at the filter
input and does not affect the coefficient values.
The default gain value is 1.0. This structure
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 - 2002.
*/
/***************************************************/
#if !defined(__FILTER_H)
#define __FILTER_H
#include "Stk.h"
class Filter : public Stk
{
public:
//! Default constructor creates a zero-order pass-through "filter".
Filter(void);
//! Overloaded constructor which takes filter coefficients.
/*!
An StkError can be thrown if either \e nb or \e na is less than
one, or if the a[0] coefficient is equal to zero.
*/
Filter(int nb, MY_FLOAT *bCoefficients, int na, MY_FLOAT *aCoefficients);
//! Class destructor.
virtual ~Filter(void);
//! Clears all internal states of the filter.
void clear(void);
//! Set filter coefficients.
/*!
An StkError can be thrown if either \e nb or \e na is less than
one, 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].
*/
void setCoefficients(int nb, MY_FLOAT *bCoefficients, int na, MY_FLOAT *aCoefficients);
//! Set numerator coefficients.
/*!
An StkError can be thrown if \e nb is less than one. Any
previously set denominator coefficients are left unaffected.
Note that the default constructor sets the single denominator
coefficient a[0] to 1.0.
*/
void setNumerator(int nb, MY_FLOAT *bCoefficients);
//! Set denominator coefficients.
/*!
An StkError can be thrown if \e na is less than one or if the
a[0] coefficient is equal to zero. Previously set 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.
*/
void setDenominator(int na, MY_FLOAT *aCoefficients);
//! Set the filter gain.
/*!
The gain is applied at the filter input and does not affect the
coefficient values. The default gain value is 1.0.
*/
virtual void setGain(MY_FLOAT theGain);
//! Return the current filter gain.
virtual MY_FLOAT getGain(void) const;
//! Return the last computed output value.
virtual MY_FLOAT lastOut(void) const;
//! Input one sample to the filter and return one output.
virtual MY_FLOAT tick(MY_FLOAT sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
virtual MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
protected:
MY_FLOAT gain;
int nB;
int nA;
MY_FLOAT *b;
MY_FLOAT *a;
MY_FLOAT *outputs;
MY_FLOAT *inputs;
};
#endif

View File

@@ -1,93 +1,93 @@
/***************************************************/
/*! \class FormSwep
\brief STK sweepable formant filter class.
This public BiQuad filter subclass implements
a formant (resonance) which can be "swept"
over time from one frequency setting to another.
It provides methods for controlling the sweep
rate and target frequency.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__FORMSWEP_H)
#define __FORMSWEP_H
#include "BiQuad.h"
class FormSwep : public BiQuad
{
public:
//! Default constructor creates a second-order pass-through filter.
FormSwep();
//! Class destructor.
~FormSwep();
//! Sets the filter coefficients for a resonance at \e frequency (in Hz).
/*!
This method determines the filter coefficients corresponding to
two complex-conjugate poles with the given \e frequency (in Hz)
and \e radius from the z-plane origin. The filter zeros are
placed at z = 1, z = -1, and the coefficients are then normalized to
produce a constant unity gain (independent of the filter \e gain
parameter). The resulting filter frequency response has a
resonance at the given \e frequency. The closer the poles are to
the unit-circle (\e radius close to one), the narrower the
resulting resonance width.
*/
void setResonance(MY_FLOAT aFrequency, MY_FLOAT aRadius);
//! Set both the current and target resonance parameters.
void setStates(MY_FLOAT aFrequency, MY_FLOAT aRadius, MY_FLOAT aGain = 1.0);
//! Set target resonance parameters.
void setTargets(MY_FLOAT aFrequency, MY_FLOAT aRadius, MY_FLOAT aGain = 1.0);
//! Set the sweep rate (between 0.0 - 1.0).
/*!
The formant parameters are varied in increments of the
sweep rate between their current and target values.
A sweep rate of 1.0 will produce an immediate change in
resonance parameters from their current values to the
target values. A sweep rate of 0.0 will produce no
change in resonance parameters.
*/
void setSweepRate(MY_FLOAT aRate);
//! Set the sweep rate in terms of a time value in seconds.
/*!
This method adjusts the sweep rate based on a
given time for the formant parameters to reach
their target values.
*/
void setSweepTime(MY_FLOAT aTime);
//! Input one sample to the filter and return one output.
MY_FLOAT tick(MY_FLOAT sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
protected:
bool dirty;
MY_FLOAT frequency;
MY_FLOAT radius;
MY_FLOAT startFrequency;
MY_FLOAT startRadius;
MY_FLOAT startGain;
MY_FLOAT targetFrequency;
MY_FLOAT targetRadius;
MY_FLOAT targetGain;
MY_FLOAT deltaFrequency;
MY_FLOAT deltaRadius;
MY_FLOAT deltaGain;
MY_FLOAT sweepState;
MY_FLOAT sweepRate;
};
#endif
/***************************************************/
/*! \class FormSwep
\brief STK sweepable formant filter class.
This public BiQuad filter subclass implements
a formant (resonance) which can be "swept"
over time from one frequency setting to another.
It provides methods for controlling the sweep
rate and target frequency.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__FORMSWEP_H)
#define __FORMSWEP_H
#include "BiQuad.h"
class FormSwep : public BiQuad
{
public:
//! Default constructor creates a second-order pass-through filter.
FormSwep();
//! Class destructor.
~FormSwep();
//! Sets the filter coefficients for a resonance at \e frequency (in Hz).
/*!
This method determines the filter coefficients corresponding to
two complex-conjugate poles with the given \e frequency (in Hz)
and \e radius from the z-plane origin. The filter zeros are
placed at z = 1, z = -1, and the coefficients are then normalized to
produce a constant unity gain (independent of the filter \e gain
parameter). The resulting filter frequency response has a
resonance at the given \e frequency. The closer the poles are to
the unit-circle (\e radius close to one), the narrower the
resulting resonance width.
*/
void setResonance(MY_FLOAT aFrequency, MY_FLOAT aRadius);
//! Set both the current and target resonance parameters.
void setStates(MY_FLOAT aFrequency, MY_FLOAT aRadius, MY_FLOAT aGain = 1.0);
//! Set target resonance parameters.
void setTargets(MY_FLOAT aFrequency, MY_FLOAT aRadius, MY_FLOAT aGain = 1.0);
//! Set the sweep rate (between 0.0 - 1.0).
/*!
The formant parameters are varied in increments of the
sweep rate between their current and target values.
A sweep rate of 1.0 will produce an immediate change in
resonance parameters from their current values to the
target values. A sweep rate of 0.0 will produce no
change in resonance parameters.
*/
void setSweepRate(MY_FLOAT aRate);
//! Set the sweep rate in terms of a time value in seconds.
/*!
This method adjusts the sweep rate based on a
given time for the formant parameters to reach
their target values.
*/
void setSweepTime(MY_FLOAT aTime);
//! Input one sample to the filter and return one output.
MY_FLOAT tick(MY_FLOAT sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
protected:
bool dirty;
MY_FLOAT frequency;
MY_FLOAT radius;
MY_FLOAT startFrequency;
MY_FLOAT startRadius;
MY_FLOAT startGain;
MY_FLOAT targetFrequency;
MY_FLOAT targetRadius;
MY_FLOAT targetGain;
MY_FLOAT deltaFrequency;
MY_FLOAT deltaRadius;
MY_FLOAT deltaGain;
MY_FLOAT sweepState;
MY_FLOAT sweepRate;
};
#endif

View File

@@ -1,53 +1,53 @@
/***************************************************/
/*! \class Instrmnt
\brief STK instrument abstract base class.
This class provides a common interface for
all STK instruments.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__INSTRMNT_H)
#define __INSTRMNT_H
#include "Stk.h"
#include <iostream.h>
class Instrmnt : public Stk
{
public:
//! Default constructor.
Instrmnt();
//! Class destructor.
virtual ~Instrmnt();
//! Start a note with the given frequency and amplitude.
virtual void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude) = 0;
//! Stop a note with the given amplitude (speed of decay).
virtual void noteOff(MY_FLOAT amplitude) = 0;
//! Set instrument parameters for a particular frequency.
virtual void setFrequency(MY_FLOAT frequency);
//! Return the last output value.
MY_FLOAT lastOut() const;
//! Compute one output sample.
virtual MY_FLOAT tick() = 0;
//! Computer \e vectorSize outputs and return them in \e vector.
virtual MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
virtual void controlChange(int number, MY_FLOAT value);
protected:
MY_FLOAT lastOutput;
};
#endif
/***************************************************/
/*! \class Instrmnt
\brief STK instrument abstract base class.
This class provides a common interface for
all STK instruments.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__INSTRMNT_H)
#define __INSTRMNT_H
#include "Stk.h"
#include <iostream.h>
class Instrmnt : public Stk
{
public:
//! Default constructor.
Instrmnt();
//! Class destructor.
virtual ~Instrmnt();
//! Start a note with the given frequency and amplitude.
virtual void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude) = 0;
//! Stop a note with the given amplitude (speed of decay).
virtual void noteOff(MY_FLOAT amplitude) = 0;
//! Set instrument parameters for a particular frequency.
virtual void setFrequency(MY_FLOAT frequency);
//! Return the last output value.
MY_FLOAT lastOut() const;
//! Compute one output sample.
virtual MY_FLOAT tick() = 0;
//! Computer \e vectorSize outputs and return them in \e vector.
virtual MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
virtual void controlChange(int number, MY_FLOAT value);
protected:
MY_FLOAT lastOutput;
};
#endif

View File

@@ -23,10 +23,10 @@
class JCRev : public Reverb
{
public:
// Class constructor taking a T60 decay time argument.
//! Class constructor taking a T60 decay time argument.
JCRev(MY_FLOAT T60);
// Class destructor.
//! Class destructor.
~JCRev();
//! Reset and clear all internal state.

View File

@@ -1,44 +1,44 @@
/***************************************************/
/*! \class JetTabl
\brief STK jet table class.
This class implements a flue jet non-linear
function, computed by a polynomial calculation.
Contrary to the name, this is not a "table".
Consult Fletcher and Rossing, Karjalainen,
Cook, and others for more information.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__JETTABL_H)
#define __JETTABL_H
#include "Stk.h"
class JetTabl : public Stk
{
public:
//! Default constructor.
JetTabl();
//! Class destructor.
~JetTabl();
//! Return the last output value.
MY_FLOAT lastOut() const;
//! Return the function value for \e input.
MY_FLOAT tick(MY_FLOAT input);
//! Take \e vectorSize inputs and return the corresponding function values in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
protected:
MY_FLOAT lastOutput;
};
#endif
/***************************************************/
/*! \class JetTabl
\brief STK jet table class.
This class implements a flue jet non-linear
function, computed by a polynomial calculation.
Contrary to the name, this is not a "table".
Consult Fletcher and Rossing, Karjalainen,
Cook, and others for more information.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__JETTABL_H)
#define __JETTABL_H
#include "Stk.h"
class JetTabl : public Stk
{
public:
//! Default constructor.
JetTabl();
//! Class destructor.
~JetTabl();
//! Return the last output value.
MY_FLOAT lastOut() const;
//! Return the function value for \e input.
MY_FLOAT tick(MY_FLOAT input);
//! Take \e vectorSize inputs and return the corresponding function values in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
protected:
MY_FLOAT lastOutput;
};
#endif

View File

@@ -1,147 +1,147 @@
/***************************************************/
/*! \class Messager
\brief STK input control message parser.
This class reads and parses control messages
from a variety of sources, such as a MIDI
port, scorefile, socket connection, or pipe.
MIDI messages are retrieved using the RtMidi
class. All other input sources (scorefile,
socket, or pipe) are assumed to provide SKINI
formatted messages.
For each call to nextMessage(), the active
input sources are queried to see if a new
control message is available.
This class is primarily for use in STK main()
event loops.
One of the original goals in creating this
class was to simplify the message acquisition
process by removing all threads. If the
windoze select() function behaved just like
the unix one, that would have been possible.
Since it does not (it can't be used to poll
STDIN), I am using a thread to acquire
messages from STDIN, which sends these
messages via a socket connection to the
message socket server. Perhaps in the future,
it will be possible to simplify things.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__MESSAGER_H)
#define __MESSSAGER_H
#include "Stk.h"
#include "SKINI.h"
#define MESSAGE_LENGTH 128
#define MAX_MESSAGES 25
#if defined(__STK_REALTIME__)
#include "Thread.h"
#include "Socket.h"
#include "RtMidi.h"
#define STK_MIDI 0x0001
#define STK_PIPE 0x0002
#define STK_SOCKET 0x0004
extern "C" THREAD_RETURN THREAD_TYPE stdinHandler(void * ptr);
#if (defined(__OS_IRIX__) || defined(__OS_LINUX__))
#include <sys/types.h>
#include <sys/time.h>
#endif
#endif // __STK_REALTIME__
class Messager : public Stk
{
public:
//! Constructor performs initialization based on an input mask.
/*!
The default constructor is set to read input from a SKINI
scorefile. The flags STK_MIDI, STK_PIPE, and STK_SOCKET can be
OR'ed together in any combination for multiple "realtime" input
source parsing. For realtime input types, an StkError can be
thrown during instantiation.
*/
Messager(int inputMask = 0);
//! Class destructor.
~Messager();
//! Check for a new input message and return the message type.
/*!
Return type values greater than zero represent valid messages.
If an input scorefile has been completely read or all realtime
input sources have closed, a negative value is returned. If the
return type is zero, no valid messages are present.
*/
long nextMessage(void);
//! Set the delta time (in samples) returned between valid realtime messages. This setting has no affect for scorefile messages.
void setRtDelta(long nSamples);
//! Return the current message "delta time" in samples.
long getDelta(void) const;
//! Return the current message type.
long getType() const;
//! Return the byte two value for the current message.
MY_FLOAT getByteTwo() const;
//! Return the byte three value for the current message.
MY_FLOAT getByteThree() const;
//! Return the channel number for the current message.
long getChannel() const;
protected:
SKINI *skini;
long type;
long channel;
MY_FLOAT byte2;
MY_FLOAT byte3;
int sources;
long delta;
long rtDelta;
char message[MAX_MESSAGES][MESSAGE_LENGTH];
unsigned int messageIndex;
int nMessages;
#if defined(__STK_REALTIME__)
// Check MIDI source for new messages.
bool midiMessage(void);
// Check socket sources for new messages.
bool socketMessage(void);
// Receive and parse socket data.
bool readSocket(int fd);
RtMidi *midi;
Thread *thread;
Socket *soket;
unsigned int nSockets;
fd_set mask;
int maxfd;
int pipefd;
int fd[16];
char error[256];
#endif // __STK_REALTIME__
};
#endif // defined(__MESSAGER_H)
/***************************************************/
/*! \class Messager
\brief STK input control message parser.
This class reads and parses control messages
from a variety of sources, such as a MIDI
port, scorefile, socket connection, or pipe.
MIDI messages are retrieved using the RtMidi
class. All other input sources (scorefile,
socket, or pipe) are assumed to provide SKINI
formatted messages.
For each call to nextMessage(), the active
input sources are queried to see if a new
control message is available.
This class is primarily for use in STK main()
event loops.
One of the original goals in creating this
class was to simplify the message acquisition
process by removing all threads. If the
windoze select() function behaved just like
the unix one, that would have been possible.
Since it does not (it can't be used to poll
STDIN), I am using a thread to acquire
messages from STDIN, which sends these
messages via a socket connection to the
message socket server. Perhaps in the future,
it will be possible to simplify things.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__MESSAGER_H)
#define __MESSSAGER_H
#include "Stk.h"
#include "SKINI.h"
#define MESSAGE_LENGTH 128
#define MAX_MESSAGES 25
#define STK_MIDI 0x0001
#define STK_PIPE 0x0002
#define STK_SOCKET 0x0004
#if defined(__STK_REALTIME__)
#include "Thread.h"
#include "Socket.h"
#include "RtMidi.h"
extern "C" THREAD_RETURN THREAD_TYPE stdinHandler(void * ptr);
#if (defined(__OS_IRIX__) || defined(__OS_LINUX__) || defined(__OS_MACOSX__))
#include <sys/types.h>
#include <sys/time.h>
#endif
#endif // __STK_REALTIME__
class Messager : public Stk
{
public:
//! Constructor performs initialization based on an input mask and an optional socket port.
/*!
The default constructor is set to read input from a SKINI
scorefile. The flags STK_MIDI, STK_PIPE, and STK_SOCKET can be
OR'ed together in any combination for multiple "realtime" input
source parsing. An optional socket port number can be specified
for use when the STK_SOCKET flag is set. For realtime input
types, an StkError can be thrown during instantiation.
*/
Messager(int inputMask = 0, int port = 2001);
//! Class destructor.
~Messager();
//! Check for a new input message and return the message type.
/*!
Return type values greater than zero represent valid messages.
If an input scorefile has been completely read or all realtime
input sources have closed, a negative value is returned. If the
return type is zero, no valid messages are present.
*/
long nextMessage(void);
//! Set the delta time (in samples) returned between valid realtime messages. This setting has no affect for scorefile messages.
void setRtDelta(long nSamples);
//! Return the current message "delta time" in samples.
long getDelta(void) const;
//! Return the current message type.
long getType() const;
//! Return the byte two value for the current message.
MY_FLOAT getByteTwo() const;
//! Return the byte three value for the current message.
MY_FLOAT getByteThree() const;
//! Return the channel number for the current message.
long getChannel() const;
protected:
SKINI *skini;
long type;
long channel;
MY_FLOAT byte2;
MY_FLOAT byte3;
int sources;
long delta;
long rtDelta;
char message[MAX_MESSAGES][MESSAGE_LENGTH];
unsigned int messageIndex;
int nMessages;
#if defined(__STK_REALTIME__)
// Check MIDI source for new messages.
bool midiMessage(void);
// Check socket sources for new messages.
bool socketMessage(void);
// Receive and parse socket data.
bool readSocket(int fd);
RtMidi *midi;
Thread *thread;
Socket *soket;
unsigned int nSockets;
fd_set mask;
int maxfd;
int pipefd;
int fd[16];
char error[256];
#endif // __STK_REALTIME__
};
#endif // defined(__MESSAGER_H)

View File

@@ -49,7 +49,7 @@ class Modulate : public Stk
MY_FLOAT lastOut() const;
protected:
WaveLoop *vibrato;
WaveLoop *vibrato;
SubNoise *noise;
OnePole *filter;
MY_FLOAT vibratoGain;

View File

@@ -25,10 +25,10 @@
class NRev : public Reverb
{
public:
// Class constructor taking a T60 decay time argument.
//! Class constructor taking a T60 decay time argument.
NRev(MY_FLOAT T60);
// Class destructor.
//! Class destructor.
~NRev();
//! Reset and clear all internal state.

View File

@@ -1,43 +1,43 @@
/***************************************************/
/*! \class Noise
\brief STK noise generator.
Generic random number generation 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 - 2002.
*/
/***************************************************/
#if !defined(__NOISE_H)
#define __NOISE_H
#include "Stk.h"
class Noise : public Stk
{
public:
//! Default constructor.
Noise();
//! Class destructor.
virtual ~Noise();
//! Return a random number between -1.0 and 1.0 using rand().
virtual MY_FLOAT tick();
//! Return \e vectorSize random numbers between -1.0 and 1.0 in \e vector.
virtual MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
//! Return the last computed value.
MY_FLOAT lastOut() const;
protected:
MY_FLOAT lastOutput;
};
#endif
/***************************************************/
/*! \class Noise
\brief STK noise generator.
Generic random number generation 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 - 2002.
*/
/***************************************************/
#if !defined(__NOISE_H)
#define __NOISE_H
#include "Stk.h"
class Noise : public Stk
{
public:
//! Default constructor.
Noise();
//! Class destructor.
virtual ~Noise();
//! Return a random number between -1.0 and 1.0 using rand().
virtual MY_FLOAT tick();
//! Return \e vectorSize random numbers between -1.0 and 1.0 in \e vector.
virtual MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
//! Return the last computed value.
MY_FLOAT lastOut() const;
protected:
MY_FLOAT lastOutput;
};
#endif

View File

@@ -1,72 +1,72 @@
/***************************************************/
/*! \class OnePole
\brief STK one-pole filter class.
This protected Filter subclass implements
a one-pole digital filter. A method is
provided for setting the pole position along
the real axis of the z-plane while maintaining
a constant peak filter gain.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__ONEPOLE_H)
#define __ONEPOLE_H
#include "Filter.h"
class OnePole : protected Filter
{
public:
//! Default constructor creates a first-order low-pass filter.
OnePole();
//! Overloaded constructor which sets the pole position during instantiation.
OnePole(MY_FLOAT thePole);
//! Class destructor.
~OnePole();
//! Clears the internal state of the filter.
void clear(void);
//! Set the b[0] coefficient value.
void setB0(MY_FLOAT b0);
//! Set the a[1] coefficient value.
void setA1(MY_FLOAT a1);
//! Set the pole position in the z-plane.
/*!
This method sets the pole position along the real-axis of the
z-plane and normalizes the coefficients for a maximum gain of one.
A positive pole value produces a low-pass filter, while a negative
pole value produces a high-pass filter. This method does not
affect the filter \e gain value.
*/
void setPole(MY_FLOAT thePole);
//! Set the filter gain.
/*!
The gain is applied at the filter input and does not affect the
coefficient values. The default gain value is 1.0.
*/
void setGain(MY_FLOAT theGain);
//! Return the current filter gain.
MY_FLOAT getGain(void) const;
//! Return the last computed output value.
MY_FLOAT lastOut(void) const;
//! Input one sample to the filter and return one output.
MY_FLOAT tick(MY_FLOAT sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
};
#endif
/***************************************************/
/*! \class OnePole
\brief STK one-pole filter class.
This protected Filter subclass implements
a one-pole digital filter. A method is
provided for setting the pole position along
the real axis of the z-plane while maintaining
a constant peak filter gain.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__ONEPOLE_H)
#define __ONEPOLE_H
#include "Filter.h"
class OnePole : protected Filter
{
public:
//! Default constructor creates a first-order low-pass filter.
OnePole();
//! Overloaded constructor which sets the pole position during instantiation.
OnePole(MY_FLOAT thePole);
//! Class destructor.
~OnePole();
//! Clears the internal state of the filter.
void clear(void);
//! Set the b[0] coefficient value.
void setB0(MY_FLOAT b0);
//! Set the a[1] coefficient value.
void setA1(MY_FLOAT a1);
//! Set the pole position in the z-plane.
/*!
This method sets the pole position along the real-axis of the
z-plane and normalizes the coefficients for a maximum gain of one.
A positive pole value produces a low-pass filter, while a negative
pole value produces a high-pass filter. This method does not
affect the filter \e gain value.
*/
void setPole(MY_FLOAT thePole);
//! Set the filter gain.
/*!
The gain is applied at the filter input and does not affect the
coefficient values. The default gain value is 1.0.
*/
void setGain(MY_FLOAT theGain);
//! Return the current filter gain.
MY_FLOAT getGain(void) const;
//! Return the last computed output value.
MY_FLOAT lastOut(void) const;
//! Input one sample to the filter and return one output.
MY_FLOAT tick(MY_FLOAT sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
};
#endif

View File

@@ -1,72 +1,72 @@
/***************************************************/
/*! \class OneZero
\brief STK one-zero filter class.
This protected Filter subclass implements
a one-zero digital filter. A method is
provided for setting the zero position
along the real axis of the z-plane while
maintaining a constant filter gain.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__ONEZERO_H)
#define __ONEZERO_H
#include "Filter.h"
class OneZero : protected Filter
{
public:
//! Default constructor creates a first-order low-pass filter.
OneZero();
//! Overloaded constructor which sets the zero position during instantiation.
OneZero(MY_FLOAT theZero);
//! Class destructor.
~OneZero();
//! Clears the internal state of the filter.
void clear(void);
//! Set the b[0] coefficient value.
void setB0(MY_FLOAT b0);
//! Set the b[1] coefficient value.
void setB1(MY_FLOAT b1);
//! Set the zero position in the z-plane.
/*!
This method sets the zero position along the real-axis of the
z-plane and normalizes the coefficients for a maximum gain of one.
A positive zero value produces a high-pass filter, while a
negative zero value produces a low-pass filter. This method does
not affect the filter \e gain value.
*/
void setZero(MY_FLOAT theZero);
//! Set the filter gain.
/*!
The gain is applied at the filter input and does not affect the
coefficient values. The default gain value is 1.0.
*/
void setGain(MY_FLOAT theGain);
//! Return the current filter gain.
MY_FLOAT getGain(void) const;
//! Return the last computed output value.
MY_FLOAT lastOut(void) const;
//! Input one sample to the filter and return one output.
MY_FLOAT tick(MY_FLOAT sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
};
#endif
/***************************************************/
/*! \class OneZero
\brief STK one-zero filter class.
This protected Filter subclass implements
a one-zero digital filter. A method is
provided for setting the zero position
along the real axis of the z-plane while
maintaining a constant filter gain.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__ONEZERO_H)
#define __ONEZERO_H
#include "Filter.h"
class OneZero : protected Filter
{
public:
//! Default constructor creates a first-order low-pass filter.
OneZero();
//! Overloaded constructor which sets the zero position during instantiation.
OneZero(MY_FLOAT theZero);
//! Class destructor.
~OneZero();
//! Clears the internal state of the filter.
void clear(void);
//! Set the b[0] coefficient value.
void setB0(MY_FLOAT b0);
//! Set the b[1] coefficient value.
void setB1(MY_FLOAT b1);
//! Set the zero position in the z-plane.
/*!
This method sets the zero position along the real-axis of the
z-plane and normalizes the coefficients for a maximum gain of one.
A positive zero value produces a high-pass filter, while a
negative zero value produces a low-pass filter. This method does
not affect the filter \e gain value.
*/
void setZero(MY_FLOAT theZero);
//! Set the filter gain.
/*!
The gain is applied at the filter input and does not affect the
coefficient values. The default gain value is 1.0.
*/
void setGain(MY_FLOAT theGain);
//! Return the current filter gain.
MY_FLOAT getGain(void) const;
//! Return the last computed output value.
MY_FLOAT lastOut(void) const;
//! Input one sample to the filter and return one output.
MY_FLOAT tick(MY_FLOAT sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
};
#endif

View File

@@ -22,11 +22,11 @@
class PRCRev : public Reverb
{
public:
// Class constructor taking a T60 decay time argument.
public:
//! Class constructor taking a T60 decay time argument.
PRCRev(MY_FLOAT T60);
// Class destructor.
//! Class destructor.
~PRCRev();
//! Reset and clear all internal state.
@@ -35,11 +35,11 @@ class PRCRev : public Reverb
//! Compute one output sample.
MY_FLOAT tick(MY_FLOAT input);
protected:
Delay *allpassDelays[2];
Delay *combDelays[2];
MY_FLOAT allpassCoefficient;
MY_FLOAT combCoefficient[2];
protected:
Delay *allpassDelays[2];
Delay *combDelays[2];
MY_FLOAT allpassCoefficient;
MY_FLOAT combCoefficient[2];
};

51
include/Phonemes.h Normal file
View File

@@ -0,0 +1,51 @@
/***************************************************/
/*! \class Phonemes
\brief STK phonemes table.
This class does nothing other than declare a
set of 32 static phoneme formant parameters
and provide access to those values.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__PHONEMES_H)
#define __PHONEMES_H
#include "Stk.h"
class Phonemes
{
public:
Phonemes(void);
~Phonemes(void);
//! Returns the phoneme name for the given index (0-31).
static const char *name( unsigned int index );
//! Returns the voiced component gain for the given phoneme index (0-31).
static MY_FLOAT voiceGain( unsigned int index );
//! Returns the unvoiced component gain for the given phoneme index (0-31).
static MY_FLOAT noiseGain( unsigned int index );
//! Returns the formant frequency for the given phoneme index (0-31) and partial (0-3).
static MY_FLOAT formantFrequency( unsigned int index, unsigned int partial );
//! Returns the formant radius for the given phoneme index (0-31) and partial (0-3).
static MY_FLOAT formantRadius( unsigned int index, unsigned int partial );
//! Returns the formant gain for the given phoneme index (0-31) and partial (0-3).
static MY_FLOAT formantGain( unsigned int index, unsigned int partial );
private:
static const char phonemeNames[][4];
static const MY_FLOAT phonemeGains[][2];
static const MY_FLOAT phonemeParameters[][4][3];
};
#endif

View File

@@ -43,7 +43,7 @@ class PitShift : public Stk
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
protected:
Delay *delayLine[2];
DelayL *delayLine[2];
MY_FLOAT lastOutput;
MY_FLOAT delay[2];
MY_FLOAT env[2];

View File

@@ -1,70 +1,70 @@
/***************************************************/
/*! \class ReedTabl
\brief STK reed table class.
This class implements a simple one breakpoint,
non-linear reed function, as described by
Smith (1986). This function is based on a
memoryless non-linear spring model of the reed
(the reed mass is ignored) which saturates when
the reed collides with the mouthpiece facing.
See McIntyre, Schumacher, & Woodhouse (1983),
Smith (1986), Hirschman, Cook, Scavone, and
others for more information.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__REEDTABL_H)
#define __REEDTABL_H
#include "Stk.h"
class ReedTabl : public Stk
{
public:
//! Default constructor.
ReedTabl();
//! Class destructor.
~ReedTabl();
//! Set the table offset value.
/*!
The table offset roughly corresponds to the size
of the initial reed tip opening (a greater offset
represents a smaller opening).
*/
void setOffset(MY_FLOAT aValue);
//! Set the table slope value.
/*!
The table slope roughly corresponds to the reed
stiffness (a greater slope represents a harder
reed).
*/
void setSlope(MY_FLOAT aValue);
//! Return the last output value.
MY_FLOAT lastOut() const;
//! Return the function value for \e input.
/*!
The function input represents the differential
pressure across the reeds.
*/
MY_FLOAT tick(MY_FLOAT input);
//! Take \e vectorSize inputs and return the corresponding function values in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
protected:
MY_FLOAT offSet;
MY_FLOAT slope;
MY_FLOAT lastOutput;
};
#endif
/***************************************************/
/*! \class ReedTabl
\brief STK reed table class.
This class implements a simple one breakpoint,
non-linear reed function, as described by
Smith (1986). This function is based on a
memoryless non-linear spring model of the reed
(the reed mass is ignored) which saturates when
the reed collides with the mouthpiece facing.
See McIntyre, Schumacher, & Woodhouse (1983),
Smith (1986), Hirschman, Cook, Scavone, and
others for more information.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__REEDTABL_H)
#define __REEDTABL_H
#include "Stk.h"
class ReedTabl : public Stk
{
public:
//! Default constructor.
ReedTabl();
//! Class destructor.
~ReedTabl();
//! Set the table offset value.
/*!
The table offset roughly corresponds to the size
of the initial reed tip opening (a greater offset
represents a smaller opening).
*/
void setOffset(MY_FLOAT aValue);
//! Set the table slope value.
/*!
The table slope roughly corresponds to the reed
stiffness (a greater slope represents a harder
reed).
*/
void setSlope(MY_FLOAT aValue);
//! Return the last output value.
MY_FLOAT lastOut() const;
//! Return the function value for \e input.
/*!
The function input represents the differential
pressure across the reeds.
*/
MY_FLOAT tick(MY_FLOAT input);
//! Take \e vectorSize inputs and return the corresponding function values in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
protected:
MY_FLOAT offSet;
MY_FLOAT slope;
MY_FLOAT lastOutput;
};
#endif

View File

@@ -1,434 +1,525 @@
/******************************************/
/*
RtAudio - realtime sound I/O C++ class
by Gary P. Scavone, 2001-2002.
*/
/******************************************/
#if !defined(__RTAUDIO_H)
#define __RTAUDIO_H
#include <map>
#if defined(__LINUX_ALSA__)
#include <alsa/asoundlib.h>
#include <pthread.h>
#include <unistd.h>
#define THREAD_TYPE
typedef snd_pcm_t *AUDIO_HANDLE;
typedef int DEVICE_ID;
typedef pthread_t THREAD_HANDLE;
typedef pthread_mutex_t MUTEX;
#elif defined(__LINUX_OSS__)
#include <pthread.h>
#include <unistd.h>
#define THREAD_TYPE
typedef int AUDIO_HANDLE;
typedef int DEVICE_ID;
typedef pthread_t THREAD_HANDLE;
typedef pthread_mutex_t MUTEX;
#elif defined(__WINDOWS_DS__)
#include <windows.h>
#include <process.h>
// The following struct is used to hold the extra variables
// specific to the DirectSound implementation.
typedef struct {
void * object;
void * buffer;
UINT bufferPointer;
} AUDIO_HANDLE;
#define THREAD_TYPE __stdcall
typedef LPGUID DEVICE_ID;
typedef unsigned long THREAD_HANDLE;
typedef CRITICAL_SECTION MUTEX;
#elif defined(__IRIX_AL__)
#include <dmedia/audio.h>
#include <pthread.h>
#include <unistd.h>
#define THREAD_TYPE
typedef ALport AUDIO_HANDLE;
typedef int DEVICE_ID;
typedef pthread_t THREAD_HANDLE;
typedef pthread_mutex_t MUTEX;
#endif
// *************************************************** //
//
// RtError class declaration.
//
// *************************************************** //
class RtError
{
public:
enum TYPE {
WARNING,
DEBUG_WARNING,
UNSPECIFIED,
NO_DEVICES_FOUND,
INVALID_DEVICE,
INVALID_STREAM,
MEMORY_ERROR,
INVALID_PARAMETER,
DRIVER_ERROR,
SYSTEM_ERROR,
THREAD_ERROR
};
protected:
char error_message[256];
TYPE type;
public:
//! The constructor.
RtError(const char *p, TYPE tipe = RtError::UNSPECIFIED);
//! The destructor.
virtual ~RtError(void);
//! Prints "thrown" error message to stdout.
virtual void printMessage(void);
//! Returns the "thrown" error message TYPE.
virtual const TYPE& getType(void) { return type; }
//! Returns the "thrown" error message string.
virtual const char *getMessage(void) { return error_message; }
};
// *************************************************** //
//
// RtAudio class declaration.
//
// *************************************************** //
class RtAudio
{
public:
// Support for signed integers and floats. Audio data fed to/from
// the tickStream() routine is assumed to ALWAYS be in host
// byte order. The internal routines will automatically take care of
// any necessary byte-swapping between the host format and the
// soundcard. Thus, endian-ness is not a concern in the following
// format definitions.
typedef unsigned long RTAUDIO_FORMAT;
static const RTAUDIO_FORMAT RTAUDIO_SINT8;
static const RTAUDIO_FORMAT RTAUDIO_SINT16;
static const RTAUDIO_FORMAT RTAUDIO_SINT24; /*!< Upper 3 bytes of 32-bit integer. */
static const RTAUDIO_FORMAT RTAUDIO_SINT32;
static const RTAUDIO_FORMAT RTAUDIO_FLOAT32; /*!< Normalized between plus/minus 1.0. */
static const RTAUDIO_FORMAT RTAUDIO_FLOAT64; /*!< Normalized between plus/minus 1.0. */
//static const int MAX_SAMPLE_RATES = 14;
enum { MAX_SAMPLE_RATES = 14 };
typedef int (*RTAUDIO_CALLBACK)(char *buffer, int bufferSize, void *userData);
typedef struct {
char name[128];
DEVICE_ID id[2]; /*!< No value reported by getDeviceInfo(). */
bool probed; /*!< true if the device capabilities were successfully probed. */
int maxOutputChannels;
int maxInputChannels;
int maxDuplexChannels;
int minOutputChannels;
int minInputChannels;
int minDuplexChannels;
bool hasDuplexSupport; /*!< true if device supports duplex mode. */
int nSampleRates; /*!< Number of discrete rates or -1 if range supported. */
int sampleRates[MAX_SAMPLE_RATES]; /*!< Supported rates or (min, max) if range. */
RTAUDIO_FORMAT nativeFormats; /*!< Bit mask of supported data formats. */
} RTAUDIO_DEVICE;
//! The default constructor.
/*!
Probes the system to make sure at least one audio
input/output device is available and determines
the api-specific identifier for each device found.
An RtError error can be thrown if no devices are
found or if a memory allocation error occurs.
*/
RtAudio();
//! A constructor which can be used to open a stream during instantiation.
/*!
The specified output and/or input device identifiers correspond
to those enumerated via the getDeviceInfo() method. If device =
0, the default or first available devices meeting the given
parameters is selected. If an output or input channel value is
zero, the corresponding device value is ignored. When a stream is
successfully opened, its identifier is returned via the "streamId"
pointer. An RtError can be thrown if no devices are found
for the given parameters, if a memory allocation error occurs, or
if a driver error occurs. \sa openStream()
*/
RtAudio(int *streamId,
int outputDevice, int outputChannels,
int inputDevice, int inputChannels,
RTAUDIO_FORMAT format, int sampleRate,
int *bufferSize, int numberOfBuffers);
//! The destructor.
/*!
Stops and closes any open streams and devices and deallocates
buffer and structure memory.
*/
~RtAudio();
//! A public method for opening a stream with the specified parameters.
/*!
If successful, the opened stream ID is returned. Otherwise, an
RtError is thrown.
\param outputDevice: If equal to 0, the default or first device
found meeting the given parameters is opened. Otherwise, the
device number should correspond to one of those enumerated via
the getDeviceInfo() method.
\param outputChannels: The desired number of output channels. If
equal to zero, the outputDevice identifier is ignored.
\param inputDevice: If equal to 0, the default or first device
found meeting the given parameters is opened. Otherwise, the
device number should correspond to one of those enumerated via
the getDeviceInfo() method.
\param inputChannels: The desired number of input channels. If
equal to zero, the inputDevice identifier is ignored.
\param format: An RTAUDIO_FORMAT specifying the desired sample data format.
\param sampleRate: The desired sample rate (sample frames per second).
\param *bufferSize: A pointer value indicating the desired internal buffer
size in sample frames. The actual value used by the device is
returned via the same pointer. A value of zero can be specified,
in which case the lowest allowable value is determined.
\param numberOfBuffers: A value which can be used to help control device
latency. More buffers typically result in more robust performance,
though at a cost of greater latency. A value of zero can be
specified, in which case the lowest allowable value is used.
*/
int openStream(int outputDevice, int outputChannels,
int inputDevice, int inputChannels,
RTAUDIO_FORMAT format, int sampleRate,
int *bufferSize, int numberOfBuffers);
//! A public method which sets a user-defined callback function for a given stream.
/*!
This method assigns a callback function to a specific,
previously opened stream for non-blocking stream functionality. A
separate process is initiated, though the user function is called
only when the stream is "running" (between calls to the
startStream() and stopStream() methods, respectively). The
callback process remains active for the duration of the stream and
is automatically shutdown when the stream is closed (via the
closeStream() method or by object destruction). The callback
process can also be shutdown and the user function de-referenced
through an explicit call to the cancelStreamCallback() method.
Note that a single stream can use only blocking or callback
functionality at the same time, though it is possible to alternate
modes on the same stream through the use of the
setStreamCallback() and cancelStreamCallback() methods (the
blocking tickStream() method can be used before a callback is set
and/or after a callback is cancelled). An RtError will be
thrown for an invalid device argument.
*/
void setStreamCallback(int streamId, RTAUDIO_CALLBACK callback, void *userData);
//! A public method which cancels a callback process and function for a given stream.
/*!
This method shuts down a callback process and de-references the
user function for a specific stream. Callback functionality can
subsequently be restarted on the stream via the
setStreamCallback() method. An RtError will be thrown for an
invalid device argument.
*/
void cancelStreamCallback(int streamId);
//! A public method which returns the number of audio devices found.
int getDeviceCount(void);
//! Fill a user-supplied RTAUDIO_DEVICE structure for a specified device.
/*!
Any device between 0 and getDeviceCount()-1 is valid. If a
device is busy or otherwise unavailable, the structure member
"probed" has a value of "false". The system default input and
output devices are referenced by device identifier = 0. On
systems which allow dynamic default device settings, the default
devices are not identified by name (specific device enumerations
are assigned device identifiers > 0). An RtError will be
thrown for an invalid device argument.
*/
void getDeviceInfo(int device, RTAUDIO_DEVICE *info);
//! A public method which returns a pointer to the buffer for an open stream.
/*!
The user should fill and/or read the buffer data in interleaved format
and then call the tickStream() method. An RtError will be
thrown for an invalid stream identifier.
*/
char * const getStreamBuffer(int streamId);
//! Public method used to trigger processing of input/output data for a stream.
/*!
This method blocks until all buffer data is read/written. An
RtError will be thrown for an invalid stream identifier or if
a driver error occurs.
*/
void tickStream(int streamId);
//! Public method which closes a stream and frees any associated buffers.
/*!
If an invalid stream identifier is specified, this method
issues a warning and returns (an RtError is not thrown).
*/
void closeStream(int streamId);
//! Public method which starts a stream.
/*!
An RtError will be thrown for an invalid stream identifier
or if a driver error occurs.
*/
void startStream(int streamId);
//! Stop a stream, allowing any samples remaining in the queue to be played out and/or read in.
/*!
An RtError will be thrown for an invalid stream identifier
or if a driver error occurs.
*/
void stopStream(int streamId);
//! Stop a stream, discarding any samples remaining in the input/output queue.
/*!
An RtError will be thrown for an invalid stream identifier
or if a driver error occurs.
*/
void abortStream(int streamId);
//! Queries a stream to determine whether a call to the tickStream() method will block.
/*!
A return value of 0 indicates that the stream will NOT block. A positive
return value indicates the number of sample frames that cannot yet be
processed without blocking.
*/
int streamWillBlock(int streamId);
protected:
private:
static const unsigned int SAMPLE_RATES[MAX_SAMPLE_RATES];
enum { FAILURE, SUCCESS };
enum STREAM_MODE {
PLAYBACK,
RECORD,
DUPLEX,
UNINITIALIZED = -75
};
enum STREAM_STATE {
STREAM_STOPPED,
STREAM_RUNNING
};
typedef struct {
int device[2]; // Playback and record, respectively.
STREAM_MODE mode; // PLAYBACK, RECORD, or DUPLEX.
AUDIO_HANDLE handle[2]; // Playback and record handles, respectively.
STREAM_STATE state; // STOPPED or RUNNING
char *userBuffer;
char *deviceBuffer;
bool doConvertBuffer[2]; // Playback and record, respectively.
bool deInterleave[2]; // Playback and record, respectively.
bool doByteSwap[2]; // Playback and record, respectively.
int sampleRate;
int bufferSize;
int nBuffers;
int nUserChannels[2]; // Playback and record, respectively.
int nDeviceChannels[2]; // Playback and record channels, respectively.
RTAUDIO_FORMAT userFormat;
RTAUDIO_FORMAT deviceFormat[2]; // Playback and record, respectively.
bool usingCallback;
THREAD_HANDLE thread;
MUTEX mutex;
RTAUDIO_CALLBACK callback;
void *userData;
} RTAUDIO_STREAM;
typedef signed short INT16;
typedef signed int INT32;
typedef float FLOAT32;
typedef double FLOAT64;
char message[256];
int nDevices;
RTAUDIO_DEVICE *devices;
std::map<int, void *> streams;
//! Private error method to allow global control over error handling.
void error(RtError::TYPE type);
/*!
Private method to count the system audio devices, allocate the
RTAUDIO_DEVICE structures, and probe the device capabilities.
*/
void initialize(void);
//! Private method to clear an RTAUDIO_DEVICE structure.
void clearDeviceInfo(RTAUDIO_DEVICE *info);
/*!
Private method which attempts to fill an RTAUDIO_DEVICE
structure for a given device. If an error is encountered during
the probe, a "warning" message is reported and the value of
"probed" remains false (no exception is thrown). A successful
probe is indicated by probed = true.
*/
void probeDeviceInfo(RTAUDIO_DEVICE *info);
/*!
Private method which attempts to open a device with the given parameters.
If an error is encountered during the probe, a "warning" message is
reported and FAILURE is returned (no exception is thrown). A
successful probe is indicated by a return value of SUCCESS.
*/
bool probeDeviceOpen(int device, RTAUDIO_STREAM *stream,
STREAM_MODE mode, int channels,
int sampleRate, RTAUDIO_FORMAT format,
int *bufferSize, int numberOfBuffers);
/*!
Private common method used to check validity of a user-passed
stream ID. When the ID is valid, this method returns a pointer to
an RTAUDIO_STREAM structure (in the form of a void pointer).
Otherwise, an "invalid identifier" exception is thrown.
*/
void *verifyStream(int streamId);
/*!
Private method used to perform format, channel number, and/or interleaving
conversions between the user and device buffers.
*/
void convertStreamBuffer(RTAUDIO_STREAM *stream, STREAM_MODE mode);
//! Private method used to perform byte-swapping on buffers.
void byteSwapBuffer(char *buffer, int samples, RTAUDIO_FORMAT format);
//! Private method which returns the number of bytes for a given format.
int formatBytes(RTAUDIO_FORMAT format);
};
// Uncomment the following definition to have extra information spewed to stderr.
//#define RTAUDIO_DEBUG
#endif
/************************************************************************/
/*! \class RtAudio
\brief Realtime audio i/o C++ class.
RtAudio provides a common API (Application Programming Interface)
for realtime audio input/output across Linux (native ALSA and
OSS), SGI, Macintosh OS X (CoreAudio), and Windows (DirectSound
and ASIO) operating systems.
RtAudio WWW site: http://www-ccrma.stanford.edu/~gary/rtaudio/
RtAudio: a realtime audio i/o C++ class
Copyright (c) 2001-2002 Gary P. Scavone
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
Any person wishing to distribute modifications to the Software is
requested to send the modifications to the original developer so that
they can be incorporated into the canonical version.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/************************************************************************/
#if !defined(__RTAUDIO_H)
#define __RTAUDIO_H
#include <map>
#if defined(__LINUX_ALSA__)
#include <alsa/asoundlib.h>
#include <pthread.h>
#include <unistd.h>
typedef snd_pcm_t *AUDIO_HANDLE;
typedef int DEVICE_ID;
typedef pthread_t THREAD_HANDLE;
typedef pthread_mutex_t MUTEX;
#elif defined(__LINUX_OSS__)
#include <pthread.h>
#include <unistd.h>
typedef int AUDIO_HANDLE;
typedef int DEVICE_ID;
typedef pthread_t THREAD_HANDLE;
typedef pthread_mutex_t MUTEX;
#elif defined(__WINDOWS_DS__)
#include <windows.h>
#include <process.h>
// The following struct is used to hold the extra variables
// specific to the DirectSound implementation.
typedef struct {
void * object;
void * buffer;
UINT bufferPointer;
} AUDIO_HANDLE;
typedef LPGUID DEVICE_ID;
typedef unsigned long THREAD_HANDLE;
typedef CRITICAL_SECTION MUTEX;
#elif defined(__WINDOWS_ASIO__)
#include <windows.h>
#include <process.h>
typedef int AUDIO_HANDLE;
typedef int DEVICE_ID;
typedef unsigned long THREAD_HANDLE;
typedef CRITICAL_SECTION MUTEX;
#elif defined(__IRIX_AL__)
#include <dmedia/audio.h>
#include <pthread.h>
#include <unistd.h>
typedef ALport AUDIO_HANDLE;
typedef long DEVICE_ID;
typedef pthread_t THREAD_HANDLE;
typedef pthread_mutex_t MUTEX;
#elif defined(__MACOSX_CORE__)
#include <CoreAudio/AudioHardware.h>
#include <pthread.h>
typedef unsigned int AUDIO_HANDLE;
typedef AudioDeviceID DEVICE_ID;
typedef pthread_t THREAD_HANDLE;
typedef pthread_mutex_t MUTEX;
#endif
/************************************************************************/
/*! \class RtError
\brief Exception handling class for RtAudio.
The RtError class is quite simple but it does allow errors to be
"caught" by RtError::TYPE. Almost all RtAudio methods can "throw"
an RtError, most typically if an invalid stream identifier is
supplied to a method or a driver error occurs. There are a number
of cases within RtAudio where warning messages may be displayed
but an exception is not thrown. There is a private RtAudio method,
error(), which can be modified to globally control how these
messages are handled and reported.
*/
/************************************************************************/
class RtError
{
public:
//! Defined RtError types.
enum TYPE {
WARNING,
DEBUG_WARNING,
UNSPECIFIED,
NO_DEVICES_FOUND,
INVALID_DEVICE,
INVALID_STREAM,
MEMORY_ERROR,
INVALID_PARAMETER,
DRIVER_ERROR,
SYSTEM_ERROR,
THREAD_ERROR
};
protected:
char error_message[256];
TYPE type;
public:
//! The constructor.
RtError(const char *p, TYPE tipe = RtError::UNSPECIFIED);
//! The destructor.
virtual ~RtError(void);
//! Prints "thrown" error message to stdout.
virtual void printMessage(void);
//! Returns the "thrown" error message TYPE.
virtual const TYPE& getType(void) { return type; }
//! Returns the "thrown" error message string.
virtual const char *getMessage(void) { return error_message; }
};
// This public structure type is used to pass callback information
// between the private RtAudio stream structure and global callback
// handling functions.
typedef struct {
void *object; // Used as a "this" pointer.
int streamId;
DEVICE_ID device[2];
THREAD_HANDLE thread;
void *callback;
void *buffers;
unsigned long waitTime;
bool blockTick;
bool stopStream;
bool usingCallback;
void *userData;
} CALLBACK_INFO;
// *************************************************** //
//
// RtAudio class declaration.
//
// *************************************************** //
class RtAudio
{
public:
// Support for signed integers and floats. Audio data fed to/from
// the tickStream() routine is assumed to ALWAYS be in host
// byte order. The internal routines will automatically take care of
// any necessary byte-swapping between the host format and the
// soundcard. Thus, endian-ness is not a concern in the following
// format definitions.
typedef unsigned long RTAUDIO_FORMAT;
static const RTAUDIO_FORMAT RTAUDIO_SINT8; /*!< 8-bit signed integer. */
static const RTAUDIO_FORMAT RTAUDIO_SINT16; /*!< 16-bit signed integer. */
static const RTAUDIO_FORMAT RTAUDIO_SINT24; /*!< Upper 3 bytes of 32-bit signed integer. */
static const RTAUDIO_FORMAT RTAUDIO_SINT32; /*!< 32-bit signed integer. */
static const RTAUDIO_FORMAT RTAUDIO_FLOAT32; /*!< Normalized between plus/minus 1.0. */
static const RTAUDIO_FORMAT RTAUDIO_FLOAT64; /*!< Normalized between plus/minus 1.0. */
//static const int MAX_SAMPLE_RATES = 14;
enum { MAX_SAMPLE_RATES = 14 };
typedef int (*RTAUDIO_CALLBACK)(char *buffer, int bufferSize, void *userData);
//! The public device information structure for passing queried values.
typedef struct {
char name[128]; /*!< Character string device identifier. */
DEVICE_ID id[2]; /* No value reported by getDeviceInfo(). */
bool probed; /*!< true if the device capabilities were successfully probed. */
int maxOutputChannels; /*!< Maximum output channels supported by device. */
int maxInputChannels; /*!< Maximum input channels supported by device. */
int maxDuplexChannels; /*!< Maximum simultaneous input/output channels supported by device. */
int minOutputChannels; /*!< Minimum output channels supported by device. */
int minInputChannels; /*!< Minimum input channels supported by device. */
int minDuplexChannels; /*!< Minimum simultaneous input/output channels supported by device. */
bool hasDuplexSupport; /*!< true if device supports duplex mode. */
bool isDefault; /*!< true if this is the default output or input device. */
int nSampleRates; /*!< Number of discrete rates or -1 if range supported. */
int sampleRates[MAX_SAMPLE_RATES]; /*!< Supported rates or (min, max) if range. */
RTAUDIO_FORMAT nativeFormats; /*!< Bit mask of supported data formats. */
} RTAUDIO_DEVICE;
//! The default constructor.
/*!
Probes the system to make sure at least one audio input/output
device is available and determines the api-specific identifier for
each device found. An RtError error can be thrown if no devices
are found or if a memory allocation error occurs.
*/
RtAudio();
//! A constructor which can be used to open a stream during instantiation.
/*!
The specified output and/or input device identifiers correspond
to those enumerated via the getDeviceInfo() method. If device =
0, the default or first available devices meeting the given
parameters is selected. If an output or input channel value is
zero, the corresponding device value is ignored. When a stream is
successfully opened, its identifier is returned via the "streamId"
pointer. An RtError can be thrown if no devices are found
for the given parameters, if a memory allocation error occurs, or
if a driver error occurs. \sa openStream()
*/
RtAudio(int *streamId,
int outputDevice, int outputChannels,
int inputDevice, int inputChannels,
RTAUDIO_FORMAT format, int sampleRate,
int *bufferSize, int numberOfBuffers);
//! The destructor.
/*!
Stops and closes any open streams and devices and deallocates
buffer and structure memory.
*/
~RtAudio();
//! A public method for opening a stream with the specified parameters.
/*!
If successful, the opened stream ID is returned. Otherwise, an
RtError is thrown.
\param outputDevice: If equal to 0, the default or first device
found meeting the given parameters is opened. Otherwise, the
device number should correspond to one of those enumerated via
the getDeviceInfo() method.
\param outputChannels: The desired number of output channels. If
equal to zero, the outputDevice identifier is ignored.
\param inputDevice: If equal to 0, the default or first device
found meeting the given parameters is opened. Otherwise, the
device number should correspond to one of those enumerated via
the getDeviceInfo() method.
\param inputChannels: The desired number of input channels. If
equal to zero, the inputDevice identifier is ignored.
\param format: An RTAUDIO_FORMAT specifying the desired sample data format.
\param sampleRate: The desired sample rate (sample frames per second).
\param *bufferSize: A pointer value indicating the desired internal buffer
size in sample frames. The actual value used by the device is
returned via the same pointer. A value of zero can be specified,
in which case the lowest allowable value is determined.
\param numberOfBuffers: A value which can be used to help control device
latency. More buffers typically result in more robust performance,
though at a cost of greater latency. A value of zero can be
specified, in which case the lowest allowable value is used.
*/
int openStream(int outputDevice, int outputChannels,
int inputDevice, int inputChannels,
RTAUDIO_FORMAT format, int sampleRate,
int *bufferSize, int numberOfBuffers);
//! A public method which sets a user-defined callback function for a given stream.
/*!
This method assigns a callback function to a specific,
previously opened stream for non-blocking stream functionality. A
separate process is initiated, though the user function is called
only when the stream is "running" (between calls to the
startStream() and stopStream() methods, respectively). The
callback process remains active for the duration of the stream and
is automatically shutdown when the stream is closed (via the
closeStream() method or by object destruction). The callback
process can also be shutdown and the user function de-referenced
through an explicit call to the cancelStreamCallback() method.
Note that a single stream can use only blocking or callback
functionality at the same time, though it is possible to alternate
modes on the same stream through the use of the
setStreamCallback() and cancelStreamCallback() methods (the
blocking tickStream() method can be used before a callback is set
and/or after a callback is cancelled). An RtError will be thrown
for an invalid device argument.
*/
void setStreamCallback(int streamId, RTAUDIO_CALLBACK callback, void *userData);
//! A public method which cancels a callback process and function for a given stream.
/*!
This method shuts down a callback process and de-references the
user function for a specific stream. Callback functionality can
subsequently be restarted on the stream via the
setStreamCallback() method. An RtError will be thrown for an
invalid device argument.
*/
void cancelStreamCallback(int streamId);
//! A public method which returns the number of audio devices found.
int getDeviceCount(void);
//! Fill a user-supplied RTAUDIO_DEVICE structure for a specified device number.
/*!
Any device integer between 1 and getDeviceCount() is valid. If
a device is busy or otherwise unavailable, the structure member
"probed" will have a value of "false" and all other members are
undefined. If the specified device is the current default input
or output device, the "isDefault" member will have a value of
"true". An RtError will be thrown for an invalid device argument.
*/
void getDeviceInfo(int device, RTAUDIO_DEVICE *info);
//! A public method which returns a pointer to the buffer for an open stream.
/*!
The user should fill and/or read the buffer data in interleaved format
and then call the tickStream() method. An RtError will be
thrown for an invalid stream identifier.
*/
char * const getStreamBuffer(int streamId);
//! Public method used to trigger processing of input/output data for a stream.
/*!
This method blocks until all buffer data is read/written. An
RtError will be thrown for an invalid stream identifier or if
a driver error occurs.
*/
void tickStream(int streamId);
//! Public method which closes a stream and frees any associated buffers.
/*!
If an invalid stream identifier is specified, this method
issues a warning and returns (an RtError is not thrown).
*/
void closeStream(int streamId);
//! Public method which starts a stream.
/*!
An RtError will be thrown for an invalid stream identifier
or if a driver error occurs.
*/
void startStream(int streamId);
//! Stop a stream, allowing any samples remaining in the queue to be played out and/or read in.
/*!
An RtError will be thrown for an invalid stream identifier
or if a driver error occurs.
*/
void stopStream(int streamId);
//! Stop a stream, discarding any samples remaining in the input/output queue.
/*!
An RtError will be thrown for an invalid stream identifier
or if a driver error occurs.
*/
void abortStream(int streamId);
//! Queries a stream to determine whether a call to the tickStream() method will block.
/*!
A return value of 0 indicates that the stream will NOT block. A positive
return value indicates the number of sample frames that cannot yet be
processed without blocking.
*/
int streamWillBlock(int streamId);
#if (defined(__MACOSX_CORE__) || defined(__WINDOWS_ASIO__))
// This function is intended for internal use only. It must be
// public because it is called by the internal callback handler,
// which is not a member of RtAudio. External use of this function
// will most likely produce highly undesireable results!
void callbackEvent(int streamId, DEVICE_ID deviceId, void *inData, void *outData);
#endif
protected:
private:
static const unsigned int SAMPLE_RATES[MAX_SAMPLE_RATES];
enum { FAILURE, SUCCESS };
enum STREAM_MODE {
OUTPUT,
INPUT,
DUPLEX,
UNINITIALIZED = -75
};
enum STREAM_STATE {
STREAM_STOPPED,
STREAM_RUNNING
};
typedef struct {
int device[2]; // Playback and record, respectively.
STREAM_MODE mode; // OUTPUT, INPUT, or DUPLEX.
AUDIO_HANDLE handle[2]; // Playback and record handles, respectively.
STREAM_STATE state; // STOPPED or RUNNING
char *userBuffer;
char *deviceBuffer;
bool doConvertBuffer[2]; // Playback and record, respectively.
bool deInterleave[2]; // Playback and record, respectively.
bool doByteSwap[2]; // Playback and record, respectively.
int sampleRate;
int bufferSize;
int nBuffers;
int nUserChannels[2]; // Playback and record, respectively.
int nDeviceChannels[2]; // Playback and record channels, respectively.
RTAUDIO_FORMAT userFormat;
RTAUDIO_FORMAT deviceFormat[2]; // Playback and record, respectively.
MUTEX mutex;
CALLBACK_INFO callbackInfo;
} RTAUDIO_STREAM;
typedef signed short INT16;
typedef signed int INT32;
typedef float FLOAT32;
typedef double FLOAT64;
char message[256];
int nDevices;
RTAUDIO_DEVICE *devices;
std::map<int, void *> streams;
//! Private error method to allow global control over error handling.
void error(RtError::TYPE type);
/*!
Private method to count the system audio devices, allocate the
RTAUDIO_DEVICE structures, and probe the device capabilities.
*/
void initialize(void);
/*!
Private method which returns the index in the devices array to
the default input device.
*/
int getDefaultInputDevice(void);
/*!
Private method which returns the index in the devices array to
the default output device.
*/
int getDefaultOutputDevice(void);
//! Private method to clear an RTAUDIO_DEVICE structure.
void clearDeviceInfo(RTAUDIO_DEVICE *info);
/*!
Private method which attempts to fill an RTAUDIO_DEVICE
structure for a given device. If an error is encountered during
the probe, a "warning" message is reported and the value of
"probed" remains false (no exception is thrown). A successful
probe is indicated by probed = true.
*/
void probeDeviceInfo(RTAUDIO_DEVICE *info);
/*!
Private method which attempts to open a device with the given parameters.
If an error is encountered during the probe, a "warning" message is
reported and FAILURE is returned (no exception is thrown). A
successful probe is indicated by a return value of SUCCESS.
*/
bool probeDeviceOpen(int device, RTAUDIO_STREAM *stream,
STREAM_MODE mode, int channels,
int sampleRate, RTAUDIO_FORMAT format,
int *bufferSize, int numberOfBuffers);
/*!
Private common method used to check validity of a user-passed
stream ID. When the ID is valid, this method returns a pointer to
an RTAUDIO_STREAM structure (in the form of a void pointer).
Otherwise, an "invalid identifier" exception is thrown.
*/
void *verifyStream(int streamId);
/*!
Private method used to perform format, channel number, and/or interleaving
conversions between the user and device buffers.
*/
void convertStreamBuffer(RTAUDIO_STREAM *stream, STREAM_MODE mode);
//! Private method used to perform byte-swapping on buffers.
void byteSwapBuffer(char *buffer, int samples, RTAUDIO_FORMAT format);
//! Private method which returns the number of bytes for a given format.
int formatBytes(RTAUDIO_FORMAT format);
};
// Define the following flag to have extra information spewed to stderr.
//#define __RTAUDIO_DEBUG__
#endif

View File

@@ -1,99 +1,99 @@
/***************************************************/
/*! \class RtDuplex
\brief STK realtime audio input/output class.
This class provides a simplified interface to
RtAudio for realtime audio input/output. It
is also possible to achieve duplex operation
using separate RtWvIn and RtWvOut classes, but
this class ensures better input/output
syncronization.
RtDuplex 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
and return samples produced by averaging across
sample frames, from the tickFrame() methods, which
take/return pointers to multi-channel sample frames.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__RTDUPLEX_H)
#define __RTDUPLEX_H
#include "Stk.h"
#include "RtAudio.h"
class RtDuplex : public Stk
{
public:
//! Default constructor.
/*!
The \e device argument is passed to RtAudio during
instantiation. The default value (zero) will select the default
device on your system or the first device found meeting the
specified parameters. On systems with multiple
soundcards/devices, values greater than zero can be specified in
accordance with the order that the devices are enumerated by the
underlying audio API. The default buffer size of RT_BUFFER_SIZE
is defined in Stk.h. An StkError will be thrown if an error
occurs duing instantiation.
*/
RtDuplex(int nChannels = 1, MY_FLOAT sampleRate = Stk::sampleRate(), int device = 0, int bufferFrames = RT_BUFFER_SIZE, int nBuffers = 2);
//! Class destructor.
~RtDuplex();
//! Start the audio input/output stream.
/*!
The stream is started automatically, if necessary, when a tick() or tickFrame method is called.
*/
void start(void);
//! Stop the audio input/output stream.
/*!
It may be necessary to use this method to avoid audio overflow/underflow problems if you wish to temporarily stop the audio stream.
*/
void stop(void);
//! Return the average across the last output sample frame.
MY_FLOAT lastOut(void) const;
//! Output a single sample to all channels in a sample frame and return the average across one new input sample frame of data.
/*!
An StkError will be thrown if an error occurs during input/output.
*/
MY_FLOAT tick(const MY_FLOAT sample);
//! Output each sample in \vector to all channels per frame and return averaged input sample frames of new data in \e vector.
/*!
An StkError will be thrown if an error occurs during input/output.
*/
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
//! Return a pointer to the last output sample frame.
const MY_FLOAT *lastFrame(void) const;
//! Output sample \e frames from \e frameVector and return new input frames in \e frameVector.
/*!
An StkError will be thrown if an error occurs during input/output.
*/
MY_FLOAT *tickFrame(MY_FLOAT *frameVector, unsigned int frames = 1);
protected:
RtAudio *audio;
MY_FLOAT *data;
MY_FLOAT *lastOutput;
int bufferSize;
bool stopped;
int stream;
long counter;
unsigned int channels;
};
#endif
/***************************************************/
/*! \class RtDuplex
\brief STK realtime audio input/output class.
This class provides a simplified interface to
RtAudio for realtime audio input/output. It
is also possible to achieve duplex operation
using separate RtWvIn and RtWvOut classes, but
this class ensures better input/output
syncronization.
RtDuplex 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
and return samples produced by averaging across
sample frames, from the tickFrame() methods, which
take/return pointers to multi-channel sample frames.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__RTDUPLEX_H)
#define __RTDUPLEX_H
#include "Stk.h"
#include "RtAudio.h"
class RtDuplex : public Stk
{
public:
//! Default constructor.
/*!
The \e device argument is passed to RtAudio during
instantiation. The default value (zero) will select the default
device on your system or the first device found meeting the
specified parameters. On systems with multiple
soundcards/devices, values greater than zero can be specified in
accordance with the order that the devices are enumerated by the
underlying audio API. The default buffer size of RT_BUFFER_SIZE
is defined in Stk.h. An StkError will be thrown if an error
occurs duing instantiation.
*/
RtDuplex(int nChannels = 1, MY_FLOAT sampleRate = Stk::sampleRate(), int device = 0, int bufferFrames = RT_BUFFER_SIZE, int nBuffers = 2);
//! Class destructor.
~RtDuplex();
//! Start the audio input/output stream.
/*!
The stream is started automatically, if necessary, when a tick() or tickFrame method is called.
*/
void start(void);
//! Stop the audio input/output stream.
/*!
It may be necessary to use this method to avoid audio overflow/underflow problems if you wish to temporarily stop the audio stream.
*/
void stop(void);
//! Return the average across the last output sample frame.
MY_FLOAT lastOut(void) const;
//! Output a single sample to all channels in a sample frame and return the average across one new input sample frame of data.
/*!
An StkError will be thrown if an error occurs during input/output.
*/
MY_FLOAT tick(const MY_FLOAT sample);
//! Output each sample in \vector to all channels per frame and return averaged input sample frames of new data in \e vector.
/*!
An StkError will be thrown if an error occurs during input/output.
*/
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
//! Return a pointer to the last output sample frame.
const MY_FLOAT *lastFrame(void) const;
//! Output sample \e frames from \e frameVector and return new input frames in \e frameVector.
/*!
An StkError will be thrown if an error occurs during input/output.
*/
MY_FLOAT *tickFrame(MY_FLOAT *frameVector, unsigned int frames = 1);
protected:
RtAudio *audio;
MY_FLOAT *data;
MY_FLOAT *lastOutput;
int bufferSize;
bool stopped;
int stream;
long counter;
unsigned int channels;
};
#endif

View File

@@ -1,80 +1,80 @@
/***************************************************/
/*! \class RtMidi
\brief STK realtime MIDI class.
At the moment, this object only handles MIDI
input, though MIDI output code can go here
when someone decides they need it (and writes
it).
This object opens a MIDI input device and
parses MIDI messages into a MIDI buffer. Time
stamp info is converted to a delta-time
value. MIDI data is stored as MY_FLOAT to
conform with SKINI. System exclusive messages
are currently ignored.
An optional argument to the constructor can be
used to specify a device or card. When no
argument is given, a default device is opened.
If a device argument fails, a list of available
devices is printed to allow selection by the user.
This code is based in part on work of Perry
Cook (SGI), Paul Leonard (Linux), the
RoseGarden team (Linux), and Bill Putnam
(Windows).
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__RTMIDI_H)
#define __RTMIDI_H
#include "Stk.h"
class RtMidi : public Stk
{
public:
//! Default constructor with optional device argument.
RtMidi(int device = 0);
//! Class destructor.
~RtMidi();
//! Print out the current message values.
void printMessage(void) const;
//! Check for and parse a new MIDI message in the queue, returning its type.
/*!
If a new message is found, the return value is greater than zero.
*/
int nextMessage(void);
//! Return the current message type.
int getType() const;
//! Return the current message channel value.
int getChannel() const;
//! Return the current message byte two value.
MY_FLOAT getByteTwo() const;
//! Return the current message byte three value.
MY_FLOAT getByteThree() const;
//! Return the current message delta time value in seconds.
MY_FLOAT getDeltaTime() const;
protected:
int messageType;
int channel;
float byteTwo;
float byteThree;
MY_FLOAT deltaTime;
int readIndex;
};
#endif
/***************************************************/
/*! \class RtMidi
\brief STK realtime MIDI class.
At the moment, this object only handles MIDI
input, though MIDI output code can go here
when someone decides they need it (and writes
it).
This object opens a MIDI input device and
parses MIDI messages into a MIDI buffer. Time
stamp info is converted to a delta-time
value. MIDI data is stored as MY_FLOAT to
conform with SKINI. System exclusive messages
are currently ignored.
An optional argument to the constructor can be
used to specify a device or card. When no
argument is given, a default device is opened.
If a device argument fails, a list of available
devices is printed to allow selection by the user.
This code is based in part on work of Perry
Cook (SGI), Paul Leonard (Linux), the
RoseGarden team (Linux), and Bill Putnam
(Windows).
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__RTMIDI_H)
#define __RTMIDI_H
#include "Stk.h"
class RtMidi : public Stk
{
public:
//! Default constructor with optional device argument.
RtMidi(int device = 0);
//! Class destructor.
~RtMidi();
//! Print out the current message values.
void printMessage(void) const;
//! Check for and parse a new MIDI message in the queue, returning its type.
/*!
If a new message is found, the return value is greater than zero.
*/
int nextMessage(void);
//! Return the current message type.
int getType() const;
//! Return the current message channel value.
int getChannel() const;
//! Return the current message byte two value.
MY_FLOAT getByteTwo() const;
//! Return the current message byte three value.
MY_FLOAT getByteThree() const;
//! Return the current message delta time value in seconds.
MY_FLOAT getDeltaTime() const;
protected:
int messageType;
int channel;
float byteTwo;
float byteThree;
MY_FLOAT deltaTime;
int readIndex;
};
#endif

View File

@@ -1,100 +1,100 @@
/***************************************************/
/*! \class RtWvIn
\brief STK realtime audio input class.
This class provides a simplified interface to
RtAudio for realtime audio input. It is a
protected subclass of WvIn.
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.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__RTWVIN_H)
#define __RTWVIN_H
#include "Stk.h"
#include "WvIn.h"
#include "RtAudio.h"
class RtWvIn : protected WvIn
{
public:
//! Default constructor.
/*!
The \e device argument is passed to RtAudio during
instantiation. The default value (zero) will select the default
device on your system or the first device found meeting the
specified parameters. On systems with multiple
soundcards/devices, values greater than zero can be specified in
accordance with the order that the devices are enumerated by the
underlying audio API. The default buffer size of RT_BUFFER_SIZE
is defined in Stk.h. An StkError will be thrown if an error
occurs duing instantiation.
*/
RtWvIn(int nChannels = 1, MY_FLOAT sampleRate = Stk::sampleRate(), int device = 0, int bufferFrames = RT_BUFFER_SIZE, int nBuffers = 2);
//! Class destructor.
~RtWvIn();
//! Start the audio input stream.
/*!
The stream is started automatically, if necessary, when a tick() or tickFrame method is called.
*/
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.
*/
void stop(void);
//! Return the average across the last output sample frame.
MY_FLOAT lastOut(void) const;
//! Read out the average across one sample frame of data.
/*!
An StkError will be thrown if an error occurs during input.
*/
MY_FLOAT tick(void);
//! Read out vectorSize averaged sample frames of data in \e vector.
/*!
An StkError will be thrown if an error occurs during input.
*/
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
//! Return a pointer to the last output sample frame.
const MY_FLOAT *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 MY_FLOAT *tickFrame(void);
//! Read out sample \e frames of data to \e frameVector.
/*!
An StkError will be thrown if an error occurs during input.
*/
MY_FLOAT *tickFrame(MY_FLOAT *frameVector, unsigned int frames);
protected:
RtAudio *audio;
bool stopped;
int stream;
long counter;
};
#endif
/***************************************************/
/*! \class RtWvIn
\brief STK realtime audio input class.
This class provides a simplified interface to
RtAudio for realtime audio input. It is a
protected subclass of WvIn.
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.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__RTWVIN_H)
#define __RTWVIN_H
#include "Stk.h"
#include "WvIn.h"
#include "RtAudio.h"
class RtWvIn : protected WvIn
{
public:
//! Default constructor.
/*!
The \e device argument is passed to RtAudio during
instantiation. The default value (zero) will select the default
device on your system or the first device found meeting the
specified parameters. On systems with multiple
soundcards/devices, values greater than zero can be specified in
accordance with the order that the devices are enumerated by the
underlying audio API. The default buffer size of RT_BUFFER_SIZE
is defined in Stk.h. An StkError will be thrown if an error
occurs duing instantiation.
*/
RtWvIn(int nChannels = 1, MY_FLOAT sampleRate = Stk::sampleRate(), int device = 0, int bufferFrames = RT_BUFFER_SIZE, int nBuffers = 2);
//! Class destructor.
~RtWvIn();
//! Start the audio input stream.
/*!
The stream is started automatically, if necessary, when a tick() or tickFrame method is called.
*/
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.
*/
void stop(void);
//! Return the average across the last output sample frame.
MY_FLOAT lastOut(void) const;
//! Read out the average across one sample frame of data.
/*!
An StkError will be thrown if an error occurs during input.
*/
MY_FLOAT tick(void);
//! Read out vectorSize averaged sample frames of data in \e vector.
/*!
An StkError will be thrown if an error occurs during input.
*/
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
//! Return a pointer to the last output sample frame.
const MY_FLOAT *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 MY_FLOAT *tickFrame(void);
//! Read out sample \e frames of data to \e frameVector.
/*!
An StkError will be thrown if an error occurs during input.
*/
MY_FLOAT *tickFrame(MY_FLOAT *frameVector, unsigned int frames);
protected:
RtAudio *audio;
bool stopped;
int stream;
long counter;
};
#endif

View File

@@ -1,92 +1,92 @@
/***************************************************/
/*! \class RtWvOut
\brief STK realtime audio output class.
This class provides a simplified interface to
RtAudio for realtime audio output. It is a
protected subclass of WvOut.
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
frame data.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__RTWVOUT_H)
#define __RTWVOUT_H
#include "WvOut.h"
#include "RtAudio.h"
class RtWvOut : protected WvOut
{
public:
//! Default constructor.
/*!
The \e device argument is passed to RtAudio during
instantiation. The default value (zero) will select the default
device on your system or the first device found meeting the
specified parameters. On systems with multiple
soundcards/devices, values greater than zero can be specified in
accordance with the order that the devices are enumerated by the
underlying audio API. The default buffer size of RT_BUFFER_SIZE
is defined in Stk.h. An StkError will be thrown if an error
occurs duing instantiation.
*/
RtWvOut(unsigned int nChannels = 1, MY_FLOAT 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.
*/
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.
*/
void stop(void);
//! Return the number of sample frames output.
unsigned long getFrames( void ) const;
//! Return the number of seconds of data output.
MY_FLOAT 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 MY_FLOAT 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 MY_FLOAT *vector, unsigned int vectorSize);
//! 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 MY_FLOAT *frameVector, unsigned int frames = 1);
protected:
RtAudio *audio;
bool stopped;
int stream;
int bufferSize;
};
#endif // defined(__RTWVOUT_H)
/***************************************************/
/*! \class RtWvOut
\brief STK realtime audio output class.
This class provides a simplified interface to
RtAudio for realtime audio output. It is a
protected subclass of WvOut.
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
frame data.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__RTWVOUT_H)
#define __RTWVOUT_H
#include "WvOut.h"
#include "RtAudio.h"
class RtWvOut : protected WvOut
{
public:
//! Default constructor.
/*!
The \e device argument is passed to RtAudio during
instantiation. The default value (zero) will select the default
device on your system or the first device found meeting the
specified parameters. On systems with multiple
soundcards/devices, values greater than zero can be specified in
accordance with the order that the devices are enumerated by the
underlying audio API. The default buffer size of RT_BUFFER_SIZE
is defined in Stk.h. An StkError will be thrown if an error
occurs duing instantiation.
*/
RtWvOut(unsigned int nChannels = 1, MY_FLOAT 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.
*/
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.
*/
void stop(void);
//! Return the number of sample frames output.
unsigned long getFrames( void ) const;
//! Return the number of seconds of data output.
MY_FLOAT 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 MY_FLOAT 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 MY_FLOAT *vector, unsigned int vectorSize);
//! 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 MY_FLOAT *frameVector, unsigned int frames = 1);
protected:
RtAudio *audio;
bool stopped;
int stream;
int bufferSize;
};
#endif // defined(__RTWVOUT_H)

View File

@@ -1,127 +1,127 @@
/***************************************************/
/*! \class SKINI
\brief STK SKINI parsing class
This class parses SKINI formatted text
messages. It can be used to parse individual
messages or it can be passed an entire file.
The file specification is Perry's and his
alone, but it's all text so it shouldn't be to
hard to figure out.
SKINI (Synthesis toolKit Instrument Network
Interface) is like MIDI, but allows for
floating-point control changes, note numbers,
etc. The following example causes a sharp
middle C to be played with a velocity of 111.132:
\code
noteOn 60.01 111.13
\endcode
\sa \ref skini
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__SKINI_H)
#define __SKINI_H
#include "Stk.h"
#include <stdio.h>
class SKINI : public Stk
{
public:
//! Default constructor used for parsing messages received externally.
SKINI();
//! Overloaded constructor taking a SKINI formatted scorefile.
SKINI(char *fileName);
//! Class destructor
~SKINI();
//! Attempt to parse the given string, returning the message type.
/*!
A type value equal to zero indicates an invalid message.
*/
long parseThis(char* aString);
//! Parse the next message (if a file is loaded) and return the message type.
/*!
A negative value is returned when the file end is reached.
*/
long nextMessage();
//! Return the current message type.
long getType() const;
//! Return the current message channel value.
long getChannel() const;
//! Return the current message delta time value (in seconds).
MY_FLOAT getDelta() const;
//! Return the current message byte two value.
MY_FLOAT getByteTwo() const;
//! Return the current message byte three value.
MY_FLOAT getByteThree() const;
//! Return the current message byte two value (integer).
long getByteTwoInt() const;
//! Return the current message byte three value (integer).
long getByteThreeInt() const;
//! Return remainder string after parsing.
const char* getRemainderString();
//! Return the message type as a string.
const char* getMessageTypeString();
//! Return the SKINI type string for the given type value.
const char* whatsThisType(long type);
//! Return the SKINI controller string for the given controller number.
const char* whatsThisController(long number);
protected:
FILE *myFile;
long messageType;
char msgTypeString[64];
long channel;
MY_FLOAT deltaTime;
MY_FLOAT byteTwo;
MY_FLOAT byteThree;
long byteTwoInt;
long byteThreeInt;
char remainderString[1024];
char whatString[1024];
};
static const double Midi2Pitch[129] = {
8.18,8.66,9.18,9.72,10.30,10.91,11.56,12.25,
12.98,13.75,14.57,15.43,16.35,17.32,18.35,19.45,
20.60,21.83,23.12,24.50,25.96,27.50,29.14,30.87,
32.70,34.65,36.71,38.89,41.20,43.65,46.25,49.00,
51.91,55.00,58.27,61.74,65.41,69.30,73.42,77.78,
82.41,87.31,92.50,98.00,103.83,110.00,116.54,123.47,
130.81,138.59,146.83,155.56,164.81,174.61,185.00,196.00,
207.65,220.00,233.08,246.94,261.63,277.18,293.66,311.13,
329.63,349.23,369.99,392.00,415.30,440.00,466.16,493.88,
523.25,554.37,587.33,622.25,659.26,698.46,739.99,783.99,
830.61,880.00,932.33,987.77,1046.50,1108.73,1174.66,1244.51,
1318.51,1396.91,1479.98,1567.98,1661.22,1760.00,1864.66,1975.53,
2093.00,2217.46,2349.32,2489.02,2637.02,2793.83,2959.96,3135.96,
3322.44,3520.00,3729.31,3951.07,4186.01,4434.92,4698.64,4978.03,
5274.04,5587.65,5919.91,6271.93,6644.88,7040.00,7458.62,7902.13,
8372.02,8869.84,9397.27,9956.06,10548.08,11175.30,11839.82,12543.85,
13289.75};
#endif
/***************************************************/
/*! \class SKINI
\brief STK SKINI parsing class
This class parses SKINI formatted text
messages. It can be used to parse individual
messages or it can be passed an entire file.
The file specification is Perry's and his
alone, but it's all text so it shouldn't be to
hard to figure out.
SKINI (Synthesis toolKit Instrument Network
Interface) is like MIDI, but allows for
floating-point control changes, note numbers,
etc. The following example causes a sharp
middle C to be played with a velocity of 111.132:
\code
noteOn 60.01 111.13
\endcode
\sa \ref skini
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__SKINI_H)
#define __SKINI_H
#include "Stk.h"
#include <stdio.h>
class SKINI : public Stk
{
public:
//! Default constructor used for parsing messages received externally.
SKINI();
//! Overloaded constructor taking a SKINI formatted scorefile.
SKINI(char *fileName);
//! Class destructor
~SKINI();
//! Attempt to parse the given string, returning the message type.
/*!
A type value equal to zero indicates an invalid message.
*/
long parseThis(char* aString);
//! Parse the next message (if a file is loaded) and return the message type.
/*!
A negative value is returned when the file end is reached.
*/
long nextMessage();
//! Return the current message type.
long getType() const;
//! Return the current message channel value.
long getChannel() const;
//! Return the current message delta time value (in seconds).
MY_FLOAT getDelta() const;
//! Return the current message byte two value.
MY_FLOAT getByteTwo() const;
//! Return the current message byte three value.
MY_FLOAT getByteThree() const;
//! Return the current message byte two value (integer).
long getByteTwoInt() const;
//! Return the current message byte three value (integer).
long getByteThreeInt() const;
//! Return remainder string after parsing.
const char* getRemainderString();
//! Return the message type as a string.
const char* getMessageTypeString();
//! Return the SKINI type string for the given type value.
const char* whatsThisType(long type);
//! Return the SKINI controller string for the given controller number.
const char* whatsThisController(long number);
protected:
FILE *myFile;
long messageType;
char msgTypeString[64];
long channel;
MY_FLOAT deltaTime;
MY_FLOAT byteTwo;
MY_FLOAT byteThree;
long byteTwoInt;
long byteThreeInt;
char remainderString[1024];
char whatString[1024];
};
static const double Midi2Pitch[129] = {
8.18,8.66,9.18,9.72,10.30,10.91,11.56,12.25,
12.98,13.75,14.57,15.43,16.35,17.32,18.35,19.45,
20.60,21.83,23.12,24.50,25.96,27.50,29.14,30.87,
32.70,34.65,36.71,38.89,41.20,43.65,46.25,49.00,
51.91,55.00,58.27,61.74,65.41,69.30,73.42,77.78,
82.41,87.31,92.50,98.00,103.83,110.00,116.54,123.47,
130.81,138.59,146.83,155.56,164.81,174.61,185.00,196.00,
207.65,220.00,233.08,246.94,261.63,277.18,293.66,311.13,
329.63,349.23,369.99,392.00,415.30,440.00,466.16,493.88,
523.25,554.37,587.33,622.25,659.26,698.46,739.99,783.99,
830.61,880.00,932.33,987.77,1046.50,1108.73,1174.66,1244.51,
1318.51,1396.91,1479.98,1567.98,1661.22,1760.00,1864.66,1975.53,
2093.00,2217.46,2349.32,2489.02,2637.02,2793.83,2959.96,3135.96,
3322.44,3520.00,3729.31,3951.07,4186.01,4434.92,4698.64,4978.03,
5274.04,5587.65,5919.91,6271.93,6644.88,7040.00,7458.62,7902.13,
8372.02,8869.84,9397.27,9956.06,10548.08,11175.30,11839.82,12543.85,
13289.75};
#endif

View File

@@ -1,123 +1,124 @@
/*********************************************************/
/*
Definition of SKINI Message Types and Special Symbols
Synthesis toolKit Instrument Network Interface
These symbols should have the form __SK_<name>_
Where <name> is the string used in the SKINI stream.
by Perry R. Cook, 1995 - 2002.
*/
/*********************************************************/
/***** MIDI COMPATIBLE MESSAGES *****/
/***** Status Bytes Have Channel=0 **/
#define NOPE -32767
#define YEP 1
#define SK_DBL -32766
#define SK_INT -32765
#define SK_STR -32764
#define __SK_NoteOff_ 128
#define __SK_NoteOn_ 144
#define __SK_PolyPressure_ 160
#define __SK_ControlChange_ 176
#define __SK_ProgramChange_ 192
#define __SK_AfterTouch_ 208
#define __SK_ChannelPressure_ __SK_AfterTouch_
#define __SK_PitchWheel_ 224
#define __SK_PitchBend_ __SK_PitchWheel_
#define __SK_Clock_ 248
#define __SK_SongStart_ 250
#define __SK_Continue_ 251
#define __SK_SongStop_ 252
#define __SK_ActiveSensing_ 254
#define __SK_SystemReset_ 255
#define __SK_Volume_ 7
#define __SK_ModWheel_ 1
#define __SK_Modulation_ __SK_ModWheel_
#define __SK_Breath_ 2
#define __SK_FootControl_ 4
#define __SK_Portamento_ 65
#define __SK_Balance_ 8
#define __SK_Pan_ 10
#define __SK_Sustain_ 64
#define __SK_Damper_ __SK_Sustain_
#define __SK_Expression_ 11
#define __SK_AfterTouch_Cont_ 128
#define __SK_ModFrequency_ __SK_Expression_
#define __SK_ProphesyRibbon_ 16
#define __SK_ProphesyWheelUp_ 2
#define __SK_ProphesyWheelDown_ 3
#define __SK_ProphesyPedal_ 18
#define __SK_ProphesyKnob1_ 21
#define __SK_ProphesyKnob2_ 22
/*** Instrument Family Specific ***/
#define __SK_NoiseLevel_ __SK_FootControl_
#define __SK_PickPosition_ __SK_FootControl_
#define __SK_StringDamping_ __SK_Expression_
#define __SK_StringDetune_ __SK_ModWheel_
#define __SK_BodySize_ __SK_Breath_
#define __SK_BowPressure_ __SK_Breath_
#define __SK_BowPosition_ __SK_PickPosition_
#define __SK_BowBeta_ __SK_BowPosition_
#define __SK_ReedStiffness_ __SK_Breath_
#define __SK_ReedRestPos_ __SK_FootControl_
#define __SK_FluteEmbouchure_ __SK_Breath_
#define __SK_JetDelay_ __SK_FluteEmbouchure_
#define __SK_LipTension_ __SK_Breath_
#define __SK_SlideLength_ __SK_FootControl_
#define __SK_StrikePosition_ __SK_PickPosition_
#define __SK_StickHardness_ __SK_Breath_
#define __SK_TrillDepth_ 1051
#define __SK_TrillSpeed_ 1052
#define __SK_StrumSpeed_ __SK_TrillSpeed_
#define __SK_RollSpeed_ __SK_TrillSpeed_
#define __SK_FilterQ_ __SK_Breath_
#define __SK_FilterFreq_ 1062
#define __SK_FilterSweepRate_ __SK_FootControl_
#define __SK_ShakerInst_ 1071
#define __SK_ShakerEnergy_ __SK_Breath_
#define __SK_ShakerDamping_ __SK_ModFrequency_
#define __SK_ShakerNumObjects_ __SK_FootControl_
#define __SK_Strumming_ 1090
#define __SK_NotStrumming_ 1091
#define __SK_Trilling_ 1092
#define __SK_NotTrilling_ 1093
#define __SK_Rolling_ __SK_Strumming_
#define __SK_NotRolling_ __SK_NotStrumming_
#define __SK_PlayerSkill_ 2001
#define __SK_Chord_ 2002
#define __SK_ChordOff_ 2003
#define __SK_SINGER_FilePath_ 3000
#define __SK_SINGER_Frequency_ 3001
#define __SK_SINGER_NoteName_ 3002
#define __SK_SINGER_Shape_ 3003
#define __SK_SINGER_Glot_ 3004
#define __SK_SINGER_VoicedUnVoiced_ 3005
#define __SK_SINGER_Synthesize_ 3006
#define __SK_SINGER_Silence_ 3007
#define __SK_SINGER_VibratoAmt_ __SK_ModWheel_
#define __SK_SINGER_RndVibAmt_ 3008
#define __SK_SINGER_VibFreq_ __SK_Expression_
/*********************************************************/
/*
Definition of SKINI Message Types and Special Symbols
Synthesis toolKit Instrument Network Interface
These symbols should have the form __SK_<name>_
Where <name> is the string used in the SKINI stream.
by Perry R. Cook, 1995 - 2002.
*/
/*********************************************************/
/***** MIDI COMPATIBLE MESSAGES *****/
/***** Status Bytes Have Channel=0 **/
#define NOPE -32767
#define YEP 1
#define SK_DBL -32766
#define SK_INT -32765
#define SK_STR -32764
#define __SK_NoteOff_ 128
#define __SK_NoteOn_ 144
#define __SK_PolyPressure_ 160
#define __SK_ControlChange_ 176
#define __SK_ProgramChange_ 192
#define __SK_AfterTouch_ 208
#define __SK_ChannelPressure_ __SK_AfterTouch_
#define __SK_PitchWheel_ 224
#define __SK_PitchBend_ __SK_PitchWheel_
#define __SK_PitchChange_ 249
#define __SK_Clock_ 248
#define __SK_SongStart_ 250
#define __SK_Continue_ 251
#define __SK_SongStop_ 252
#define __SK_ActiveSensing_ 254
#define __SK_SystemReset_ 255
#define __SK_Volume_ 7
#define __SK_ModWheel_ 1
#define __SK_Modulation_ __SK_ModWheel_
#define __SK_Breath_ 2
#define __SK_FootControl_ 4
#define __SK_Portamento_ 65
#define __SK_Balance_ 8
#define __SK_Pan_ 10
#define __SK_Sustain_ 64
#define __SK_Damper_ __SK_Sustain_
#define __SK_Expression_ 11
#define __SK_AfterTouch_Cont_ 128
#define __SK_ModFrequency_ __SK_Expression_
#define __SK_ProphesyRibbon_ 16
#define __SK_ProphesyWheelUp_ 2
#define __SK_ProphesyWheelDown_ 3
#define __SK_ProphesyPedal_ 18
#define __SK_ProphesyKnob1_ 21
#define __SK_ProphesyKnob2_ 22
/*** Instrument Family Specific ***/
#define __SK_NoiseLevel_ __SK_FootControl_
#define __SK_PickPosition_ __SK_FootControl_
#define __SK_StringDamping_ __SK_Expression_
#define __SK_StringDetune_ __SK_ModWheel_
#define __SK_BodySize_ __SK_Breath_
#define __SK_BowPressure_ __SK_Breath_
#define __SK_BowPosition_ __SK_PickPosition_
#define __SK_BowBeta_ __SK_BowPosition_
#define __SK_ReedStiffness_ __SK_Breath_
#define __SK_ReedRestPos_ __SK_FootControl_
#define __SK_FluteEmbouchure_ __SK_Breath_
#define __SK_JetDelay_ __SK_FluteEmbouchure_
#define __SK_LipTension_ __SK_Breath_
#define __SK_SlideLength_ __SK_FootControl_
#define __SK_StrikePosition_ __SK_PickPosition_
#define __SK_StickHardness_ __SK_Breath_
#define __SK_TrillDepth_ 1051
#define __SK_TrillSpeed_ 1052
#define __SK_StrumSpeed_ __SK_TrillSpeed_
#define __SK_RollSpeed_ __SK_TrillSpeed_
#define __SK_FilterQ_ __SK_Breath_
#define __SK_FilterFreq_ 1062
#define __SK_FilterSweepRate_ __SK_FootControl_
#define __SK_ShakerInst_ 1071
#define __SK_ShakerEnergy_ __SK_Breath_
#define __SK_ShakerDamping_ __SK_ModFrequency_
#define __SK_ShakerNumObjects_ __SK_FootControl_
#define __SK_Strumming_ 1090
#define __SK_NotStrumming_ 1091
#define __SK_Trilling_ 1092
#define __SK_NotTrilling_ 1093
#define __SK_Rolling_ __SK_Strumming_
#define __SK_NotRolling_ __SK_NotStrumming_
#define __SK_PlayerSkill_ 2001
#define __SK_Chord_ 2002
#define __SK_ChordOff_ 2003
#define __SK_SINGER_FilePath_ 3000
#define __SK_SINGER_Frequency_ 3001
#define __SK_SINGER_NoteName_ 3002
#define __SK_SINGER_Shape_ 3003
#define __SK_SINGER_Glot_ 3004
#define __SK_SINGER_VoicedUnVoiced_ 3005
#define __SK_SINGER_Synthesize_ 3006
#define __SK_SINGER_Silence_ 3007
#define __SK_SINGER_VibratoAmt_ __SK_ModWheel_
#define __SK_SINGER_RndVibAmt_ 3008
#define __SK_SINGER_VibFreq_ __SK_Expression_

View File

@@ -1,130 +1,131 @@
#include "SKINI.msg"
#define __SK_MaxMsgTypes_ 128
struct SKINISpec { char messageString[32];
long type;
long data2;
long data3;
};
/* SEE COMMENT BLOCK AT BOTTOM FOR FIELDS AND USES */
/* MessageString ,type, ch?, data2 , data3 */
struct SKINISpec skini_msgs[__SK_MaxMsgTypes_] =
{
{"NoteOff" , __SK_NoteOff_, SK_DBL, SK_DBL},
{"NoteOn" , __SK_NoteOn_, SK_DBL, SK_DBL},
{"PolyPressure" , __SK_PolyPressure_, SK_DBL, SK_DBL},
{"ControlChange" , __SK_ControlChange_, SK_INT, SK_DBL},
{"ProgramChange" , __SK_ProgramChange_, SK_DBL, SK_DBL},
{"AfterTouch" , __SK_AfterTouch_, SK_DBL, NOPE},
{"ChannelPressure" ,__SK_ChannelPressure_, SK_DBL, NOPE},
{"PitchWheel" , __SK_PitchWheel_, SK_DBL, NOPE},
{"PitchBend" , __SK_PitchBend_, SK_DBL, NOPE},
{"Clock" , __SK_Clock_, NOPE, NOPE},
{"Undefined" , 249, NOPE, NOPE},
{"SongStart" , __SK_SongStart_, NOPE, NOPE},
{"Continue" , __SK_Continue_, NOPE, NOPE},
{"SongStop" , __SK_SongStop_, NOPE, NOPE},
{"Undefined" , 253, NOPE, NOPE},
{"ActiveSensing" , __SK_ActiveSensing_, NOPE, NOPE},
{"SystemReset" , __SK_SystemReset_, NOPE, NOPE},
{"Volume" , __SK_ControlChange_, __SK_Volume_ , SK_DBL},
{"ModWheel" , __SK_ControlChange_, __SK_ModWheel_ , SK_DBL},
{"Modulation" , __SK_ControlChange_, __SK_Modulation_ , SK_DBL},
{"Breath" , __SK_ControlChange_, __SK_Breath_ , SK_DBL},
{"FootControl" , __SK_ControlChange_, __SK_FootControl_ , SK_DBL},
{"Portamento" , __SK_ControlChange_, __SK_Portamento_ , SK_DBL},
{"Balance" , __SK_ControlChange_, __SK_Balance_ , SK_DBL},
{"Pan" , __SK_ControlChange_, __SK_Pan_ , SK_DBL},
{"Sustain" , __SK_ControlChange_, __SK_Sustain_ , SK_DBL},
{"Damper" , __SK_ControlChange_, __SK_Damper_ , SK_DBL},
{"Expression" , __SK_ControlChange_, __SK_Expression_ , SK_DBL},
{"NoiseLevel" , __SK_ControlChange_, __SK_NoiseLevel_ , SK_DBL},
{"PickPosition" , __SK_ControlChange_, __SK_PickPosition_ , SK_DBL},
{"StringDamping" , __SK_ControlChange_, __SK_StringDamping_ , SK_DBL},
{"StringDetune" , __SK_ControlChange_, __SK_StringDetune_ , SK_DBL},
{"BodySize" , __SK_ControlChange_, __SK_BodySize_ , SK_DBL},
{"BowPressure" , __SK_ControlChange_, __SK_BowPressure_ , SK_DBL},
{"BowPosition" , __SK_ControlChange_, __SK_BowPosition_ , SK_DBL},
{"BowBeta" , __SK_ControlChange_, __SK_BowBeta_ , SK_DBL},
{"ReedStiffness" , __SK_ControlChange_, __SK_ReedStiffness_ , SK_DBL},
{"ReedRestPos" , __SK_ControlChange_, __SK_ReedRestPos_ , SK_DBL},
{"FluteEmbouchure" , __SK_ControlChange_, __SK_FluteEmbouchure_, SK_DBL},
{"LipTension" , __SK_ControlChange_, __SK_LipTension_ , SK_DBL},
{"StrikePosition" , __SK_ControlChange_, __SK_StrikePosition_, SK_DBL},
{"StickHardness" , __SK_ControlChange_, __SK_StickHardness_ , SK_DBL},
{"TrillDepth" , __SK_ControlChange_, __SK_TrillDepth_ , SK_DBL},
{"TrillSpeed" , __SK_ControlChange_, __SK_TrillSpeed_ , SK_DBL},
{"Strumming" , __SK_ControlChange_, __SK_Strumming_ , 127 },
{"NotStrumming" , __SK_ControlChange_, __SK_Strumming_ , 0 },
{"PlayerSkill" , __SK_ControlChange_, __SK_PlayerSkill_ , SK_DBL},
{"Chord" , __SK_Chord_ , SK_DBL , SK_STR },
{"ChordOff" , __SK_ChordOff_ , SK_DBL , NOPE },
{"ShakerInst" , __SK_ControlChange_, __SK_ShakerInst_ , SK_DBL},
{"Maraca" , __SK_ControlChange_, __SK_ShakerInst_ , 0 },
{"Sekere" , __SK_ControlChange_, __SK_ShakerInst_ , 1 },
{"Cabasa" , __SK_ControlChange_, __SK_ShakerInst_ , 2 },
{"Bamboo" , __SK_ControlChange_, __SK_ShakerInst_ , 3 },
{"Waterdrp" , __SK_ControlChange_, __SK_ShakerInst_ , 4 },
{"Tambourn" , __SK_ControlChange_, __SK_ShakerInst_ , 5 },
{"Sleighbl" , __SK_ControlChange_, __SK_ShakerInst_ , 6 },
{"Guiro" , __SK_ControlChange_, __SK_ShakerInst_ , 7 },
{"OpenFile" , 256, SK_STR , NOPE},
{"SetPath" , 257, SK_STR , NOPE},
{"FilePath" , __SK_SINGER_FilePath_, SK_STR , NOPE},
{"Frequency" , __SK_SINGER_Frequency_, SK_STR , NOPE},
{"NoteName" , __SK_SINGER_NoteName_, SK_STR , NOPE},
{"VocalShape" , __SK_SINGER_Shape_ , SK_STR , NOPE},
{"Glottis" , __SK_SINGER_Glot_ , SK_STR , NOPE},
{"VoicedUnVoiced" , __SK_SINGER_VoicedUnVoiced_, SK_DBL , SK_STR},
{"Synthesize" , __SK_SINGER_Synthesize_, SK_STR , NOPE},
{"Silence" , __SK_SINGER_Silence_, SK_STR , NOPE},
{"VibratoAmt" , __SK_ControlChange_ ,__SK_SINGER_VibratoAmt_,SK_DBL},
{"RndVibAmt" , __SK_SINGER_RndVibAmt_ ,SK_STR, NOPE},
{"VibFreq" , __SK_ControlChange_ ,__SK_SINGER_VibFreq_ ,SK_DBL}
};
/** FORMAT: *************************************************************/
/* */
/* MessageStr$ ,type, data2, data3, */
/* */
/* type is the message type sent back from the SKINI line parser. */
/* data<n> is either */
/* NOPE : field not used, specifically, there aren't going */
/* to be any more fields on this line. So if there */
/* is is NOPE in data2, data3 won't even be checked */
/* SK_INT : byte (actually scanned as 32 bit signed integer) */
/* If it's a MIDI data field which is required to */
/* be an integer, like a controller number, it's */
/* 0-127. Otherwise) get creative with SK_INTs */
/* SK_DBL : double precision floating point. SKINI uses these */
/* in the MIDI context for note numbers with micro */
/* tuning, velocities, controller values, etc. */
/* SK_STR : only valid in final field. This allows (nearly) */
/* arbitrary message types to be supported by simply */
/* scanning the string to EndOfLine and then passing */
/* it to a more intellegent handler. For example, */
/* MIDI SYSEX (system exclusive) messages of up to */
/* 256bytes can be read as space-delimited integers */
/* into the 1K SK_STR buffer. Longer bulk dumps, */
/* soundfiles, etc. should be handled as a new */
/* message type pointing to a FileName stored in the */
/* SK_STR field, or as a new type of multi-line */
/* message. */
/* */
/*************************************************************************/
#include "SKINI.msg"
#define __SK_MaxMsgTypes_ 128
struct SKINISpec { char messageString[32];
long type;
long data2;
long data3;
};
/* SEE COMMENT BLOCK AT BOTTOM FOR FIELDS AND USES */
/* MessageString ,type, ch?, data2 , data3 */
struct SKINISpec skini_msgs[__SK_MaxMsgTypes_] =
{
{"NoteOff" , __SK_NoteOff_, SK_DBL, SK_DBL},
{"NoteOn" , __SK_NoteOn_, SK_DBL, SK_DBL},
{"PolyPressure" , __SK_PolyPressure_, SK_DBL, SK_DBL},
{"ControlChange" , __SK_ControlChange_, SK_INT, SK_DBL},
{"ProgramChange" , __SK_ProgramChange_, SK_DBL, SK_DBL},
{"AfterTouch" , __SK_AfterTouch_, SK_DBL, NOPE},
{"ChannelPressure" ,__SK_ChannelPressure_, SK_DBL, NOPE},
{"PitchWheel" , __SK_PitchWheel_, SK_DBL, NOPE},
{"PitchBend" , __SK_PitchBend_, SK_DBL, NOPE},
{"PitchChange" , __SK_PitchChange_, SK_DBL, NOPE},
{"Clock" , __SK_Clock_, NOPE, NOPE},
{"Undefined" , 249, NOPE, NOPE},
{"SongStart" , __SK_SongStart_, NOPE, NOPE},
{"Continue" , __SK_Continue_, NOPE, NOPE},
{"SongStop" , __SK_SongStop_, NOPE, NOPE},
{"Undefined" , 253, NOPE, NOPE},
{"ActiveSensing" , __SK_ActiveSensing_, NOPE, NOPE},
{"SystemReset" , __SK_SystemReset_, NOPE, NOPE},
{"Volume" , __SK_ControlChange_, __SK_Volume_ , SK_DBL},
{"ModWheel" , __SK_ControlChange_, __SK_ModWheel_ , SK_DBL},
{"Modulation" , __SK_ControlChange_, __SK_Modulation_ , SK_DBL},
{"Breath" , __SK_ControlChange_, __SK_Breath_ , SK_DBL},
{"FootControl" , __SK_ControlChange_, __SK_FootControl_ , SK_DBL},
{"Portamento" , __SK_ControlChange_, __SK_Portamento_ , SK_DBL},
{"Balance" , __SK_ControlChange_, __SK_Balance_ , SK_DBL},
{"Pan" , __SK_ControlChange_, __SK_Pan_ , SK_DBL},
{"Sustain" , __SK_ControlChange_, __SK_Sustain_ , SK_DBL},
{"Damper" , __SK_ControlChange_, __SK_Damper_ , SK_DBL},
{"Expression" , __SK_ControlChange_, __SK_Expression_ , SK_DBL},
{"NoiseLevel" , __SK_ControlChange_, __SK_NoiseLevel_ , SK_DBL},
{"PickPosition" , __SK_ControlChange_, __SK_PickPosition_ , SK_DBL},
{"StringDamping" , __SK_ControlChange_, __SK_StringDamping_ , SK_DBL},
{"StringDetune" , __SK_ControlChange_, __SK_StringDetune_ , SK_DBL},
{"BodySize" , __SK_ControlChange_, __SK_BodySize_ , SK_DBL},
{"BowPressure" , __SK_ControlChange_, __SK_BowPressure_ , SK_DBL},
{"BowPosition" , __SK_ControlChange_, __SK_BowPosition_ , SK_DBL},
{"BowBeta" , __SK_ControlChange_, __SK_BowBeta_ , SK_DBL},
{"ReedStiffness" , __SK_ControlChange_, __SK_ReedStiffness_ , SK_DBL},
{"ReedRestPos" , __SK_ControlChange_, __SK_ReedRestPos_ , SK_DBL},
{"FluteEmbouchure" , __SK_ControlChange_, __SK_FluteEmbouchure_, SK_DBL},
{"LipTension" , __SK_ControlChange_, __SK_LipTension_ , SK_DBL},
{"StrikePosition" , __SK_ControlChange_, __SK_StrikePosition_, SK_DBL},
{"StickHardness" , __SK_ControlChange_, __SK_StickHardness_ , SK_DBL},
{"TrillDepth" , __SK_ControlChange_, __SK_TrillDepth_ , SK_DBL},
{"TrillSpeed" , __SK_ControlChange_, __SK_TrillSpeed_ , SK_DBL},
{"Strumming" , __SK_ControlChange_, __SK_Strumming_ , 127 },
{"NotStrumming" , __SK_ControlChange_, __SK_Strumming_ , 0 },
{"PlayerSkill" , __SK_ControlChange_, __SK_PlayerSkill_ , SK_DBL},
{"Chord" , __SK_Chord_ , SK_DBL , SK_STR },
{"ChordOff" , __SK_ChordOff_ , SK_DBL , NOPE },
{"ShakerInst" , __SK_ControlChange_, __SK_ShakerInst_ , SK_DBL},
{"Maraca" , __SK_ControlChange_, __SK_ShakerInst_ , 0 },
{"Sekere" , __SK_ControlChange_, __SK_ShakerInst_ , 1 },
{"Cabasa" , __SK_ControlChange_, __SK_ShakerInst_ , 2 },
{"Bamboo" , __SK_ControlChange_, __SK_ShakerInst_ , 3 },
{"Waterdrp" , __SK_ControlChange_, __SK_ShakerInst_ , 4 },
{"Tambourn" , __SK_ControlChange_, __SK_ShakerInst_ , 5 },
{"Sleighbl" , __SK_ControlChange_, __SK_ShakerInst_ , 6 },
{"Guiro" , __SK_ControlChange_, __SK_ShakerInst_ , 7 },
{"OpenFile" , 256, SK_STR , NOPE},
{"SetPath" , 257, SK_STR , NOPE},
{"FilePath" , __SK_SINGER_FilePath_, SK_STR , NOPE},
{"Frequency" , __SK_SINGER_Frequency_, SK_STR , NOPE},
{"NoteName" , __SK_SINGER_NoteName_, SK_STR , NOPE},
{"VocalShape" , __SK_SINGER_Shape_ , SK_STR , NOPE},
{"Glottis" , __SK_SINGER_Glot_ , SK_STR , NOPE},
{"VoicedUnVoiced" , __SK_SINGER_VoicedUnVoiced_, SK_DBL , SK_STR},
{"Synthesize" , __SK_SINGER_Synthesize_, SK_STR , NOPE},
{"Silence" , __SK_SINGER_Silence_, SK_STR , NOPE},
{"VibratoAmt" , __SK_ControlChange_ ,__SK_SINGER_VibratoAmt_,SK_DBL},
{"RndVibAmt" , __SK_SINGER_RndVibAmt_ ,SK_STR, NOPE},
{"VibFreq" , __SK_ControlChange_ ,__SK_SINGER_VibFreq_ ,SK_DBL}
};
/** FORMAT: *************************************************************/
/* */
/* MessageStr$ ,type, data2, data3, */
/* */
/* type is the message type sent back from the SKINI line parser. */
/* data<n> is either */
/* NOPE : field not used, specifically, there aren't going */
/* to be any more fields on this line. So if there */
/* is is NOPE in data2, data3 won't even be checked */
/* SK_INT : byte (actually scanned as 32 bit signed integer) */
/* If it's a MIDI data field which is required to */
/* be an integer, like a controller number, it's */
/* 0-127. Otherwise) get creative with SK_INTs */
/* SK_DBL : double precision floating point. SKINI uses these */
/* in the MIDI context for note numbers with micro */
/* tuning, velocities, controller values, etc. */
/* SK_STR : only valid in final field. This allows (nearly) */
/* arbitrary message types to be supported by simply */
/* scanning the string to EndOfLine and then passing */
/* it to a more intellegent handler. For example, */
/* MIDI SYSEX (system exclusive) messages of up to */
/* 256bytes can be read as space-delimited integers */
/* into the 1K SK_STR buffer. Longer bulk dumps, */
/* soundfiles, etc. should be handled as a new */
/* message type pointing to a FileName stored in the */
/* SK_STR field, or as a new type of multi-line */
/* message. */
/* */
/*************************************************************************/

90
include/SingWave.h Normal file
View File

@@ -0,0 +1,90 @@
/***************************************************/
/*! \class SingWave
\brief STK "singing" looped soundfile class.
This class contains all that is needed to make
a pitched musical sound, like a simple voice
or violin. In general, it will not be used
alone because of munchkinification effects
from pitch shifting. It will be used as an
excitation source for other instruments.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__SINGWAVE_H)
#define __SINGWAVE_H
#include "WaveLoop.h"
#include "Modulate.h"
#include "Envelope.h"
class SingWave : public Stk
{
public:
//! Class constructor taking filename argument.
/*!
An StkError will be thrown if the file is not found, its format is
unknown, or a read error occurs.
*/
SingWave(const char *fileName, bool raw=FALSE);
//! Class destructor.
~SingWave();
//! Reset file to beginning.
void reset();
//! Normalize the file to a maximum of +-1.0.
void normalize();
//! Normalize the file to a maximum of \e +- peak.
void normalize(MY_FLOAT peak);
//! Set instrument parameters for a particular frequency.
void setFrequency(MY_FLOAT frequency);
//! Set the vibrato frequency in Hz.
void setVibratoRate(MY_FLOAT aRate);
//! Set the vibrato gain.
void setVibratoGain(MY_FLOAT gain);
//! Set the random-ness amount.
void setRandomGain(MY_FLOAT gain);
//! Set the sweep rate.
void setSweepRate(MY_FLOAT aRate);
//! Set the gain rate.
void setGainRate(MY_FLOAT aRate);
//! Set the gain target value.
void setGainTarget(MY_FLOAT target);
//! Start a note.
void noteOn();
//! Stop a note.
void noteOff();
//! Return the last output value.
MY_FLOAT lastOut();
//! Compute one output sample.
MY_FLOAT tick();
protected:
WaveLoop *wave;
Modulate *modulator;
Envelope *envelope;
Envelope *pitchEnvelope;
MY_FLOAT rate;
MY_FLOAT sweepRate;
MY_FLOAT lastOutput;
};
#endif

View File

@@ -1,103 +1,103 @@
/***************************************************/
/*! \class Socket
\brief STK TCP socket client/server 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.
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 - 2002.
*/
/***************************************************/
#if !defined(__SOCKET_H)
#define __SOCKET_H
#include "Stk.h"
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 );
//! The class destructor closes the socket instance, breaking any existing connections.
~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" );
//! Close this socket.
void close( void );
//! Return the server/client socket descriptor.
int socket( void ) const;
//! Return the server/client 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 is the socket descriptor is valid.
static bool isValid( int socket );
//! 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);
//! 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 );
protected:
char msg[256];
int soket;
int poort;
bool server;
};
#endif // defined(__SOCKET_H)
/***************************************************/
/*! \class Socket
\brief STK TCP socket client/server 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.
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 - 2002.
*/
/***************************************************/
#if !defined(__SOCKET_H)
#define __SOCKET_H
#include "Stk.h"
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 );
//! The class destructor closes the socket instance, breaking any existing connections.
~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" );
//! Close this socket.
void close( void );
//! Return the server/client socket descriptor.
int socket( void ) const;
//! Return the server/client 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 is the socket descriptor is valid.
static bool isValid( int socket );
//! 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);
//! 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 );
protected:
char msg[256];
int soket;
int poort;
bool server;
};
#endif // defined(__SOCKET_H)

70
include/Sphere.h Normal file
View File

@@ -0,0 +1,70 @@
/***************************************************/
/*! \class Sphere
\brief STK sphere class.
This class implements a spherical ball with
radius, mass, position, and velocity parameters.
by Perry R. Cook, 1995 - 2002.
*/
/***************************************************/
#if !defined(__SPHERE_H)
#define __SPHERE_H
#include "Vector3D.h"
class Sphere
{
public:
//! Constructor taking an initial radius value.
Sphere(double initRadius);
//! Class destructor.
~Sphere();
//! Set the 3D center position of the sphere.
void setPosition(double anX, double aY, double aZ);
//! Set the 3D velocity of the sphere.
void setVelocity(double anX, double aY, double aZ);
//! Set the radius of the sphere.
void setRadius(double aRadius);
//! Set the mass of the sphere.
void setMass(double aMass);
//! Get the current position of the sphere as a 3D vector.
Vector3D* getPosition();
//! Get the relative position of the given point to the sphere as a 3D vector.
Vector3D* getRelativePosition(Vector3D *aPosition);
//! Set the velcoity of the sphere as a 3D vector.
double getVelocity(Vector3D* aVelocity);
//! Returns the distance from the sphere boundary to the given position (< 0 if inside).
double isInside(Vector3D *aPosition);
//! Get the current sphere radius.
double getRadius();
//! Get the current sphere mass.
double getMass();
//! Increase the current sphere velocity by the given 3D components.
void addVelocity(double anX, double aY, double aZ);
//! Move the sphere for the given time increment.
void tick(double timeIncrement);
private:
Vector3D *myPosition;
Vector3D *myVelocity;
Vector3D workingVector;
double myRadius;
double myMass;
};
#endif

View File

@@ -1,168 +1,174 @@
/***************************************************/
/*! \class Stk
\brief STK base class
Nearly all STK classes inherit from this class.
The global sample rate can be queried and
modified via Stk. In addition, this class
provides error handling and byte-swapping
functions.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__STK_H)
#define __STK_H
// Most data in STK is passed and calculated with the following
// user-definable floating-point type. You can change this to "float"
// if you prefer or perhaps a "long double" in the future.
typedef double MY_FLOAT;
//! STK error handling class.
/*!
This is a fairly abstract exception handling class. There could
be sub-classes to take care of more specific error conditions ... or
not.
*/
class StkError
{
public:
enum TYPE {
WARNING,
DEBUG_WARNING,
FUNCTION_ARGUMENT,
FILE_NOT_FOUND,
FILE_UNKNOWN_FORMAT,
FILE_ERROR,
PROCESS_THREAD,
PROCESS_SOCKET,
PROCESS_SOCKET_IPADDR,
AUDIO_SYSTEM,
MIDI_SYSTEM,
UNSPECIFIED
};
protected:
char message[256];
TYPE type;
public:
//! The constructor.
StkError(const char *p, TYPE tipe = StkError::UNSPECIFIED);
//! The destructor.
virtual ~StkError(void);
//! Prints "thrown" error message to stdout.
virtual void printMessage(void);
//! Returns the "thrown" error message TYPE.
virtual const TYPE& getType(void) { return type; }
//! Returns the "thrown" error message string.
virtual const char *getMessage(void) const { return message; }
};
class Stk
{
public:
typedef unsigned long STK_FORMAT;
static const STK_FORMAT STK_SINT8; /*!< -128 to +127 */
static const STK_FORMAT STK_SINT16; /*!< -32768 to +32767 */
static const STK_FORMAT STK_SINT32; /*!< -2147483648 to +2147483647. */
static const STK_FORMAT STK_FLOAT32; /*!< Normalized between plus/minus 1.0. */
static const STK_FORMAT STK_FLOAT64; /*!< Normalized between plus/minus 1.0. */
//! Static method which returns the current STK sample rate.
static MY_FLOAT sampleRate(void);
//! Static method which sets the STK sample rate.
/*!
The sample rate set using this method is queried by all STK
classes which depend on its value. It is initialized to the
default SRATE set in Stk.h. Many STK classes use the sample rate
during instantiation. Therefore, if you wish to use a rate which
is different from the default rate, it is imperative that it be
set \e BEFORE STK objects are instantiated.
*/
static void setSampleRate(MY_FLOAT newRate);
//! Static method which byte-swaps a 16-bit data type.
static void swap16(unsigned char *ptr);
//! Static method which byte-swaps a 32-bit data type.
static void swap32(unsigned char *ptr);
//! Static method which byte-swaps a 64-bit data type.
static void swap64(unsigned char *ptr);
//! Static cross-platform method to sleep for a number of milliseconds.
static void sleep(unsigned long milliseconds);
private:
static MY_FLOAT srate;
protected:
//! Default constructor.
Stk(void);
//! Class destructor.
virtual ~Stk(void);
//! Function for error reporting and handling.
static void handleError( const char *message, StkError::TYPE type );
};
// Here are a few other useful typedefs.
typedef signed short SINT16;
typedef signed int SINT32;
typedef float FLOAT32;
typedef double FLOAT64;
// Boolean values
#define FALSE 0
#define TRUE 1
// The default sampling rate.
#define SRATE (MY_FLOAT) 22050.0
// Real-time audio input and output buffer size. If clicks are
// occuring in the input and/or output sound stream, a larger buffer
// size may help. Larger buffer sizes, however, produce more latency.
#define RT_BUFFER_SIZE 512
// The RAWWAVE_PATH definition is concatenated to the beginning of all
// references to rawwave files in the various STK core classes
// (ex. Clarinet.cpp). If you wish to move the rawwaves directory to
// a different location in your file system, you will need to set this
// path definition appropriately. The current definition is a
// relative reference that will work "out of the box" for the STK
// distribution.
#define RAWWAVE_PATH "../../"
#define PI (MY_FLOAT) 3.14159265359
#define TWO_PI (MY_FLOAT) (MY_FLOAT) (2 * PI)
#define ONE_OVER_128 (MY_FLOAT) 0.0078125
#if defined(__WINDOWS_DS__)
#define __OS_WINDOWS__
#define __STK_REALTIME__
#elif defined(__LINUX_OSS__) || defined(__LINUX_ALSA__)
#define __OS_LINUX__
#define __STK_REALTIME__
#elif defined(__IRIX_AL__)
#define __OS_IRIX__
#define __STK_REALTIME__
#endif
//#define _STK_DEBUG_
#endif
/***************************************************/
/*! \class Stk
\brief STK base class
Nearly all STK classes inherit from this class.
The global sample rate can be queried and
modified via Stk. In addition, this class
provides error handling and byte-swapping
functions.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__STK_H)
#define __STK_H
// Most data in STK is passed and calculated with the following
// user-definable floating-point type. You can change this to "float"
// if you prefer or perhaps a "long double" in the future.
typedef double MY_FLOAT;
//! STK error handling class.
/*!
This is a fairly abstract exception handling class. There could
be sub-classes to take care of more specific error conditions ... or
not.
*/
class StkError
{
public:
enum TYPE {
WARNING,
DEBUG_WARNING,
FUNCTION_ARGUMENT,
FILE_NOT_FOUND,
FILE_UNKNOWN_FORMAT,
FILE_ERROR,
PROCESS_THREAD,
PROCESS_SOCKET,
PROCESS_SOCKET_IPADDR,
AUDIO_SYSTEM,
MIDI_SYSTEM,
UNSPECIFIED
};
protected:
char message[256];
TYPE type;
public:
//! The constructor.
StkError(const char *p, TYPE tipe = StkError::UNSPECIFIED);
//! The destructor.
virtual ~StkError(void);
//! Prints "thrown" error message to stdout.
virtual void printMessage(void);
//! Returns the "thrown" error message TYPE.
virtual const TYPE& getType(void) { return type; }
//! Returns the "thrown" error message string.
virtual const char *getMessage(void) const { return message; }
};
class Stk
{
public:
typedef unsigned long STK_FORMAT;
static const STK_FORMAT STK_SINT8; /*!< -128 to +127 */
static const STK_FORMAT STK_SINT16; /*!< -32768 to +32767 */
static const STK_FORMAT STK_SINT32; /*!< -2147483648 to +2147483647. */
static const STK_FORMAT STK_FLOAT32; /*!< Normalized between plus/minus 1.0. */
static const STK_FORMAT STK_FLOAT64; /*!< Normalized between plus/minus 1.0. */
//! Static method which returns the current STK sample rate.
static MY_FLOAT sampleRate(void);
//! Static method which sets the STK sample rate.
/*!
The sample rate set using this method is queried by all STK
classes which depend on its value. It is initialized to the
default SRATE set in Stk.h. Many STK classes use the sample rate
during instantiation. Therefore, if you wish to use a rate which
is different from the default rate, it is imperative that it be
set \e BEFORE STK objects are instantiated.
*/
static void setSampleRate(MY_FLOAT newRate);
//! Static method which byte-swaps a 16-bit data type.
static void swap16(unsigned char *ptr);
//! Static method which byte-swaps a 32-bit data type.
static void swap32(unsigned char *ptr);
//! Static method which byte-swaps a 64-bit data type.
static void swap64(unsigned char *ptr);
//! Static cross-platform method to sleep for a number of milliseconds.
static void sleep(unsigned long milliseconds);
private:
static MY_FLOAT srate;
protected:
//! Default constructor.
Stk(void);
//! Class destructor.
virtual ~Stk(void);
//! Function for error reporting and handling.
static void handleError( const char *message, StkError::TYPE type );
};
// Here are a few other useful typedefs.
typedef signed short SINT16;
typedef signed int SINT32;
typedef float FLOAT32;
typedef double FLOAT64;
// Boolean values
#define FALSE 0
#define TRUE 1
// The default sampling rate.
#define SRATE (MY_FLOAT) 22050.0
// Real-time audio input and output buffer size. If clicks are
// occuring in the input and/or output sound stream, a larger buffer
// size may help. Larger buffer sizes, however, produce more latency.
#define RT_BUFFER_SIZE 512
// The RAWWAVE_PATH definition is concatenated to the beginning of all
// references to rawwave files in the various STK core classes
// (ex. Clarinet.cpp). If you wish to move the rawwaves directory to
// a different location in your file system, you will need to set this
// path definition appropriately. The current definition is a
// relative reference that will work for the programs in the STK
// projects directory. The path can also be specified to configure and
// set via the Makefiles.
#if !defined(RAWWAVE_PATH)
#define RAWWAVE_PATH "../../rawwaves/"
#endif
#define PI (MY_FLOAT) 3.14159265359
#define TWO_PI (MY_FLOAT) (MY_FLOAT) (2 * PI)
#define ONE_OVER_128 (MY_FLOAT) 0.0078125
#if defined(__WINDOWS_DS__)
#define __OS_WINDOWS__
#define __STK_REALTIME__
#elif defined(__LINUX_OSS__) || defined(__LINUX_ALSA__)
#define __OS_LINUX__
#define __STK_REALTIME__
#elif defined(__IRIX_AL__)
#define __OS_IRIX__
#define __STK_REALTIME__
#elif defined(__MACOSX_CORE__)
#define __OS_MACOSX__
#define __STK_REALTIME__
#endif
//#define _STK_DEBUG_
#endif

View File

@@ -1,43 +1,43 @@
/***************************************************/
/*! \class SubNoise
\brief STK sub-sampled noise generator.
Generates a new random number every "rate" ticks
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 - 2002.
*/
/***************************************************/
#if !defined(__SUBNOISE_H)
#define __SUBNOISE_H
#include "Noise.h"
class SubNoise : public Noise
{
public:
//! Default constructor sets sub-sample rate to 16.
SubNoise(int subRate = 16);
//! Class destructor.
~SubNoise();
//! Return the current sub-sampling rate.
int subRate(void) const;
//! Set the sub-sampling rate.
void setRate(int subRate);
//! Return a sub-sampled random number between -1.0 and 1.0.
MY_FLOAT tick();
protected:
int counter;
int rate;
};
#endif
/***************************************************/
/*! \class SubNoise
\brief STK sub-sampled noise generator.
Generates a new random number every "rate" ticks
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 - 2002.
*/
/***************************************************/
#if !defined(__SUBNOISE_H)
#define __SUBNOISE_H
#include "Noise.h"
class SubNoise : public Noise
{
public:
//! Default constructor sets sub-sample rate to 16.
SubNoise(int subRate = 16);
//! Class destructor.
~SubNoise();
//! Return the current sub-sampling rate.
int subRate(void) const;
//! Set the sub-sampling rate.
void setRate(int subRate);
//! Return a sub-sampled random number between -1.0 and 1.0.
MY_FLOAT tick();
protected:
int counter;
int rate;
};
#endif

View File

@@ -1,54 +1,54 @@
/***************************************************/
/*! \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 - 2002.
*/
/***************************************************/
#if !defined(__TABLE_H)
#define __TABLE_H
#include "Stk.h"
class Table : public Stk
{
public:
//! Constructor loads the data from \e fileName.
Table(char *fileName);
//! Class destructor.
~Table();
//! Return the number of elements in the table.
long getLength() const;
//! Return the last output value.
MY_FLOAT lastOut() const;
//! Return the table value at position \e index.
/*!
Linear interpolation is performed if \e index is
fractional.
*/
MY_FLOAT tick(MY_FLOAT index);
//! Take \e vectorSize index positions and return the corresponding table values in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
protected:
long length;
MY_FLOAT *data;
MY_FLOAT lastOutput;
};
#endif // defined(__TABLE_H)
/***************************************************/
/*! \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 - 2002.
*/
/***************************************************/
#if !defined(__TABLE_H)
#define __TABLE_H
#include "Stk.h"
class Table : public Stk
{
public:
//! Constructor loads the data from \e fileName.
Table(char *fileName);
//! Class destructor.
~Table();
//! Return the number of elements in the table.
long getLength() const;
//! Return the last output value.
MY_FLOAT lastOut() const;
//! Return the table value at position \e index.
/*!
Linear interpolation is performed if \e index is
fractional.
*/
MY_FLOAT tick(MY_FLOAT index);
//! Take \e vectorSize index positions and return the corresponding table values in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
protected:
long length;
MY_FLOAT *data;
MY_FLOAT lastOutput;
};
#endif // defined(__TABLE_H)

View File

@@ -1,113 +1,113 @@
/***************************************************/
/*! \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
STK_FORMATs are permissible.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__TCPWVIN_H)
#define __TCPWVIN_H
#include "WvIn.h"
#include "Socket.h"
#include "Thread.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::STK_FORMAT 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.
MY_FLOAT lastOut(void) const;
//! Read out the average across one sample frame of data.
MY_FLOAT tick(void);
//! Read out vectorSize averaged sample frames of data in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
//! Return a pointer to the last output sample frame.
const MY_FLOAT *lastFrame(void) const;
//! Return a pointer to the next sample frame of data.
const MY_FLOAT *tickFrame(void);
//! Read out sample \e frames of data to \e frameVector.
MY_FLOAT *tickFrame(MY_FLOAT *frameVector, unsigned int 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
/***************************************************/
/*! \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
STK_FORMATs are permissible.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__TCPWVIN_H)
#define __TCPWVIN_H
#include "WvIn.h"
#include "Socket.h"
#include "Thread.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::STK_FORMAT 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.
MY_FLOAT lastOut(void) const;
//! Read out the average across one sample frame of data.
MY_FLOAT tick(void);
//! Read out vectorSize averaged sample frames of data in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
//! Return a pointer to the last output sample frame.
const MY_FLOAT *lastFrame(void) const;
//! Return a pointer to the next sample frame of data.
const MY_FLOAT *tickFrame(void);
//! Read out sample \e frames of data to \e frameVector.
MY_FLOAT *tickFrame(MY_FLOAT *frameVector, unsigned int 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,93 +1,93 @@
/***************************************************/
/*! \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 STK_FORMATs are permissible.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__TCPWVOUT_H)
#define __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::STK_FORMAT 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::STK_FORMAT 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.
MY_FLOAT 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(MY_FLOAT 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 MY_FLOAT *vector, unsigned int vectorSize);
//! Output the \e frameVector of sample frames of the given length.
/*!
An StkError is thrown if a socket write error occurs.
*/
void tickFrame(const MY_FLOAT *frameVector, unsigned int frames = 1);
protected:
// Write a buffer of length \e frames via the socket connection.
void writeData( long frames );
char msg[256];
char *buffer;
Socket *soket;
int dataSize;
};
#endif // defined(__TCPWVOUT_H)
/***************************************************/
/*! \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 STK_FORMATs are permissible.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__TCPWVOUT_H)
#define __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::STK_FORMAT 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::STK_FORMAT 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.
MY_FLOAT 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(MY_FLOAT 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 MY_FLOAT *vector, unsigned int vectorSize);
//! Output the \e frameVector of sample frames of the given length.
/*!
An StkError is thrown if a socket write error occurs.
*/
void tickFrame(const MY_FLOAT *frameVector, unsigned int frames = 1);
protected:
// Write a buffer of length \e frames via the socket connection.
void writeData( long frames );
char msg[256];
char *buffer;
Socket *soket;
int dataSize;
};
#endif // defined(__TCPWVOUT_H)

View File

@@ -1,95 +1,95 @@
/***************************************************/
/*! \class Thread
\brief STK thread class.
This class provides a uniform interface for
cross-platform threads. On unix systems,
the pthread library is used. Under Windows,
the C runtime threadex functions are used.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__THREAD_H)
#define __THREAD_H
#include "Stk.h"
#if (defined(__OS_IRIX__) || defined(__OS_LINUX__))
#include <pthread.h>
#define THREAD_TYPE
typedef pthread_t THREAD_HANDLE;
typedef void * THREAD_RETURN;
typedef void * (*THREAD_FUNCTION)(void *);
typedef pthread_mutex_t MUTEX;
#elif defined(__OS_WINDOWS__)
#include <windows.h>
#include <process.h>
#define THREAD_TYPE __stdcall
typedef unsigned long THREAD_HANDLE;
typedef unsigned THREAD_RETURN;
typedef unsigned (__stdcall *THREAD_FUNCTION)(void *);
typedef CRITICAL_SECTION MUTEX;
#endif
class Thread : public Stk
{
public:
//! Default constructor.
Thread();
//! The class destructor waits indefinitely for the thread to end before returning.
~Thread();
//! Begin execution of the thread \e routine. Upon success, TRUE is returned.
/*!
The thread routine can be passed an argument via \e ptr. If
the thread cannot be created, the return value is FALSE.
*/
bool start( THREAD_FUNCTION routine, void * ptr = NULL );
//! Wait the specified number of milliseconds for the thread to terminate. Return TRUE on success.
/*!
If the specified time value is negative, the function will
block indefinitely. Otherwise, the function will block up to a
maximum of the specified time. A return value of FALSE indicates
the thread did not terminate within the specified time limit.
*/
bool wait( long milliseconds = -1 );
//! Test for a thread cancellation request.
static void test(void);
protected:
THREAD_HANDLE thread;
};
class Mutex : public Stk
{
public:
//! Default constructor.
Mutex();
//! Class destructor.
~Mutex();
//! Lock the mutex.
void lock(void);
//! Unlock the mutex.
void unlock(void);
protected:
MUTEX mutex;
};
#endif // defined(__THREAD_H)
/***************************************************/
/*! \class Thread
\brief STK thread class.
This class provides a uniform interface for
cross-platform threads. On unix systems,
the pthread library is used. Under Windows,
the C runtime threadex functions are used.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__THREAD_H)
#define __THREAD_H
#include "Stk.h"
#if (defined(__OS_IRIX__) || defined(__OS_LINUX__) || defined(__OS_MACOSX__))
#include <pthread.h>
#define THREAD_TYPE
typedef pthread_t THREAD_HANDLE;
typedef void * THREAD_RETURN;
typedef void * (*THREAD_FUNCTION)(void *);
typedef pthread_mutex_t MUTEX;
#elif defined(__OS_WINDOWS__)
#include <windows.h>
#include <process.h>
#define THREAD_TYPE __stdcall
typedef unsigned long THREAD_HANDLE;
typedef unsigned THREAD_RETURN;
typedef unsigned (__stdcall *THREAD_FUNCTION)(void *);
typedef CRITICAL_SECTION MUTEX;
#endif
class Thread : public Stk
{
public:
//! Default constructor.
Thread();
//! The class destructor waits indefinitely for the thread to end before returning.
~Thread();
//! Begin execution of the thread \e routine. Upon success, TRUE is returned.
/*!
The thread routine can be passed an argument via \e ptr. If
the thread cannot be created, the return value is FALSE.
*/
bool start( THREAD_FUNCTION routine, void * ptr = NULL );
//! Wait the specified number of milliseconds for the thread to terminate. Return TRUE on success.
/*!
If the specified time value is negative, the function will
block indefinitely. Otherwise, the function will block up to a
maximum of the specified time. A return value of FALSE indicates
the thread did not terminate within the specified time limit.
*/
bool wait( long milliseconds = -1 );
//! Test for a thread cancellation request.
static void test(void);
protected:
THREAD_HANDLE thread;
};
class Mutex : public Stk
{
public:
//! Default constructor.
Mutex();
//! Class destructor.
~Mutex();
//! Lock the mutex.
void lock(void);
//! Unlock the mutex.
void unlock(void);
protected:
MUTEX mutex;
};
#endif // defined(__THREAD_H)

View File

@@ -1,78 +1,78 @@
/***************************************************/
/*! \class TwoPole
\brief STK two-pole filter class.
This protected Filter subclass implements
a two-pole digital filter. A method is
provided for creating a resonance in the
frequency response while maintaining a nearly
constant filter gain.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__TWOPOLE_H)
#define __TWOPOLE_H
#include "Filter.h"
class TwoPole : protected Filter
{
public:
//! Default constructor creates a second-order pass-through filter.
TwoPole();
//! Class destructor.
~TwoPole();
//! Clears the internal states of the filter.
void clear(void);
//! Set the b[0] coefficient value.
void setB0(MY_FLOAT b0);
//! Set the a[1] coefficient value.
void setA1(MY_FLOAT a1);
//! Set the a[2] coefficient value.
void setA2(MY_FLOAT a2);
//! Sets the filter coefficients for a resonance at \e frequency (in Hz).
/*!
This method determines the filter coefficients corresponding to
two complex-conjugate poles with the given \e frequency (in Hz)
and \e radius from the z-plane origin. If \e normalize is true,
the coefficients are then normalized to produce unity gain at \e
frequency (the actual maximum filter gain tends to be slightly
greater than unity when \e radius is not close to one). The
resulting filter frequency response has a resonance at the given
\e frequency. The closer the poles are to the unit-circle (\e
radius close to one), the narrower the resulting resonance width.
An unstable filter will result for \e radius >= 1.0. For a better
resonance filter, use a BiQuad filter. \sa BiQuad filter class
*/
void setResonance(MY_FLOAT frequency, MY_FLOAT radius, bool normalize = FALSE);
//! Set the filter gain.
/*!
The gain is applied at the filter input and does not affect the
coefficient values. The default gain value is 1.0.
*/
void setGain(MY_FLOAT theGain);
//! Return the current filter gain.
MY_FLOAT getGain(void) const;
//! Return the last computed output value.
MY_FLOAT lastOut(void) const;
//! Input one sample to the filter and return one output.
MY_FLOAT tick(MY_FLOAT sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
};
#endif
/***************************************************/
/*! \class TwoPole
\brief STK two-pole filter class.
This protected Filter subclass implements
a two-pole digital filter. A method is
provided for creating a resonance in the
frequency response while maintaining a nearly
constant filter gain.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__TWOPOLE_H)
#define __TWOPOLE_H
#include "Filter.h"
class TwoPole : protected Filter
{
public:
//! Default constructor creates a second-order pass-through filter.
TwoPole();
//! Class destructor.
~TwoPole();
//! Clears the internal states of the filter.
void clear(void);
//! Set the b[0] coefficient value.
void setB0(MY_FLOAT b0);
//! Set the a[1] coefficient value.
void setA1(MY_FLOAT a1);
//! Set the a[2] coefficient value.
void setA2(MY_FLOAT a2);
//! Sets the filter coefficients for a resonance at \e frequency (in Hz).
/*!
This method determines the filter coefficients corresponding to
two complex-conjugate poles with the given \e frequency (in Hz)
and \e radius from the z-plane origin. If \e normalize is true,
the coefficients are then normalized to produce unity gain at \e
frequency (the actual maximum filter gain tends to be slightly
greater than unity when \e radius is not close to one). The
resulting filter frequency response has a resonance at the given
\e frequency. The closer the poles are to the unit-circle (\e
radius close to one), the narrower the resulting resonance width.
An unstable filter will result for \e radius >= 1.0. For a better
resonance filter, use a BiQuad filter. \sa BiQuad filter class
*/
void setResonance(MY_FLOAT frequency, MY_FLOAT radius, bool normalize = FALSE);
//! Set the filter gain.
/*!
The gain is applied at the filter input and does not affect the
coefficient values. The default gain value is 1.0.
*/
void setGain(MY_FLOAT theGain);
//! Return the current filter gain.
MY_FLOAT getGain(void) const;
//! Return the last computed output value.
MY_FLOAT lastOut(void) const;
//! Input one sample to the filter and return one output.
MY_FLOAT tick(MY_FLOAT sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
};
#endif

View File

@@ -1,74 +1,74 @@
/***************************************************/
/*! \class TwoZero
\brief STK two-zero filter class.
This protected Filter subclass implements
a two-zero digital filter. A method is
provided for creating a "notch" in the
frequency response while maintaining a
constant filter gain.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__TWOZERO_H)
#define __TWOZERO_H
#include "Filter.h"
class TwoZero : protected Filter
{
public:
//! Default constructor creates a second-order pass-through filter.
TwoZero();
//! Class destructor.
~TwoZero();
//! Clears the internal states of the filter.
void clear(void);
//! Set the b[0] coefficient value.
void setB0(MY_FLOAT b0);
//! Set the b[1] coefficient value.
void setB1(MY_FLOAT b1);
//! Set the b[2] coefficient value.
void setB2(MY_FLOAT b2);
//! Sets the filter coefficients for a "notch" at \e frequency (in Hz).
/*!
This method determines the filter coefficients corresponding to
two complex-conjugate zeros with the given \e frequency (in Hz)
and \e radius from the z-plane origin. The coefficients are then
normalized to produce a maximum filter gain of one (independent of
the filter \e gain parameter). The resulting filter frequency
response has a "notch" or anti-resonance at the given \e
frequency. The closer the zeros are to the unit-circle (\e radius
close to or equal to one), the narrower the resulting notch width.
*/
void setNotch(MY_FLOAT frequency, MY_FLOAT radius);
//! Set the filter gain.
/*!
The gain is applied at the filter input and does not affect the
coefficient values. The default gain value is 1.0.
*/
void setGain(MY_FLOAT theGain);
//! Return the current filter gain.
MY_FLOAT getGain(void) const;
//! Return the last computed output value.
MY_FLOAT lastOut(void) const;
//! Input one sample to the filter and return one output.
MY_FLOAT tick(MY_FLOAT sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
};
#endif
/***************************************************/
/*! \class TwoZero
\brief STK two-zero filter class.
This protected Filter subclass implements
a two-zero digital filter. A method is
provided for creating a "notch" in the
frequency response while maintaining a
constant filter gain.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__TWOZERO_H)
#define __TWOZERO_H
#include "Filter.h"
class TwoZero : protected Filter
{
public:
//! Default constructor creates a second-order pass-through filter.
TwoZero();
//! Class destructor.
~TwoZero();
//! Clears the internal states of the filter.
void clear(void);
//! Set the b[0] coefficient value.
void setB0(MY_FLOAT b0);
//! Set the b[1] coefficient value.
void setB1(MY_FLOAT b1);
//! Set the b[2] coefficient value.
void setB2(MY_FLOAT b2);
//! Sets the filter coefficients for a "notch" at \e frequency (in Hz).
/*!
This method determines the filter coefficients corresponding to
two complex-conjugate zeros with the given \e frequency (in Hz)
and \e radius from the z-plane origin. The coefficients are then
normalized to produce a maximum filter gain of one (independent of
the filter \e gain parameter). The resulting filter frequency
response has a "notch" or anti-resonance at the given \e
frequency. The closer the zeros are to the unit-circle (\e radius
close to or equal to one), the narrower the resulting notch width.
*/
void setNotch(MY_FLOAT frequency, MY_FLOAT radius);
//! Set the filter gain.
/*!
The gain is applied at the filter input and does not affect the
coefficient values. The default gain value is 1.0.
*/
void setGain(MY_FLOAT theGain);
//! Return the current filter gain.
MY_FLOAT getGain(void) const;
//! Return the last computed output value.
MY_FLOAT lastOut(void) const;
//! Input one sample to the filter and return one output.
MY_FLOAT tick(MY_FLOAT sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
};
#endif

53
include/Vector3D.h Normal file
View File

@@ -0,0 +1,53 @@
/***************************************************/
/*! \class Vector3D
\brief STK 3D vector class.
This class implements a three-dimensional vector.
by Perry R. Cook, 1995 - 2002.
*/
/***************************************************/
#if !defined(__VECTOR3D_H)
#define __VECTOR3D_H
class Vector3D {
public:
//! Default constructor taking optional initial X, Y, and Z values.
Vector3D(double initX=0.0, double initY=0.0, double initZ=0.0);
//! Class destructor.
~Vector3D();
//! Get the current X value.
double getX();
//! Get the current Y value.
double getY();
//! Get the current Z value.
double getZ();
//! Calculate the vector length.
double getLength();
//! Set the X, Y, and Z values simultaniously.
void setXYZ(double anX, double aY, double aZ);
//! Set the X value.
void setX(double aval);
//! Set the Y value.
void setY(double aval);
//! Set the Z value.
void setZ(double aval);
protected:
double myX;
double myY;
double myZ;
};
#endif

97
include/VoicForm.h Normal file
View File

@@ -0,0 +1,97 @@
/***************************************************/
/*! \class VoicForm
\brief Four formant synthesis instrument.
This instrument contains an excitation singing
wavetable (looping wave with random and
periodic vibrato, smoothing on frequency,
etc.), excitation noise, and four sweepable
complex resonances.
Measured formant data is included, and enough
data is there to support either parallel or
cascade synthesis. In the floating point case
cascade synthesis is the most natural so
that's what you'll find here.
Control Change Numbers:
- Voiced/Unvoiced Mix = 2
- Vowel/Phoneme Selection = 4
- Vibrato Frequency = 11
- Vibrato Gain = 1
- Loudness (Spectral Tilt) = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__VOICFORM_H)
#define __VOICFORM_H
#include "Instrmnt.h"
#include "Envelope.h"
#include "Noise.h"
#include "SingWave.h"
#include "FormSwep.h"
#include "OnePole.h"
#include "OneZero.h"
class VoicForm : public Instrmnt
{
public:
//! Class constructor, taking the lowest desired playing frequency.
VoicForm();
//! Class destructor.
~VoicForm();
//! Reset and clear all internal state.
void clear();
//! Set instrument parameters for a particular frequency.
void setFrequency(MY_FLOAT frequency);
//! Set instrument parameters for the given phoneme. Returns FALSE if phoneme not found.
bool setPhoneme(const char* phoneme);
//! Set the voiced component gain.
void setVoiced(MY_FLOAT vGain);
//! Set the unvoiced component gain.
void setUnVoiced(MY_FLOAT nGain);
//! Set the sweep rate for a particular formant filter (0-3).
void setFilterSweepRate(int whichOne, MY_FLOAT rate);
//! Set voiced component pitch sweep rate.
void setPitchSweepRate(MY_FLOAT rate);
//! Start the voice.
void speak();
//! Stop the voice.
void quiet();
//! Start a note with the given frequency and amplitude.
void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
//! Stop a note with the given amplitude (speed of decay).
void noteOff(MY_FLOAT amplitude);
//! Compute one output sample.
MY_FLOAT tick();
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, MY_FLOAT value);
protected:
SingWave *voiced;
Noise *noise;
Envelope *noiseEnv;
FormSwep *filters[4];
OnePole *onepole;
OneZero *onezero;
};
#endif

141
include/Voicer.h Normal file
View File

@@ -0,0 +1,141 @@
/***************************************************/
/*! \class Voicer
\brief STK voice manager class.
This class can be used to manage a group of
STK instrument classes. Individual voices can
be controlled via unique note tags.
Instrument groups can be controlled by channel
number.
A previously constructed STK instrument class
is linked with a voice manager using the
addInstrument() function. An optional channel
number argument can be specified to the
addInstrument() function as well (default
channel = 0). The voice manager does not
delete any instrument instances ... it is the
responsibility of the user to allocate and
deallocate all instruments.
The tick() function returns the mix of all
sounding voices. Each noteOn returns a unique
tag (credits to the NeXT MusicKit), so you can
send control changes to specific voices within
an ensemble. Alternately, control changes can
be sent to all voices on a given channel.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__VOICER_H)
#define __VOICER_H
#include "Stk.h"
#include "Instrmnt.h"
class Voicer : public Stk
{
public:
//! Class constructor taking the maximum number of instruments to control and an optional note decay time (in seconds).
Voicer( int maxInstruments, MY_FLOAT decayTime=0.2 );
//! Class destructor.
~Voicer();
//! Add an instrument with an optional channel number to the voice manager.
/*!
A set of instruments can be grouped by channel number and
controlled via the functions which take a channel number argument.
*/
void addInstrument( Instrmnt *instrument, int channel=0 );
//! Remove the given instrument pointer from the voice manager's control.
/*!
It is important that any instruments which are to be deleted by
the user while the voice manager is running be first removed from
the manager's control via this function!!
*/
void removeInstrument( Instrmnt *instrument );
//! Initiate a noteOn event with the given note number and amplitude and return a unique note tag.
/*!
Send the noteOn message to the first available unused voice.
If all voices are sounding, the oldest voice is interrupted and
sent the noteOn message. If the optional channel argument is
non-zero, only voices on that channel are used. If no voices are
found for a specified non-zero channel value, the function returns
-1. The amplitude value should be in the range 0.0 - 128.0.
*/
long noteOn( MY_FLOAT noteNumber, MY_FLOAT amplitude, int channel=0 );
//! Send a noteOff to all voices having the given noteNumber and optional channel (default channel = 0).
/*!
The amplitude value should be in the range 0.0 - 128.0.
*/
void noteOff( MY_FLOAT noteNumber, MY_FLOAT amplitude, int channel=0 );
//! Send a noteOff to the voice with the given note tag.
/*!
The amplitude value should be in the range 0.0 - 128.0.
*/
void noteOff( long tag, MY_FLOAT amplitude );
//! Send a frequency update message to all voices assigned to the optional channel argument (default channel = 0).
/*!
The \e noteNumber argument corresponds to a MIDI note number, though it is a floating-point value and can range beyond the normal 0-127 range.
*/
void setFrequency( MY_FLOAT noteNumber, int channel=0 );
//! Send a frequency update message to the voice with the given note tag.
/*!
The \e noteNumber argument corresponds to a MIDI note number, though it is a floating-point value and can range beyond the normal 0-127 range.
*/
void setFrequency( long tag, MY_FLOAT noteNumber );
//! Send a pitchBend message to all voices assigned to the optional channel argument (default channel = 0).
void pitchBend( MY_FLOAT value, int channel=0 );
//! Send a pitchBend message to the voice with the given note tag.
void pitchBend( long tag, MY_FLOAT value );
//! Send a controlChange to all instruments assigned to the optional channel argument (default channel = 0).
void controlChange( int number, MY_FLOAT value, int channel=0 );
//! Send a controlChange to the voice with the given note tag.
void controlChange( long tag, int number, MY_FLOAT value );
//! Send a noteOff message to all existing voices.
void silence( void );
//! Mix the output for all sounding voices.
MY_FLOAT tick();
//! Computer \e vectorSize output mixes and return them in \e vector.
MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
//! Return the last output value.
MY_FLOAT lastOut() const;
protected:
typedef struct {
Instrmnt *instrument;
long tag;
MY_FLOAT noteNumber;
MY_FLOAT frequency;
int sounding;
int channel;
} Voice;
int nVoices;
int maxVoices;
Voice *voices;
long tags;
int muteTime;
MY_FLOAT lastOutput;
};
#endif

View File

@@ -1,76 +1,76 @@
/***************************************************/
/*! \class WaveLoop
\brief STK waveform oscillator class.
This class inherits from WvIn and provides
audio file looping functionality.
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.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__WAVELOOP_H)
#define __WAVELOOP_H
#include "WvIn.h"
#include <stdio.h>
class WaveLoop : public WvIn
{
public:
//! Class constructor.
WaveLoop( const char *fileName, bool raw = FALSE );
//! Class destructor.
virtual ~WaveLoop();
//! 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
corresponds to file cycles per second. The frequency can be
negative, in which case the loop is read in reverse order.
*/
void setFrequency(MY_FLOAT aFrequency);
//! Increment the read pointer by \e aTime samples, modulo file size.
void addTime(MY_FLOAT aTime);
//! Increment current read pointer by \e anAngle, 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(MY_FLOAT anAngle);
//! 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
is a multiple of file size.
*/
void addPhaseOffset(MY_FLOAT anAngle);
//! Return a pointer to the next sample frame of data.
const MY_FLOAT *tickFrame(void);
protected:
// Read file data.
void readData(unsigned long index);
MY_FLOAT phaseOffset;
};
#endif // defined(__WAVELOOP_H)
/***************************************************/
/*! \class WaveLoop
\brief STK waveform oscillator class.
This class inherits from WvIn and provides
audio file looping functionality.
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.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__WAVELOOP_H)
#define __WAVELOOP_H
#include "WvIn.h"
#include <stdio.h>
class WaveLoop : public WvIn
{
public:
//! Class constructor.
WaveLoop( const char *fileName, bool raw = FALSE );
//! Class destructor.
virtual ~WaveLoop();
//! 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
corresponds to file cycles per second. The frequency can be
negative, in which case the loop is read in reverse order.
*/
void setFrequency(MY_FLOAT aFrequency);
//! Increment the read pointer by \e aTime samples, modulo file size.
void addTime(MY_FLOAT aTime);
//! Increment current read pointer by \e anAngle, 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(MY_FLOAT anAngle);
//! 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
is a multiple of file size.
*/
void addPhaseOffset(MY_FLOAT anAngle);
//! Return a pointer to the next sample frame of data.
const MY_FLOAT *tickFrame(void);
protected:
// Read file data.
void readData(unsigned long index);
MY_FLOAT phaseOffset;
};
#endif // defined(__WAVELOOP_H)

85
include/Whistle.h Normal file
View File

@@ -0,0 +1,85 @@
/***************************************************/
/*! \class Whistle
\brief STK police/referee whistle instrument class.
This class implements a hybrid physical/spectral
model of a police whistle (a la Cook).
Control Change Numbers:
- Noise Gain = 4
- Fipple Modulation Frequency = 11
- Fipple Modulation Gain = 1
- Blowing Frequency Modulation = 2
- Volume = 128
by Perry R. Cook 1996 - 2002.
*/
/***************************************************/
#if !defined(__WHISTLE_H)
#define __WHISTLE_H
#include "Instrmnt.h"
#include "Sphere.h"
#include "Vector3D.h"
#include "Noise.h"
#include "WaveLoop.h"
#include "OnePole.h"
#include "Envelope.h"
class Whistle : public Instrmnt
{
public:
//! Class constructor.
Whistle();
//! Class destructor.
~Whistle();
//! Reset and clear all internal state.
void clear();
//! Set instrument parameters for a particular frequency.
void setFrequency(MY_FLOAT frequency);
//! Apply breath velocity to instrument with given amplitude and rate of increase.
void startBlowing(MY_FLOAT amplitude, MY_FLOAT rate);
//! Decrease breath velocity with given rate of decrease.
void stopBlowing(MY_FLOAT rate);
//! Start a note with the given frequency and amplitude.
void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
//! Stop a note with the given amplitude (speed of decay).
void noteOff(MY_FLOAT amplitude);
//! Compute one output sample.
MY_FLOAT tick();
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, MY_FLOAT value);
protected:
Vector3D *tempVectorP;
Vector3D *tempVector;
OnePole onepole;
Noise noise;
Envelope envelope;
Sphere *can; // Declare a Spherical "can".
Sphere *pea, *bumper; // One spherical "pea", and a spherical "bumper".
WaveLoop *sine;
MY_FLOAT baseFrequency;
MY_FLOAT maxPressure;
MY_FLOAT noiseGain;
MY_FLOAT fippleFreqMod;
MY_FLOAT fippleGainMod;
MY_FLOAT blowFreqMod;
MY_FLOAT tickSize;
MY_FLOAT canLoss;
int subSample, subSampCount;
};
#endif

View File

@@ -1,207 +1,207 @@
/***************************************************/
/*! \class WvIn
\brief STK audio data input base class.
This class provides input support for various
audio file formats. It also serves as a base
class for "realtime" streaming 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 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.
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.
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.
Uncompressed data types are not supported. If
using MAT-files, data should be saved in an array
with each data channel filling a matrix row.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__WVIN_H)
#define __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.
#define CHUNK_THRESHOLD 5000000 // 5 Mb
#define CHUNK_SIZE 1024 // sample frames
#include "Stk.h"
#include <stdio.h>
class WvIn : public Stk
{
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( const char *fileName, bool raw = FALSE );
//! 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( const char *fileName, bool raw = FALSE );
//! 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(MY_FLOAT 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.
*/
MY_FLOAT 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(MY_FLOAT aRate);
//! Increment the read pointer by \e aTime samples.
virtual void addTime(MY_FLOAT 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 average across the last output sample frame.
virtual MY_FLOAT lastOut(void) const;
//! 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.
*/
virtual MY_FLOAT 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 MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
//! Return a pointer to the last output sample frame.
virtual const MY_FLOAT *lastFrame(void) const;
//! Return a pointer to the next sample frame of data.
/*!
An StkError will be thrown if a file is read incrementally and a read error occurs.
*/
virtual const MY_FLOAT *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 MY_FLOAT *tickFrame(MY_FLOAT *frameVector, unsigned int frames);
protected:
// Initialize class variables.
void init( void );
// Read file data.
virtual void readData(unsigned long index);
// 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 );
char msg[256];
FILE *fd;
MY_FLOAT *data;
MY_FLOAT *lastOutput;
bool chunking;
bool finished;
bool interpolate;
bool byteswap;
unsigned long fileSize;
unsigned long bufferSize;
unsigned long dataOffset;
unsigned int channels;
long chunkPointer;
STK_FORMAT dataType;
MY_FLOAT fileRate;
MY_FLOAT gain;
MY_FLOAT time;
MY_FLOAT rate;
};
#endif // defined(__WVIN_H)
/***************************************************/
/*! \class WvIn
\brief STK audio data input base class.
This class provides input support for various
audio file formats. It also serves as a base
class for "realtime" streaming 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 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.
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.
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.
Uncompressed data types are not supported. If
using MAT-files, data should be saved in an array
with each data channel filling a matrix row.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__WVIN_H)
#define __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.
#define CHUNK_THRESHOLD 5000000 // 5 Mb
#define CHUNK_SIZE 1024 // sample frames
#include "Stk.h"
#include <stdio.h>
class WvIn : public Stk
{
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( const char *fileName, bool raw = FALSE );
//! 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( const char *fileName, bool raw = FALSE );
//! 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(MY_FLOAT 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.
*/
MY_FLOAT 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(MY_FLOAT aRate);
//! Increment the read pointer by \e aTime samples.
virtual void addTime(MY_FLOAT 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 average across the last output sample frame.
virtual MY_FLOAT lastOut(void) const;
//! 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.
*/
virtual MY_FLOAT 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 MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
//! Return a pointer to the last output sample frame.
virtual const MY_FLOAT *lastFrame(void) const;
//! Return a pointer to the next sample frame of data.
/*!
An StkError will be thrown if a file is read incrementally and a read error occurs.
*/
virtual const MY_FLOAT *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 MY_FLOAT *tickFrame(MY_FLOAT *frameVector, unsigned int frames);
protected:
// Initialize class variables.
void init( void );
// Read file data.
virtual void readData(unsigned long index);
// 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 );
char msg[256];
FILE *fd;
MY_FLOAT *data;
MY_FLOAT *lastOutput;
bool chunking;
bool finished;
bool interpolate;
bool byteswap;
unsigned long fileSize;
unsigned long bufferSize;
unsigned long dataOffset;
unsigned int channels;
long chunkPointer;
STK_FORMAT dataType;
MY_FLOAT fileRate;
MY_FLOAT gain;
MY_FLOAT time;
MY_FLOAT rate;
};
#endif // defined(__WVIN_H)

View File

@@ -1,149 +1,149 @@
/***************************************************/
/*! \class WvOut
\brief STK audio data output base class.
This class provides output support for various
audio file formats. It also serves as a base
class for "realtime" streaming 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 currently supports 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. Uncompressed data types are not
supported.
Currently, WvOut is non-interpolating and the
output rate is always Stk::sampleRate().
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__WVOUT_H)
#define __WVOUT_H
#include "Stk.h"
#include <stdio.h>
#define BUFFER_SIZE 1024 // sample frames
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::STK_FORMAT 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::STK_FORMAT 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;
//! Return the number of seconds of data output.
MY_FLOAT getTime( void ) const;
//! Output a single sample to all channels in a sample frame.
/*!
An StkError is thrown if a file read error occurs.
*/
virtual void tick(const MY_FLOAT sample);
//! Output each sample in \e vector to all channels in \e vectorSize sample frames.
/*!
An StkError is thrown if a file read error occurs.
*/
virtual void tick(const MY_FLOAT *vector, unsigned int vectorSize);
//! Output the \e frameVector of sample frames of the given length.
/*!
An StkError is thrown if a file read error occurs.
*/
virtual void tickFrame(const MY_FLOAT *frameVector, unsigned int frames = 1);
protected:
// Initialize class variables.
void init( void );
// Write data to output file;
virtual void writeData( unsigned long frames );
// 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 );
char msg[256];
FILE *fd;
MY_FLOAT *data;
FILE_TYPE fileType;
STK_FORMAT dataType;
bool byteswap;
unsigned int channels;
unsigned long counter;
unsigned long totalCount;
};
#endif // defined(__WVOUT_H)
/***************************************************/
/*! \class WvOut
\brief STK audio data output base class.
This class provides output support for various
audio file formats. It also serves as a base
class for "realtime" streaming 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 currently supports 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. Uncompressed data types are not
supported.
Currently, WvOut is non-interpolating and the
output rate is always Stk::sampleRate().
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#if !defined(__WVOUT_H)
#define __WVOUT_H
#include "Stk.h"
#include <stdio.h>
#define BUFFER_SIZE 1024 // sample frames
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::STK_FORMAT 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::STK_FORMAT 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;
//! Return the number of seconds of data output.
MY_FLOAT getTime( void ) const;
//! Output a single sample to all channels in a sample frame.
/*!
An StkError is thrown if a file read error occurs.
*/
virtual void tick(const MY_FLOAT sample);
//! Output each sample in \e vector to all channels in \e vectorSize sample frames.
/*!
An StkError is thrown if a file read error occurs.
*/
virtual void tick(const MY_FLOAT *vector, unsigned int vectorSize);
//! Output the \e frameVector of sample frames of the given length.
/*!
An StkError is thrown if a file read error occurs.
*/
virtual void tickFrame(const MY_FLOAT *frameVector, unsigned int frames = 1);
protected:
// Initialize class variables.
void init( void );
// Write data to output file;
virtual void writeData( unsigned long frames );
// 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 );
char msg[256];
FILE *fd;
MY_FLOAT *data;
FILE_TYPE fileType;
STK_FORMAT dataType;
bool byteswap;
unsigned int channels;
unsigned long counter;
unsigned long totalCount;
};
#endif // defined(__WVOUT_H)

View File

@@ -1,189 +0,0 @@
double phonGains[32][2] =
{{1.0,0.0}, // eee
{1.0,0.0}, // ihh
{1.0,0.0}, // ehh
{1.0,0.0}, // aaa
{1.0,0.0}, // ahh
{1.0,0.0}, // aww
{1.0,0.0}, // ohh
{1.0,0.0}, // uhh
{1.0,0.0}, // uuu
{1.0,0.0}, // ooo
{1.0,0.0}, // rrr
{1.0,0.0}, // lll
{1.0,0.0}, // mmm
{1.0,0.0}, // nnn
{1.0,0.0}, // nng
{1.0,0.0}, // ngg
{0.0,1.0}, // fff
{0.0,1.0}, // sss
{0.0,1.0}, // thh
{0.0,1.0}, // shh
{0.0,1.0}, // xxx
{0.0,0.1}, // hee
{0.0,0.1}, // hoo
{0.0,0.1}, // hah
{1.0,0.1}, // bbb
{1.0,0.1}, // ddd
{1.0,0.1}, // jjj
{1.0,0.1}, // ggg
{1.0,1.0}, // vvv
{1.0,1.0}, // zzz
{1.0,1.0}, // thz
{1.0,1.0} // zhh
};
double phonParams[32][4][3] =
{{ { 273,0.996, 0}, // eee (beet)
{2086,0.945, -16},
{2754,0.979, -12},
{3270,0.440, -17}},
{ { 385,0.987, 10}, // ihh (bit)
{2056,0.930, -20},
{2587,0.890, -20},
{3150,0.400, -20}},
{ { 515,0.977, 10}, // ehh (bet)
{1805,0.810, -10},
{2526,0.875, -10},
{3103,0.400, -13}},
{ { 773,0.950, 10}, // aaa (bat)
{1676,0.830, -6},
{2380,0.880, -20},
{3027,0.600, -20}},
{ { 770,0.950, 0}, // ahh (father)
{1153,0.970, -9},
{2450,0.780, -29},
{3140,0.800, -39}},
{ { 637,0.910, 0}, // aww (bought)
{ 895,0.900, -3},
{2556,0.950, -17},
{3070,0.910, -20}},
{ { 637,0.910, 0}, // ohh (bone) NOTE:: same as aww (bought)
{ 895,0.900, -3},
{2556,0.950, -17},
{3070,0.910, -20}},
{ { 561,0.965, 0}, // uhh (but)
{1084,0.930, -10},
{2541,0.930, -15},
{3345,0.900, -20}},
{ { 515,0.976, 0}, // uuu (foot)
{1031,0.950, -3},
{2572,0.960, -11},
{3345,0.960, -20}},
{ { 349,0.986, -10}, // ooo (boot)
{ 918,0.940, -20},
{2350,0.960, -27},
{2731,0.950, -33}},
{ { 394,0.959, -10}, // rrr (bird)
{1297,0.780, -16},
{1441,0.980, -16},
{2754,0.950, -40}},
{ { 462,0.990, +5}, // lll (lull)
{1200,0.640, -10},
{2500,0.200, -20},
{3000,0.100, -30}},
{ { 265,0.987, -10}, // mmm (mom)
{1176,0.940, -22},
{2352,0.970, -20},
{3277,0.940, -31}},
{ { 204,0.980, -10}, // nnn (nun)
{1570,0.940, -15},
{2481,0.980, -12},
{3133,0.800, -30}},
{ { 204,0.980, -10}, // nng (sang) NOTE:: same as nnn
{1570,0.940, -15},
{2481,0.980, -12},
{3133,0.800, -30}},
{ { 204,0.980, -10}, // ngg (bong) NOTE:: same as nnn
{1570,0.940, -15},
{2481,0.980, -12},
{3133,0.800, -30}},
{ {1000,0.300, 0}, // fff
{2800,0.860, -10},
{7425,0.740, 0},
{8140,0.860, 0}},
{ {0,0.000, 0}, // sss
{2000,0.700, -15},
{5257,0.750, -3},
{7171,0.840, 0}},
{ { 100,0.900, 0}, // thh
{4000,0.500, -20},
{5500,0.500, -15},
{8000,0.400, -20}},
{ {2693,0.940, 0}, // shh
{4000,0.720, -10},
{6123,0.870, -10},
{7755,0.750, -18}},
{ {1000,0.300, -10}, // xxx NOTE:: Not Really Done Yet
{2800,0.860, -10},
{7425,0.740, 0},
{8140,0.860, 0}},
{ { 273,0.996, -40}, // hee (beet) (noisy eee)
{2086,0.945, -16},
{2754,0.979, -12},
{3270,0.440, -17}},
{ { 349,0.986, -40}, // hoo (boot) (noisy ooo)
{ 918,0.940, -10},
{2350,0.960, -17},
{2731,0.950, -23}},
{ { 770,0.950, -40}, // hah (father) (noisy ahh)
{1153,0.970, -3},
{2450,0.780, -20},
{3140,0.800, -32}},
{ {2000,0.700, -20}, // bbb NOTE:: Not Really Done Yet
{5257,0.750, -15},
{7171,0.840, -3},
{9000,0.900, 0}},
{ { 100,0.900, 0}, // ddd NOTE:: Not Really Done Yet
{4000,0.500, -20},
{5500,0.500, -15},
{8000,0.400, -20}},
{ {2693,0.940, 0}, // jjj NOTE:: Not Really Done Yet
{4000,0.720, -10},
{6123,0.870, -10},
{7755,0.750, -18}},
{ {2693,0.940, 0}, // ggg NOTE:: Not Really Done Yet
{4000,0.720, -10},
{6123,0.870, -10},
{7755,0.750, -18}},
{ {2000,0.700, -20}, // vvv NOTE:: Not Really Done Yet
{5257,0.750, -15},
{7171,0.840, -3},
{9000,0.900, 0}},
{ { 100,0.900, 0}, // zzz NOTE:: Not Really Done Yet
{4000,0.500, -20},
{5500,0.500, -15},
{8000,0.400, -20}},
{ {2693,0.940, 0}, // thz NOTE:: Not Really Done Yet
{4000,0.720, -10},
{6123,0.870, -10},
{7755,0.750, -18}},
{ {2693,0.940, 0}, // zhh NOTE:: Not Really Done Yet
{4000,0.720, -10},
{6123,0.870, -10},
{7755,0.750, -18}}
};
char phonemes[32][4] =
{"eee","ihh","ehh","aaa",
"ahh","aww","ohh","uhh",
"uuu","ooo","rrr","lll",
"mmm","nnn","nng","ngg",
"fff","sss","thh","shh",
"xxx","hee","hoo","hah",
"bbb","ddd","jjj","ggg",
"vvv","zzz","thz","zhh"};