mirror of
https://github.com/thestk/stk
synced 2026-01-14 21:41:53 +00:00
Version 4.4.4
This commit is contained in:
committed by
Stephen Sinclair
parent
0aec39260a
commit
fc877b87bf
@@ -14,9 +14,10 @@ namespace stk {
|
||||
messages, keeping track of its state. The \e state = ADSR::IDLE
|
||||
before being triggered and after the envelope value reaches 0.0 in
|
||||
the ADSR::RELEASE state. All rate, target and level settings must
|
||||
be non-negative. All time settings must be positive.
|
||||
be non-negative. All time settings are in seconds and must be
|
||||
positive.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
@@ -45,22 +46,22 @@ class ADSR : public Generator
|
||||
//! Set target = 0, state = \e ADSR::RELEASE.
|
||||
void keyOff( void );
|
||||
|
||||
//! Set the attack rate.
|
||||
//! Set the attack rate (gain / sample).
|
||||
void setAttackRate( StkFloat rate );
|
||||
|
||||
//! Set the target value for the attack (default = 1.0).
|
||||
void setAttackTarget( StkFloat target );
|
||||
|
||||
//! Set the decay rate.
|
||||
//! Set the decay rate (gain / sample).
|
||||
void setDecayRate( StkFloat rate );
|
||||
|
||||
//! Set the sustain level.
|
||||
void setSustainLevel( StkFloat level );
|
||||
|
||||
//! Set the release rate.
|
||||
//! Set the release rate (gain / sample).
|
||||
void setReleaseRate( StkFloat rate );
|
||||
|
||||
//! Set the attack rate based on a time duration.
|
||||
//! Set the attack rate based on a time duration (seconds).
|
||||
void setAttackTime( StkFloat time );
|
||||
|
||||
//! Set the decay rate based on a time duration (seconds).
|
||||
@@ -69,7 +70,7 @@ class ADSR : public Generator
|
||||
//! Set the release rate based on a time duration (seconds).
|
||||
void setReleaseTime( StkFloat time );
|
||||
|
||||
//! Set sustain level and attack, decay, and release time durations.
|
||||
//! Set sustain level and attack, decay, and release time durations (seconds).
|
||||
void setAllTimes( StkFloat aTime, StkFloat dTime, StkFloat sLevel, StkFloat rTime );
|
||||
|
||||
//! Set a sustain target value and attack or decay from current value to target.
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace stk {
|
||||
to \e keyOn and \e keyOff messages by ramping to
|
||||
1.0 on keyOn and to 0.0 on keyOff.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace stk {
|
||||
type who should worry about this (making
|
||||
money) worry away.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace stk {
|
||||
Methods are provided for creating a resonance or notch in the
|
||||
frequency response while maintaining a constant filter gain.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace stk {
|
||||
- Vibrato Gain = 1
|
||||
- Volume = 128
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace stk {
|
||||
- Register State = 1
|
||||
- Breath Pressure = 128
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace stk {
|
||||
(1986). The output is an instantaneous
|
||||
reflection coefficient value.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace stk {
|
||||
- Frequency = 101
|
||||
- Volume = 128
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
Contributions by Esteban Maestre, 2011.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace stk {
|
||||
- Vibrato Gain = 1
|
||||
- Volume = 128
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace stk {
|
||||
This class implements a chorus effect. It takes a monophonic
|
||||
input signal and produces a stereo output signal.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace stk {
|
||||
- Vibrato Gain = 1
|
||||
- Breath Pressure = 128
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace stk {
|
||||
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-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace stk {
|
||||
minimum delay possible in this implementation is limited to a
|
||||
value of 0.5.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef STK_DELAYL_H
|
||||
#define STK_DELAYL_H
|
||||
|
||||
#include "Delay.h"
|
||||
#include "Filter.h"
|
||||
|
||||
namespace stk {
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace stk {
|
||||
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-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace stk {
|
||||
of simultaneous voices) via a #define in the
|
||||
Drummer.h.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace stk {
|
||||
|
||||
This class implements an echo effect.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace stk {
|
||||
subclasses. It is general enough to support both monophonic and
|
||||
polyphonic input/output classes.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
@@ -34,7 +34,7 @@ class Effect : public Stk
|
||||
virtual void clear() = 0;
|
||||
|
||||
//! Set the mixture of input and "effected" levels in the output (0.0 = input only, 1.0 = effect only).
|
||||
void setEffectMix( StkFloat mix );
|
||||
virtual void setEffectMix( StkFloat mix );
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace stk {
|
||||
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-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace stk {
|
||||
type who should worry about this (making
|
||||
money) worry away.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace stk {
|
||||
type who should worry about this (making
|
||||
money) worry away.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace stk {
|
||||
the overloaded one that takes an StkFrames object for
|
||||
multi-channel and/or multi-frame data.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace stk {
|
||||
such variable is found, the sample rate is
|
||||
assumed to be 44100 Hz.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace stk {
|
||||
type, the data type will automatically be modified. Compressed
|
||||
data types are not supported.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace stk {
|
||||
See the FileRead class for a description of the supported audio
|
||||
file formats.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
@@ -89,7 +89,7 @@ public:
|
||||
virtual void normalize( StkFloat peak );
|
||||
|
||||
//! Return the file size in sample frames.
|
||||
virtual unsigned long getSize( void ) const { return data_.frames(); };
|
||||
virtual unsigned long getSize( void ) const { return file_.fileSize(); };
|
||||
|
||||
//! Return the input file sample rate in Hz (not the data read rate).
|
||||
/*!
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace stk {
|
||||
Currently, FileWvOut is non-interpolating and the output rate is
|
||||
always Stk::sampleRate().
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace stk {
|
||||
filter subclasses. It is general enough to support both
|
||||
monophonic and polyphonic input/output classes.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
@@ -97,7 +97,7 @@ inline StkFloat Filter :: phaseDelay( StkFloat frequency )
|
||||
handleError( StkError::WARNING ); return 0.0;
|
||||
}
|
||||
|
||||
StkFloat omegaT = 2 * M_PI * frequency / Stk::sampleRate();
|
||||
StkFloat omegaT = 2 * PI * frequency / Stk::sampleRate();
|
||||
StkFloat real = 0.0, imag = 0.0;
|
||||
for ( unsigned int i=0; i<b_.size(); i++ ) {
|
||||
real += b_[i] * std::cos( i * omegaT );
|
||||
@@ -115,7 +115,7 @@ inline StkFloat Filter :: phaseDelay( StkFloat frequency )
|
||||
}
|
||||
|
||||
phase -= std::atan2( imag, real );
|
||||
phase = std::fmod( -phase, 2 * M_PI );
|
||||
phase = std::fmod( -phase, 2 * PI );
|
||||
return phase / omegaT;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace stk {
|
||||
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-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace stk {
|
||||
- Vibrato Gain = 1
|
||||
- Breath Pressure = 128
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace stk {
|
||||
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-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
255
include/FreeVerb.h
Normal file
255
include/FreeVerb.h
Normal file
@@ -0,0 +1,255 @@
|
||||
#ifndef STK_FREEVERB_H
|
||||
#define STK_FREEVERB_H
|
||||
|
||||
#include "Effect.h"
|
||||
#include "Delay.h"
|
||||
#include "OnePole.h"
|
||||
|
||||
namespace stk {
|
||||
|
||||
/***********************************************************************/
|
||||
/*! \class FreeVerb
|
||||
\brief Jezar at Dreampoint's FreeVerb, implemented in STK.
|
||||
|
||||
Freeverb is a free and open-source Schroeder reverberator
|
||||
originally implemented in C++. The parameters of the reverberation
|
||||
model are exceptionally well tuned. FreeVerb uses 8
|
||||
lowpass-feedback-comb-filters in parallel, followed by 4 Schroeder
|
||||
allpass filters in series. The input signal can be either mono or
|
||||
stereo, and the output signal is stereo. The delay lengths are
|
||||
optimized for a sample rate of 44100 Hz.
|
||||
|
||||
Ported to STK by Gregory Burlet, 2012.
|
||||
*/
|
||||
/***********************************************************************/
|
||||
|
||||
class FreeVerb : public Effect
|
||||
{
|
||||
public:
|
||||
//! FreeVerb Constructor
|
||||
/*!
|
||||
Initializes the effect with default parameters. Note that these defaults
|
||||
are slightly different than those in the original implementation of
|
||||
FreeVerb [Effect Mix: 0.75; Room Size: 0.75; Damping: 0.25; Width: 1.0;
|
||||
Mode: freeze mode off].
|
||||
*/
|
||||
FreeVerb();
|
||||
|
||||
//! Destructor
|
||||
~FreeVerb();
|
||||
|
||||
//! Set the effect mix [0 = mostly dry, 1 = mostly wet].
|
||||
void setEffectMix( StkFloat mix );
|
||||
|
||||
//! Set the room size (comb filter feedback gain) parameter [0,1].
|
||||
void setRoomSize( StkFloat value );
|
||||
|
||||
//! Get the room size (comb filter feedback gain) parameter.
|
||||
StkFloat getRoomSize( void );
|
||||
|
||||
//! Set the damping parameter [0=low damping, 1=higher damping].
|
||||
void setDamping( StkFloat value );
|
||||
|
||||
//! Get the damping parameter.
|
||||
StkFloat getDamping( void );
|
||||
|
||||
//! Set the width (left-right mixing) parameter [0,1].
|
||||
void setWidth( StkFloat value );
|
||||
|
||||
//! Get the width (left-right mixing) parameter.
|
||||
StkFloat getWidth( void );
|
||||
|
||||
//! Set the mode [frozen = 1, unfrozen = 0].
|
||||
void setMode( bool isFrozen );
|
||||
|
||||
//! Get the current freeze mode [frozen = 1, unfrozen = 0].
|
||||
StkFloat getMode( void );
|
||||
|
||||
//! Clears delay lines, etc.
|
||||
void clear( void );
|
||||
|
||||
//! Return the specified channel value of the last computed stereo frame.
|
||||
/*!
|
||||
Use the lastFrame() function to get both values of the last
|
||||
computed stereo frame. The \c channel argument must be 0 or 1
|
||||
(the first channel is specified by 0). However, range checking is
|
||||
only performed if _STK_DEBUG_ is defined during compilation, in
|
||||
which case an out-of-range value will trigger an StkError
|
||||
exception.
|
||||
*/
|
||||
StkFloat lastOut( unsigned int channel = 0 );
|
||||
|
||||
//! Input one or two samples to the effect and return the specified \c channel value of the computed stereo frame.
|
||||
/*!
|
||||
Use the lastFrame() function to get both values of the computed
|
||||
stereo output frame. The \c channel argument must be 0 or 1 (the
|
||||
first channel is specified by 0). However, range checking is only
|
||||
performed if _STK_DEBUG_ is defined during compilation, in which
|
||||
case an out-of-range value will trigger an StkError exception.
|
||||
*/
|
||||
StkFloat tick( StkFloat inputL, StkFloat inputR = 0.0, unsigned int channel = 0 );
|
||||
|
||||
//! Take two channels of the StkFrames object as inputs to the effect and replace with stereo outputs.
|
||||
/*!
|
||||
The StkFrames argument reference is returned. The stereo
|
||||
inputs are taken from (and written back to) the StkFrames argument
|
||||
starting at the specified \c channel. Therefore, the \c channel
|
||||
argument must be less than ( channels() - 1 ) of the StkFrames
|
||||
argument (the first channel is specified by 0). However, range
|
||||
checking is only performed if _STK_DEBUG_ is defined during
|
||||
compilation, in which case an out-of-range value will trigger an
|
||||
StkError exception.
|
||||
*/
|
||||
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
|
||||
|
||||
//! Take one or two channels of the \c iFrames object as inputs to the effect and write stereo outputs to the \c oFrames object.
|
||||
/*!
|
||||
The \c iFrames object reference is returned. The \c iChannel
|
||||
argument must be less than the number of channels in the \c
|
||||
iFrames argument (the first channel is specified by 0). If more
|
||||
than one channel of data exists in \c iFrames starting from \c
|
||||
iChannel, stereo data is input to the effect. The \c oChannel
|
||||
argument must be less than ( channels() - 1 ) of the \c oFrames
|
||||
argument. However, range checking is only performed if
|
||||
_STK_DEBUG_ is defined during compilation, in which case an
|
||||
out-of-range value will trigger an StkError exception.
|
||||
*/
|
||||
StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
|
||||
|
||||
protected:
|
||||
//! Update interdependent parameters.
|
||||
void update( void );
|
||||
|
||||
// Clamp very small floats to zero, version from
|
||||
// http://music.columbia.edu/pipermail/linux-audio-user/2004-July/013489.html .
|
||||
// However, this is for 32-bit floats only.
|
||||
//static inline StkFloat undenormalize( volatile StkFloat s ) {
|
||||
// s += 9.8607615E-32f;
|
||||
// return s - 9.8607615E-32f;
|
||||
//}
|
||||
|
||||
static const int nCombs = 8;
|
||||
static const int nAllpasses = 4;
|
||||
static const int stereoSpread = 23;
|
||||
static const StkFloat fixedGain;
|
||||
static const StkFloat scaleWet;
|
||||
static const StkFloat scaleDry;
|
||||
static const StkFloat scaleDamp;
|
||||
static const StkFloat scaleRoom;
|
||||
static const StkFloat offsetRoom;
|
||||
|
||||
// Delay line lengths for 44100Hz sampling rate.
|
||||
static int cDelayLengths[nCombs];
|
||||
static int aDelayLengths[nAllpasses];
|
||||
|
||||
StkFloat g_; // allpass coefficient
|
||||
StkFloat gain_;
|
||||
StkFloat roomSizeMem_, roomSize_;
|
||||
StkFloat dampMem_, damp_;
|
||||
StkFloat wet1_, wet2_;
|
||||
StkFloat dry_;
|
||||
StkFloat width_;
|
||||
bool frozenMode_;
|
||||
|
||||
// LBFC: Lowpass Feedback Comb Filters
|
||||
Delay combDelayL_[nCombs];
|
||||
Delay combDelayR_[nCombs];
|
||||
OnePole combLPL_[nCombs];
|
||||
OnePole combLPR_[nCombs];
|
||||
|
||||
// AP: Allpass Filters
|
||||
Delay allPassDelayL_[nAllpasses];
|
||||
Delay allPassDelayR_[nAllpasses];
|
||||
};
|
||||
|
||||
inline StkFloat FreeVerb :: lastOut( unsigned int channel )
|
||||
{
|
||||
#if defined(_STK_DEBUG_)
|
||||
if ( channel > 1 ) {
|
||||
oStream_ << "FreeVerb::lastOut(): channel argument must be less than 2!";
|
||||
handleError( StkError::FUNCTION_ARGUMENT );
|
||||
}
|
||||
#endif
|
||||
|
||||
return lastFrame_[channel];
|
||||
}
|
||||
|
||||
inline StkFloat FreeVerb::tick( StkFloat inputL, StkFloat inputR, unsigned int channel )
|
||||
{
|
||||
#if defined(_STK_DEBUG_)
|
||||
if ( channel > 1 ) {
|
||||
oStream_ << "FreeVerb::tick(): channel argument must be less than 2!";
|
||||
handleError(StkError::FUNCTION_ARGUMENT);
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( !inputR ) {
|
||||
inputR = inputL;
|
||||
}
|
||||
|
||||
StkFloat fInput = (inputL + inputR) * gain_;
|
||||
StkFloat outL = 0.0;
|
||||
StkFloat outR = 0.0;
|
||||
|
||||
// Parallel LBCF filters
|
||||
for ( int i = 0; i < nCombs; i++ ) {
|
||||
// Left channel
|
||||
//StkFloat yn = fInput + (roomSize_ * FreeVerb::undenormalize(combLPL_[i].tick(FreeVerb::undenormalize(combDelayL_[i].nextOut()))));
|
||||
StkFloat yn = fInput + (roomSize_ * combLPL_[i].tick( combDelayL_[i].nextOut() ) );
|
||||
combDelayL_[i].tick(yn);
|
||||
outL += yn;
|
||||
|
||||
// Right channel
|
||||
//yn = fInput + (roomSize_ * FreeVerb::undenormalize(combLPR_[i].tick(FreeVerb::undenormalize(combDelayR_[i].nextOut()))));
|
||||
yn = fInput + (roomSize_ * combLPR_[i].tick( combDelayR_[i].nextOut() ) );
|
||||
combDelayR_[i].tick(yn);
|
||||
outR += yn;
|
||||
}
|
||||
|
||||
// Series allpass filters
|
||||
for ( int i = 0; i < nAllpasses; i++ ) {
|
||||
// Left channel
|
||||
//StkFloat vn_m = FreeVerb::undenormalize(allPassDelayL_[i].nextOut());
|
||||
StkFloat vn_m = allPassDelayL_[i].nextOut();
|
||||
StkFloat vn = outL + (g_ * vn_m);
|
||||
allPassDelayL_[i].tick(vn);
|
||||
|
||||
// calculate output
|
||||
outL = -vn + (1.0 + g_)*vn_m;
|
||||
|
||||
// Right channel
|
||||
//vn_m = FreeVerb::undenormalize(allPassDelayR_[i].nextOut());
|
||||
vn_m = allPassDelayR_[i].nextOut();
|
||||
vn = outR + (g_ * vn_m);
|
||||
allPassDelayR_[i].tick(vn);
|
||||
|
||||
// calculate output
|
||||
outR = -vn + (1.0 + g_)*vn_m;
|
||||
}
|
||||
|
||||
// Mix output
|
||||
lastFrame_[0] = outL*wet1_ + outR*wet2_ + inputL*dry_;
|
||||
lastFrame_[1] = outR*wet1_ + outL*wet2_ + inputR*dry_;
|
||||
|
||||
/*
|
||||
// Hard limiter ... there's not much else we can do at this point
|
||||
if ( lastFrame_[0] >= 1.0 ) {
|
||||
lastFrame_[0] = 0.9999;
|
||||
}
|
||||
if ( lastFrame_[0] <= -1.0 ) {
|
||||
lastFrame_[0] = -0.9999;
|
||||
}
|
||||
if ( lastFrame_[1] >= 1.0 ) {
|
||||
lastFrame_[1] = 0.9999;
|
||||
}
|
||||
if ( lastFrame_[1] <= -1.0 ) {
|
||||
lastFrame_[1] = -0.9999;
|
||||
}
|
||||
*/
|
||||
|
||||
return lastFrame_[channel];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -13,7 +13,7 @@ namespace stk {
|
||||
implement tables or other types of input to output function
|
||||
mappings.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace stk {
|
||||
generator sample-source subclasses. It is general enough to
|
||||
support both monophonic and polyphonic output classes.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
199
include/Guitar.h
Normal file
199
include/Guitar.h
Normal file
@@ -0,0 +1,199 @@
|
||||
#ifndef STK_GUITAR_H
|
||||
#define STK_GUITAR_H
|
||||
|
||||
#include "Stk.h"
|
||||
#include "Twang.h"
|
||||
#include "OnePole.h"
|
||||
#include "OneZero.h"
|
||||
|
||||
namespace stk {
|
||||
|
||||
/***************************************************/
|
||||
/*! \class Guitar
|
||||
\brief STK guitar model class.
|
||||
|
||||
This class implements a guitar model with an arbitrary number of
|
||||
strings (specified during instantiation). Each string is
|
||||
represented by an stk::Twang object. The model supports commuted
|
||||
synthesis, as discussed by Smith and Karjalainen. It also includes
|
||||
a basic body coupling model and supports feedback.
|
||||
|
||||
This class does not attempt voice management. Rather, most
|
||||
functions support a parameter to specify a particular string
|
||||
number and string (voice) management is assumed to occur
|
||||
externally. Note that this class does not inherit from
|
||||
stk::Instrmnt because of API inconsistencies.
|
||||
|
||||
This is a digital waveguide model, making its use possibly subject
|
||||
to patents held by Stanford University, Yamaha, and others.
|
||||
|
||||
Control Change Numbers:
|
||||
- Bridge Coupling Gain = 2
|
||||
- Pluck Position = 4
|
||||
- Loop Gain = 11
|
||||
- Coupling Filter Pole = 1
|
||||
- Pick Filter Pole = 128
|
||||
|
||||
by Gary P. Scavone, 2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
class Guitar : public Stk
|
||||
{
|
||||
public:
|
||||
//! Class constructor, specifying an arbitrary number of strings (default = 6).
|
||||
Guitar( unsigned int nStrings = 6, std::string bodyfile = "" );
|
||||
|
||||
//! Reset and clear all internal state.
|
||||
void clear( void );
|
||||
|
||||
//! Set the string excitation, using either a soundfile or computed noise.
|
||||
/*!
|
||||
If no argument is provided, the std::string is empty, or an error
|
||||
occurs reading the file data, an enveloped noise signal will be
|
||||
generated for use as the pluck excitation.
|
||||
*/
|
||||
void setBodyFile( std::string bodyfile = "" );
|
||||
|
||||
//! Set the pluck position for one or all strings.
|
||||
/*!
|
||||
If the \c string argument is < 0, the pluck position is set
|
||||
for all strings.
|
||||
*/
|
||||
void setPluckPosition( StkFloat position, int string = -1 );
|
||||
|
||||
//! Set the loop gain for one or all strings.
|
||||
/*!
|
||||
If the \c string argument is < 0, the loop gain is set for all
|
||||
strings.
|
||||
*/
|
||||
void setLoopGain( StkFloat gain, int string = -1 );
|
||||
|
||||
//! Set instrument parameters for a particular frequency.
|
||||
void setFrequency( StkFloat frequency, unsigned int string = 0 );
|
||||
|
||||
//! Start a note with the given frequency and amplitude.
|
||||
/*!
|
||||
If the \c amplitude parameter is less than 0.2, the string will
|
||||
be undamped but it will not be "plucked."
|
||||
*/
|
||||
void noteOn( StkFloat frequency, StkFloat amplitude, unsigned int string = 0 );
|
||||
|
||||
//! Stop a note with the given amplitude (speed of decay).
|
||||
void noteOff( StkFloat amplitude, unsigned int string = 0 );
|
||||
|
||||
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
|
||||
/*!
|
||||
If the \c string argument is < 0, then the control change is
|
||||
applied to all strings (if appropriate).
|
||||
*/
|
||||
void controlChange( int number, StkFloat value, int string = -1 );
|
||||
|
||||
//! Return the last computed output value.
|
||||
StkFloat lastOut( void ) { return lastFrame_[0]; };
|
||||
|
||||
//! Take an optional input sample and compute one output sample.
|
||||
StkFloat tick( StkFloat input = 0.0 );
|
||||
|
||||
//! Take a channel of the \c iFrames object as inputs to the class and write outputs to the \c oFrames object.
|
||||
/*!
|
||||
The \c iFrames object reference is returned. Each channel
|
||||
argument must be less than the number of channels in the
|
||||
corresponding StkFrames argument (the first channel is specified
|
||||
by 0). However, range checking is only performed if _STK_DEBUG_
|
||||
is defined during compilation, in which case an out-of-range value
|
||||
will trigger an StkError exception.
|
||||
*/
|
||||
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
|
||||
|
||||
//! Take a channel of the \c iFrames object as inputs to the effect and write outputs to the \c oFrames object.
|
||||
/*!
|
||||
The \c iFrames object reference is returned. Each channel
|
||||
argument must be less than the number of channels in the
|
||||
corresponding StkFrames argument (the first channel is specified
|
||||
by 0). However, range checking is only performed if _STK_DEBUG_
|
||||
is defined during compilation, in which case an out-of-range value
|
||||
will trigger an StkError exception.
|
||||
*/
|
||||
StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
|
||||
|
||||
protected:
|
||||
|
||||
std::vector< stk::Twang > strings_;
|
||||
std::vector< int > stringState_; // 0 = off, 1 = decaying, 2 = on
|
||||
std::vector< unsigned int > decayCounter_;
|
||||
std::vector< unsigned int > filePointer_;
|
||||
std::vector< StkFloat > pluckGains_;
|
||||
|
||||
OnePole pickFilter_;
|
||||
OnePole couplingFilter_;
|
||||
StkFloat couplingGain_;
|
||||
StkFrames excitation_;
|
||||
StkFrames lastFrame_;
|
||||
};
|
||||
|
||||
inline StkFloat Guitar :: tick( StkFloat input )
|
||||
{
|
||||
StkFloat temp, output = 0.0;
|
||||
lastFrame_[0] /= strings_.size(); // evenly spread coupling across strings
|
||||
for ( unsigned int i=0; i<strings_.size(); i++ ) {
|
||||
if ( stringState_[i] ) {
|
||||
temp = input;
|
||||
// If pluckGain < 0.2, let string ring but don't pluck it.
|
||||
if ( filePointer_[i] < excitation_.frames() && pluckGains_[i] > 0.2 )
|
||||
temp += pluckGains_[i] * excitation_[filePointer_[i]++];
|
||||
temp += couplingGain_ * couplingFilter_.tick( lastFrame_[0] ); // bridge coupling
|
||||
output += strings_[i].tick( temp );
|
||||
// Check if string energy has decayed sufficiently to turn it off.
|
||||
if ( stringState_[i] == 1 ) {
|
||||
if ( fabs( strings_[i].lastOut() ) < 0.001 ) decayCounter_[i]++;
|
||||
else decayCounter_[i] = 0;
|
||||
if ( decayCounter_[i] > (unsigned int) floor( 0.1 * Stk::sampleRate() ) ) {
|
||||
stringState_[i] = 0;
|
||||
decayCounter_[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return lastFrame_[0] = output;
|
||||
}
|
||||
|
||||
inline StkFrames& Guitar :: tick( StkFrames& frames, unsigned int channel )
|
||||
{
|
||||
#if defined(_STK_DEBUG_)
|
||||
if ( channel >= frames.channels() ) {
|
||||
oStream_ << "Guitar::tick(): channel and StkFrames arguments are incompatible!";
|
||||
handleError( StkError::FUNCTION_ARGUMENT );
|
||||
}
|
||||
#endif
|
||||
|
||||
StkFloat *samples = &frames[channel];
|
||||
unsigned int hop = frames.channels();
|
||||
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
|
||||
*samples = tick( *samples );
|
||||
|
||||
return frames;
|
||||
}
|
||||
|
||||
inline StkFrames& Guitar :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
|
||||
{
|
||||
#if defined(_STK_DEBUG_)
|
||||
if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
|
||||
oStream_ << "Guitar::tick(): channel and StkFrames arguments are incompatible!";
|
||||
handleError( StkError::FUNCTION_ARGUMENT );
|
||||
}
|
||||
#endif
|
||||
|
||||
StkFloat *iSamples = &iFrames[iChannel];
|
||||
StkFloat *oSamples = &oFrames[oChannel];
|
||||
unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
|
||||
for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop )
|
||||
*oSamples = tick( *iSamples );
|
||||
|
||||
return iFrames;
|
||||
}
|
||||
|
||||
} // stk namespace
|
||||
|
||||
#endif
|
||||
@@ -31,7 +31,7 @@ namespace stk {
|
||||
type who should worry about this (making
|
||||
money) worry away.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace stk {
|
||||
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-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace stk {
|
||||
data type for the incoming stream is signed 16-bit integers,
|
||||
though any of the defined StkFormats are permissible.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace stk {
|
||||
data type is signed 16-bit integers but any of the defined
|
||||
StkFormats are permissible.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace stk {
|
||||
This class provides a common interface for
|
||||
all STK instruments.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace stk {
|
||||
one-pole lowpass filters have been added inside
|
||||
the feedback comb filters.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace stk {
|
||||
Consult Fletcher and Rossing, Karjalainen,
|
||||
Cook, and others for more information.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef STK_LENLentPitShift_H
|
||||
#define STK_LENLentPitShift_H
|
||||
#ifndef STK_LENTPITSHIFT_H
|
||||
#define STK_LENTPITSHIFT_H
|
||||
|
||||
#include "Effect.h"
|
||||
#include "Delay.h"
|
||||
@@ -25,13 +25,9 @@ class LentPitShift : public Effect
|
||||
|
||||
~LentPitShift( void ) {
|
||||
delete window;
|
||||
window = NULL;
|
||||
delete dt;
|
||||
dt = NULL;
|
||||
delete dpt;
|
||||
dpt = NULL;
|
||||
delete cumDt;
|
||||
cumDt = NULL;
|
||||
}
|
||||
|
||||
//! Reset and clear all internal state.
|
||||
@@ -70,7 +66,7 @@ class LentPitShift : public Effect
|
||||
//! Apply the effect on the input samples and store it.
|
||||
/*!
|
||||
The samples stored in the input frame vector are processed
|
||||
and the delayed result are stored in the output frame vector
|
||||
and the delayed result are stored in the output frame vector.
|
||||
*/
|
||||
void process( );
|
||||
|
||||
@@ -195,8 +191,8 @@ inline void LentPitShift::process()
|
||||
for ( unsigned int j=0; j<2*lastPeriod_; j++,M--,N-- ) {
|
||||
sample = inputLine_.tapOut(M) * window[j] / 2.;
|
||||
// Linear interpolation
|
||||
outputLine_.addTo(N, env[0] * sample);
|
||||
outputLine_.addTo(N-1, env[1] * sample);
|
||||
outputLine_.addTo(env[0] * sample, N);
|
||||
outputLine_.addTo(env[1] * sample, N-1);
|
||||
}
|
||||
outputPtr = outputPtr + lastPeriod_ * periodRatio_; // new output pointer
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace stk {
|
||||
- String Detuning = 1
|
||||
- Microphone Position = 128
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace stk {
|
||||
This class is primarily for use in STK example programs but it is
|
||||
generic enough to work in many other contexts.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace stk {
|
||||
(non-sweeping BiQuad filters), where N is set
|
||||
during instantiation.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace stk {
|
||||
- Two Fixed = 7
|
||||
- Clump = 8
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace stk {
|
||||
modulations to give a nice, natural human
|
||||
modulation function.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace stk {
|
||||
- Vibrato Gain = 1
|
||||
- Gain = 128
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace stk {
|
||||
systems, the pthread library is used. Under
|
||||
Windows, critical sections are used.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace stk {
|
||||
another allpass in series, followed by two allpass filters in
|
||||
parallel with corresponding right and left outputs.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define STK_NOISE_H
|
||||
|
||||
#include "Generator.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace stk {
|
||||
|
||||
@@ -13,7 +14,7 @@ namespace stk {
|
||||
C rand() function. The quality of the rand()
|
||||
function varies from one OS to another.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace stk {
|
||||
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-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace stk {
|
||||
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-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace stk {
|
||||
allpass and comb delay filters. This class implements two series
|
||||
allpass units and two parallel comb filters.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace stk {
|
||||
type who should worry about this (making
|
||||
money) worry away.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace stk {
|
||||
set of 32 static phoneme formant parameters
|
||||
and provide access to those values.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace stk {
|
||||
This class implements a simple pitch shifter
|
||||
using delay lines.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace stk {
|
||||
Stanford, bearing the names of Karplus and/or
|
||||
Strong.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace stk {
|
||||
coefficient. Another method is provided to create a DC blocking
|
||||
filter.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace stk {
|
||||
Smith (1986), Hirschman, Cook, Scavone, and
|
||||
others for more information.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace stk {
|
||||
- Zero Radii = 1
|
||||
- Envelope Gain = 128
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace stk {
|
||||
type who should worry about this (making
|
||||
money) worry away.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
RtAudio WWW site: http://www.music.mcgill.ca/~gary/rtaudio/
|
||||
|
||||
RtAudio: realtime audio i/o C++ classes
|
||||
Copyright (c) 2001-2011 Gary P. Scavone
|
||||
Copyright (c) 2001-2012 Gary P. Scavone
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation files
|
||||
@@ -42,7 +42,7 @@
|
||||
\file RtAudio.h
|
||||
*/
|
||||
|
||||
// RtAudio: Version 4.0.10
|
||||
// RtAudio: Version 4.0.11
|
||||
|
||||
#ifndef __RTAUDIO_H
|
||||
#define __RTAUDIO_H
|
||||
@@ -210,6 +210,7 @@ class RtAudio
|
||||
enum Api {
|
||||
UNSPECIFIED, /*!< Search for a working compiled API. */
|
||||
LINUX_ALSA, /*!< The Advanced Linux Sound Architecture API. */
|
||||
LINUX_PULSE, /*!< The Linux PulseAudio API. */
|
||||
LINUX_OSS, /*!< The Linux Open Sound System API. */
|
||||
UNIX_JACK, /*!< The Jack Low-Latency Audio Server API. */
|
||||
MACOSX_CORE, /*!< Macintosh OS-X Core Audio API. */
|
||||
@@ -511,7 +512,7 @@ class RtAudio
|
||||
typedef unsigned long ThreadHandle;
|
||||
typedef CRITICAL_SECTION StreamMutex;
|
||||
|
||||
#elif defined(__LINUX_ALSA__) || defined(__UNIX_JACK__) || defined(__LINUX_OSS__) || defined(__MACOSX_CORE__)
|
||||
#elif defined(__LINUX_ALSA__) || defined(__LINUX_PULSE__) || defined(__UNIX_JACK__) || defined(__LINUX_OSS__) || defined(__MACOSX_CORE__)
|
||||
// Using pthread library for various flavors of unix.
|
||||
#include <pthread.h>
|
||||
|
||||
@@ -552,7 +553,7 @@ struct CallbackInfo {
|
||||
// Note that RtApi is an abstract base class and cannot be
|
||||
// explicitly instantiated. The class RtAudio will create an
|
||||
// instance of an RtApi subclass (RtApiOss, RtApiAlsa,
|
||||
// RtApiJack, RtApiCore, RtApiAl, RtApiDs, or RtApiAsio).
|
||||
// RtApiJack, RtApiCore, RtApiDs, or RtApiAsio).
|
||||
//
|
||||
// **************************************************************** //
|
||||
|
||||
@@ -599,6 +600,7 @@ protected:
|
||||
|
||||
enum StreamState {
|
||||
STREAM_STOPPED,
|
||||
STREAM_STOPPING,
|
||||
STREAM_RUNNING,
|
||||
STREAM_CLOSED = -50
|
||||
};
|
||||
@@ -911,6 +913,38 @@ public:
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__LINUX_PULSE__)
|
||||
|
||||
class RtApiPulse: public RtApi
|
||||
{
|
||||
public:
|
||||
~RtApiPulse();
|
||||
RtAudio::Api getCurrentApi() { return RtAudio::LINUX_PULSE; };
|
||||
unsigned int getDeviceCount( void );
|
||||
RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
|
||||
void closeStream( void );
|
||||
void startStream( void );
|
||||
void stopStream( void );
|
||||
void abortStream( void );
|
||||
|
||||
// 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( void );
|
||||
|
||||
private:
|
||||
|
||||
std::vector<RtAudio::DeviceInfo> devices_;
|
||||
void saveDeviceInfo( void );
|
||||
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
|
||||
unsigned int firstChannel, unsigned int sampleRate,
|
||||
RtAudioFormat format, unsigned int *bufferSize,
|
||||
RtAudio::StreamOptions *options );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__LINUX_OSS__)
|
||||
|
||||
class RtApiOss: public RtApi
|
||||
|
||||
601
include/RtMidi.h
601
include/RtMidi.h
@@ -8,7 +8,7 @@
|
||||
RtMidi WWW site: http://music.mcgill.ca/~gary/rtmidi/
|
||||
|
||||
RtMidi: realtime MIDI i/o C++ classes
|
||||
Copyright (c) 2003-2011 Gary P. Scavone
|
||||
Copyright (c) 2003-2012 Gary P. Scavone
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation files
|
||||
@@ -22,8 +22,9 @@
|
||||
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.
|
||||
asked to send the modifications to the original developer so that
|
||||
they can be incorporated into the canonical version. This is,
|
||||
however, not a binding provision of this license.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
@@ -35,18 +36,42 @@
|
||||
*/
|
||||
/**********************************************************************/
|
||||
|
||||
// RtMidi: Version 1.0.15
|
||||
/*!
|
||||
\file RtMidi.h
|
||||
*/
|
||||
|
||||
// RtMidi: Version 2.0.1
|
||||
|
||||
#ifndef RTMIDI_H
|
||||
#define RTMIDI_H
|
||||
|
||||
#include "RtError.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class RtMidi
|
||||
{
|
||||
public:
|
||||
|
||||
//! MIDI API specifier arguments.
|
||||
enum Api {
|
||||
UNSPECIFIED, /*!< Search for a working compiled API. */
|
||||
MACOSX_CORE, /*!< Macintosh OS-X Core Midi API. */
|
||||
LINUX_ALSA, /*!< The Advanced Linux Sound Architecture API. */
|
||||
UNIX_JACK, /*!< The Jack Low-Latency MIDI Server API. */
|
||||
WINDOWS_MM, /*!< The Microsoft Multimedia MIDI API. */
|
||||
WINDOWS_KS, /*!< The Microsoft Kernel Streaming MIDI API. */
|
||||
RTMIDI_DUMMY /*!< A compilable but non-functional API. */
|
||||
};
|
||||
|
||||
//! A static function to determine the available compiled MIDI APIs.
|
||||
/*!
|
||||
The values returned in the std::vector can be compared against
|
||||
the enumerated list values. Note that there can be more than one
|
||||
API compiled for certain operating systems.
|
||||
*/
|
||||
static void getCompiledApi( std::vector<RtMidi::Api> &apis ) throw();
|
||||
|
||||
//! Pure virtual openPort() function.
|
||||
virtual void openPort( unsigned int portNumber = 0, const std::string portName = std::string( "RtMidi" ) ) = 0;
|
||||
|
||||
@@ -62,19 +87,13 @@ class RtMidi
|
||||
//! Pure virtual closePort() function.
|
||||
virtual void closePort( void ) = 0;
|
||||
|
||||
//! A basic error reporting function for RtMidi classes.
|
||||
static void error( RtError::Type type, std::string errorString );
|
||||
|
||||
protected:
|
||||
|
||||
RtMidi();
|
||||
RtMidi() {};
|
||||
virtual ~RtMidi() {};
|
||||
|
||||
// A basic error reporting function for internal use in the RtMidi
|
||||
// subclasses. The behavior of this function can be modified to
|
||||
// suit specific needs.
|
||||
void error( RtError::Type type );
|
||||
|
||||
void *apiData_;
|
||||
bool connected_;
|
||||
std::string errorString_;
|
||||
};
|
||||
|
||||
/**********************************************************************/
|
||||
@@ -91,11 +110,26 @@ class RtMidi
|
||||
to open a virtual input port to which other MIDI software clients
|
||||
can connect.
|
||||
|
||||
by Gary P. Scavone, 2003-2008.
|
||||
by Gary P. Scavone, 2003-2012.
|
||||
*/
|
||||
/**********************************************************************/
|
||||
|
||||
#include <vector>
|
||||
// **************************************************************** //
|
||||
//
|
||||
// RtMidiIn and RtMidiOut class declarations.
|
||||
//
|
||||
// RtMidiIn / RtMidiOut are "controllers" used to select an available
|
||||
// MIDI input or output interface. They present common APIs for the
|
||||
// user to call but all functionality is implemented by the classes
|
||||
// MidiInApi, MidiOutApi and their subclasses. RtMidiIn and RtMidiOut
|
||||
// each create an instance of a MidiInApi or MidiOutApi subclass based
|
||||
// on the user's API choice. If no choice is made, they attempt to
|
||||
// make a "logical" API selection.
|
||||
//
|
||||
// **************************************************************** //
|
||||
|
||||
class MidiInApi;
|
||||
class MidiOutApi;
|
||||
|
||||
class RtMidiIn : public RtMidi
|
||||
{
|
||||
@@ -104,48 +138,57 @@ class RtMidiIn : public RtMidi
|
||||
//! User callback function type definition.
|
||||
typedef void (*RtMidiCallback)( double timeStamp, std::vector<unsigned char> *message, void *userData);
|
||||
|
||||
//! Default constructor that allows an optional client name and queue size.
|
||||
//! Default constructor that allows an optional api, client name and queue size.
|
||||
/*!
|
||||
An exception will be thrown if a MIDI system initialization
|
||||
error occurs. The queue size defines the maximum number of
|
||||
messages that can be held in the MIDI queue (when not using a
|
||||
callback function). If the queue size limit is reached,
|
||||
incoming messages will be ignored.
|
||||
An exception will be thrown if a MIDI system initialization
|
||||
error occurs. The queue size defines the maximum number of
|
||||
messages that can be held in the MIDI queue (when not using a
|
||||
callback function). If the queue size limit is reached,
|
||||
incoming messages will be ignored.
|
||||
|
||||
If no API argument is specified and multiple API support has been
|
||||
compiled, the default order of use is JACK, ALSA (Linux) and CORE,
|
||||
Jack (OS-X).
|
||||
*/
|
||||
RtMidiIn( const std::string clientName = std::string( "RtMidi Input Client"), unsigned int queueSizeLimit = 100 );
|
||||
RtMidiIn( RtMidi::Api api=UNSPECIFIED,
|
||||
const std::string clientName = std::string( "RtMidi Input Client"),
|
||||
unsigned int queueSizeLimit = 100 );
|
||||
|
||||
//! If a MIDI connection is still open, it will be closed by the destructor.
|
||||
~RtMidiIn();
|
||||
~RtMidiIn ( void ) throw();
|
||||
|
||||
//! Returns the MIDI API specifier for the current instance of RtMidiIn.
|
||||
RtMidi::Api getCurrentApi( void ) throw();
|
||||
|
||||
//! Open a MIDI input connection.
|
||||
/*!
|
||||
An optional port number greater than 0 can be specified.
|
||||
Otherwise, the default or first port found is opened.
|
||||
An optional port number greater than 0 can be specified.
|
||||
Otherwise, the default or first port found is opened.
|
||||
*/
|
||||
void openPort( unsigned int portNumber = 0, const std::string Portname = std::string( "RtMidi Input" ) );
|
||||
void openPort( unsigned int portNumber = 0, const std::string portName = std::string( "RtMidi Input" ) );
|
||||
|
||||
//! Create a virtual input port, with optional name, to allow software connections (OS X and ALSA only).
|
||||
/*!
|
||||
This function creates a virtual MIDI input port to which other
|
||||
software applications can connect. This type of functionality
|
||||
is currently only supported by the Macintosh OS-X and Linux ALSA
|
||||
APIs (the function does nothing for the other APIs).
|
||||
This function creates a virtual MIDI input port to which other
|
||||
software applications can connect. This type of functionality
|
||||
is currently only supported by the Macintosh OS-X and Linux ALSA
|
||||
APIs (the function does nothing for the other APIs).
|
||||
*/
|
||||
void openVirtualPort( const std::string portName = std::string( "RtMidi Input" ) );
|
||||
|
||||
//! Set a callback function to be invoked for incoming MIDI messages.
|
||||
/*!
|
||||
The callback function will be called whenever an incoming MIDI
|
||||
message is received. While not absolutely necessary, it is best
|
||||
to set the callback function before opening a MIDI port to avoid
|
||||
leaving some messages in the queue.
|
||||
The callback function will be called whenever an incoming MIDI
|
||||
message is received. While not absolutely necessary, it is best
|
||||
to set the callback function before opening a MIDI port to avoid
|
||||
leaving some messages in the queue.
|
||||
*/
|
||||
void setCallback( RtMidiCallback callback, void *userData = 0 );
|
||||
|
||||
//! Cancel use of the current callback function (if one exists).
|
||||
/*!
|
||||
Subsequent incoming MIDI messages will be written to the queue
|
||||
and can be retrieved with the \e getMessage function.
|
||||
Subsequent incoming MIDI messages will be written to the queue
|
||||
and can be retrieved with the \e getMessage function.
|
||||
*/
|
||||
void cancelCallback();
|
||||
|
||||
@@ -157,30 +200,148 @@ class RtMidiIn : public RtMidi
|
||||
|
||||
//! Return a string identifier for the specified MIDI input port number.
|
||||
/*!
|
||||
An empty string is returned if an invalid port specifier is provided.
|
||||
An empty string is returned if an invalid port specifier is provided.
|
||||
*/
|
||||
std::string getPortName( unsigned int portNumber = 0 );
|
||||
|
||||
//! Specify whether certain MIDI message types should be queued or ignored during input.
|
||||
/*!
|
||||
o By default, MIDI timing and active sensing messages are ignored
|
||||
during message input because of their relative high data rates.
|
||||
MIDI sysex messages are ignored by default as well. Variable
|
||||
values of "true" imply that the respective message type will be
|
||||
ignored.
|
||||
o By default, MIDI timing and active sensing messages are ignored
|
||||
during message input because of their relative high data rates.
|
||||
MIDI sysex messages are ignored by default as well. Variable
|
||||
values of "true" imply that the respective message type will be
|
||||
ignored.
|
||||
*/
|
||||
void ignoreTypes( bool midiSysex = true, bool midiTime = true, bool midiSense = true );
|
||||
|
||||
//! Fill the user-provided vector with the data bytes for the next available MIDI message in the input queue and return the event delta-time in seconds.
|
||||
/*!
|
||||
This function returns immediately whether a new message is
|
||||
available or not. A valid message is indicated by a non-zero
|
||||
vector size. An exception is thrown if an error occurs during
|
||||
message retrieval or an input connection was not previously
|
||||
established.
|
||||
This function returns immediately whether a new message is
|
||||
available or not. A valid message is indicated by a non-zero
|
||||
vector size. An exception is thrown if an error occurs during
|
||||
message retrieval or an input connection was not previously
|
||||
established.
|
||||
*/
|
||||
double getMessage( std::vector<unsigned char> *message );
|
||||
|
||||
protected:
|
||||
void openMidiApi( RtMidi::Api api, const std::string clientName, unsigned int queueSizeLimit );
|
||||
MidiInApi *rtapi_;
|
||||
|
||||
};
|
||||
|
||||
/**********************************************************************/
|
||||
/*! \class RtMidiOut
|
||||
\brief A realtime MIDI output class.
|
||||
|
||||
This class provides a common, platform-independent API for MIDI
|
||||
output. It allows one to probe available MIDI output ports, to
|
||||
connect to one such port, and to send MIDI bytes immediately over
|
||||
the connection. Create multiple instances of this class to
|
||||
connect to more than one MIDI device at the same time. With the
|
||||
OS-X and Linux ALSA MIDI APIs, it is also possible to open a
|
||||
virtual port to which other MIDI software clients can connect.
|
||||
|
||||
by Gary P. Scavone, 2003-2012.
|
||||
*/
|
||||
/**********************************************************************/
|
||||
|
||||
class RtMidiOut : public RtMidi
|
||||
{
|
||||
public:
|
||||
|
||||
//! Default constructor that allows an optional client name.
|
||||
/*!
|
||||
An exception will be thrown if a MIDI system initialization error occurs.
|
||||
|
||||
If no API argument is specified and multiple API support has been
|
||||
compiled, the default order of use is JACK, ALSA (Linux) and CORE,
|
||||
Jack (OS-X).
|
||||
*/
|
||||
RtMidiOut( RtMidi::Api api=UNSPECIFIED,
|
||||
const std::string clientName = std::string( "RtMidi Output Client") );
|
||||
|
||||
//! The destructor closes any open MIDI connections.
|
||||
~RtMidiOut( void ) throw();
|
||||
|
||||
//! Returns the MIDI API specifier for the current instance of RtMidiOut.
|
||||
RtMidi::Api getCurrentApi( void ) throw();
|
||||
|
||||
//! Open a MIDI output connection.
|
||||
/*!
|
||||
An optional port number greater than 0 can be specified.
|
||||
Otherwise, the default or first port found is opened. An
|
||||
exception is thrown if an error occurs while attempting to make
|
||||
the port connection.
|
||||
*/
|
||||
void openPort( unsigned int portNumber = 0, const std::string portName = std::string( "RtMidi Output" ) );
|
||||
|
||||
//! Close an open MIDI connection (if one exists).
|
||||
void closePort( void );
|
||||
|
||||
//! Create a virtual output port, with optional name, to allow software connections (OS X and ALSA only).
|
||||
/*!
|
||||
This function creates a virtual MIDI output port to which other
|
||||
software applications can connect. This type of functionality
|
||||
is currently only supported by the Macintosh OS-X and Linux ALSA
|
||||
APIs (the function does nothing with the other APIs). An
|
||||
exception is thrown if an error occurs while attempting to create
|
||||
the virtual port.
|
||||
*/
|
||||
void openVirtualPort( const std::string portName = std::string( "RtMidi Output" ) );
|
||||
|
||||
//! Return the number of available MIDI output ports.
|
||||
unsigned int getPortCount( void );
|
||||
|
||||
//! Return a string identifier for the specified MIDI port type and number.
|
||||
/*!
|
||||
An empty string is returned if an invalid port specifier is provided.
|
||||
*/
|
||||
std::string getPortName( unsigned int portNumber = 0 );
|
||||
|
||||
//! Immediately send a single message out an open MIDI output port.
|
||||
/*!
|
||||
An exception is thrown if an error occurs during output or an
|
||||
output connection was not previously established.
|
||||
*/
|
||||
void sendMessage( std::vector<unsigned char> *message );
|
||||
|
||||
protected:
|
||||
void openMidiApi( RtMidi::Api api, const std::string clientName );
|
||||
MidiOutApi *rtapi_;
|
||||
};
|
||||
|
||||
|
||||
// **************************************************************** //
|
||||
//
|
||||
// MidiInApi / MidiOutApi class declarations.
|
||||
//
|
||||
// Subclasses of MidiInApi and MidiOutApi contain all API- and
|
||||
// OS-specific code necessary to fully implement the RtMidi API.
|
||||
//
|
||||
// Note that MidiInApi and MidiOutApi are abstract base classes and
|
||||
// cannot be explicitly instantiated. RtMidiIn and RtMidiOut will
|
||||
// create instances of a MidiInApi or MidiOutApi subclass.
|
||||
//
|
||||
// **************************************************************** //
|
||||
|
||||
class MidiInApi
|
||||
{
|
||||
public:
|
||||
|
||||
MidiInApi( unsigned int queueSizeLimit );
|
||||
virtual ~MidiInApi( void );
|
||||
virtual RtMidi::Api getCurrentApi( void ) = 0;
|
||||
virtual void openPort( unsigned int portNumber, const std::string portName ) = 0;
|
||||
virtual void openVirtualPort( const std::string portName ) = 0;
|
||||
virtual void closePort( void ) = 0;
|
||||
void setCallback( RtMidiIn::RtMidiCallback callback, void *userData );
|
||||
void cancelCallback( void );
|
||||
virtual unsigned int getPortCount( void ) = 0;
|
||||
virtual std::string getPortName( unsigned int portNumber ) = 0;
|
||||
virtual void ignoreTypes( bool midiSysex, bool midiTime, bool midiSense );
|
||||
double getMessage( std::vector<unsigned char> *message );
|
||||
|
||||
// A MIDI structure used internally by the class to store incoming
|
||||
// messages. Each message represents one and only one MIDI message.
|
||||
struct MidiMessage {
|
||||
@@ -188,8 +349,8 @@ o By default, MIDI timing and active sensing messages are ignored
|
||||
double timeStamp;
|
||||
|
||||
// Default constructor.
|
||||
MidiMessage()
|
||||
:bytes(0), timeStamp(0.0) {}
|
||||
MidiMessage()
|
||||
:bytes(0), timeStamp(0.0) {}
|
||||
};
|
||||
|
||||
struct MidiQueue {
|
||||
@@ -197,11 +358,11 @@ o By default, MIDI timing and active sensing messages are ignored
|
||||
unsigned int back;
|
||||
unsigned int size;
|
||||
unsigned int ringSize;
|
||||
MidiMessage *ring;
|
||||
MidiMessage *ring;
|
||||
|
||||
// Default constructor.
|
||||
MidiQueue()
|
||||
:front(0), back(0), size(0), ringSize(0) {}
|
||||
MidiQueue()
|
||||
:front(0), back(0), size(0), ringSize(0) {}
|
||||
};
|
||||
|
||||
// The RtMidiInData structure is used to pass private class data to
|
||||
@@ -219,88 +380,296 @@ o By default, MIDI timing and active sensing messages are ignored
|
||||
bool continueSysex;
|
||||
|
||||
// Default constructor.
|
||||
RtMidiInData()
|
||||
: ignoreFlags(7), doInput(false), firstMessage(true),
|
||||
apiData(0), usingCallback(false), userCallback(0), userData(0),
|
||||
continueSysex(false) {}
|
||||
RtMidiInData()
|
||||
: ignoreFlags(7), doInput(false), firstMessage(true),
|
||||
apiData(0), usingCallback(false), userCallback(0), userData(0),
|
||||
continueSysex(false) {}
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
void initialize( const std::string& clientName );
|
||||
protected:
|
||||
virtual void initialize( const std::string& clientName ) = 0;
|
||||
RtMidiInData inputData_;
|
||||
|
||||
void *apiData_;
|
||||
bool connected_;
|
||||
std::string errorString_;
|
||||
};
|
||||
|
||||
/**********************************************************************/
|
||||
/*! \class RtMidiOut
|
||||
\brief A realtime MIDI output class.
|
||||
|
||||
This class provides a common, platform-independent API for MIDI
|
||||
output. It allows one to probe available MIDI output ports, to
|
||||
connect to one such port, and to send MIDI bytes immediately over
|
||||
the connection. Create multiple instances of this class to
|
||||
connect to more than one MIDI device at the same time.
|
||||
|
||||
by Gary P. Scavone, 2003-2008.
|
||||
*/
|
||||
/**********************************************************************/
|
||||
|
||||
class RtMidiOut : public RtMidi
|
||||
class MidiOutApi
|
||||
{
|
||||
public:
|
||||
|
||||
//! Default constructor that allows an optional client name.
|
||||
/*!
|
||||
An exception will be thrown if a MIDI system initialization error occurs.
|
||||
*/
|
||||
RtMidiOut( const std::string clientName = std::string( "RtMidi Output Client" ) );
|
||||
MidiOutApi( void );
|
||||
virtual ~MidiOutApi( void );
|
||||
virtual RtMidi::Api getCurrentApi( void ) = 0;
|
||||
virtual void openPort( unsigned int portNumber, const std::string portName ) = 0;
|
||||
virtual void openVirtualPort( const std::string portName ) = 0;
|
||||
virtual void closePort( void ) = 0;
|
||||
virtual unsigned int getPortCount( void ) = 0;
|
||||
virtual std::string getPortName( unsigned int portNumber ) = 0;
|
||||
virtual void sendMessage( std::vector<unsigned char> *message ) = 0;
|
||||
|
||||
//! The destructor closes any open MIDI connections.
|
||||
~RtMidiOut();
|
||||
protected:
|
||||
virtual void initialize( const std::string& clientName ) = 0;
|
||||
|
||||
//! Open a MIDI output connection.
|
||||
/*!
|
||||
An optional port number greater than 0 can be specified.
|
||||
Otherwise, the default or first port found is opened. An
|
||||
exception is thrown if an error occurs while attempting to make
|
||||
the port connection.
|
||||
*/
|
||||
void openPort( unsigned int portNumber = 0, const std::string portName = std::string( "RtMidi Output" ) );
|
||||
void *apiData_;
|
||||
bool connected_;
|
||||
std::string errorString_;
|
||||
};
|
||||
|
||||
//! Close an open MIDI connection (if one exists).
|
||||
void closePort();
|
||||
// **************************************************************** //
|
||||
//
|
||||
// Inline RtMidiIn and RtMidiOut definitions.
|
||||
//
|
||||
// **************************************************************** //
|
||||
|
||||
//! Create a virtual output port, with optional name, to allow software connections (OS X and ALSA only).
|
||||
/*!
|
||||
This function creates a virtual MIDI output port to which other
|
||||
software applications can connect. This type of functionality
|
||||
is currently only supported by the Macintosh OS-X and Linux ALSA
|
||||
APIs (the function does nothing with the other APIs). An
|
||||
exception is thrown if an error occurs while attempting to create
|
||||
the virtual port.
|
||||
*/
|
||||
void openVirtualPort( const std::string portName = std::string( "RtMidi Output" ) );
|
||||
inline RtMidi::Api RtMidiIn :: getCurrentApi( void ) throw() { return rtapi_->getCurrentApi(); }
|
||||
inline void RtMidiIn :: openPort( unsigned int portNumber, const std::string portName ) { return rtapi_->openPort( portNumber, portName ); }
|
||||
inline void RtMidiIn :: openVirtualPort( const std::string portName ) { return rtapi_->openVirtualPort( portName ); }
|
||||
inline void RtMidiIn :: closePort( void ) { return rtapi_->closePort(); }
|
||||
inline void RtMidiIn :: setCallback( RtMidiCallback callback, void *userData ) { return rtapi_->setCallback( callback, userData ); }
|
||||
inline void RtMidiIn :: cancelCallback( void ) { return rtapi_->cancelCallback(); }
|
||||
inline unsigned int RtMidiIn :: getPortCount( void ) { return rtapi_->getPortCount(); }
|
||||
inline std::string RtMidiIn :: getPortName( unsigned int portNumber ) { return rtapi_->getPortName( portNumber ); }
|
||||
inline void RtMidiIn :: ignoreTypes( bool midiSysex, bool midiTime, bool midiSense ) { return rtapi_->ignoreTypes( midiSysex, midiTime, midiSense ); }
|
||||
inline double RtMidiIn :: getMessage( std::vector<unsigned char> *message ) { return rtapi_->getMessage( message ); }
|
||||
|
||||
//! Return the number of available MIDI output ports.
|
||||
unsigned int getPortCount();
|
||||
inline RtMidi::Api RtMidiOut :: getCurrentApi( void ) throw() { return rtapi_->getCurrentApi(); }
|
||||
inline void RtMidiOut :: openPort( unsigned int portNumber, const std::string portName ) { return rtapi_->openPort( portNumber, portName ); }
|
||||
inline void RtMidiOut :: openVirtualPort( const std::string portName ) { return rtapi_->openVirtualPort( portName ); }
|
||||
inline void RtMidiOut :: closePort( void ) { return rtapi_->closePort(); }
|
||||
inline unsigned int RtMidiOut :: getPortCount( void ) { return rtapi_->getPortCount(); }
|
||||
inline std::string RtMidiOut :: getPortName( unsigned int portNumber ) { return rtapi_->getPortName( portNumber ); }
|
||||
inline void RtMidiOut :: sendMessage( std::vector<unsigned char> *message ) { return rtapi_->sendMessage( message ); }
|
||||
|
||||
//! Return a string identifier for the specified MIDI port type and number.
|
||||
/*!
|
||||
An empty string is returned if an invalid port specifier is provided.
|
||||
*/
|
||||
std::string getPortName( unsigned int portNumber = 0 );
|
||||
// **************************************************************** //
|
||||
//
|
||||
// MidiInApi and MidiOutApi subclass prototypes.
|
||||
//
|
||||
// **************************************************************** //
|
||||
|
||||
//! Immediately send a single message out an open MIDI output port.
|
||||
/*!
|
||||
An exception is thrown if an error occurs during output or an
|
||||
output connection was not previously established.
|
||||
*/
|
||||
#if !defined(__LINUX_ALSA__) && !defined(__UNIX_JACK__) && !defined(__MACOSX_CORE__) && !defined(__WINDOWS_MM__) && !defined(__WINDOWS_KS__)
|
||||
#define __RTMIDI_DUMMY__
|
||||
#endif
|
||||
|
||||
#if defined(__MACOSX_CORE__)
|
||||
|
||||
class MidiInCore: public MidiInApi
|
||||
{
|
||||
public:
|
||||
MidiInCore( const std::string clientName, unsigned int queueSizeLimit );
|
||||
~MidiInCore( void );
|
||||
RtMidi::Api getCurrentApi( void ) { return RtMidi::MACOSX_CORE; };
|
||||
void openPort( unsigned int portNumber, const std::string portName );
|
||||
void openVirtualPort( const std::string portName );
|
||||
void closePort( void );
|
||||
unsigned int getPortCount( void );
|
||||
std::string getPortName( unsigned int portNumber );
|
||||
|
||||
protected:
|
||||
void initialize( const std::string& clientName );
|
||||
};
|
||||
|
||||
class MidiOutCore: public MidiOutApi
|
||||
{
|
||||
public:
|
||||
MidiOutCore( const std::string clientName );
|
||||
~MidiOutCore( void );
|
||||
RtMidi::Api getCurrentApi( void ) { return RtMidi::MACOSX_CORE; };
|
||||
void openPort( unsigned int portNumber, const std::string portName );
|
||||
void openVirtualPort( const std::string portName );
|
||||
void closePort( void );
|
||||
unsigned int getPortCount( void );
|
||||
std::string getPortName( unsigned int portNumber );
|
||||
void sendMessage( std::vector<unsigned char> *message );
|
||||
|
||||
private:
|
||||
|
||||
protected:
|
||||
void initialize( const std::string& clientName );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__UNIX_JACK__)
|
||||
|
||||
class MidiInJack: public MidiInApi
|
||||
{
|
||||
public:
|
||||
MidiInJack( const std::string clientName, unsigned int queueSizeLimit );
|
||||
~MidiInJack( void );
|
||||
RtMidi::Api getCurrentApi( void ) { return RtMidi::UNIX_JACK; };
|
||||
void openPort( unsigned int portNumber, const std::string portName );
|
||||
void openVirtualPort( const std::string portName );
|
||||
void closePort( void );
|
||||
unsigned int getPortCount( void );
|
||||
std::string getPortName( unsigned int portNumber );
|
||||
|
||||
protected:
|
||||
void initialize( const std::string& clientName );
|
||||
};
|
||||
|
||||
class MidiOutJack: public MidiOutApi
|
||||
{
|
||||
public:
|
||||
MidiOutJack( const std::string clientName );
|
||||
~MidiOutJack( void );
|
||||
RtMidi::Api getCurrentApi( void ) { return RtMidi::UNIX_JACK; };
|
||||
void openPort( unsigned int portNumber, const std::string portName );
|
||||
void openVirtualPort( const std::string portName );
|
||||
void closePort( void );
|
||||
unsigned int getPortCount( void );
|
||||
std::string getPortName( unsigned int portNumber );
|
||||
void sendMessage( std::vector<unsigned char> *message );
|
||||
|
||||
protected:
|
||||
void initialize( const std::string& clientName );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__LINUX_ALSA__)
|
||||
|
||||
class MidiInAlsa: public MidiInApi
|
||||
{
|
||||
public:
|
||||
MidiInAlsa( const std::string clientName, unsigned int queueSizeLimit );
|
||||
~MidiInAlsa( void );
|
||||
RtMidi::Api getCurrentApi( void ) { return RtMidi::LINUX_ALSA; };
|
||||
void openPort( unsigned int portNumber, const std::string portName );
|
||||
void openVirtualPort( const std::string portName );
|
||||
void closePort( void );
|
||||
unsigned int getPortCount( void );
|
||||
std::string getPortName( unsigned int portNumber );
|
||||
|
||||
protected:
|
||||
void initialize( const std::string& clientName );
|
||||
};
|
||||
|
||||
class MidiOutAlsa: public MidiOutApi
|
||||
{
|
||||
public:
|
||||
MidiOutAlsa( const std::string clientName );
|
||||
~MidiOutAlsa( void );
|
||||
RtMidi::Api getCurrentApi( void ) { return RtMidi::LINUX_ALSA; };
|
||||
void openPort( unsigned int portNumber, const std::string portName );
|
||||
void openVirtualPort( const std::string portName );
|
||||
void closePort( void );
|
||||
unsigned int getPortCount( void );
|
||||
std::string getPortName( unsigned int portNumber );
|
||||
void sendMessage( std::vector<unsigned char> *message );
|
||||
|
||||
protected:
|
||||
void initialize( const std::string& clientName );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__WINDOWS_MM__)
|
||||
|
||||
class MidiInWinMM: public MidiInApi
|
||||
{
|
||||
public:
|
||||
MidiInWinMM( const std::string clientName, unsigned int queueSizeLimit );
|
||||
~MidiInWinMM( void );
|
||||
RtMidi::Api getCurrentApi( void ) { return RtMidi::WINDOWS_MM; };
|
||||
void openPort( unsigned int portNumber, const std::string portName );
|
||||
void openVirtualPort( const std::string portName );
|
||||
void closePort( void );
|
||||
unsigned int getPortCount( void );
|
||||
std::string getPortName( unsigned int portNumber );
|
||||
|
||||
protected:
|
||||
void initialize( const std::string& clientName );
|
||||
};
|
||||
|
||||
class MidiOutWinMM: public MidiOutApi
|
||||
{
|
||||
public:
|
||||
MidiOutWinMM( const std::string clientName );
|
||||
~MidiOutWinMM( void );
|
||||
RtMidi::Api getCurrentApi( void ) { return RtMidi::WINDOWS_MM; };
|
||||
void openPort( unsigned int portNumber, const std::string portName );
|
||||
void openVirtualPort( const std::string portName );
|
||||
void closePort( void );
|
||||
unsigned int getPortCount( void );
|
||||
std::string getPortName( unsigned int portNumber );
|
||||
void sendMessage( std::vector<unsigned char> *message );
|
||||
|
||||
protected:
|
||||
void initialize( const std::string& clientName );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__WINDOWS_KS__)
|
||||
|
||||
class MidiInWinKS: public MidiInApi
|
||||
{
|
||||
public:
|
||||
MidiInWinKS( const std::string clientName, unsigned int queueSizeLimit );
|
||||
~MidiInWinKS( void );
|
||||
RtMidi::Api getCurrentApi( void ) { return RtMidi::WINDOWS_KS; };
|
||||
void openPort( unsigned int portNumber, const std::string portName );
|
||||
void openVirtualPort( const std::string portName );
|
||||
void closePort( void );
|
||||
unsigned int getPortCount( void );
|
||||
std::string getPortName( unsigned int portNumber );
|
||||
|
||||
protected:
|
||||
void initialize( const std::string& clientName );
|
||||
};
|
||||
|
||||
class MidiOutWinKS: public MidiOutApi
|
||||
{
|
||||
public:
|
||||
MidiOutWinKS( const std::string clientName );
|
||||
~MidiOutWinKS( void );
|
||||
RtMidi::Api getCurrentApi( void ) { return RtMidi::WINDOWS_KS; };
|
||||
void openPort( unsigned int portNumber, const std::string portName );
|
||||
void openVirtualPort( const std::string portName );
|
||||
void closePort( void );
|
||||
unsigned int getPortCount( void );
|
||||
std::string getPortName( unsigned int portNumber );
|
||||
void sendMessage( std::vector<unsigned char> *message );
|
||||
|
||||
protected:
|
||||
void initialize( const std::string& clientName );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__RTMIDI_DUMMY__)
|
||||
|
||||
class MidiInDummy: public MidiInApi
|
||||
{
|
||||
public:
|
||||
MidiInDummy( const std::string clientName, unsigned int queueSizeLimit ) : MidiInApi( queueSizeLimit ) { errorString_ = "MidiInDummy: This class provides no functionality."; RtMidi::error( RtError::WARNING, errorString_ ); };
|
||||
RtMidi::Api getCurrentApi( void ) { return RtMidi::RTMIDI_DUMMY; };
|
||||
void openPort( unsigned int portNumber, const std::string portName ) {};
|
||||
void openVirtualPort( const std::string portName ) {};
|
||||
void closePort( void ) {};
|
||||
unsigned int getPortCount( void ) { return 0; };
|
||||
std::string getPortName( unsigned int portNumber ) { return ""; };
|
||||
|
||||
protected:
|
||||
void initialize( const std::string& clientName ) {};
|
||||
};
|
||||
|
||||
class MidiOutDummy: public MidiOutApi
|
||||
{
|
||||
public:
|
||||
MidiOutDummy( const std::string clientName ) { errorString_ = "MidiOutDummy: This class provides no functionality."; RtMidi::error( RtError::WARNING, errorString_ ); };
|
||||
RtMidi::Api getCurrentApi( void ) { return RtMidi::RTMIDI_DUMMY; };
|
||||
void openPort( unsigned int portNumber, const std::string portName ) {};
|
||||
void openVirtualPort( const std::string portName ) {};
|
||||
void closePort( void ) {};
|
||||
unsigned int getPortCount( void ) { return 0; };
|
||||
std::string getPortName( unsigned int portNumber ) { return ""; };
|
||||
void sendMessage( std::vector<unsigned char> *message ) {};
|
||||
|
||||
protected:
|
||||
void initialize( const std::string& clientName ) {};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace stk {
|
||||
that takes an StkFrames object for multi-channel and/or
|
||||
multi-frame data.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace stk {
|
||||
that takes a reference to an StkFrames object for multi-channel
|
||||
and/or multi-frame data.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
where <name> is the string used in the SKINI stream.
|
||||
|
||||
by Perry R. Cook, 1995-2011.
|
||||
by Perry R. Cook, 1995-2012.
|
||||
*/
|
||||
/*********************************************************/
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace stk {
|
||||
This instrument provides an ADSR envelope, a one-pole filter, and
|
||||
structures for an arbitrary number of attack and looped files.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace stk {
|
||||
- Vibrato Gain = 1
|
||||
- Breath Pressure = 128
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#define STK_SHAKERS_H
|
||||
|
||||
#include "Instrmnt.h"
|
||||
#include <cmath>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace stk {
|
||||
|
||||
@@ -9,67 +11,57 @@ namespace stk {
|
||||
/*! \class Shakers
|
||||
\brief PhISEM and PhOLIES class.
|
||||
|
||||
PhISEM (Physically Informed Stochastic Event
|
||||
Modeling) is an algorithmic approach for
|
||||
simulating collisions of multiple independent
|
||||
sound producing objects. This class is a
|
||||
meta-model that can simulate a Maraca, Sekere,
|
||||
Cabasa, Bamboo Wind Chimes, Water Drops,
|
||||
Tambourine, Sleighbells, and a Guiro.
|
||||
PhISEM (Physically Informed Stochastic Event Modeling) is an
|
||||
algorithmic approach for simulating collisions of multiple
|
||||
independent sound producing objects. This class is a meta-model
|
||||
that can simulate a Maraca, Sekere, Cabasa, Bamboo Wind Chimes,
|
||||
Water Drops, Tambourine, Sleighbells, and a Guiro.
|
||||
|
||||
PhOLIES (Physically-Oriented Library of
|
||||
Imitated Environmental Sounds) is a similar
|
||||
approach for the synthesis of environmental
|
||||
sounds. This class implements simulations of
|
||||
breaking sticks, crunchy snow (or not), a
|
||||
wrench, sandpaper, and more.
|
||||
PhOLIES (Physically-Oriented Library of Imitated Environmental
|
||||
Sounds) is a similar approach for the synthesis of environmental
|
||||
sounds. This class implements simulations of breaking sticks,
|
||||
crunchy snow (or not), a wrench, sandpaper, and more.
|
||||
|
||||
Control Change Numbers:
|
||||
- Shake Energy = 2
|
||||
- System Decay = 4
|
||||
- Number Of Objects = 11
|
||||
- Resonance Frequency = 1
|
||||
- Shake Energy = 128
|
||||
- Instrument Selection = 1071
|
||||
- Maraca = 0
|
||||
- Cabasa = 1
|
||||
- Sekere = 2
|
||||
- Guiro = 3
|
||||
- Water Drops = 4
|
||||
- Bamboo Chimes = 5
|
||||
- Tambourine = 6
|
||||
- Sleigh Bells = 7
|
||||
- Sticks = 8
|
||||
- Crunch = 9
|
||||
- Wrench = 10
|
||||
- Sand Paper = 11
|
||||
- Coke Can = 12
|
||||
- Next Mug = 13
|
||||
- Penny + Mug = 14
|
||||
- Nickle + Mug = 15
|
||||
- Dime + Mug = 16
|
||||
- Quarter + Mug = 17
|
||||
- Franc + Mug = 18
|
||||
- Peso + Mug = 19
|
||||
- Big Rocks = 20
|
||||
- Little Rocks = 21
|
||||
- Tuned Bamboo Chimes = 22
|
||||
- Shake Energy = 2
|
||||
- System Decay = 4
|
||||
- Number Of Objects = 11
|
||||
- Resonance Frequency = 1
|
||||
- Shake Energy = 128
|
||||
- Instrument Selection = 1071
|
||||
- Maraca = 0
|
||||
- Cabasa = 1
|
||||
- Sekere = 2
|
||||
- Tambourine = 3
|
||||
- Sleigh Bells = 4
|
||||
- Bamboo Chimes = 5
|
||||
- Sand Paper = 6
|
||||
- Coke Can = 7
|
||||
- Sticks = 8
|
||||
- Crunch = 9
|
||||
- Big Rocks = 10
|
||||
- Little Rocks = 11
|
||||
- Next Mug = 12
|
||||
- Penny + Mug = 13
|
||||
- Nickle + Mug = 14
|
||||
- Dime + Mug = 15
|
||||
- Quarter + Mug = 16
|
||||
- Franc + Mug = 17
|
||||
- Peso + Mug = 18
|
||||
- Guiro = 19
|
||||
- Wrench = 20
|
||||
- Water Drops = 21
|
||||
- Tuned Bamboo Chimes = 22
|
||||
|
||||
by Perry R. Cook, 1995-2011.
|
||||
by Perry R. Cook with updates by Gary Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
const int MAX_FREQS = 8;
|
||||
const int NUM_INSTR = 24;
|
||||
|
||||
class Shakers : public Instrmnt
|
||||
{
|
||||
public:
|
||||
//! Class constructor.
|
||||
Shakers( void );
|
||||
|
||||
//! Class destructor.
|
||||
~Shakers( void );
|
||||
//! Class constructor taking instrument type argument.
|
||||
Shakers( int type = 0 );
|
||||
|
||||
//! Start a note with the given instrument and amplitude.
|
||||
/*!
|
||||
@@ -97,45 +89,217 @@ class Shakers : public Instrmnt
|
||||
*/
|
||||
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
|
||||
|
||||
struct BiQuad {
|
||||
StkFloat gain;
|
||||
StkFloat b[3];
|
||||
StkFloat a[3]; // a0 term assumed equal to 1.0
|
||||
StkFloat inputs[3];
|
||||
StkFloat outputs[3];
|
||||
|
||||
// Default constructor.
|
||||
BiQuad()
|
||||
{
|
||||
gain = 0.0;
|
||||
for ( int i=0; i<3; i++ ) {
|
||||
b[i] = 0.0;
|
||||
a[i] = 0.0;
|
||||
inputs[i] = 0.0;
|
||||
outputs[i] = 0.0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
int setupName( char* instr );
|
||||
int setupNum( int inst );
|
||||
int setFreqAndReson( int which, StkFloat freq, StkFloat reson );
|
||||
void setDecays( StkFloat sndDecay, StkFloat sysDecay );
|
||||
void setFinalZs( StkFloat z0, StkFloat z1, StkFloat z2 );
|
||||
StkFloat wuter_tick( void );
|
||||
StkFloat tbamb_tick( void );
|
||||
StkFloat ratchet_tick( void );
|
||||
void setType( int type );
|
||||
void setResonance( BiQuad &filter, StkFloat frequency, StkFloat radius );
|
||||
StkFloat tickResonance( BiQuad &filter, StkFloat input );
|
||||
void setEqualization( StkFloat b0, StkFloat b1, StkFloat b2 );
|
||||
StkFloat tickEqualize( StkFloat input );
|
||||
int randomInt( int max );
|
||||
StkFloat randomFloat( StkFloat max = 1.0 );
|
||||
StkFloat noise( void );
|
||||
void waterDrop( void );
|
||||
|
||||
int instType_;
|
||||
int ratchetPos_, lastRatchetPos_;
|
||||
int shakerType_;
|
||||
unsigned int nResonances_;
|
||||
StkFloat shakeEnergy_;
|
||||
StkFloat inputs_[MAX_FREQS];
|
||||
StkFloat outputs_[MAX_FREQS][2];
|
||||
StkFloat coeffs_[MAX_FREQS][2];
|
||||
StkFloat sndLevel_;
|
||||
StkFloat baseGain_;
|
||||
StkFloat gains_[MAX_FREQS];
|
||||
int nFreqs_;
|
||||
StkFloat t_center_freqs_[MAX_FREQS];
|
||||
StkFloat center_freqs_[MAX_FREQS];
|
||||
StkFloat resons_[MAX_FREQS];
|
||||
StkFloat freq_rand_[MAX_FREQS];
|
||||
int freqalloc_[MAX_FREQS];
|
||||
StkFloat soundDecay_;
|
||||
StkFloat systemDecay_;
|
||||
StkFloat nObjects_;
|
||||
StkFloat totalEnergy_;
|
||||
StkFloat ratchet_, ratchetDelta_;
|
||||
StkFloat finalZ_[3];
|
||||
StkFloat finalZCoeffs_[3];
|
||||
StkFloat defObjs_[NUM_INSTR];
|
||||
StkFloat defDecays_[NUM_INSTR];
|
||||
StkFloat decayScale_[NUM_INSTR];
|
||||
StkFloat sndLevel_;
|
||||
StkFloat baseGain_;
|
||||
StkFloat currentGain_;
|
||||
StkFloat baseDecay_;
|
||||
StkFloat baseObjects_;
|
||||
StkFloat decayScale_;
|
||||
BiQuad equalizer_;
|
||||
StkFloat ratchetCount_;
|
||||
StkFloat ratchetDelta_;
|
||||
StkFloat baseRatchetDelta_;
|
||||
int lastRatchetValue_;
|
||||
|
||||
std::vector< BiQuad > filters_;
|
||||
std::vector< StkFloat > baseFrequencies_;
|
||||
std::vector< StkFloat > baseRadii_;
|
||||
std::vector< bool > doVaryFrequency_;
|
||||
std::vector< StkFloat > tempFrequencies_;
|
||||
StkFloat varyFactor_;
|
||||
};
|
||||
|
||||
inline void Shakers :: setResonance( BiQuad &filter, StkFloat frequency, StkFloat radius )
|
||||
{
|
||||
filter.a[1] = -2.0 * radius * cos( TWO_PI * frequency / Stk::sampleRate());
|
||||
filter.a[2] = radius * radius;
|
||||
}
|
||||
|
||||
inline StkFloat Shakers :: tickResonance( BiQuad &filter, StkFloat input )
|
||||
{
|
||||
filter.outputs[0] = input * filter.gain * currentGain_;
|
||||
filter.outputs[0] -= filter.a[1] * filter.outputs[1] + filter.a[2] * filter.outputs[2];
|
||||
filter.outputs[2] = filter.outputs[1];
|
||||
filter.outputs[1] = filter.outputs[0];
|
||||
return filter.outputs[0];
|
||||
}
|
||||
|
||||
inline void Shakers :: setEqualization( StkFloat b0, StkFloat b1, StkFloat b2 )
|
||||
{
|
||||
equalizer_.b[0] = b0;
|
||||
equalizer_.b[1] = b1;
|
||||
equalizer_.b[2] = b2;
|
||||
}
|
||||
|
||||
inline StkFloat Shakers :: tickEqualize( StkFloat input )
|
||||
{
|
||||
equalizer_.inputs[0] = input;
|
||||
equalizer_.outputs[0] = equalizer_.b[0] * equalizer_.inputs[0] + equalizer_.b[1] * equalizer_.inputs[1] + equalizer_.b[2] * equalizer_.inputs[2];
|
||||
equalizer_.inputs[2] = equalizer_.inputs[1];
|
||||
equalizer_.inputs[1] = equalizer_.inputs[0];
|
||||
return equalizer_.outputs[0];
|
||||
}
|
||||
|
||||
inline int Shakers :: randomInt( int max ) // Return random integer between 0 and max-1
|
||||
{
|
||||
return (int) ((float)max * rand() / (RAND_MAX + 1.0) );
|
||||
}
|
||||
|
||||
inline StkFloat Shakers :: randomFloat( StkFloat max ) // Return random float between 0.0 and max
|
||||
{
|
||||
return (StkFloat) (max * rand() / (RAND_MAX + 1.0) );
|
||||
}
|
||||
|
||||
inline StkFloat Shakers :: noise( void ) // Return random StkFloat float between -1.0 and 1.0
|
||||
{
|
||||
return ( (StkFloat) ( 2.0 * rand() / (RAND_MAX + 1.0) ) - 1.0 );
|
||||
}
|
||||
|
||||
const StkFloat MIN_ENERGY = 0.001;
|
||||
const StkFloat WATER_FREQ_SWEEP = 1.0001;
|
||||
|
||||
inline void Shakers :: waterDrop( void )
|
||||
{
|
||||
if ( randomInt( 32767 ) < nObjects_) {
|
||||
sndLevel_ = shakeEnergy_;
|
||||
unsigned int j = randomInt( 3 );
|
||||
if ( j == 0 && filters_[0].gain == 0.0 ) { // don't change unless fully decayed
|
||||
tempFrequencies_[0] = baseFrequencies_[1] * (0.75 + (0.25 * noise()));
|
||||
filters_[0].gain = fabs( noise() );
|
||||
}
|
||||
else if (j == 1 && filters_[1].gain == 0.0) {
|
||||
tempFrequencies_[1] = baseFrequencies_[1] * (1.0 + (0.25 * noise()));
|
||||
filters_[1].gain = fabs( noise() );
|
||||
}
|
||||
else if ( filters_[2].gain == 0.0 ) {
|
||||
tempFrequencies_[2] = baseFrequencies_[1] * (1.25 + (0.25 * noise()));
|
||||
filters_[2].gain = fabs( noise() );
|
||||
}
|
||||
}
|
||||
|
||||
// Sweep center frequencies.
|
||||
for ( unsigned int i=0; i<3; i++ ) { // WATER_RESONANCES = 3
|
||||
filters_[i].gain *= baseRadii_[i];
|
||||
if ( filters_[i].gain > 0.001 ) {
|
||||
tempFrequencies_[i] *= WATER_FREQ_SWEEP;
|
||||
filters_[i].a[1] = -2.0 * baseRadii_[i] * cos( TWO_PI * tempFrequencies_[i] / Stk::sampleRate() );
|
||||
}
|
||||
else
|
||||
filters_[i].gain = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
inline StkFloat Shakers :: tick( unsigned int )
|
||||
{
|
||||
unsigned int iTube = 0;
|
||||
StkFloat input = 0.0;
|
||||
if ( shakerType_ == 19 || shakerType_ == 20 ) {
|
||||
if ( ratchetCount_ <= 0 ) return lastFrame_[0] = 0.0;
|
||||
|
||||
shakeEnergy_ -= ( ratchetDelta_ + ( 0.002 * shakeEnergy_ ) );
|
||||
if ( shakeEnergy_ < 0.0 ) {
|
||||
shakeEnergy_ = 1.0;
|
||||
ratchetCount_--;
|
||||
}
|
||||
|
||||
if ( randomFloat( 1024 ) < nObjects_ )
|
||||
sndLevel_ += shakeEnergy_ * shakeEnergy_;
|
||||
|
||||
// Sound is enveloped noise
|
||||
input = sndLevel_ * noise() * shakeEnergy_;
|
||||
}
|
||||
else {
|
||||
if ( shakeEnergy_ < MIN_ENERGY ) return lastFrame_[0] = 0.0;
|
||||
|
||||
// Exponential system decay
|
||||
shakeEnergy_ *= systemDecay_;
|
||||
|
||||
// Random events
|
||||
if ( shakerType_ == 21 ) {
|
||||
waterDrop();
|
||||
input = sndLevel_;
|
||||
}
|
||||
else {
|
||||
if ( randomFloat( 1024.0 ) < nObjects_ ) {
|
||||
sndLevel_ += shakeEnergy_;
|
||||
input = sndLevel_;
|
||||
// Vary resonance frequencies if specified.
|
||||
for ( unsigned int i=0; i<nResonances_; i++ ) {
|
||||
if ( doVaryFrequency_[i] ) {
|
||||
StkFloat tempRand = baseFrequencies_[i] * ( 1.0 + ( varyFactor_ * noise() ) );
|
||||
filters_[i].a[1] = -2.0 * baseRadii_[i] * cos( TWO_PI * tempRand / Stk::sampleRate() );
|
||||
}
|
||||
}
|
||||
if ( shakerType_ == 22 ) iTube = randomInt( 7 ); // ANGKLUNG_RESONANCES
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Exponential sound decay
|
||||
sndLevel_ *= soundDecay_;
|
||||
|
||||
// Do resonance filtering
|
||||
lastFrame_[0] = 0.0;
|
||||
if ( shakerType_ == 22 ) {
|
||||
for ( unsigned int i=0; i<nResonances_; i++ ) {
|
||||
if ( i == iTube )
|
||||
lastFrame_[0] += tickResonance( filters_[i], input );
|
||||
else
|
||||
lastFrame_[0] += tickResonance( filters_[i], 0.0 );
|
||||
}
|
||||
}
|
||||
else {
|
||||
for ( unsigned int i=0; i<nResonances_; i++ )
|
||||
lastFrame_[0] += tickResonance( filters_[i], input );
|
||||
}
|
||||
|
||||
// Do final FIR filtering (lowpass or highpass)
|
||||
lastFrame_[0] = tickEqualize( lastFrame_[0] );
|
||||
|
||||
//if ( std::abs(lastFrame_[0]) > 1.0 )
|
||||
// std::cout << "lastOutput = " << lastFrame_[0] << std::endl;
|
||||
|
||||
return lastFrame_[0];
|
||||
}
|
||||
|
||||
inline StkFrames& Shakers :: tick( StkFrames& frames, unsigned int channel )
|
||||
{
|
||||
unsigned int nChannels = lastFrame_.channels();
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace stk {
|
||||
- Envelope Rate = 11
|
||||
- Gain = 128
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace stk {
|
||||
|
||||
The "table" length, set in SineWave.h, is 2048 samples by default.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace stk {
|
||||
Within STK, it is used as an excitation source for other
|
||||
instruments.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace stk {
|
||||
Stanford, bearing the names of Karplus and/or
|
||||
Strong.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace stk {
|
||||
|
||||
\sa \ref skini
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace stk {
|
||||
number of static functions for use with external socket
|
||||
descriptors.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace stk {
|
||||
This class implements a spherical ball with
|
||||
radius, mass, position, and velocity parameters.
|
||||
|
||||
by Perry R. Cook, 1995-2011.
|
||||
by Perry R. Cook, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace stk {
|
||||
- String Sustain = 11
|
||||
- String Stretch = 1
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
//#include <cstdlib>
|
||||
|
||||
/*! \namespace stk
|
||||
\brief The STK namespace.
|
||||
@@ -39,7 +39,7 @@ namespace stk {
|
||||
STK WWW site: http://ccrma.stanford.edu/software/stk/
|
||||
|
||||
The Synthesis ToolKit in C++ (STK)
|
||||
Copyright (c) 1995-2011 Perry R. Cook and Gary P. Scavone
|
||||
Copyright (c) 1995-2012 Perry R. Cook and Gary P. Scavone
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation files
|
||||
@@ -264,7 +264,7 @@ protected:
|
||||
Possible future improvements in this class could include functions
|
||||
to convert to and return other data types.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace stk {
|
||||
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-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace stk {
|
||||
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-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace stk {
|
||||
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-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace stk {
|
||||
|
||||
THREAD_RETURN THREAD_TYPE thread_function(void *ptr)
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace stk {
|
||||
type who should worry about this (making
|
||||
money) worry away.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace stk {
|
||||
use possibly subject to patents held by Stanford
|
||||
University, Yamaha, and others.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
@@ -37,9 +37,6 @@ class Twang : public Stk
|
||||
//! Class constructor, taking the lowest desired playing frequency.
|
||||
Twang( StkFloat lowestFrequency = 50.0 );
|
||||
|
||||
//! Class destructor.
|
||||
~Twang( void );
|
||||
|
||||
//! Reset and clear all internal state.
|
||||
void clear( void );
|
||||
|
||||
@@ -70,7 +67,11 @@ class Twang : public Stk
|
||||
void setLoopFilter( std::vector<StkFloat> coefficients );
|
||||
|
||||
//! Return an StkFrames reference to the last output sample frame.
|
||||
const StkFrames& lastFrame( void ) const { return lastFrame_; };
|
||||
//const StkFrames& lastFrame( void ) const { return lastFrame_; };
|
||||
|
||||
//! Return the last computed output value.
|
||||
// StkFloat lastOut( void ) { return lastFrame_[0]; };
|
||||
StkFloat lastOut( void ) { return lastOutput_; };
|
||||
|
||||
//! Compute and return one output sample.
|
||||
StkFloat tick( StkFloat input );
|
||||
@@ -103,7 +104,7 @@ class Twang : public Stk
|
||||
DelayL combDelay_;
|
||||
Fir loopFilter_;
|
||||
|
||||
StkFrames lastFrame_;
|
||||
StkFloat lastOutput_;
|
||||
StkFloat frequency_;
|
||||
StkFloat loopGain_;
|
||||
StkFloat pluckPosition_;
|
||||
@@ -111,10 +112,11 @@ class Twang : public Stk
|
||||
|
||||
inline StkFloat Twang :: tick( StkFloat input )
|
||||
{
|
||||
lastFrame_[0] = delayLine_.tick( input + loopFilter_.tick( delayLine_.lastOut() ) );
|
||||
lastFrame_[0] -= combDelay_.tick( lastFrame_[0] ); // comb filtering on output
|
||||
lastOutput_ = delayLine_.tick( input + loopFilter_.tick( delayLine_.lastOut() ) );
|
||||
lastOutput_ -= combDelay_.tick( lastOutput_ ); // comb filtering on output
|
||||
lastOutput_ *= 0.5;
|
||||
|
||||
return lastFrame_[0] * 0.5;
|
||||
return lastOutput_;
|
||||
}
|
||||
|
||||
inline StkFrames& Twang :: tick( StkFrames& frames, unsigned int channel )
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace stk {
|
||||
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-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace stk {
|
||||
provided for creating a "notch" in the frequency response while
|
||||
maintaining a constant filter gain.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace stk {
|
||||
read/write methods. Values less than or equal to zero indicate
|
||||
the occurence of an error.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace stk {
|
||||
|
||||
This class implements a three-dimensional vector.
|
||||
|
||||
by Perry R. Cook, 1995-2011.
|
||||
by Perry R. Cook, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace stk {
|
||||
- Vibrato Gain = 1
|
||||
- Loudness (Spectral Tilt) = 128
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace stk {
|
||||
Alternately, control changes can be sent to all voices in a given
|
||||
group.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace stk {
|
||||
- Blowing Frequency Modulation = 2
|
||||
- Volume = 128
|
||||
|
||||
by Perry R. Cook 1995-2011.
|
||||
by Perry R. Cook 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace stk {
|
||||
type who should worry about this (making
|
||||
money) worry away.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace stk {
|
||||
This class provides common functionality for a variety of audio
|
||||
data input subclasses.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace stk {
|
||||
Currently, WvOut is non-interpolating and the output rate is
|
||||
always Stk::sampleRate().
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2012.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user