1 /*----------------------------------------------------------------------------
2 ChucK Concurrent, On-the-fly Audio Programming Language
3 Compiler and Virtual Machine
5 Copyright (c) 2004 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.cs.princeton.edu/
7 http://soundlab.cs.princeton.edu/
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 -----------------------------------------------------------------------------*/
25 //-----------------------------------------------------------------------------
27 // desc: ChucK import for Synthesis ToolKit (STK)
29 // author: Ge Wang (gewang@cs.princeton.edu)
30 // Perry R. Cook (prc@cs.princeton.edu)
31 // Ananya Misra (amisra@cs.princeton.edu)
32 // Ari Lazier (alazier@cs.princeton.edu)
33 // Philip L. Davidson (philipd@cs.princeton.edu)
35 //-----------------------------------------------------------------------------
36 #ifndef __UGEN_STK_H__
37 #define __UGEN_STK_H__
43 DLL_QUERY
stk_query( Chuck_DL_Query
* QUERY
);
44 t_CKBOOL
stk_detach( t_CKUINT type
, void * data
);
47 // this determines STK float type and de-denormal method
49 #define MY_FLOAT double
50 #define CK_STK_DDN CK_DDN_DOUBLE
52 #define MY_FLOAT float
53 #define CK_STK_DDN CK_DDN_SINGLE
57 /***************************************************/
61 Nearly all STK classes inherit from this class.
62 The global sample rate and rawwave path variables
63 can be queried and modified via Stk. In addition,
64 this class provides error handling and
65 byte-swapping functions.
67 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
69 /***************************************************/
77 // Most data in STK is passed and calculated with the
78 // following user-definable floating-point type. You
79 // can change this to "float" if you prefer or perhaps
80 // a "long double" in the future.
82 //XXX sample is already defined in chuck_def.h!!!
84 typedef SAMPLE MY_FLOAT
;
86 // The "MY_FLOAT" type will be deprecated in STK
87 // versions higher than 4.1.2 and replaced with the variable
89 //typedef double StkFloat;
90 //#if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__)
91 // #pragma deprecated(MY_FLOAT)
93 // typedef StkFloat MY_FLOAT __attribute__ ((deprecated));
96 //! STK error handling class.
98 This is a fairly abstract exception handling class. There could
99 be sub-classes to take care of more specific error conditions ... or
114 PROCESS_SOCKET_IPADDR
,
120 public: // SWAP formerly protected
126 StkError(const char *p
, TYPE tipe
= StkError::UNSPECIFIED
);
129 virtual ~StkError(void);
131 //! Prints "thrown" error message to stdout.
132 virtual void printMessage(void);
134 //! Returns the "thrown" error message TYPE.
135 virtual const TYPE
& getType(void) { return type
; }
137 //! Returns the "thrown" error message string.
138 virtual const char *getMessage(void) const { return message
; }
146 typedef unsigned long STK_FORMAT
;
147 static const STK_FORMAT STK_SINT8
; /*!< -128 to +127 */
148 static const STK_FORMAT STK_SINT16
; /*!< -32768 to +32767 */
149 static const STK_FORMAT STK_SINT32
; /*!< -2147483648 to +2147483647. */
150 static const STK_FORMAT MY_FLOAT32
; /*!< Normalized between plus/minus 1.0. */
151 static const STK_FORMAT MY_FLOAT64
; /*!< Normalized between plus/minus 1.0. */
153 //! Static method which returns the current STK sample rate.
154 static MY_FLOAT
sampleRate(void);
156 //! Static method which sets the STK sample rate.
158 The sample rate set using this method is queried by all STK
159 classes which depend on its value. It is initialized to the
160 default SRATE set in Stk.h. Many STK classes use the sample rate
161 during instantiation. Therefore, if you wish to use a rate which
162 is different from the default rate, it is imperative that it be
163 set \e BEFORE STK objects are instantiated.
165 static void setSampleRate(MY_FLOAT newRate
);
167 //! Static method which returns the current rawwave path.
168 static std::string
rawwavePath(void);
170 //! Static method which sets the STK rawwave path.
171 static void setRawwavePath(std::string newPath
);
173 //! Static method which byte-swaps a 16-bit data type.
174 static void swap16(unsigned char *ptr
);
176 //! Static method which byte-swaps a 32-bit data type.
177 static void swap32(unsigned char *ptr
);
179 //! Static method which byte-swaps a 64-bit data type.
180 static void swap64(unsigned char *ptr
);
182 //! Static cross-platform method to sleep for a number of milliseconds.
183 static void sleep(unsigned long milliseconds
);
185 public: // SWAP formerly private
186 static MY_FLOAT srate
;
187 static std::string rawwavepath
;
189 public: // SWAP formerly protected
191 //! Default constructor.
194 //! Class destructor.
197 //! Function for error reporting and handling.
198 static void handleError( const char *message
, StkError::TYPE type
);
202 // Here are a few other useful typedefs.
203 typedef signed short SINT16
;
204 typedef signed int SINT32
;
205 typedef float FLOAT32
;
206 typedef double FLOAT64
;
214 // The default sampling rate.
215 #define SRATE (MY_FLOAT) 44100.0
217 // The default real-time audio input and output buffer size. If
218 // clicks are occuring in the input and/or output sound stream, a
219 // larger buffer size may help. Larger buffer sizes, however, produce
221 #define RT_BUFFER_SIZE 512
223 // The default rawwave path value is set with the preprocessor
224 // definition RAWWAVE_PATH. This can be specified as an argument to
225 // the configure script, in an integrated development environment, or
226 // below. The global STK rawwave path variable can be dynamically set
227 // with the Stk::setRawwavePath() function. This value is
228 // concatenated to the beginning of all references to rawwave files in
229 // the various STK core classes (ex. Clarinet.cpp). If you wish to
230 // move the rawwaves directory to a different location in your file
231 // system, you will need to set this path definition appropriately.
232 #if !defined(RAWWAVE_PATH)
233 #define RAWWAVE_PATH "../../rawwaves/"
236 //#define PI (MY_FLOAT) 3.14159265359
237 //#define TWO_PI (MY_FLOAT) (2 * PI)
239 #define ONE_OVER_128 (MY_FLOAT) 0.0078125
241 #if defined(__WINDOWS_PTHREAD__)
242 #define __OS_WINDOWS_CYGWIN__
243 #define __STK_REALTIME__
244 #elif defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__)
245 #define __OS_WINDOWS__
246 #define __STK_REALTIME__
247 #elif defined(__LINUX_OSS__) || defined(__LINUX_ALSA__) || defined(__LINUX_JACK__)
249 #define __STK_REALTIME__
250 #elif defined(__IRIX_AL__)
252 #define __STK_REALTIME__
253 #elif defined(__MACOSX_CORE__)
254 #define __OS_MACOSX__
255 #define __STK_REALTIME__
258 //#define _STK_DEBUG_
265 /***************************************************/
267 \brief STK envelope base class.
269 This class implements a simple envelope
270 generator which is capable of ramping to
271 a target value by a specified \e rate.
272 It also responds to simple \e keyOn and
273 \e keyOff messages, ramping to 1.0 on
274 keyOn and to 0.0 on keyOff.
276 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
278 /***************************************************/
280 #if !defined(__ENVELOPE_H)
284 class Envelope
: public Stk
288 //! Default constructor.
291 //! Class destructor.
292 virtual ~Envelope(void);
295 virtual void keyOn(void);
298 virtual void keyOff(void);
301 void setRate(MY_FLOAT aRate
);
303 //! Set the \e rate based on a time duration.
304 void setTime(MY_FLOAT aTime
);
306 //! Set the target value.
307 virtual void setTarget(MY_FLOAT aTarget
);
309 //! Set current and target values to \e aValue.
310 virtual void setValue(MY_FLOAT aValue
);
312 //! Return the current envelope \e state (0 = at target, 1 otherwise).
313 virtual int getState(void) const;
315 //! Return one envelope output value.
316 virtual MY_FLOAT
tick(void);
318 //! Return \e vectorSize envelope outputs in \e vector.
319 virtual MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
321 //! Return the last computed output value.
322 MY_FLOAT
lastOut(void) const;
328 MY_FLOAT m_target
; // chuck
329 MY_FLOAT m_time
; // chuck
338 /***************************************************/
340 \brief STK ADSR envelope class.
342 This Envelope subclass implements a
343 traditional ADSR (Attack, Decay,
344 Sustain, Release) envelope. It
345 responds to simple keyOn and keyOff
346 messages, keeping track of its state.
347 The \e state = ADSR::DONE after the
348 envelope value reaches 0.0 in the
351 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
353 /***************************************************/
355 #if !defined(__ADSR_H)
359 class ADSR
: public Envelope
364 enum { ATTACK
, DECAY
, SUSTAIN
, RELEASE
, DONE
};
366 //! Default constructor.
369 //! Class destructor.
372 //! Set target = 1, state = \e ADSR::ATTACK.
373 virtual void keyOn(void);
375 //! Set target = 0, state = \e ADSR::RELEASE.
376 virtual void keyOff(void);
378 //! Set the attack rate.
379 void setAttackRate(MY_FLOAT aRate
);
381 //! Set the decay rate.
382 void setDecayRate(MY_FLOAT aRate
);
384 //! Set the sustain level.
385 void setSustainLevel(MY_FLOAT aLevel
);
387 //! Set the release rate.
388 void setReleaseRate(MY_FLOAT aRate
);
390 //! Set the attack rate based on a time duration.
391 void setAttackTime(MY_FLOAT aTime
);
393 //! Set the decay rate based on a time duration.
394 void setDecayTime(MY_FLOAT aTime
);
396 //! Set the release rate based on a time duration.
397 void setReleaseTime(MY_FLOAT aTime
);
399 //! Set sustain level and attack, decay, and release state rates based on time durations.
400 void setAllTimes(MY_FLOAT aTime
, MY_FLOAT dTime
, MY_FLOAT sLevel
, MY_FLOAT rTime
);
402 //! Set the target value.
403 void setTarget(MY_FLOAT aTarget
);
405 //! Return the current envelope \e state (ATTACK, DECAY, SUSTAIN, RELEASE, DONE).
406 int getState(void) const;
408 //! Set to state = ADSR::SUSTAIN with current and target values of \e aValue.
409 void setValue(MY_FLOAT aValue
);
411 //! Return one envelope output value.
414 //! Return \e vectorSize envelope outputs in \e vector.
415 MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
418 MY_FLOAT
getAttackTime();
419 MY_FLOAT
getDecayTime();
420 MY_FLOAT
getReleaseTime();
425 MY_FLOAT sustainLevel
;
426 MY_FLOAT releaseRate
;
428 MY_FLOAT m_decayTime
;
429 MY_FLOAT m_releaseTime
;
437 /***************************************************/
439 \brief STK instrument abstract base class.
441 This class provides a common interface for
444 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
446 /***************************************************/
448 #if !defined(__INSTRMNT_H)
453 class Instrmnt
: public Stk
456 //! Default constructor.
459 //! Class destructor.
462 //! Start a note with the given frequency and amplitude.
463 virtual void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
) = 0;
465 //! Stop a note with the given amplitude (speed of decay).
466 virtual void noteOff(MY_FLOAT amplitude
) = 0;
468 //! Set instrument parameters for a particular frequency.
469 virtual void setFrequency(MY_FLOAT frequency
);
471 //! Return the last output value.
472 MY_FLOAT
lastOut() const;
474 //! Return the last left output value.
475 MY_FLOAT
lastOutLeft() const;
477 //! Return the last right output value.
478 MY_FLOAT
lastOutRight() const;
480 //! Compute one output sample.
481 virtual MY_FLOAT
tick() = 0;
483 //! Computer \e vectorSize outputs and return them in \e vector.
484 virtual MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
486 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
487 virtual void controlChange(int number
, MY_FLOAT value
);
489 public: // SWAP formerly protected
491 t_CKFLOAT m_frequency
;
502 /***************************************************/
503 /*! \class Filter (renamed to FilterStk)
504 \brief STK filter class.
506 This class implements a generic structure which
507 can be used to create a wide range of filters.
508 It can function independently or be subclassed
509 to provide more specific controls based on a
510 particular filter type.
512 In particular, this class implements the standard
515 a[0]*y[n] = b[0]*x[n] + ... + b[nb]*x[n-nb] -
516 a[1]*y[n-1] - ... - a[na]*y[n-na]
518 If a[0] is not equal to 1, the filter coeffcients
519 are normalized by a[0].
521 The \e gain parameter is applied at the filter
522 input and does not affect the coefficient values.
523 The default gain value is 1.0. This structure
524 results in one extra multiply per computed sample,
525 but allows easy control of the overall filter gain.
527 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
529 /***************************************************/
531 #if !defined(__FILTER_H)
535 class FilterStk
: public Stk
538 //! Default constructor creates a zero-order pass-through "filter".
541 //! Overloaded constructor which takes filter coefficients.
543 An StkError can be thrown if either \e nb or \e na is less than
544 one, or if the a[0] coefficient is equal to zero.
546 FilterStk(int nb
, MY_FLOAT
*bCoefficients
, int na
, MY_FLOAT
*aCoefficients
);
548 //! Class destructor.
549 virtual ~FilterStk(void);
551 //! Clears all internal states of the filter.
554 //! Set filter coefficients.
556 An StkError can be thrown if either \e nb or \e na is less than
557 one, or if the a[0] coefficient is equal to zero. If a[0] is not
558 equal to 1, the filter coeffcients are normalized by a[0].
560 void setCoefficients(int nb
, MY_FLOAT
*bCoefficients
, int na
, MY_FLOAT
*aCoefficients
);
562 //! Set numerator coefficients.
564 An StkError can be thrown if \e nb is less than one. Any
565 previously set denominator coefficients are left unaffected.
566 Note that the default constructor sets the single denominator
567 coefficient a[0] to 1.0.
569 void setNumerator(int nb
, MY_FLOAT
*bCoefficients
);
571 //! Set denominator coefficients.
573 An StkError can be thrown if \e na is less than one or if the
574 a[0] coefficient is equal to zero. Previously set numerator
575 coefficients are unaffected unless a[0] is not equal to 1, in
576 which case all coeffcients are normalized by a[0]. Note that the
577 default constructor sets the single numerator coefficient b[0]
580 void setDenominator(int na
, MY_FLOAT
*aCoefficients
);
582 //! Set the filter gain.
584 The gain is applied at the filter input and does not affect the
585 coefficient values. The default gain value is 1.0.
587 virtual void setGain(MY_FLOAT theGain
);
589 //! Return the current filter gain.
590 virtual MY_FLOAT
getGain(void) const;
592 //! Return the last computed output value.
593 virtual MY_FLOAT
lastOut(void) const;
595 //! Input one sample to the filter and return one output.
596 virtual MY_FLOAT
tick(MY_FLOAT sample
);
598 //! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
599 virtual MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
617 /***************************************************/
619 \brief STK non-interpolating delay line class.
621 This protected Filter subclass implements
622 a non-interpolating digital delay-line.
623 A fixed maximum length of 4095 and a delay
624 of zero is set using the default constructor.
625 Alternatively, the delay and maximum length
626 can be set during instantiation with an
627 overloaded constructor.
629 A non-interpolating delay line is typically
630 used in fixed delay-length applications, such
631 as for reverberation.
633 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
635 /***************************************************/
637 #if !defined(__DELAY_H)
641 class Delay
: public FilterStk
645 //! Default constructor creates a delay-line with maximum length of 4095 samples and zero delay.
648 //! Overloaded constructor which specifies the current and maximum delay-line lengths.
649 Delay(long theDelay
, long maxDelay
);
651 //! Class destructor.
654 //! Clears the internal state of the delay line.
657 //! Set the delay-line length.
659 The valid range for \e theDelay is from 0 to the maximum delay-line length.
661 void setDelay(long theDelay
);
662 void set( long delay
, long max
);
664 //! Return the current delay-line length.
665 MY_FLOAT
getDelay(void) const;
667 //! Calculate and return the signal energy in the delay-line.
668 MY_FLOAT
energy(void) const;
670 //! Return the value at \e tapDelay samples from the delay-line input.
672 The tap point is determined modulo the delay-line length and is
673 relative to the last input value (i.e., a tapDelay of zero returns
674 the last input value).
676 MY_FLOAT
contentsAt(unsigned long tapDelay
) const;
678 //! Return the last computed output value.
679 MY_FLOAT
lastOut(void) const;
681 //! Return the value which will be output by the next call to tick().
683 This method is valid only for delay settings greater than zero!
685 virtual MY_FLOAT
nextOut(void) const;
687 //! Input one sample to the delay-line and return one output.
688 virtual MY_FLOAT
tick(MY_FLOAT sample
);
690 //! Input \e vectorSize samples to the delay-line and return an equal number of outputs in \e vector.
691 virtual MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
705 /***************************************************/
707 \brief STK linear interpolating delay line class.
709 This Delay subclass implements a fractional-
710 length digital delay-line using first-order
711 linear interpolation. A fixed maximum length
712 of 4095 and a delay of zero is set using the
713 default constructor. Alternatively, the
714 delay and maximum length can be set during
715 instantiation with an overloaded constructor.
717 Linear interpolation is an efficient technique
718 for achieving fractional delay lengths, though
719 it does introduce high-frequency signal
720 attenuation to varying degrees depending on the
721 fractional delay setting. The use of higher
722 order Lagrange interpolators can typically
723 improve (minimize) this attenuation characteristic.
725 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
727 /***************************************************/
729 #if !defined(__DELAYL_H)
733 class DelayL
: public Delay
737 //! Default constructor creates a delay-line with maximum length of 4095 samples and zero delay.
740 //! Overloaded constructor which specifies the current and maximum delay-line lengths.
742 DelayL(MY_FLOAT theDelay
, long maxDelay
);
744 //! Class destructor.
747 //! Set the delay-line length.
749 The valid range for \e theDelay is from 0 to the maximum delay-line length.
751 void setDelay(MY_FLOAT theDelay
);
752 void set( MY_FLOAT delay
, long max
);
754 //! Return the value which will be output by the next call to tick().
756 This method is valid only for delay settings greater than zero!
758 MY_FLOAT
nextOut(void);
760 //! Input one sample to the delay-line and return one output.
761 MY_FLOAT
tick(MY_FLOAT sample
);
763 public: // SWAP formerly protected
775 /***************************************************/
777 \brief STK bowed string table class.
779 This class implements a simple bowed string
780 non-linear function, as described by Smith (1986).
782 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
784 /***************************************************/
786 #if !defined(__BOWTABL_H)
790 class BowTabl
: public Stk
793 //! Default constructor.
796 //! Class destructor.
799 //! Set the table offset value.
801 The table offset is a bias which controls the
802 symmetry of the friction. If you want the
803 friction to vary with direction, use a non-zero
804 value for the offset. The default value is zero.
806 void setOffset(MY_FLOAT aValue
);
808 //! Set the table slope value.
810 The table slope controls the width of the friction
811 pulse, which is related to bow force.
813 void setSlope(MY_FLOAT aValue
);
815 //! Return the last output value.
816 MY_FLOAT
lastOut(void) const;
818 //! Return the function value for \e input.
820 The function input represents differential
821 string-to-bow velocity.
823 MY_FLOAT
tick(const MY_FLOAT input
);
825 //! Take \e vectorSize inputs and return the corresponding function values in \e vector.
826 MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
828 public: // SWAP formerly protected
840 /***************************************************/
842 \brief STK biquad (two-pole, two-zero) filter class.
844 This protected Filter subclass implements a
845 two-pole, two-zero digital filter. A method
846 is provided for creating a resonance in the
847 frequency response while maintaining a constant
850 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
852 /***************************************************/
854 #if !defined(__BIQUAD_H)
858 class BiQuad
: public FilterStk
862 //! Default constructor creates a second-order pass-through filter.
865 //! Class destructor.
868 //! Clears all internal states of the filter.
871 //! Set the b[0] coefficient value.
872 void setB0(MY_FLOAT b0
);
874 //! Set the b[1] coefficient value.
875 void setB1(MY_FLOAT b1
);
877 //! Set the b[2] coefficient value.
878 void setB2(MY_FLOAT b2
);
880 //! Set the a[1] coefficient value.
881 void setA1(MY_FLOAT a1
);
883 //! Set the a[2] coefficient value.
884 void setA2(MY_FLOAT a2
);
886 //! Sets the filter coefficients for a resonance at \e frequency (in Hz).
888 This method determines the filter coefficients corresponding to
889 two complex-conjugate poles with the given \e frequency (in Hz)
890 and \e radius from the z-plane origin. If \e normalize is true,
891 the filter zeros are placed at z = 1, z = -1, and the coefficients
892 are then normalized to produce a constant unity peak gain
893 (independent of the filter \e gain parameter). The resulting
894 filter frequency response has a resonance at the given \e
895 frequency. The closer the poles are to the unit-circle (\e radius
896 close to one), the narrower the resulting resonance width.
898 void setResonance(MY_FLOAT frequency
, MY_FLOAT radius
, bool normalize
= FALSE
);
900 //! Set the filter coefficients for a notch at \e frequency (in Hz).
902 This method determines the filter coefficients corresponding to
903 two complex-conjugate zeros with the given \e frequency (in Hz)
904 and \e radius from the z-plane origin. No filter normalization
907 void setNotch(MY_FLOAT frequency
, MY_FLOAT radius
);
909 //! Sets the filter zeroes for equal resonance gain.
911 When using the filter as a resonator, zeroes places at z = 1, z
912 = -1 will result in a constant gain at resonance of 1 / (1 - R),
913 where R is the pole radius setting.
916 void setEqualGainZeroes();
918 //! Set the filter gain.
920 The gain is applied at the filter input and does not affect the
921 coefficient values. The default gain value is 1.0.
923 void setGain(MY_FLOAT theGain
);
925 //! Return the current filter gain.
926 MY_FLOAT
getGain(void) const;
928 //! Return the last computed output value.
929 MY_FLOAT
lastOut(void) const;
931 //! Input one sample to the filter and return one output.
932 MY_FLOAT
tick(MY_FLOAT sample
);
934 //! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
935 MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
943 /***************************************************/
945 \brief Banded waveguide modeling class.
947 This class uses banded waveguide techniques to
948 model a variety of sounds, including bowed
949 bars, glasses, and bowls. For more
950 information, see Essl, G. and Cook, P. "Banded
951 Waveguides: Towards Physical Modelling of Bar
952 Percussion Instruments", Proceedings of the
953 1999 International Computer Music Conference.
955 Control Change Numbers:
958 - Strike Position = 8 (not implemented)
959 - Vibrato Frequency = 11
963 - Instrument Presets = 16
966 - Glass Harmonica = 2
969 by Georg Essl, 1999 - 2002.
970 Modified for Stk 4.0 by Gary Scavone.
972 /***************************************************/
974 #if !defined(__BANDEDWG_H)
977 #define MAX_BANDED_MODES 20
980 class BandedWG
: public Instrmnt
983 //! Class constructor.
986 //! Class destructor.
989 //! Reset and clear all internal state.
992 //! Set strike position (0.0 - 1.0).
993 void setStrikePosition(MY_FLOAT position
);
996 void setPreset(int preset
);
998 //! Set instrument parameters for a particular frequency.
999 void setFrequency(MY_FLOAT frequency
);
1001 //! Apply bow velocity/pressure to instrument with given amplitude and rate of increase.
1002 void startBowing(MY_FLOAT amplitude
, MY_FLOAT rate
);
1004 //! Decrease bow velocity/breath pressure with given rate of decrease.
1005 void stopBowing(MY_FLOAT rate
);
1007 //! Pluck the instrument with given amplitude.
1008 void pluck(MY_FLOAT amp
);
1010 //! Start a note with the given frequency and amplitude.
1011 void noteOn(MY_FLOAT amplitude
) { noteOn ( freakency
, amplitude
); }
1012 void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
1014 //! Stop a note with the given amplitude (speed of decay).
1015 void noteOff(MY_FLOAT amplitude
);
1017 //! Compute one output sample.
1020 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
1021 void controlChange(int number
, MY_FLOAT value
);
1023 public: // SWAP formerly protected
1027 t_CKFLOAT m_bowPressure
;
1028 t_CKFLOAT m_bowMotion
;
1029 t_CKFLOAT m_modesGain
;
1030 t_CKFLOAT m_strikePosition
;
1040 MY_FLOAT maxVelocity
;
1041 MY_FLOAT modes
[MAX_BANDED_MODES
];
1044 MY_FLOAT gains
[MAX_BANDED_MODES
];
1045 MY_FLOAT basegains
[MAX_BANDED_MODES
];
1046 MY_FLOAT excitation
[MAX_BANDED_MODES
];
1047 MY_FLOAT integrationConstant
;
1048 MY_FLOAT velocityInput
;
1049 MY_FLOAT bowVelocity
;
1051 MY_FLOAT bowPosition
;
1061 /***************************************************/
1063 \brief STK audio data input base class.
1065 This class provides input support for various
1066 audio file formats. It also serves as a base
1067 class for "realtime" streaming subclasses.
1069 WvIn loads the contents of an audio file for
1070 subsequent output. Linear interpolation is
1071 used for fractional "read rates".
1073 WvIn supports multi-channel data in interleaved
1074 format. It is important to distinguish the
1075 tick() methods, which return samples produced
1076 by averaging across sample frames, from the
1077 tickFrame() methods, which return pointers to
1078 multi-channel sample frames. For single-channel
1079 data, these methods return equivalent values.
1081 Small files are completely read into local memory
1082 during instantiation. Large files are read
1083 incrementally from disk. The file size threshold
1084 and the increment size values are defined in
1087 WvIn currently supports WAV, AIFF, SND (AU),
1088 MAT-file (Matlab), and STK RAW file formats.
1089 Signed integer (8-, 16-, and 32-bit) and floating-
1090 point (32- and 64-bit) data types are supported.
1091 Uncompressed data types are not supported. If
1092 using MAT-files, data should be saved in an array
1093 with each data channel filling a matrix row.
1095 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
1097 /***************************************************/
1099 #if !defined(__WVIN_H)
1102 // Files larger than CHUNK_THRESHOLD will be copied into memory
1103 // in CHUNK_SIZE increments, rather than completely loaded into
1104 // a buffer at once.
1106 #define CHUNK_THRESHOLD 5000000 // 5 Mb
1107 #define CHUNK_SIZE 1024 // sample frames
1111 class WvIn
: public Stk
1114 //! Default constructor.
1117 //! Overloaded constructor for file input.
1119 An StkError will be thrown if the file is not found, its format is
1120 unknown, or a read error occurs.
1122 WvIn( const char *fileName
, bool raw
= FALSE
, bool doNormalize
= TRUE
, bool generate
=true );
1124 //! Class destructor.
1127 //! Open the specified file and load its data.
1129 An StkError will be thrown if the file is not found, its format is
1130 unknown, or a read error occurs.
1132 virtual void openFile( const char *fileName
, bool raw
= FALSE
, bool doNormalize
= TRUE
, bool generate
= true );
1134 //! If a file is open, close it.
1135 void closeFile(void);
1137 //! Clear outputs and reset time (file pointer) to zero.
1140 //! Normalize data to a maximum of +-1.0.
1142 For large, incrementally loaded files with integer data types,
1143 normalization is computed relative to the data type maximum.
1144 No normalization is performed for incrementally loaded files
1145 with floating-point data types.
1147 void normalize(void);
1149 //! Normalize data to a maximum of \e +-peak.
1151 For large, incrementally loaded files with integer data types,
1152 normalization is computed relative to the data type maximum
1153 (\e peak/maximum). For incrementally loaded files with floating-
1154 point data types, direct scaling by \e peak is performed.
1156 void normalize(MY_FLOAT peak
);
1158 //! Return the file size in sample frames.
1159 unsigned long getSize(void) const;
1161 //! Return the number of audio channels in the file.
1162 unsigned int getChannels(void) const;
1164 //! Return the input file sample rate in Hz (not the data read rate).
1166 WAV, SND, and AIF formatted files specify a sample rate in
1167 their headers. STK RAW files have a sample rate of 22050 Hz
1168 by definition. MAT-files are assumed to have a rate of 44100 Hz.
1170 MY_FLOAT
getFileRate(void) const;
1172 //! Query whether reading is complete.
1173 bool isFinished(void) const;
1175 //! Set the data read rate in samples. The rate can be negative.
1177 If the rate value is negative, the data is read in reverse order.
1179 void setRate(MY_FLOAT aRate
);
1181 //! Increment the read pointer by \e aTime samples.
1182 virtual void addTime(MY_FLOAT aTime
);
1184 //! Turn linear interpolation on/off.
1186 Interpolation is automatically off when the read rate is
1187 an integer value. If interpolation is turned off for a
1188 fractional rate, the time index is truncated to an integer
1191 void setInterpolate(bool doInterpolate
);
1193 //! Return the average across the last output sample frame.
1194 virtual MY_FLOAT
lastOut(void) const;
1196 //! Read out the average across one sample frame of data.
1198 An StkError will be thrown if a file is read incrementally and a read error occurs.
1200 virtual MY_FLOAT
tick(void);
1202 //! Read out vectorSize averaged sample frames of data in \e vector.
1204 An StkError will be thrown if a file is read incrementally and a read error occurs.
1206 virtual MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
1208 //! Return a pointer to the last output sample frame.
1209 virtual const MY_FLOAT
*lastFrame(void) const;
1211 //! Return a pointer to the next sample frame of data.
1213 An StkError will be thrown if a file is read incrementally and a read error occurs.
1215 virtual const MY_FLOAT
*tickFrame(void);
1217 //! Read out sample \e frames of data to \e frameVector.
1219 An StkError will be thrown if a file is read incrementally and a read error occurs.
1221 virtual MY_FLOAT
*tickFrame(MY_FLOAT
*frameVector
, unsigned int frames
);
1223 public: // SWAP formerly protected
1225 // Initialize class variables.
1229 virtual void readData(unsigned long index
);
1231 // Get STK RAW file information.
1232 bool getRawInfo( const char *fileName
);
1234 // Get WAV file header information.
1235 bool getWavInfo( const char *fileName
);
1237 // Get SND (AU) file header information.
1238 bool getSndInfo( const char *fileName
);
1240 // Get AIFF file header information.
1241 bool getAifInfo( const char *fileName
);
1243 // Get MAT-file header information.
1244 bool getMatInfo( const char *fileName
);
1247 // char m_filename[256]; // chuck data
1248 Chuck_String str_filename
; // chuck data
1251 MY_FLOAT
*lastOutput
;
1256 unsigned long fileSize
;
1257 unsigned long bufferSize
;
1258 unsigned long dataOffset
;
1259 unsigned int channels
;
1261 STK_FORMAT dataType
;
1270 #endif // defined(__WVIN_H)
1275 /***************************************************/
1277 \brief STK waveform oscillator class.
1279 This class inherits from WvIn and provides
1280 audio file looping functionality.
1282 WaveLoop supports multi-channel data in
1283 interleaved format. It is important to
1284 distinguish the tick() methods, which return
1285 samples produced by averaging across sample
1286 frames, from the tickFrame() methods, which
1287 return pointers to multi-channel sample frames.
1288 For single-channel data, these methods return
1291 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
1293 /***************************************************/
1295 #if !defined(__WAVELOOP_H)
1296 #define __WAVELOOP_H
1300 class WaveLoop
: public WvIn
1304 //! Class constructor.
1305 WaveLoop( const char *fileName
, bool raw
= FALSE
, bool generate
= true );
1307 virtual void openFile( const char * fileName
, bool raw
= FALSE
, bool n
= TRUE
);
1309 //! Class destructor.
1310 virtual ~WaveLoop();
1312 //! Set the data interpolation rate based on a looping frequency.
1314 This function determines the interpolation rate based on the file
1315 size and the current Stk::sampleRate. The \e aFrequency value
1316 corresponds to file cycles per second. The frequency can be
1317 negative, in which case the loop is read in reverse order.
1319 void setFrequency(MY_FLOAT aFrequency
);
1321 //! Increment the read pointer by \e aTime samples, modulo file size.
1322 void addTime(MY_FLOAT aTime
);
1324 //! Increment current read pointer by \e anAngle, relative to a looping frequency.
1326 This function increments the read pointer based on the file
1327 size and the current Stk::sampleRate. The \e anAngle value
1328 is a multiple of file size.
1330 void addPhase(MY_FLOAT anAngle
);
1332 //! Add a phase offset to the current read pointer.
1334 This function determines a time offset based on the file
1335 size and the current Stk::sampleRate. The \e anAngle value
1336 is a multiple of file size.
1338 void addPhaseOffset(MY_FLOAT anAngle
);
1340 //! Return a pointer to the next sample frame of data.
1341 const MY_FLOAT
*tickFrame(void);
1346 void readData(unsigned long index
);
1347 MY_FLOAT phaseOffset
;
1348 MY_FLOAT m_freq
; // chuck data;
1351 #endif // defined(__WAVELOOP_H)
1356 /***************************************************/
1358 \brief STK two-zero filter class.
1360 This protected Filter subclass implements
1361 a two-zero digital filter. A method is
1362 provided for creating a "notch" in the
1363 frequency response while maintaining a
1364 constant filter gain.
1366 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
1368 /***************************************************/
1370 #if !defined(__TWOZERO_H)
1374 class TwoZero
: public FilterStk
// formerly protected Filter
1377 //! Default constructor creates a second-order pass-through filter.
1380 //! Class destructor.
1383 //! Clears the internal states of the filter.
1386 //! Set the b[0] coefficient value.
1387 void setB0(MY_FLOAT b0
);
1389 //! Set the b[1] coefficient value.
1390 void setB1(MY_FLOAT b1
);
1392 //! Set the b[2] coefficient value.
1393 void setB2(MY_FLOAT b2
);
1395 //! Sets the filter coefficients for a "notch" at \e frequency (in Hz).
1397 This method determines the filter coefficients corresponding to
1398 two complex-conjugate zeros with the given \e frequency (in Hz)
1399 and \e radius from the z-plane origin. The coefficients are then
1400 normalized to produce a maximum filter gain of one (independent of
1401 the filter \e gain parameter). The resulting filter frequency
1402 response has a "notch" or anti-resonance at the given \e
1403 frequency. The closer the zeros are to the unit-circle (\e radius
1404 close to or equal to one), the narrower the resulting notch width.
1406 void setNotch(MY_FLOAT frequency
, MY_FLOAT radius
);
1408 void ck_setNotchFreq ( MY_FLOAT freq
) { m_notchFreq
= freq
; setNotch (m_notchFreq
, m_notchRad
); }
1409 void ck_setNotchRad ( MY_FLOAT rad
) { m_notchRad
= rad
; setNotch (m_notchFreq
, m_notchRad
); }
1412 //chuck helper functions
1413 MY_FLOAT m_notchFreq
;
1414 MY_FLOAT m_notchRad
;
1416 //! Set the filter gain.
1418 The gain is applied at the filter input and does not affect the
1419 coefficient values. The default gain value is 1.0.
1421 void setGain(MY_FLOAT theGain
);
1423 //! Return the current filter gain.
1424 MY_FLOAT
getGain(void) const;
1426 //! Return the last computed output value.
1427 MY_FLOAT
lastOut(void) const;
1429 //! Input one sample to the filter and return one output.
1430 MY_FLOAT
tick(MY_FLOAT sample
);
1432 //! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
1433 MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
1441 /***************************************************/
1443 \brief STK abstract FM synthesis base class.
1445 This class controls an arbitrary number of
1446 waves and envelopes, determined via a
1447 constructor argument.
1449 Control Change Numbers:
1454 - ADSR 2 & 4 Target = 128
1456 The basic Chowning/Stanford FM patent expired
1457 in 1995, but there exist follow-on patents,
1458 mostly assigned to Yamaha. If you are of the
1459 type who should worry about this (making
1462 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
1464 /***************************************************/
1466 #if !defined(__FM_H)
1470 class FM
: public Instrmnt
1473 //! Class constructor, taking the number of wave/envelope operators to control.
1474 FM( int operators
= 4 );
1476 //! Class destructor.
1479 //! Reset and clear all wave and envelope states.
1482 //! Load the rawwave filenames in waves.
1483 void loadWaves(const char **filenames
);
1485 //! Set instrument parameters for a particular frequency.
1486 virtual void setFrequency(MY_FLOAT frequency
);
1488 //! Set the frequency ratio for the specified wave.
1489 void setRatio(int waveIndex
, MY_FLOAT ratio
);
1491 //! Set the gain for the specified wave.
1492 void setGain(int waveIndex
, MY_FLOAT gain
);
1494 //! Set the modulation speed in Hz.
1495 void setModulationSpeed(MY_FLOAT mSpeed
);
1497 //! Set the modulation depth.
1498 void setModulationDepth(MY_FLOAT mDepth
);
1500 //! Set the value of control1.
1501 void setControl1(MY_FLOAT cVal
);
1503 //! Set the value of control1.
1504 void setControl2(MY_FLOAT cVal
);
1506 //! Start envelopes toward "on" targets.
1509 //! Start envelopes toward "off" targets.
1512 //! Stop a note with the given amplitude (speed of decay).
1513 void noteOff(MY_FLOAT amplitude
);
1515 //! Pure virtual function ... must be defined in subclasses.
1516 virtual MY_FLOAT
tick() = 0;
1518 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
1519 virtual void controlChange(int number
, MY_FLOAT value
);
1521 public: // SWAP formerly protected
1527 MY_FLOAT baseFrequency
;
1533 MY_FLOAT __FM_gains
[100];
1534 MY_FLOAT __FM_susLevels
[16];
1535 MY_FLOAT __FM_attTimes
[32];
1544 /***************************************************/
1546 \brief STK Hammond-oid organ FM synthesis instrument.
1548 This class implements a simple 4 operator
1549 topology, also referred to as algorithm 8 of
1561 Control Change Numbers:
1562 - Operator 4 (feedback) Gain = 2
1563 - Operator 3 Gain = 4
1566 - ADSR 2 & 4 Target = 128
1568 The basic Chowning/Stanford FM patent expired
1569 in 1995, but there exist follow-on patents,
1570 mostly assigned to Yamaha. If you are of the
1571 type who should worry about this (making
1574 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
1576 /***************************************************/
1578 #if !defined(__BEETHREE_H)
1579 #define __BEETHREE_H
1582 class BeeThree
: public FM
1585 //! Class constructor.
1588 //! Class destructor.
1591 //! Start a note with the given frequency and amplitude.
1592 void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
1593 void noteOn( MY_FLOAT amplitude
) { noteOn( baseFrequency
, amplitude
); }
1594 //! Compute one output sample.
1603 /***************************************************/
1605 \brief STK jet table class.
1607 This class implements a flue jet non-linear
1608 function, computed by a polynomial calculation.
1609 Contrary to the name, this is not a "table".
1611 Consult Fletcher and Rossing, Karjalainen,
1612 Cook, and others for more information.
1614 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
1616 /***************************************************/
1618 #if !defined(__JETTABL_H)
1622 class JetTabl
: public Stk
1625 //! Default constructor.
1628 //! Class destructor.
1631 //! Return the last output value.
1632 MY_FLOAT
lastOut() const;
1634 //! Return the function value for \e input.
1635 MY_FLOAT
tick(MY_FLOAT input
);
1637 //! Take \e vectorSize inputs and return the corresponding function values in \e vector.
1638 MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
1640 public: // SWAP formerly protected
1641 MY_FLOAT lastOutput
;
1650 /***************************************************/
1652 \brief STK one-pole, one-zero filter class.
1654 This protected Filter subclass implements
1655 a one-pole, one-zero digital filter. A
1656 method is provided for creating an allpass
1657 filter with a given coefficient. Another
1658 method is provided to create a DC blocking filter.
1660 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
1662 /***************************************************/
1664 #if !defined(__POLEZERO_H)
1665 #define __POLEZERO_H
1668 class PoleZero
: public FilterStk
// formerly protected Filter
1672 //! Default constructor creates a first-order pass-through filter.
1675 //! Class destructor.
1678 //! Clears the internal states of the filter.
1681 //! Set the b[0] coefficient value.
1682 void setB0(MY_FLOAT b0
);
1684 //! Set the b[1] coefficient value.
1685 void setB1(MY_FLOAT b1
);
1687 //! Set the a[1] coefficient value.
1688 void setA1(MY_FLOAT a1
);
1690 //! Set the filter for allpass behavior using \e coefficient.
1692 This method uses \e coefficient to create an allpass filter,
1693 which has unity gain at all frequencies. Note that the \e
1694 coefficient magnitude must be less than one to maintain stability.
1696 void setAllpass(MY_FLOAT coefficient
);
1698 //! Create a DC blocking filter with the given pole position in the z-plane.
1700 This method sets the given pole position, together with a zero
1701 at z=1, to create a DC blocking filter. \e thePole should be
1702 close to one to minimize low-frequency attenuation.
1705 void setBlockZero(MY_FLOAT thePole
= 0.99);
1707 //! Set the filter gain.
1709 The gain is applied at the filter input and does not affect the
1710 coefficient values. The default gain value is 1.0.
1712 void setGain(MY_FLOAT theGain
);
1714 //! Return the current filter gain.
1715 MY_FLOAT
getGain(void) const;
1717 //! Return the last computed output value.
1718 MY_FLOAT
lastOut(void) const;
1720 //! Input one sample to the filter and return one output.
1721 MY_FLOAT
tick(MY_FLOAT sample
);
1723 //! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
1724 MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
1732 /***************************************************/
1734 \brief STK noise generator.
1736 Generic random number generation using the
1737 C rand() function. The quality of the rand()
1738 function varies from one OS to another.
1740 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
1742 /***************************************************/
1744 #if !defined(__NOISE_H)
1748 class Noise
: public Stk
1752 //! Default constructor which seeds the random number generator with the system time.
1755 //! Constructor which seeds the random number generator with a given seed.
1757 If the seed value is zero, the random number generator is
1758 seeded with the system time.
1760 Noise( unsigned int seed
);
1762 //! Class destructor.
1765 //! Seed the random number generator with a specific seed value.
1767 If no seed is provided or the seed value is zero, the random
1768 number generator is seeded with the current system time.
1770 void setSeed( unsigned int seed
= 0 );
1772 //! Return a random number between -1.0 and 1.0 using rand().
1773 virtual MY_FLOAT
tick();
1775 //! Return \e vectorSize random numbers between -1.0 and 1.0 in \e vector.
1776 virtual MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
1778 //! Return the last computed value.
1779 MY_FLOAT
lastOut() const;
1781 public: // SWAP formerly protected
1783 MY_FLOAT lastOutput
;
1792 /***************************************************/
1794 \brief STK blown bottle instrument class.
1796 This class implements a helmholtz resonator
1797 (biquad filter) with a polynomial jet
1798 excitation (a la Cook).
1800 Control Change Numbers:
1802 - Vibrato Frequency = 11
1806 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
1808 /***************************************************/
1810 #if !defined(__BOTTLE_H)
1814 class BlowBotl
: public Instrmnt
1817 //! Class constructor.
1820 //! Class destructor.
1823 //! Reset and clear all internal state.
1826 //! Set instrument parameters for a particular frequency.
1827 void setFrequency(MY_FLOAT frequency
);
1829 //! Apply breath velocity to instrument
1830 void startBlowing(MY_FLOAT amplitude
) { startBlowing ( amplitude
, m_rate
); } //chuck
1832 //! Apply breath velocity to instrument with given amplitude and rate of increase.
1833 void startBlowing(MY_FLOAT amplitude
, MY_FLOAT rate
);
1835 //! Decrease breath velocity with given rate of decrease.
1836 void stopBlowing(MY_FLOAT rate
);
1838 //! Start a note with the given frequency and amplitude.
1839 void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
1841 //! Stop a note with the given amplitude (speed of decay).
1842 void noteOff(MY_FLOAT amplitude
);
1844 //! Compute one output sample.
1847 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
1848 void controlChange(int number
, MY_FLOAT value
);
1850 public: // SWAP formerly protected
1853 t_CKFLOAT m_noiseGain
;
1854 t_CKFLOAT m_vibratoFreq
;
1855 t_CKFLOAT m_vibratoGain
;
1858 void setVibratoFreq(MY_FLOAT freq
)
1859 { vibrato
->setFrequency( freq
); m_vibratoFreq
= vibrato
->m_freq
; }
1860 void setVibratoGain(MY_FLOAT gain
)
1861 { vibratoGain
= gain
; m_vibratoGain
= vibratoGain
; }
1862 void setNoiseGain(MY_FLOAT gain
)
1863 { noiseGain
= gain
; m_noiseGain
= gain
; }
1871 MY_FLOAT maxPressure
;
1873 MY_FLOAT vibratoGain
;
1874 MY_FLOAT outputGain
;
1882 /***************************************************/
1884 \brief STK reed table class.
1886 This class implements a simple one breakpoint,
1887 non-linear reed function, as described by
1888 Smith (1986). This function is based on a
1889 memoryless non-linear spring model of the reed
1890 (the reed mass is ignored) which saturates when
1891 the reed collides with the mouthpiece facing.
1893 See McIntyre, Schumacher, & Woodhouse (1983),
1894 Smith (1986), Hirschman, Cook, Scavone, and
1895 others for more information.
1897 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
1899 /***************************************************/
1901 #if !defined(__REEDTABL_H)
1902 #define __REEDTABL_H
1905 class ReedTabl
: public Stk
1908 //! Default constructor.
1911 //! Class destructor.
1914 //! Set the table offset value.
1916 The table offset roughly corresponds to the size
1917 of the initial reed tip opening (a greater offset
1918 represents a smaller opening).
1920 void setOffset(MY_FLOAT aValue
);
1922 //! Set the table slope value.
1924 The table slope roughly corresponds to the reed
1925 stiffness (a greater slope represents a harder
1928 void setSlope(MY_FLOAT aValue
);
1930 //! Return the last output value.
1931 MY_FLOAT
lastOut() const;
1933 //! Return the function value for \e input.
1935 The function input represents the differential
1936 pressure across the reeds.
1938 MY_FLOAT
tick(MY_FLOAT input
);
1940 //! Take \e vectorSize inputs and return the corresponding function values in \e vector.
1941 MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
1943 public: // SWAP formerly protected
1946 MY_FLOAT lastOutput
;
1955 /***************************************************/
1957 \brief STK one-zero filter class.
1959 This protected Filter subclass implements
1960 a one-zero digital filter. A method is
1961 provided for setting the zero position
1962 along the real axis of the z-plane while
1963 maintaining a constant filter gain.
1965 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
1967 /***************************************************/
1969 #if !defined(__ONEZERO_H)
1973 class OneZero
: public FilterStk
// formerly protected Filter
1977 //! Default constructor creates a first-order low-pass filter.
1980 //! Overloaded constructor which sets the zero position during instantiation.
1981 OneZero(MY_FLOAT theZero
);
1983 //! Class destructor.
1986 //! Clears the internal state of the filter.
1989 //! Set the b[0] coefficient value.
1990 void setB0(MY_FLOAT b0
);
1992 //! Set the b[1] coefficient value.
1993 void setB1(MY_FLOAT b1
);
1995 //! Set the zero position in the z-plane.
1997 This method sets the zero position along the real-axis of the
1998 z-plane and normalizes the coefficients for a maximum gain of one.
1999 A positive zero value produces a high-pass filter, while a
2000 negative zero value produces a low-pass filter. This method does
2001 not affect the filter \e gain value.
2003 void setZero(MY_FLOAT theZero
);
2005 //! Set the filter gain.
2007 The gain is applied at the filter input and does not affect the
2008 coefficient values. The default gain value is 1.0.
2010 void setGain(MY_FLOAT theGain
);
2012 //! Return the current filter gain.
2013 MY_FLOAT
getGain(void) const;
2015 //! Return the last computed output value.
2016 MY_FLOAT
lastOut(void) const;
2018 //! Input one sample to the filter and return one output.
2019 MY_FLOAT
tick(MY_FLOAT sample
);
2021 //! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
2022 MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
2030 /***************************************************/
2032 \brief STK clarinet physical model with one register hole and one tonehole.
2034 This class is based on the clarinet model,
2035 with the addition of a two-port register hole
2036 and a three-port dynamic tonehole
2037 implementation, as discussed by Scavone and
2040 In this implementation, the distances between
2041 the reed/register hole and tonehole/bell are
2042 fixed. As a result, both the tonehole and
2043 register hole will have variable influence on
2044 the playing frequency, which is dependent on
2045 the length of the air column. In addition,
2046 the highest playing freqeuency is limited by
2047 these fixed lengths.
2049 This is a digital waveguide model, making its
2050 use possibly subject to patents held by Stanford
2051 University, Yamaha, and others.
2053 Control Change Numbers:
2054 - Reed Stiffness = 2
2056 - Tonehole State = 11
2057 - Register State = 1
2058 - Breath Pressure = 128
2060 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
2062 /***************************************************/
2064 #if !defined(__BLOWHOLE_H)
2065 #define __BLOWHOLE_H
2068 class BlowHole
: public Instrmnt
2071 //! Class constructor.
2072 BlowHole(MY_FLOAT lowestFrequency
);
2074 //! Class destructor.
2077 //! Reset and clear all internal state.
2080 //! Set instrument parameters for a particular frequency.
2081 void setFrequency(MY_FLOAT frequency
);
2083 //! Set the tonehole state (0.0 = closed, 1.0 = fully open).
2084 void setTonehole(MY_FLOAT newValue
);
2086 //! Set the register hole state (0.0 = closed, 1.0 = fully open).
2087 void setVent(MY_FLOAT newValue
);
2089 //! Apply breath velocity to instrument
2090 void startBlowing(MY_FLOAT amplitude
) { startBlowing ( amplitude
, m_rate
); } //chuck
2092 //! Apply breath pressure to instrument with given amplitude and rate of increase.
2093 void startBlowing(MY_FLOAT amplitude
, MY_FLOAT rate
);
2095 //! Decrease breath pressure with given rate of decrease.
2096 void stopBlowing(MY_FLOAT rate
);
2098 //! Start a note with the given frequency and amplitude.
2099 void noteOn( MY_FLOAT amplitude
) { noteOn ( m_frequency
, amplitude
); }
2100 void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
2102 //! Stop a note with the given amplitude (speed of decay).
2103 void noteOff(MY_FLOAT amplitude
);
2105 //! Compute one output sample.
2108 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
2109 void controlChange(int number
, MY_FLOAT value
);
2111 public: // SWAP formerly protected
2115 t_CKFLOAT m_noiseGain
;
2116 t_CKFLOAT m_tonehole
;
2118 t_CKFLOAT m_pressure
;
2122 ReedTabl
*reedTable
;
2135 MY_FLOAT outputGain
;
2137 MY_FLOAT vibratoGain
;
2146 /***************************************************/
2148 \brief STK one-pole filter class.
2150 This protected Filter subclass implements
2151 a one-pole digital filter. A method is
2152 provided for setting the pole position along
2153 the real axis of the z-plane while maintaining
2154 a constant peak filter gain.
2156 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
2158 /***************************************************/
2160 #if !defined(__ONEPOLE_H)
2163 class OnePole
: public FilterStk
// formerly protected Filter
2167 //! Default constructor creates a first-order low-pass filter.
2170 //! Overloaded constructor which sets the pole position during instantiation.
2171 OnePole(MY_FLOAT thePole
);
2173 //! Class destructor.
2176 //! Clears the internal state of the filter.
2179 //! Set the b[0] coefficient value.
2180 void setB0(MY_FLOAT b0
);
2182 //! Set the a[1] coefficient value.
2183 void setA1(MY_FLOAT a1
);
2185 //! Set the pole position in the z-plane.
2187 This method sets the pole position along the real-axis of the
2188 z-plane and normalizes the coefficients for a maximum gain of one.
2189 A positive pole value produces a low-pass filter, while a negative
2190 pole value produces a high-pass filter. This method does not
2191 affect the filter \e gain value.
2193 void setPole(MY_FLOAT thePole
);
2195 //! Set the filter gain.
2197 The gain is applied at the filter input and does not affect the
2198 coefficient values. The default gain value is 1.0.
2200 void setGain(MY_FLOAT theGain
);
2202 //! Return the current filter gain.
2203 MY_FLOAT
getGain(void) const;
2205 //! Return the last computed output value.
2206 MY_FLOAT
lastOut(void) const;
2208 //! Input one sample to the filter and return one output.
2209 MY_FLOAT
tick(MY_FLOAT sample
);
2211 //! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
2212 MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
2220 /***************************************************/
2222 \brief STK bowed string instrument class.
2224 This class implements a bowed string model, a
2225 la Smith (1986), after McIntyre, Schumacher,
2228 This is a digital waveguide model, making its
2229 use possibly subject to patents held by
2230 Stanford University, Yamaha, and others.
2232 Control Change Numbers:
2235 - Vibrato Frequency = 11
2239 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
2241 /***************************************************/
2243 #if !defined(__BOWED_H)
2247 class Bowed
: public Instrmnt
2250 //! Class constructor, taking the lowest desired playing frequency.
2251 Bowed(MY_FLOAT lowestFrequency
);
2253 //! Class destructor.
2256 //! Reset and clear all internal state.
2259 //! Set instrument parameters for a particular frequency.
2260 void setFrequency(MY_FLOAT frequency
);
2262 //! Set vibrato gain.
2263 void setVibrato(MY_FLOAT gain
);
2265 void startBowing(MY_FLOAT amplitude
) { startBowing(amplitude
, m_rate
); }
2266 //! Apply breath pressure to instrument with given amplitude and rate of increase.
2267 void startBowing(MY_FLOAT amplitude
, MY_FLOAT rate
);
2269 //! Decrease breath pressure with given rate of decrease.
2270 void stopBowing(MY_FLOAT rate
);
2272 void noteOn(MY_FLOAT amplitude
) { noteOn ( m_frequency
, amplitude
); }
2273 //! Start a note with the given frequency and amplitude.
2274 void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
2276 //! Stop a note with the given amplitude (speed of decay).
2277 void noteOff(MY_FLOAT amplitude
);
2279 //! Compute one output sample.
2282 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
2283 void controlChange(int number
, MY_FLOAT value
);
2285 public: // SWAP formerly protected
2288 t_CKFLOAT m_bowPressure
;
2289 t_CKFLOAT m_bowPosition
;
2290 t_CKFLOAT m_vibratoFreq
;
2291 t_CKFLOAT m_vibratoGain
;
2295 void setVibratoFreq(MY_FLOAT freq
)
2296 { vibrato
->setFrequency( freq
); m_vibratoFreq
= vibrato
->m_freq
; }
2297 void setVibratoGain(MY_FLOAT gain
)
2298 { vibratoGain
= gain
; m_vibratoGain
= vibratoGain
; }
2301 DelayL
*bridgeDelay
;
2303 OnePole
*stringFilter
;
2307 MY_FLOAT maxVelocity
;
2309 MY_FLOAT vibratoGain
;
2319 /***************************************************/
2321 \brief STK allpass interpolating delay line class.
2323 This Delay subclass implements a fractional-
2324 length digital delay-line using a first-order
2325 allpass filter. A fixed maximum length
2326 of 4095 and a delay of 0.5 is set using the
2327 default constructor. Alternatively, the
2328 delay and maximum length can be set during
2329 instantiation with an overloaded constructor.
2331 An allpass filter has unity magnitude gain but
2332 variable phase delay properties, making it useful
2333 in achieving fractional delays without affecting
2334 a signal's frequency magnitude response. In
2335 order to achieve a maximally flat phase delay
2336 response, the minimum delay possible in this
2337 implementation is limited to a value of 0.5.
2339 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
2341 /***************************************************/
2343 #if !defined(__DelayA_h)
2347 class DelayA
: public Delay
2351 //! Default constructor creates a delay-line with maximum length of 4095 samples and zero delay.
2354 //! Overloaded constructor which specifies the current and maximum delay-line lengths.
2356 DelayA(MY_FLOAT theDelay
, long maxDelay
);
2358 //! Class destructor.
2361 //! Clears the internal state of the delay line.
2364 //! Set the delay-line length
2366 The valid range for \e theDelay is from 0.5 to the maximum delay-line length.
2368 void setDelay(MY_FLOAT theDelay
);
2369 void set( MY_FLOAT delay
, long max
);
2371 //! Return the value which will be output by the next call to tick().
2373 This method is valid only for delay settings greater than zero!
2375 MY_FLOAT
nextOut(void);
2377 //! Input one sample to the delay-line and return one output.
2378 MY_FLOAT
tick(MY_FLOAT sample
);
2380 public: // SWAP formerly protected
2384 MY_FLOAT nextOutput
;
2393 /***************************************************/
2395 \brief STK simple brass instrument class.
2397 This class implements a simple brass instrument
2398 waveguide model, a la Cook (TBone, HosePlayer).
2400 This is a digital waveguide model, making its
2401 use possibly subject to patents held by
2402 Stanford University, Yamaha, and others.
2404 Control Change Numbers:
2407 - Vibrato Frequency = 11
2411 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
2413 /***************************************************/
2415 #if !defined(__BRASS_H)
2419 class Brass
: public Instrmnt
2422 //! Class constructor, taking the lowest desired playing frequency.
2423 Brass(MY_FLOAT lowestFrequency
);
2425 //! Class destructor.
2428 //! Reset and clear all internal state.
2431 //! Set instrument parameters for a particular frequency.
2432 void setFrequency(MY_FLOAT frequency
);
2434 //! Set the lips frequency.
2435 void setLip(MY_FLOAT frequency
);
2437 //! Apply breath pressure to instrument with given amplitude and rate of increase.
2438 void startBlowing(MY_FLOAT amplitude
,MY_FLOAT rate
);
2440 //! Decrease breath pressure with given rate of decrease.
2441 void stopBlowing(MY_FLOAT rate
);
2443 //! Start a note with the given frequency and amplitude.
2444 void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
2446 //! Stop a note with the given amplitude (speed of decay).
2447 void noteOff(MY_FLOAT amplitude
);
2449 //! Compute one output sample.
2452 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
2453 void controlChange(int number
, MY_FLOAT value
);
2455 public: // SWAP formerly protected
2461 t_CKFLOAT m_vibratoFreq
;
2462 t_CKFLOAT m_vibratoGain
;
2465 void setVibratoFreq(MY_FLOAT freq
)
2466 { vibrato
->setFrequency( freq
); m_vibratoFreq
= vibrato
->m_freq
; }
2467 void setVibratoGain(MY_FLOAT gain
)
2468 { vibratoGain
= gain
; m_vibratoGain
= vibratoGain
; }
2477 MY_FLOAT slideTarget
;
2478 MY_FLOAT vibratoGain
;
2479 MY_FLOAT maxPressure
;
2488 /***************************************************/
2490 \brief STK chorus effect class.
2492 This class implements a chorus effect.
2494 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
2496 /***************************************************/
2498 #if !defined(__CHORUS_H)
2502 class Chorus
: public Stk
2505 //! Class constructor, taking the longest desired delay length.
2506 Chorus(MY_FLOAT baseDelay
);
2508 //! Class destructor.
2511 //! Set baseDelay and modDepth
2512 void set(MY_FLOAT baseDelay
, MY_FLOAT depth
);
2514 //! Reset and clear all internal state.
2518 void setDelay(MY_FLOAT baseDelay
); // chuck
2520 //! Set modulation depth.
2521 void setModDepth(MY_FLOAT depth
);
2523 //! Set modulation frequency.
2524 void setModFrequency(MY_FLOAT frequency
);
2526 //! Set the mixture of input and processed levels in the output (0.0 = input only, 1.0 = processed only).
2527 void setEffectMix(MY_FLOAT mix
);
2529 //! Return the last output value.
2530 MY_FLOAT
lastOut() const;
2532 //! Return the last left output value.
2533 MY_FLOAT
lastOutLeft() const;
2535 //! Return the last right output value.
2536 MY_FLOAT
lastOutRight() const;
2538 //! Compute one output sample.
2539 MY_FLOAT
tick(MY_FLOAT input
);
2541 //! Take \e vectorSize inputs, compute the same number of outputs and return them in \e vector.
2542 MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
2544 public: // SWAP formerly protected
2545 DelayL
*delayLine
[2];
2547 MY_FLOAT baseLength
;
2549 MY_FLOAT lastOutput
[2];
2560 /***************************************************/
2562 \brief STK clarinet physical model class.
2564 This class implements a simple clarinet
2565 physical model, as discussed by Smith (1986),
2566 McIntyre, Schumacher, Woodhouse (1983), and
2569 This is a digital waveguide model, making its
2570 use possibly subject to patents held by Stanford
2571 University, Yamaha, and others.
2573 Control Change Numbers:
2574 - Reed Stiffness = 2
2576 - Vibrato Frequency = 11
2578 - Breath Pressure = 128
2580 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
2582 /***************************************************/
2584 #if !defined(__CLARINET_H)
2585 #define __CLARINET_H
2588 class Clarinet
: public Instrmnt
2591 //! Class constructor, taking the lowest desired playing frequency.
2592 Clarinet(MY_FLOAT lowestFrequency
);
2594 //! Class destructor.
2597 //! Reset and clear all internal state.
2600 //! Set instrument parameters for a particular frequency.
2601 void setFrequency(MY_FLOAT frequency
);
2603 //! Apply breath pressure to instrument with given amplitude and rate of increase.
2604 void startBlowing(MY_FLOAT amplitude
, MY_FLOAT rate
);
2606 //! Decrease breath pressure with given rate of decrease.
2607 void stopBlowing(MY_FLOAT rate
);
2609 //! Start a note with the given frequency and amplitude.
2610 void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
2612 //! Stop a note with the given amplitude (speed of decay).
2613 void noteOff(MY_FLOAT amplitude
);
2615 //! Compute one output sample.
2618 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
2619 void controlChange(int number
, MY_FLOAT value
);
2621 public: // SWAP formerly protected
2625 t_CKFLOAT m_noiseGain
;
2626 t_CKFLOAT m_vibratoFreq
;
2627 t_CKFLOAT m_vibratoGain
;
2631 void setVibratoFreq(MY_FLOAT freq
)
2632 { vibrato
->setFrequency( freq
); m_vibratoFreq
= vibrato
->m_freq
; }
2633 void setVibratoGain(MY_FLOAT gain
)
2634 { vibratoGain
= gain
; m_vibratoGain
= vibratoGain
; }
2635 void setNoiseGain(MY_FLOAT gain
)
2636 { noiseGain
= gain
; m_noiseGain
= gain
; }
2639 ReedTabl
*reedTable
;
2645 MY_FLOAT outputGain
;
2647 MY_FLOAT vibratoGain
;
2656 /***************************************************/
2658 \brief STK drum sample player class.
2660 This class implements a drum sampling
2661 synthesizer using WvIn objects and one-pole
2662 filters. The drum rawwave files are sampled
2663 at 22050 Hz, but will be appropriately
2664 interpolated for other sample rates. You can
2665 specify the maximum polyphony (maximum number
2666 of simultaneous voices) via a #define in the
2669 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
2671 /***************************************************/
2673 #if !defined(__DRUMMER_H)
2677 #define DRUM_NUMWAVES 11
2678 #define DRUM_POLYPHONY 4
2680 class Drummer
: public Instrmnt
2683 //! Class constructor.
2686 //! Class destructor.
2689 //! Start a note with the given drum type and amplitude.
2691 Use general MIDI drum instrument numbers, converted to
2692 frequency values as if MIDI note numbers, to select a
2693 particular instrument.
2695 void noteOn(MY_FLOAT instrument
, MY_FLOAT amplitude
);
2697 //! Stop a note with the given amplitude (speed of decay).
2698 void noteOff(MY_FLOAT amplitude
);
2700 //! Compute one output sample.
2703 public: // SWAP formerly protected
2704 WvIn
*waves
[DRUM_POLYPHONY
];
2705 OnePole
*filters
[DRUM_POLYPHONY
];
2706 int sounding
[DRUM_POLYPHONY
];
2716 /***************************************************/
2718 \brief STK echo effect class.
2720 This class implements a echo effect.
2722 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
2724 /***************************************************/
2726 #if !defined(__ECHO_H)
2730 class Echo
: public Stk
2733 //! Class constructor, taking the longest desired delay length.
2734 Echo(MY_FLOAT longestDelay
);
2736 //! Class destructor.
2739 //! Reset and clear all internal state.
2742 //! Set the delay line length in samples.
2743 void setDelay(MY_FLOAT delay
);
2744 void set(MY_FLOAT max
);
2745 MY_FLOAT
getDelay();
2747 //! Set the mixture of input and processed levels in the output (0.0 = input only, 1.0 = processed only).
2748 void setEffectMix(MY_FLOAT mix
);
2750 //! Return the last output value.
2751 MY_FLOAT
lastOut() const;
2753 //! Compute one output sample.
2754 MY_FLOAT
tick(MY_FLOAT input
);
2756 //! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
2757 MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
2762 MY_FLOAT lastOutput
;
2773 /***************************************************/
2775 \brief STK singing FM synthesis instrument.
2777 This class implements 3 carriers and a common
2778 modulator, also referred to as algorithm 6 of
2788 Control Change Numbers:
2793 - ADSR 2 & 4 Target = 128
2795 The basic Chowning/Stanford FM patent expired
2796 in 1995, but there exist follow-on patents,
2797 mostly assigned to Yamaha. If you are of the
2798 type who should worry about this (making
2801 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
2803 /***************************************************/
2805 #if !defined(__FMVOICES_H)
2806 #define __FMVOICES_H
2809 class FMVoices
: public FM
2812 //! Class constructor.
2815 //! Class destructor.
2818 //! Set instrument parameters for a particular frequency.
2819 virtual void setFrequency(MY_FLOAT frequency
);
2821 //! Start a note with the given frequency and amplitude.
2822 void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
2823 void noteOn( MY_FLOAT amplitude
) { noteOn(baseFrequency
, amplitude
); }
2825 //! Compute one output sample.
2828 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
2829 virtual void controlChange(int number
, MY_FLOAT value
);
2831 public: // SWAP formerly protected
2842 /***************************************************/
2844 \brief STK flute physical model class.
2846 This class implements a simple flute
2847 physical model, as discussed by Karjalainen,
2848 Smith, Waryznyk, etc. The jet model uses
2849 a polynomial, a la Cook.
2851 This is a digital waveguide model, making its
2852 use possibly subject to patents held by Stanford
2853 University, Yamaha, and others.
2855 Control Change Numbers:
2858 - Vibrato Frequency = 11
2860 - Breath Pressure = 128
2862 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
2864 /***************************************************/
2866 #if !defined(__FLUTE_H)
2870 class Flute
: public Instrmnt
2873 //! Class constructor, taking the lowest desired playing frequency.
2874 Flute(MY_FLOAT lowestFrequency
);
2876 //! Class destructor.
2879 //! Reset and clear all internal state.
2882 //! Set instrument parameters for a particular frequency.
2883 void setFrequency(MY_FLOAT frequency
);
2885 //! Set the reflection coefficient for the jet delay (-1.0 - 1.0).
2886 void setJetReflection(MY_FLOAT coefficient
);
2888 //! Set the reflection coefficient for the air column delay (-1.0 - 1.0).
2889 void setEndReflection(MY_FLOAT coefficient
);
2891 //! Set the length of the jet delay in terms of a ratio of jet delay to air column delay lengths.
2892 void setJetDelay(MY_FLOAT aRatio
);
2894 //! Apply breath velocity to instrument with given amplitude and rate of increase.
2895 void startBlowing(MY_FLOAT amplitude
, MY_FLOAT rate
);
2897 //! Decrease breath velocity with given rate of decrease.
2898 void stopBlowing(MY_FLOAT rate
);
2900 //! Start a note with the given frequency and amplitude.
2901 void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
2903 //! Stop a note with the given amplitude (speed of decay).
2904 void noteOff(MY_FLOAT amplitude
);
2906 //! Compute one output sample.
2909 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
2910 void controlChange(int number
, MY_FLOAT value
);
2912 public: // SWAP formerly protected
2915 t_CKFLOAT m_jetDelay
;
2916 t_CKFLOAT m_jetReflection
;
2917 t_CKFLOAT m_endReflection
;
2918 t_CKFLOAT m_noiseGain
;
2919 t_CKFLOAT m_vibratoFreq
;
2920 t_CKFLOAT m_vibratoGain
;
2921 t_CKFLOAT m_pressure
;
2924 void setVibratoFreq(MY_FLOAT freq
)
2925 { vibrato
->setFrequency( freq
); m_vibratoFreq
= vibrato
->m_freq
; }
2926 void setVibratoGain(MY_FLOAT gain
)
2927 { vibratoGain
= gain
; m_vibratoGain
= vibratoGain
; }
2928 void setNoiseGain(MY_FLOAT gain
)
2929 { noiseGain
= gain
; m_noiseGain
= gain
; }
2940 MY_FLOAT lastFrequency
;
2941 MY_FLOAT maxPressure
;
2942 MY_FLOAT jetReflection
;
2943 MY_FLOAT endReflection
;
2945 MY_FLOAT vibratoGain
;
2946 MY_FLOAT outputGain
;
2956 /***************************************************/
2958 \brief STK sweepable formant filter class.
2960 This public BiQuad filter subclass implements
2961 a formant (resonance) which can be "swept"
2962 over time from one frequency setting to another.
2963 It provides methods for controlling the sweep
2964 rate and target frequency.
2966 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
2968 /***************************************************/
2970 #if !defined(__FORMSWEP_H)
2971 #define __FORMSWEP_H
2974 class FormSwep
: public BiQuad
2978 //! Default constructor creates a second-order pass-through filter.
2981 //! Class destructor.
2984 //! Sets the filter coefficients for a resonance at \e frequency (in Hz).
2986 This method determines the filter coefficients corresponding to
2987 two complex-conjugate poles with the given \e frequency (in Hz)
2988 and \e radius from the z-plane origin. The filter zeros are
2989 placed at z = 1, z = -1, and the coefficients are then normalized to
2990 produce a constant unity gain (independent of the filter \e gain
2991 parameter). The resulting filter frequency response has a
2992 resonance at the given \e frequency. The closer the poles are to
2993 the unit-circle (\e radius close to one), the narrower the
2994 resulting resonance width.
2996 void setResonance(MY_FLOAT aFrequency
, MY_FLOAT aRadius
);
2998 //! Set both the current and target resonance parameters.
2999 void setStates(MY_FLOAT aFrequency
, MY_FLOAT aRadius
, MY_FLOAT aGain
= 1.0);
3001 //! Set target resonance parameters.
3002 void setTargets(MY_FLOAT aFrequency
, MY_FLOAT aRadius
, MY_FLOAT aGain
= 1.0);
3004 //! Set the sweep rate (between 0.0 - 1.0).
3006 The formant parameters are varied in increments of the
3007 sweep rate between their current and target values.
3008 A sweep rate of 1.0 will produce an immediate change in
3009 resonance parameters from their current values to the
3010 target values. A sweep rate of 0.0 will produce no
3011 change in resonance parameters.
3013 void setSweepRate(MY_FLOAT aRate
);
3015 //! Set the sweep rate in terms of a time value in seconds.
3017 This method adjusts the sweep rate based on a
3018 given time for the formant parameters to reach
3019 their target values.
3021 void setSweepTime(MY_FLOAT aTime
);
3023 //! Input one sample to the filter and return one output.
3024 MY_FLOAT
tick(MY_FLOAT sample
);
3026 //! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
3027 MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
3029 public: // SWAP formerly protected
3033 MY_FLOAT startFrequency
;
3034 MY_FLOAT startRadius
;
3036 MY_FLOAT targetFrequency
;
3037 MY_FLOAT targetRadius
;
3038 MY_FLOAT targetGain
;
3039 MY_FLOAT deltaFrequency
;
3040 MY_FLOAT deltaRadius
;
3042 MY_FLOAT sweepState
;
3052 /***************************************************/
3054 \brief STK heavy metal FM synthesis instrument.
3056 This class implements 3 cascade operators with
3057 feedback modulation, also referred to as
3058 algorithm 3 of the TX81Z.
3061 Algorithm 3 is : 4--\
3062 3-->2-- + -->1-->Out
3065 Control Change Numbers:
3066 - Total Modulator Index = 2
3067 - Modulator Crossfade = 4
3070 - ADSR 2 & 4 Target = 128
3072 The basic Chowning/Stanford FM patent expired
3073 in 1995, but there exist follow-on patents,
3074 mostly assigned to Yamaha. If you are of the
3075 type who should worry about this (making
3078 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
3080 /***************************************************/
3082 #if !defined(__HEVYMETL_H)
3083 #define __HEVYMETL_H
3086 class HevyMetl
: public FM
3089 //! Class constructor.
3092 //! Class destructor.
3095 //! Start a note with the given frequency and amplitude.
3096 void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
3097 void noteOn( MY_FLOAT amplitude
) { noteOn(baseFrequency
, amplitude
); }
3099 //! Compute one output sample.
3108 /***************************************************/
3110 \brief STK abstract reverberator parent class.
3112 This class provides common functionality for
3113 STK reverberator subclasses.
3115 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
3117 /***************************************************/
3120 #if !defined(__REVERB_H)
3123 class Reverb
: public Stk
3126 //! Class constructor.
3129 //! Class destructor.
3132 //! Reset and clear all internal state.
3133 virtual void clear() = 0;
3135 //! Set the mixture of input and "reverberated" levels in the output (0.0 = input only, 1.0 = reverb only).
3136 void setEffectMix(MY_FLOAT mix
);
3138 //! Return the last output value.
3139 MY_FLOAT
lastOut() const;
3141 //! Return the last left output value.
3142 MY_FLOAT
lastOutLeft() const;
3144 //! Return the last right output value.
3145 MY_FLOAT
lastOutRight() const;
3147 //! Abstract tick function ... must be implemented in subclasses.
3148 virtual MY_FLOAT
tick(MY_FLOAT input
) = 0;
3150 //! Take \e vectorSize inputs, compute the same number of outputs and return them in \e vector.
3151 virtual MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
3153 public: // SWAP formerly protected
3155 // Returns true if argument value is prime.
3156 bool isPrime(int number
);
3158 MY_FLOAT lastOutput
[2];
3163 #endif // defined(__REVERB_H)
3168 /***************************************************/
3170 \brief John Chowning's reverberator class.
3172 This class is derived from the CLM JCRev
3173 function, which is based on the use of
3174 networks of simple allpass and comb delay
3175 filters. This class implements three series
3176 allpass units, followed by four parallel comb
3177 filters, and two decorrelation delay lines in
3178 parallel at the output.
3180 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
3182 /***************************************************/
3184 #if !defined(__JCREV_H)
3188 class JCRev
: public Reverb
3191 //! Class constructor taking a T60 decay time argument.
3192 JCRev(MY_FLOAT T60
);
3194 //! Class destructor.
3197 //! Reset and clear all internal state.
3200 //! Compute one output sample.
3201 MY_FLOAT
tick(MY_FLOAT input
);
3203 public: // SWAP formerly protected
3204 Delay
*allpassDelays
[3];
3205 Delay
*combDelays
[4];
3206 Delay
*outLeftDelay
;
3207 Delay
*outRightDelay
;
3208 MY_FLOAT allpassCoefficient
;
3209 MY_FLOAT combCoefficient
[4];
3218 /***************************************************/
3220 \brief STK enhanced plucked string model class.
3222 This class implements an enhanced two-string,
3223 plucked physical model, a la Jaffe-Smith,
3226 PluckTwo is an abstract class, with no excitation
3227 specified. Therefore, it can't be directly
3230 This is a digital waveguide model, making its
3231 use possibly subject to patents held by
3232 Stanford University, Yamaha, and others.
3234 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
3236 /***************************************************/
3238 #if !defined(__PLUCKTWO_H)
3239 #define __PLUCKTWO_H
3242 class PluckTwo
: public Instrmnt
3245 //! Class constructor, taking the lowest desired playing frequency.
3246 PluckTwo(MY_FLOAT lowestFrequency
);
3248 //! Class destructor.
3249 virtual ~PluckTwo();
3251 //! Reset and clear all internal state.
3254 //! Set instrument parameters for a particular frequency.
3255 virtual void setFrequency(MY_FLOAT frequency
);
3257 //! Detune the two strings by the given factor. A value of 1.0 produces unison strings.
3258 void setDetune(MY_FLOAT detune
);
3260 //! Efficient combined setting of frequency and detuning.
3261 void setFreqAndDetune(MY_FLOAT frequency
, MY_FLOAT detune
);
3263 //! Set the pluck or "excitation" position along the string (0.0 - 1.0).
3264 void setPluckPosition(MY_FLOAT position
);
3266 //! Set the base loop gain.
3268 The actual loop gain is set according to the frequency.
3269 Because of high-frequency loop filter roll-off, higher
3270 frequency settings have greater loop gains.
3272 void setBaseLoopGain(MY_FLOAT aGain
);
3274 //! Stop a note with the given amplitude (speed of decay).
3275 virtual void noteOff(MY_FLOAT amplitude
);
3277 //! Virtual (abstract) tick function is implemented by subclasses.
3278 virtual MY_FLOAT
tick() = 0;
3280 public: // SWAP formerly protected
3288 MY_FLOAT baseLoopGain
;
3289 MY_FLOAT lastFrequency
;
3290 MY_FLOAT lastLength
;
3292 MY_FLOAT pluckAmplitude
;
3293 MY_FLOAT pluckPosition
;
3302 /***************************************************/
3304 \brief STK mandolin instrument model class.
3306 This class inherits from PluckTwo and uses
3307 "commuted synthesis" techniques to model a
3308 mandolin instrument.
3310 This is a digital waveguide model, making its
3311 use possibly subject to patents held by
3312 Stanford University, Yamaha, and others.
3313 Commuted Synthesis, in particular, is covered
3314 by patents, granted, pending, and/or
3315 applied-for. All are assigned to the Board of
3316 Trustees, Stanford University. For
3317 information, contact the Office of Technology
3318 Licensing, Stanford University.
3320 Control Change Numbers:
3322 - Pluck Position = 4
3323 - String Sustain = 11
3324 - String Detuning = 1
3325 - Microphone Position = 128
3327 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
3329 /***************************************************/
3331 #if !defined(__MANDOLIN_H)
3332 #define __MANDOLIN_H
3335 class Mandolin
: public PluckTwo
3338 //! Class constructor, taking the lowest desired playing frequency.
3339 Mandolin(MY_FLOAT lowestFrequency
);
3341 //! Class destructor.
3342 virtual ~Mandolin();
3344 //! Pluck the strings with the given amplitude (0.0 - 1.0) using the current frequency.
3345 void pluck(MY_FLOAT amplitude
);
3347 //! Pluck the strings with the given amplitude (0.0 - 1.0) and position (0.0 - 1.0).
3348 void pluck(MY_FLOAT amplitude
,MY_FLOAT position
);
3350 //! Start a note with the given frequency and amplitude (0.0 - 1.0).
3351 virtual void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
3353 //! Set the body size (a value of 1.0 produces the "default" size).
3354 void setBodySize(MY_FLOAT size
);
3356 //! Set the body impulse response
3357 bool setBodyIR( const char * path
, bool isRaw
);
3359 //! Compute one output sample.
3360 virtual MY_FLOAT
tick();
3362 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
3363 virtual void controlChange(int number
, MY_FLOAT value
);
3365 public: // SWAP formerly protected
3366 WvIn
*soundfile
[12];
3367 MY_FLOAT directBody
;
3371 MY_FLOAT m_bodySize
;
3372 // MY_FLOAT m_stringDamping;
3373 // MY_FLOAT m_stringDetune;
3381 /***************************************************/
3383 \brief Two-dimensional rectilinear waveguide mesh class.
3385 This class implements a rectilinear,
3386 two-dimensional digital waveguide mesh
3387 structure. For details, see Van Duyne and
3388 Smith, "Physical Modeling with the 2-D Digital
3389 Waveguide Mesh", Proceedings of the 1993
3390 International Computer Music Conference.
3392 This is a digital waveguide model, making its
3393 use possibly subject to patents held by Stanford
3394 University, Yamaha, and others.
3396 Control Change Numbers:
3400 - X-Y Input Position = 1
3402 by Julius Smith, 2000 - 2002.
3403 Revised by Gary Scavone for STK, 2002.
3405 /***************************************************/
3407 #if !defined(__MESH2D_H)
3411 #define NXMAX ((short)(12))
3412 #define NYMAX ((short)(12))
3414 class Mesh2D
: public Instrmnt
3417 //! Class constructor, taking the x and y dimensions in samples.
3418 Mesh2D(short nX
, short nY
);
3420 //! Class destructor.
3423 //! Reset and clear all internal state.
3426 //! Set the x dimension size in samples.
3427 void setNX(short lenX
);
3429 //! Set the y dimension size in samples.
3430 void setNY(short lenY
);
3432 //! Set the x, y input position on a 0.0 - 1.0 scale.
3433 void setInputPosition(MY_FLOAT xFactor
, MY_FLOAT yFactor
);
3435 //! Set the loss filters gains (0.0 - 1.0).
3436 void setDecay(MY_FLOAT decayFactor
);
3438 //! Impulse the mesh with the given amplitude (frequency ignored).
3439 void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
3441 //! Stop a note with the given amplitude (speed of decay) ... currently ignored.
3442 void noteOff(MY_FLOAT amplitude
);
3444 //! Calculate and return the signal energy stored in the mesh.
3447 //! Compute one output sample, without adding energy to the mesh.
3450 //! Input a sample to the mesh and compute one output sample.
3451 MY_FLOAT
tick(MY_FLOAT input
);
3453 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
3454 void controlChange(int number
, MY_FLOAT value
);
3456 public: // SWAP formerly protected
3463 short xInput
, yInput
;
3464 OnePole
*filterX
[NXMAX
];
3465 OnePole
*filterY
[NYMAX
];
3466 MY_FLOAT v
[NXMAX
-1][NYMAX
-1]; // junction velocities
3467 MY_FLOAT vxp
[NXMAX
][NYMAX
]; // positive-x velocity wave
3468 MY_FLOAT vxm
[NXMAX
][NYMAX
]; // negative-x velocity wave
3469 MY_FLOAT vyp
[NXMAX
][NYMAX
]; // positive-y velocity wave
3470 MY_FLOAT vym
[NXMAX
][NYMAX
]; // negative-y velocity wave
3472 // Alternate buffers
3473 MY_FLOAT vxp1
[NXMAX
][NYMAX
]; // positive-x velocity wave
3474 MY_FLOAT vxm1
[NXMAX
][NYMAX
]; // negative-x velocity wave
3475 MY_FLOAT vyp1
[NXMAX
][NYMAX
]; // positive-y velocity wave
3476 MY_FLOAT vym1
[NXMAX
][NYMAX
]; // negative-y velocity wave
3478 int counter
; // time in samples
3488 /***************************************************/
3490 \brief STK resonance model instrument.
3492 This class contains an excitation wavetable,
3493 an envelope, an oscillator, and N resonances
3494 (non-sweeping BiQuad filters), where N is set
3495 during instantiation.
3497 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
3499 /***************************************************/
3500 #if !defined(__MODAL_H)
3503 class Modal
: public Instrmnt
3506 //! Class constructor, taking the desired number of modes to create.
3507 Modal( int modes
= 4 );
3509 //! Class destructor.
3512 //! Reset and clear all internal state.
3515 //! Set instrument parameters for a particular frequency.
3516 virtual void setFrequency(MY_FLOAT frequency
);
3518 //! Set the ratio and radius for a specified mode filter.
3519 void setRatioAndRadius(int modeIndex
, MY_FLOAT ratio
, MY_FLOAT radius
);
3521 //! Set the master gain.
3522 void setMasterGain(MY_FLOAT aGain
);
3524 //! Set the direct gain.
3525 void setDirectGain(MY_FLOAT aGain
);
3527 //! Set the gain for a specified mode filter.
3528 void setModeGain(int modeIndex
, MY_FLOAT gain
);
3530 //! Initiate a strike with the given amplitude (0.0 - 1.0).
3531 virtual void strike(MY_FLOAT amplitude
);
3533 //! Damp modes with a given decay factor (0.0 - 1.0).
3534 void damp(MY_FLOAT amplitude
);
3536 //! Start a note with the given frequency and amplitude.
3537 void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
3539 //! Stop a note with the given amplitude (speed of decay).
3540 void noteOff(MY_FLOAT amplitude
);
3542 //! Compute one output sample.
3543 virtual MY_FLOAT
tick();
3545 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
3546 virtual void controlChange(int number
, MY_FLOAT value
) = 0;
3548 public: // SWAP formerly protected
3550 t_CKFLOAT m_vibratoGain
;
3551 t_CKFLOAT m_vibratoFreq
;
3560 MY_FLOAT vibratoGain
;
3561 MY_FLOAT masterGain
;
3562 MY_FLOAT directGain
;
3563 MY_FLOAT stickHardness
;
3564 MY_FLOAT strikePosition
;
3565 MY_FLOAT baseFrequency
;
3576 /***************************************************/
3578 \brief STK resonant bar instrument class.
3580 This class implements a number of different
3581 struck bar instruments. It inherits from the
3584 Control Change Numbers:
3585 - Stick Hardness = 2
3586 - Stick Position = 4
3588 - Vibrato Frequency = 7
3590 - Modal Presets = 16
3601 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
3603 /***************************************************/
3605 #if !defined(__MODALBAR_H)
3606 #define __MODALBAR_H
3609 class ModalBar
: public Modal
3612 //! Class constructor.
3615 //! Class destructor.
3618 //! Set stick hardness (0.0 - 1.0).
3619 void setStickHardness(MY_FLOAT hardness
);
3621 //! Set stick position (0.0 - 1.0).
3622 void setStrikePosition(MY_FLOAT position
);
3624 //! Select a bar preset (currently modulo 9).
3625 void setPreset(int preset
);
3627 //! Set the modulation (vibrato) depth.
3628 void setModulationDepth(MY_FLOAT mDepth
);
3630 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
3631 void controlChange(int number
, MY_FLOAT value
);
3639 /***************************************************/
3641 \brief STK sub-sampled noise generator.
3643 Generates a new random number every "rate" ticks
3644 using the C rand() function. The quality of the
3645 rand() function varies from one OS to another.
3647 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
3649 /***************************************************/
3651 #if !defined(__SUBNOISE_H)
3652 #define __SUBNOISE_H
3655 class SubNoise
: public Noise
3659 //! Default constructor sets sub-sample rate to 16.
3660 SubNoise(int subRate
= 16);
3662 //! Class destructor.
3665 //! Return the current sub-sampling rate.
3666 int subRate(void) const;
3668 //! Set the sub-sampling rate.
3669 void setRate(int subRate
);
3671 //! Return a sub-sampled random number between -1.0 and 1.0.
3674 public: // SWAP formerly protected
3685 /***************************************************/
3687 \brief STK periodic/random modulator.
3689 This class combines random and periodic
3690 modulations to give a nice, natural human
3691 modulation function.
3693 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
3695 /***************************************************/
3697 #if !defined(__MODULATE_H)
3698 #define __MODULATE_H
3701 class Modulate
: public Stk
3704 //! Class constructor.
3707 //! Class destructor.
3710 //! Reset internal state.
3713 //! Set the periodic (vibrato) rate or frequency in Hz.
3714 void setVibratoRate(MY_FLOAT aRate
);
3716 //! Set the periodic (vibrato) gain.
3717 void setVibratoGain(MY_FLOAT aGain
);
3719 //! Set the random modulation gain.
3720 void setRandomGain(MY_FLOAT aGain
);
3722 //! Compute one output sample.
3725 //! Return \e vectorSize outputs in \e vector.
3726 virtual MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
3728 //! Return the last computed output value.
3729 MY_FLOAT
lastOut() const;
3731 public: // SWAP formerly protected
3735 MY_FLOAT vibratoGain
;
3736 MY_FLOAT randomGain
;
3737 MY_FLOAT lastOutput
;
3746 /***************************************************/
3748 \brief STK sampling synthesis abstract base class.
3750 This instrument contains up to 5 attack waves,
3751 5 looped waves, and an ADSR envelope.
3753 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
3755 /***************************************************/
3757 #if !defined(__SAMPLER_H)
3761 class Sampler
: public Instrmnt
3764 //! Default constructor.
3767 //! Class destructor.
3770 //! Reset and clear all internal state.
3773 //! Set instrument parameters for a particular frequency.
3774 virtual void setFrequency(MY_FLOAT frequency
) = 0;
3776 //! Initiate the envelopes with a key-on event and reset the attack waves.
3779 //! Signal a key-off event to the envelopes.
3782 //! Stop a note with the given amplitude (speed of decay).
3783 virtual void noteOff(MY_FLOAT amplitude
);
3785 //! Compute one output sample.
3786 virtual MY_FLOAT
tick();
3788 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
3789 virtual void controlChange(int number
, MY_FLOAT value
) = 0;
3791 public: // SWAP formerly protected
3796 MY_FLOAT baseFrequency
;
3797 MY_FLOAT attackRatios
[5];
3798 MY_FLOAT loopRatios
[5];
3799 MY_FLOAT attackGain
;
3810 /***************************************************/
3812 \brief STK moog-like swept filter sampling synthesis class.
3814 This instrument uses one attack wave, one
3815 looped wave, and an ADSR envelope (inherited
3816 from the Sampler class) and adds two sweepable
3817 formant (FormSwep) filters.
3819 Control Change Numbers:
3821 - Filter Sweep Rate = 4
3822 - Vibrato Frequency = 11
3826 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
3828 /***************************************************/
3830 #if !defined(__MOOG_H)
3834 class Moog
: public Sampler
3837 //! Class constructor.
3840 //! Class destructor.
3843 //! Set instrument parameters for a particular frequency.
3844 virtual void setFrequency(MY_FLOAT frequency
);
3846 //! Start a note with the given frequency and amplitude.
3847 virtual void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
3848 virtual void noteOn(MY_FLOAT amplitude
); //CHUCK! note start note with current frequency
3850 //! Set the modulation (vibrato) speed in Hz.
3851 void setModulationSpeed(MY_FLOAT mSpeed
);
3853 //! Set the modulation (vibrato) depth.
3854 void setModulationDepth(MY_FLOAT mDepth
);
3856 //! Compute one output sample.
3857 virtual MY_FLOAT
tick();
3859 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
3860 virtual void controlChange(int number
, MY_FLOAT value
);
3862 public: // SWAP formerly protected
3864 t_CKFLOAT m_vibratoFreq
;
3865 t_CKFLOAT m_vibratoGain
;
3868 FormSwep
*filters
[2];
3871 MY_FLOAT filterRate
;
3880 /***************************************************/
3882 \brief CCRMA's NRev reverberator class.
3884 This class is derived from the CLM NRev
3885 function, which is based on the use of
3886 networks of simple allpass and comb delay
3887 filters. This particular arrangement consists
3888 of 6 comb filters in parallel, followed by 3
3889 allpass filters, a lowpass filter, and another
3890 allpass in series, followed by two allpass
3891 filters in parallel with corresponding right
3894 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
3896 /***************************************************/
3898 #if !defined(__NREV_H)
3902 class NRev
: public Reverb
3905 //! Class constructor taking a T60 decay time argument.
3908 //! Class destructor.
3911 //! Reset and clear all internal state.
3914 //! Compute one output sample.
3915 MY_FLOAT
tick(MY_FLOAT input
);
3917 public: // SWAP formerly protected
3918 Delay
*allpassDelays
[8];
3919 Delay
*combDelays
[6];
3920 MY_FLOAT allpassCoefficient
;
3921 MY_FLOAT combCoefficient
[6];
3922 MY_FLOAT lowpassState
;
3932 /***************************************************/
3934 \brief Perry's simple reverberator class.
3936 This class is based on some of the famous
3937 Stanford/CCRMA reverbs (NRev, KipRev), which
3938 were based on the Chowning/Moorer/Schroeder
3939 reverberators using networks of simple allpass
3940 and comb delay filters. This class implements
3941 two series allpass units and two parallel comb
3944 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
3946 /***************************************************/
3948 #if !defined(__PRCREV_H)
3952 class PRCRev
: public Reverb
3955 //! Class constructor taking a T60 decay time argument.
3956 PRCRev(MY_FLOAT T60
);
3958 //! Class destructor.
3961 //! Reset and clear all internal state.
3964 //! Compute one output sample.
3965 MY_FLOAT
tick(MY_FLOAT input
);
3967 public: // SWAP formerly protected
3968 Delay
*allpassDelays
[2];
3969 Delay
*combDelays
[2];
3970 MY_FLOAT allpassCoefficient
;
3971 MY_FLOAT combCoefficient
[2];
3981 /***************************************************/
3983 \brief STK percussive flute FM synthesis instrument.
3985 This class implements algorithm 4 of the TX81Z.
3988 Algorithm 4 is : 4->3--\
3992 Control Change Numbers:
3993 - Total Modulator Index = 2
3994 - Modulator Crossfade = 4
3997 - ADSR 2 & 4 Target = 128
3999 The basic Chowning/Stanford FM patent expired
4000 in 1995, but there exist follow-on patents,
4001 mostly assigned to Yamaha. If you are of the
4002 type who should worry about this (making
4005 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
4007 /***************************************************/
4009 #if !defined(__PERCFLUT_H)
4010 #define __PERCFLUT_H
4013 class PercFlut
: public FM
4016 //! Class constructor.
4019 //! Class destructor.
4022 //! Set instrument parameters for a particular frequency.
4023 void setFrequency(MY_FLOAT frequency
);
4025 //! Start a note with the given frequency and amplitude.
4026 void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
4027 void noteOn( MY_FLOAT amplitude
) { noteOn(baseFrequency
, amplitude
); }
4029 //! Compute one output sample.
4038 /***************************************************/
4040 \brief STK phonemes table.
4042 This class does nothing other than declare a
4043 set of 32 static phoneme formant parameters
4044 and provide access to those values.
4046 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
4048 /***************************************************/
4050 #if !defined(__PHONEMES_H)
4051 #define __PHONEMES_H
4061 //! Returns the phoneme name for the given index (0-31).
4062 static const char *name( unsigned int index
);
4064 //! Returns the voiced component gain for the given phoneme index (0-31).
4065 static MY_FLOAT
voiceGain( unsigned int index
);
4067 //! Returns the unvoiced component gain for the given phoneme index (0-31).
4068 static MY_FLOAT
noiseGain( unsigned int index
);
4070 //! Returns the formant frequency for the given phoneme index (0-31) and partial (0-3).
4071 static MY_FLOAT
formantFrequency( unsigned int index
, unsigned int partial
);
4073 //! Returns the formant radius for the given phoneme index (0-31) and partial (0-3).
4074 static MY_FLOAT
formantRadius( unsigned int index
, unsigned int partial
);
4076 //! Returns the formant gain for the given phoneme index (0-31) and partial (0-3).
4077 static MY_FLOAT
formantGain( unsigned int index
, unsigned int partial
);
4079 public: // SWAP formerly private
4081 static const char phonemeNames
[][4];
4082 static const MY_FLOAT phonemeGains
[][2];
4083 static const MY_FLOAT phonemeParameters
[][4][3];
4092 /***************************************************/
4094 \brief STK simple pitch shifter effect class.
4096 This class implements a simple pitch shifter
4099 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
4101 /***************************************************/
4103 #if !defined(__PITSHIFT_H)
4104 #define __PITSHIFT_H
4107 class PitShift
: public Stk
4110 //! Class constructor.
4113 //! Class destructor.
4116 //! Reset and clear all internal state.
4119 //! Set the pitch shift factor (1.0 produces no shift).
4120 void setShift(MY_FLOAT shift
);
4122 //! Set the mixture of input and processed levels in the output (0.0 = input only, 1.0 = processed only).
4123 void setEffectMix(MY_FLOAT mix
);
4125 //! Return the last output value.
4126 MY_FLOAT
lastOut() const;
4128 //! Compute one output sample.
4129 MY_FLOAT
tick(MY_FLOAT input
);
4131 //! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
4132 MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
4134 public: // SWAP formerly protected
4136 t_CKFLOAT m_vibratoGain
;
4137 t_CKFLOAT m_vibratoFreq
;
4140 DelayL
*delayLine
[2];
4141 MY_FLOAT lastOutput
;
4155 /***************************************************/
4157 \brief STK plucked string model class.
4159 This class implements a simple plucked string
4160 physical model based on the Karplus-Strong
4163 This is a digital waveguide model, making its
4164 use possibly subject to patents held by
4165 Stanford University, Yamaha, and others.
4166 There exist at least two patents, assigned to
4167 Stanford, bearing the names of Karplus and/or
4170 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
4172 /***************************************************/
4174 #if !defined(__PLUCKED_H)
4178 class Plucked
: public Instrmnt
4181 //! Class constructor, taking the lowest desired playing frequency.
4182 Plucked(MY_FLOAT lowestFrequency
);
4184 //! Class destructor.
4187 //! Reset and clear all internal state.
4190 //! Set instrument parameters for a particular frequency.
4191 virtual void setFrequency(MY_FLOAT frequency
);
4193 //! Pluck the string with the given amplitude using the current frequency.
4194 void pluck(MY_FLOAT amplitude
);
4196 //! Start a note with the given frequency and amplitude.
4197 virtual void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
4199 //! Stop a note with the given amplitude (speed of decay).
4200 virtual void noteOff(MY_FLOAT amplitude
);
4202 //! Compute one output sample.
4203 virtual MY_FLOAT
tick();
4205 public: // SWAP formerly protected
4207 OneZero
*loopFilter
;
4208 OnePole
*pickFilter
;
4221 /***************************************************/
4223 \brief STK noise driven formant filter.
4225 This instrument contains a noise source, which
4226 excites a biquad resonance filter, with volume
4227 controlled by an ADSR.
4229 Control Change Numbers:
4230 - Resonance Frequency (0-Nyquist) = 2
4232 - Notch Frequency (0-Nyquist) = 11
4234 - Envelope Gain = 128
4236 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
4238 /***************************************************/
4240 #if !defined(__RESONATE_H)
4241 #define __RESONATE_H
4244 class Resonate
: public Instrmnt
4247 //! Class constructor.
4250 //! Class destructor.
4253 //! Reset and clear all internal state.
4256 //! Set the filter for a resonance at the given frequency (Hz) and radius.
4257 void setResonance(MY_FLOAT frequency
, MY_FLOAT radius
);
4259 //! Set the filter for a notch at the given frequency (Hz) and radius.
4260 void setNotch(MY_FLOAT frequency
, MY_FLOAT radius
);
4262 //! Set the filter zero coefficients for contant resonance gain.
4263 void setEqualGainZeroes();
4265 //! Initiate the envelope with a key-on event.
4268 //! Signal a key-off event to the envelope.
4271 //! Start a note with the given frequency and amplitude.
4272 void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
4274 //! Stop a note with the given amplitude (speed of decay).
4275 void noteOff(MY_FLOAT amplitude
);
4277 //! Compute one output sample.
4280 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
4281 virtual void controlChange(int number
, MY_FLOAT value
);
4283 public: // SWAP formerly protected
4287 MY_FLOAT poleFrequency
;
4288 MY_FLOAT poleRadius
;
4289 MY_FLOAT zeroFrequency
;
4290 MY_FLOAT zeroRadius
;
4299 /***************************************************/
4301 \brief STK Fender Rhodes electric piano FM
4302 synthesis instrument.
4304 This class implements two simple FM Pairs
4305 summed together, also referred to as algorithm
4309 Algorithm 5 is : 4->3--\
4314 Control Change Numbers:
4315 - Modulator Index One = 2
4316 - Crossfade of Outputs = 4
4319 - ADSR 2 & 4 Target = 128
4321 The basic Chowning/Stanford FM patent expired
4322 in 1995, but there exist follow-on patents,
4323 mostly assigned to Yamaha. If you are of the
4324 type who should worry about this (making
4327 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
4329 /***************************************************/
4331 #if !defined(__RHODEY_H)
4335 class Rhodey
: public FM
4338 //! Class constructor.
4341 //! Class destructor.
4344 //! Set instrument parameters for a particular frequency.
4345 void setFrequency(MY_FLOAT frequency
);
4347 //! Start a note with the given frequency and amplitude.
4348 void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
4349 void noteOn(MY_FLOAT amplitude
) { noteOn(baseFrequency
* 0.5, amplitude
); }
4351 //! Compute one output sample.
4360 /***************************************************/
4362 \brief STK SKINI parsing class
4364 This class parses SKINI formatted text
4365 messages. It can be used to parse individual
4366 messages or it can be passed an entire file.
4367 The file specification is Perry's and his
4368 alone, but it's all text so it shouldn't be to
4371 SKINI (Synthesis toolKit Instrument Network
4372 Interface) is like MIDI, but allows for
4373 floating-point control changes, note numbers,
4374 etc. The following example causes a sharp
4375 middle C to be played with a velocity of 111.132:
4383 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
4385 /***************************************************/
4387 #if !defined(__SKINI_H)
4392 class SKINI
: public Stk
4395 //! Default constructor used for parsing messages received externally.
4398 //! Overloaded constructor taking a SKINI formatted scorefile.
4399 SKINI(char *fileName
);
4401 //! Class destructor
4404 //! Attempt to parse the given string, returning the message type.
4406 A type value equal to zero indicates an invalid message.
4408 long parseThis(char* aString
);
4410 //! Parse the next message (if a file is loaded) and return the message type.
4412 A negative value is returned when the file end is reached.
4416 //! Return the current message type.
4417 long getType() const;
4419 //! Return the current message channel value.
4420 long getChannel() const;
4422 //! Return the current message delta time value (in seconds).
4423 MY_FLOAT
getDelta() const;
4425 //! Return the current message byte two value.
4426 MY_FLOAT
getByteTwo() const;
4428 //! Return the current message byte three value.
4429 MY_FLOAT
getByteThree() const;
4431 //! Return the current message byte two value (integer).
4432 long getByteTwoInt() const;
4434 //! Return the current message byte three value (integer).
4435 long getByteThreeInt() const;
4437 //! Return remainder string after parsing.
4438 const char* getRemainderString();
4440 //! Return the message type as a string.
4441 const char* getMessageTypeString();
4443 //! Return the SKINI type string for the given type value.
4444 const char* whatsThisType(long type
);
4446 //! Return the SKINI controller string for the given controller number.
4447 const char* whatsThisController(long number
);
4449 public: // SWAP formerly protected
4453 char msgTypeString
[64];
4460 char remainderString
[1024];
4461 char whatString
[1024];
4464 static const double Midi2Pitch
[129] = {
4465 8.18,8.66,9.18,9.72,10.30,10.91,11.56,12.25,
4466 12.98,13.75,14.57,15.43,16.35,17.32,18.35,19.45,
4467 20.60,21.83,23.12,24.50,25.96,27.50,29.14,30.87,
4468 32.70,34.65,36.71,38.89,41.20,43.65,46.25,49.00,
4469 51.91,55.00,58.27,61.74,65.41,69.30,73.42,77.78,
4470 82.41,87.31,92.50,98.00,103.83,110.00,116.54,123.47,
4471 130.81,138.59,146.83,155.56,164.81,174.61,185.00,196.00,
4472 207.65,220.00,233.08,246.94,261.63,277.18,293.66,311.13,
4473 329.63,349.23,369.99,392.00,415.30,440.00,466.16,493.88,
4474 523.25,554.37,587.33,622.25,659.26,698.46,739.99,783.99,
4475 830.61,880.00,932.33,987.77,1046.50,1108.73,1174.66,1244.51,
4476 1318.51,1396.91,1479.98,1567.98,1661.22,1760.00,1864.66,1975.53,
4477 2093.00,2217.46,2349.32,2489.02,2637.02,2793.83,2959.96,3135.96,
4478 3322.44,3520.00,3729.31,3951.07,4186.01,4434.92,4698.64,4978.03,
4479 5274.04,5587.65,5919.91,6271.93,6644.88,7040.00,7458.62,7902.13,
4480 8372.02,8869.84,9397.27,9956.06,10548.08,11175.30,11839.82,12543.85,
4490 /***************************************************/
4492 \brief STK faux conical bore reed instrument class.
4494 This class implements a "hybrid" digital
4495 waveguide instrument that can generate a
4496 variety of wind-like sounds. It has also been
4497 referred to as the "blowed string" model. The
4498 waveguide section is essentially that of a
4499 string, with one rigid and one lossy
4500 termination. The non-linear function is a
4501 reed table. The string can be "blown" at any
4502 point between the terminations, though just as
4503 with strings, it is impossible to excite the
4504 system at either end. If the excitation is
4505 placed at the string mid-point, the sound is
4506 that of a clarinet. At points closer to the
4507 "bridge", the sound is closer to that of a
4508 saxophone. See Scavone (2002) for more details.
4510 This is a digital waveguide model, making its
4511 use possibly subject to patents held by Stanford
4512 University, Yamaha, and others.
4514 Control Change Numbers:
4515 - Reed Stiffness = 2
4516 - Reed Aperture = 26
4518 - Blow Position = 11
4519 - Vibrato Frequency = 29
4521 - Breath Pressure = 128
4523 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
4525 /***************************************************/
4527 #if !defined(__SAXOFONY_H)
4528 #define __SAXOFONY_H
4531 class Saxofony
: public Instrmnt
4534 //! Class constructor, taking the lowest desired playing frequency.
4535 Saxofony(MY_FLOAT lowestFrequency
);
4537 //! Class destructor.
4540 //! Reset and clear all internal state.
4543 //! Set instrument parameters for a particular frequency.
4544 void setFrequency(MY_FLOAT frequency
);
4546 //! Set the "blowing" position between the air column terminations (0.0 - 1.0).
4547 void setBlowPosition(MY_FLOAT aPosition
);
4549 //! Apply breath pressure to instrument with given amplitude and rate of increase.
4550 void startBlowing(MY_FLOAT amplitude
, MY_FLOAT rate
);
4552 //! Decrease breath pressure with given rate of decrease.
4553 void stopBlowing(MY_FLOAT rate
);
4555 //! Start a note with the given frequency and amplitude.
4556 void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
4558 //! Stop a note with the given amplitude (speed of decay).
4559 void noteOff(MY_FLOAT amplitude
);
4561 //! Compute one output sample.
4564 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
4565 void controlChange(int number
, MY_FLOAT value
);
4567 public: // SWAP formerly protected
4570 t_CKFLOAT m_stiffness
;
4571 t_CKFLOAT m_aperture
;
4572 t_CKFLOAT m_noiseGain
;
4573 t_CKFLOAT m_vibratoGain
;
4574 t_CKFLOAT m_pressure
;
4577 ReedTabl
*reedTable
;
4583 MY_FLOAT outputGain
;
4585 MY_FLOAT vibratoGain
;
4595 /***************************************************/
4597 \brief PhISEM and PhOLIES class.
4599 PhISEM (Physically Informed Stochastic Event
4600 Modeling) is an algorithmic approach for
4601 simulating collisions of multiple independent
4602 sound producing objects. This class is a
4603 meta-model that can simulate a Maraca, Sekere,
4604 Cabasa, Bamboo Wind Chimes, Water Drops,
4605 Tambourine, Sleighbells, and a Guiro.
4607 PhOLIES (Physically-Oriented Library of
4608 Imitated Environmental Sounds) is a similar
4609 approach for the synthesis of environmental
4610 sounds. This class implements simulations of
4611 breaking sticks, crunchy snow (or not), a
4612 wrench, sandpaper, and more.
4614 Control Change Numbers:
4617 - Number Of Objects = 11
4618 - Resonance Frequency = 1
4619 - Shake Energy = 128
4620 - Instrument Selection = 1071
4638 - Quarter + Mug = 17
4643 - Tuned Bamboo Chimes = 22
4645 by Perry R. Cook, 1996 - 1999.
4647 /***************************************************/
4649 #if !defined(__SHAKERS_H)
4654 #define NUM_INSTR 24
4656 class Shakers
: public Instrmnt
4659 //! Class constructor.
4662 //! Class destructor.
4665 //! Start a note with the given instrument and amplitude.
4667 Use the instrument numbers above, converted to frequency values
4668 as if MIDI note numbers, to select a particular instrument.
4670 virtual void ck_noteOn(MY_FLOAT amplitude
); // chuck single arg call
4671 virtual void noteOn(MY_FLOAT instrument
, MY_FLOAT amplitude
);
4673 //! Stop a note with the given amplitude (speed of decay).
4674 virtual void noteOff(MY_FLOAT amplitude
);
4676 //! Compute one output sample.
4679 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
4680 virtual void controlChange(int number
, MY_FLOAT value
);
4682 int m_noteNum
; // chuck data
4684 int setupName(char* instr
);
4685 int setupNum(int inst
);
4687 public: // SWAP formerly protected
4691 t_CKFLOAT m_objects
;
4693 int setFreqAndReson(int which
, MY_FLOAT freq
, MY_FLOAT reson
);
4694 void setDecays(MY_FLOAT sndDecay
, MY_FLOAT sysDecay
);
4695 void setFinalZs(MY_FLOAT z0
, MY_FLOAT z1
, MY_FLOAT z2
);
4696 MY_FLOAT
wuter_tick();
4697 MY_FLOAT
tbamb_tick();
4698 MY_FLOAT
ratchet_tick();
4701 int ratchetPos
, lastRatchetPos
;
4702 MY_FLOAT shakeEnergy
;
4703 MY_FLOAT inputs
[MAX_FREQS
];
4704 MY_FLOAT outputs
[MAX_FREQS
][2];
4705 MY_FLOAT coeffs
[MAX_FREQS
][2];
4708 MY_FLOAT gains
[MAX_FREQS
];
4710 MY_FLOAT t_center_freqs
[MAX_FREQS
];
4711 MY_FLOAT center_freqs
[MAX_FREQS
];
4712 MY_FLOAT resons
[MAX_FREQS
];
4713 MY_FLOAT freq_rand
[MAX_FREQS
];
4714 int freqalloc
[MAX_FREQS
];
4715 MY_FLOAT soundDecay
;
4716 MY_FLOAT systemDecay
;
4718 MY_FLOAT collLikely
;
4719 MY_FLOAT totalEnergy
;
4720 MY_FLOAT ratchet
,ratchetDelta
;
4722 MY_FLOAT finalZCoeffs
[3];
4723 MY_FLOAT defObjs
[NUM_INSTR
];
4724 MY_FLOAT defDecays
[NUM_INSTR
];
4725 MY_FLOAT decayScale
[NUM_INSTR
];
4733 /***************************************************/
4735 \brief STK wavetable/noise instrument.
4737 This class combines a looped wave, a
4738 noise source, a biquad resonance filter,
4739 a one-pole filter, and an ADSR envelope
4740 to create some interesting sounds.
4742 Control Change Numbers:
4743 - Filter Pole Position = 2
4744 - Noise/Pitched Cross-Fade = 4
4745 - Envelope Rate = 11
4748 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
4750 /***************************************************/
4752 #if !defined(__SIMPLE_H)
4756 class Simple
: public Instrmnt
4759 //! Class constructor.
4762 //! Class destructor.
4765 //! Clear internal states.
4768 //! Set instrument parameters for a particular frequency.
4769 virtual void setFrequency(MY_FLOAT frequency
);
4771 //! Start envelope toward "on" target.
4774 //! Start envelope toward "off" target.
4777 //! Start a note with the given frequency and amplitude.
4778 virtual void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
4780 //! Stop a note with the given amplitude (speed of decay).
4781 virtual void noteOff(MY_FLOAT amplitude
);
4783 //! Compute one output sample.
4784 virtual MY_FLOAT
tick();
4786 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
4787 virtual void controlChange(int number
, MY_FLOAT value
);
4789 public: // SWAP formerly protected
4795 MY_FLOAT baseFrequency
;
4805 /***************************************************/
4807 \brief STK "singing" looped soundfile class.
4809 This class contains all that is needed to make
4810 a pitched musical sound, like a simple voice
4811 or violin. In general, it will not be used
4812 alone because of munchkinification effects
4813 from pitch shifting. It will be used as an
4814 excitation source for other instruments.
4816 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
4818 /***************************************************/
4820 #if !defined(__SINGWAVE_H)
4821 #define __SINGWAVE_H
4824 class SingWave
: public Stk
4827 //! Class constructor taking filename argument.
4829 An StkError will be thrown if the file is not found, its format is
4830 unknown, or a read error occurs.
4832 SingWave(const char *fileName
, bool raw
=FALSE
);
4834 //! Class destructor.
4837 //! Reset file to beginning.
4840 //! Normalize the file to a maximum of +-1.0.
4843 //! Normalize the file to a maximum of \e +- peak.
4844 void normalize(MY_FLOAT peak
);
4846 //! Set instrument parameters for a particular frequency.
4847 void setFrequency(MY_FLOAT frequency
);
4849 //! Set the vibrato frequency in Hz.
4850 void setVibratoRate(MY_FLOAT aRate
);
4852 //! Set the vibrato gain.
4853 void setVibratoGain(MY_FLOAT gain
);
4855 //! Set the random-ness amount.
4856 void setRandomGain(MY_FLOAT gain
);
4858 //! Set the sweep rate.
4859 void setSweepRate(MY_FLOAT aRate
);
4861 //! Set the gain rate.
4862 void setGainRate(MY_FLOAT aRate
);
4864 //! Set the gain target value.
4865 void setGainTarget(MY_FLOAT target
);
4873 //! Return the last output value.
4876 //! Compute one output sample.
4879 public: // SWAP formerly protected
4882 Modulate
*modulator
;
4884 Envelope
*pitchEnvelope
;
4887 MY_FLOAT lastOutput
;
4888 MY_FLOAT m_freq
; //chuck data
4897 /***************************************************/
4899 \brief STK sitar string model class.
4901 This class implements a sitar plucked string
4902 physical model based on the Karplus-Strong
4905 This is a digital waveguide model, making its
4906 use possibly subject to patents held by
4907 Stanford University, Yamaha, and others.
4908 There exist at least two patents, assigned to
4909 Stanford, bearing the names of Karplus and/or
4912 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
4914 /***************************************************/
4916 #if !defined(__SITAR_H)
4920 class Sitar
: public Instrmnt
4923 //! Class constructor, taking the lowest desired playing frequency.
4924 Sitar(MY_FLOAT lowestFrequency
);
4926 //! Class destructor.
4929 //! Reset and clear all internal state.
4932 //! Set instrument parameters for a particular frequency.
4933 void setFrequency(MY_FLOAT frequency
);
4935 //! Pluck the string with the given amplitude using the current frequency.
4936 void pluck(MY_FLOAT amplitude
);
4938 //! Start a note with the given frequency and amplitude.
4939 void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
4941 //! Stop a note with the given amplitude (speed of decay).
4942 void noteOff(MY_FLOAT amplitude
);
4944 //! Compute one output sample.
4947 public: // SWAP formerly protected
4949 OneZero
*loopFilter
;
4956 MY_FLOAT targetDelay
;
4966 /***************************************************/
4968 \brief STK TCP socket client/server class.
4970 This class provides a uniform cross-platform
4971 TCP socket client or socket server interface.
4972 Methods are provided for reading or writing
4973 data buffers to/from connections. This class
4974 also provides a number of static functions for
4975 use with external socket descriptors.
4977 The user is responsible for checking the values
4978 returned by the read/write methods. Values
4979 less than or equal to zero indicate a closed
4980 or lost connection or the occurence of an error.
4982 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
4984 /***************************************************/
4986 #if !defined(__SOCKET_H)
4990 class Socket
: public Stk
4993 //! Default constructor which creates a local socket server on port 2006 (or the specified port number).
4995 An StkError will be thrown if a socket error occurs during instantiation.
4997 Socket( int port
= 2006 );
4999 //! Class constructor which creates a socket client connection to the specified host and port.
5001 An StkError will be thrown if a socket error occurs during instantiation.
5003 Socket( int port
, const char *hostname
);
5005 //! The class destructor closes the socket instance, breaking any existing connections.
5008 //! Connect a socket client to the specified host and port and returns the resulting socket descriptor.
5010 This method is valid for socket clients only. If it is called for
5011 a socket server, -1 is returned. If the socket client is already
5012 connected, that connection is terminated and a new connection is
5013 attempted. Server connections are made using the accept() method.
5014 An StkError will be thrown if a socket error occurs during
5015 instantiation. \sa accept
5017 int connect( int port
, const char *hostname
= "localhost" );
5019 //! Close this socket.
5022 //! Return the server/client socket descriptor.
5023 int socket( void ) const;
5025 //! Return the server/client port number.
5026 int port( void ) const;
5028 //! If this is a socket server, extract the first pending connection request from the queue and create a new connection, returning the descriptor for the accepted socket.
5030 If no connection requests are pending and the socket has not
5031 been set non-blocking, this function will block until a connection
5032 is present. If an error occurs or this is a socket client, -1 is
5037 //! If enable = false, the socket is set to non-blocking mode. When first created, sockets are by default in blocking mode.
5038 static void setBlocking( int socket
, bool enable
);
5040 //! Close the socket with the given descriptor.
5041 static void close( int socket
);
5043 //! Returns TRUE is the socket descriptor is valid.
5044 static bool isValid( int socket
);
5046 //! Write a buffer over the socket connection. Returns the number of bytes written or -1 if an error occurs.
5047 int writeBuffer(const void *buffer
, long bufferSize
, int flags
= 0);
5049 //! Write a buffer via the specified socket. Returns the number of bytes written or -1 if an error occurs.
5050 static int writeBuffer(int socket
, const void *buffer
, long bufferSize
, int flags
);
5052 //! Read a buffer from the socket connection, up to length \e bufferSize. Returns the number of bytes read or -1 if an error occurs.
5053 int readBuffer(void *buffer
, long bufferSize
, int flags
= 0);
5055 //! Read a buffer via the specified socket. Returns the number of bytes read or -1 if an error occurs.
5056 static int readBuffer(int socket
, void *buffer
, long bufferSize
, int flags
);
5058 public: // SWAP formerly protected
5067 #endif // defined(__SOCKET_H)
5072 /***************************************************/
5074 \brief STK 3D vector class.
5076 This class implements a three-dimensional vector.
5078 by Perry R. Cook, 1995 - 2002.
5080 /***************************************************/
5082 #if !defined(__VECTOR3D_H)
5083 #define __VECTOR3D_H
5088 //! Default constructor taking optional initial X, Y, and Z values.
5089 Vector3D(double initX
=0.0, double initY
=0.0, double initZ
=0.0);
5091 //! Class destructor.
5094 //! Get the current X value.
5097 //! Get the current Y value.
5100 //! Get the current Z value.
5103 //! Calculate the vector length.
5106 //! Set the X, Y, and Z values simultaniously.
5107 void setXYZ(double anX
, double aY
, double aZ
);
5109 //! Set the X value.
5110 void setX(double aval
);
5112 //! Set the Y value.
5113 void setY(double aval
);
5115 //! Set the Z value.
5116 void setZ(double aval
);
5118 public: // SWAP formerly protected
5129 /***************************************************/
5131 \brief STK sphere class.
5133 This class implements a spherical ball with
5134 radius, mass, position, and velocity parameters.
5136 by Perry R. Cook, 1995 - 2002.
5138 /***************************************************/
5140 #if !defined(__SPHERE_H)
5147 //! Constructor taking an initial radius value.
5148 Sphere(double initRadius
);
5150 //! Class destructor.
5153 //! Set the 3D center position of the sphere.
5154 void setPosition(double anX
, double aY
, double aZ
);
5156 //! Set the 3D velocity of the sphere.
5157 void setVelocity(double anX
, double aY
, double aZ
);
5159 //! Set the radius of the sphere.
5160 void setRadius(double aRadius
);
5162 //! Set the mass of the sphere.
5163 void setMass(double aMass
);
5165 //! Get the current position of the sphere as a 3D vector.
5166 Vector3D
* getPosition();
5168 //! Get the relative position of the given point to the sphere as a 3D vector.
5169 Vector3D
* getRelativePosition(Vector3D
*aPosition
);
5171 //! Set the velcoity of the sphere as a 3D vector.
5172 double getVelocity(Vector3D
* aVelocity
);
5174 //! Returns the distance from the sphere boundary to the given position (< 0 if inside).
5175 double isInside(Vector3D
*aPosition
);
5177 //! Get the current sphere radius.
5180 //! Get the current sphere mass.
5183 //! Increase the current sphere velocity by the given 3D components.
5184 void addVelocity(double anX
, double aY
, double aZ
);
5186 //! Move the sphere for the given time increment.
5187 void tick(double timeIncrement
);
5189 public: // SWAP formerly private
5190 Vector3D
*myPosition
;
5191 Vector3D
*myVelocity
;
5192 Vector3D workingVector
;
5202 /***************************************************/
5204 \brief STK plucked stiff string instrument.
5206 This class implements a simple plucked string
5207 algorithm (Karplus Strong) with enhancements
5208 (Jaffe-Smith, Smith, and others), including
5209 string stiffness and pluck position controls.
5210 The stiffness is modeled with allpass filters.
5212 This is a digital waveguide model, making its
5213 use possibly subject to patents held by
5214 Stanford University, Yamaha, and others.
5216 Control Change Numbers:
5217 - Pickup Position = 4
5218 - String Sustain = 11
5219 - String Stretch = 1
5221 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
5223 /***************************************************/
5225 #if !defined(__StifKarp_h)
5226 #define __StifKarp_h
5229 class StifKarp
: public Instrmnt
5232 //! Class constructor, taking the lowest desired playing frequency.
5233 StifKarp(MY_FLOAT lowestFrequency
);
5235 //! Class destructor.
5238 //! Reset and clear all internal state.
5241 //! Set instrument parameters for a particular frequency.
5242 void setFrequency(MY_FLOAT frequency
);
5244 //! Set the stretch "factor" of the string (0.0 - 1.0).
5245 void setStretch(MY_FLOAT stretch
);
5247 //! Set the pluck or "excitation" position along the string (0.0 - 1.0).
5248 void setPickupPosition(MY_FLOAT position
);
5250 //! Set the base loop gain.
5252 The actual loop gain is set according to the frequency.
5253 Because of high-frequency loop filter roll-off, higher
5254 frequency settings have greater loop gains.
5256 void setBaseLoopGain(MY_FLOAT aGain
);
5258 //! Pluck the string with the given amplitude using the current frequency.
5259 void pluck(MY_FLOAT amplitude
);
5261 //! Start a note with the given frequency and amplitude.
5262 void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
5264 //! Stop a note with the given amplitude (speed of decay).
5265 void noteOff(MY_FLOAT amplitude
);
5267 //! Compute one output sample.
5270 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
5271 void controlChange(int number
, MY_FLOAT value
);
5273 public: // SWAP formerly protected
5275 t_CKFLOAT m_sustain
;
5284 MY_FLOAT baseLoopGain
;
5285 MY_FLOAT lastFrequency
;
5286 MY_FLOAT lastLength
;
5287 MY_FLOAT stretching
;
5288 MY_FLOAT pluckAmplitude
;
5289 MY_FLOAT pickupPosition
;
5298 /***************************************************/
5300 \brief STK table lookup class.
5302 This class loads a table of floating-point
5303 doubles, which are assumed to be in big-endian
5304 format. Linear interpolation is performed for
5305 fractional lookup indexes.
5307 An StkError will be thrown if the table file
5310 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
5312 /***************************************************/
5314 #if !defined(__TABLE_H)
5318 class Table
: public Stk
5321 //! Constructor loads the data from \e fileName.
5322 Table(char *fileName
);
5324 //! Class destructor.
5327 //! Return the number of elements in the table.
5328 long getLength() const;
5330 //! Return the last output value.
5331 MY_FLOAT
lastOut() const;
5333 //! Return the table value at position \e index.
5335 Linear interpolation is performed if \e index is
5338 MY_FLOAT
tick(MY_FLOAT index
);
5340 //! Take \e vectorSize index positions and return the corresponding table values in \e vector.
5341 MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
5343 public: // SWAP formerly protected
5346 MY_FLOAT lastOutput
;
5350 #endif // defined(__TABLE_H)
5355 /***************************************************/
5357 \brief STK audio data output base class.
5359 This class provides output support for various
5360 audio file formats. It also serves as a base
5361 class for "realtime" streaming subclasses.
5363 WvOut writes samples to an audio file. It
5364 supports multi-channel data in interleaved
5365 format. It is important to distinguish the
5366 tick() methods, which output single samples
5367 to all channels in a sample frame, from the
5368 tickFrame() method, which takes a pointer
5369 to multi-channel sample frame data.
5371 WvOut currently supports WAV, AIFF, AIFC, SND
5372 (AU), MAT-file (Matlab), and STK RAW file
5373 formats. Signed integer (8-, 16-, and 32-bit)
5374 and floating- point (32- and 64-bit) data types
5375 are supported. STK RAW files use 16-bit
5376 integers by definition. MAT-files will always
5377 be written as 64-bit floats. If a data type
5378 specification does not match the specified file
5379 type, the data type will automatically be
5380 modified. Uncompressed data types are not
5383 Currently, WvOut is non-interpolating and the
5384 output rate is always Stk::sampleRate().
5386 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
5388 /***************************************************/
5390 #if !defined(__WVOUT_H)
5395 #define BUFFER_SIZE 1024 // sample frames
5397 class WvOut
: public Stk
5401 typedef unsigned long FILE_TYPE
;
5403 static const FILE_TYPE WVOUT_RAW
; /*!< STK RAW file type. */
5404 static const FILE_TYPE WVOUT_WAV
; /*!< WAV file type. */
5405 static const FILE_TYPE WVOUT_SND
; /*!< SND (AU) file type. */
5406 static const FILE_TYPE WVOUT_AIF
; /*!< AIFF file type. */
5407 static const FILE_TYPE WVOUT_MAT
; /*!< Matlab MAT-file type. */
5409 //! Default constructor.
5412 //! Overloaded constructor used to specify a file name, type, and data format with this object.
5414 An StkError is thrown for invalid argument values or if an error occurs when initializing the output file.
5416 WvOut( const char *fileName
, unsigned int nChannels
= 1, FILE_TYPE type
= WVOUT_WAV
, Stk::STK_FORMAT format
= STK_SINT16
);
5418 //! Class destructor.
5421 //! Create a file of the specified type and name and output samples to it in the given data format.
5423 An StkError is thrown for invalid argument values or if an error occurs when initializing the output file.
5425 void openFile( const char *fileName
, unsigned int nChannels
= 1, \
5426 WvOut::FILE_TYPE type
= WVOUT_WAV
, Stk::STK_FORMAT
= STK_SINT16
);
5427 //! If a file is open, write out samples in the queue and then close it.
5428 void closeFile( void );
5430 //! Return the number of sample frames output.
5431 unsigned long getFrames( void ) const;
5433 //! Return the number of seconds of data output.
5434 MY_FLOAT
getTime( void ) const;
5436 //! Output a single sample to all channels in a sample frame.
5438 An StkError is thrown if a file write error occurs.
5440 virtual void tick(const MY_FLOAT sample
);
5442 //! Output each sample in \e vector to all channels in \e vectorSize sample frames.
5444 An StkError is thrown if a file write error occurs.
5446 virtual void tick(const MY_FLOAT
*vector
, unsigned int vectorSize
);
5448 //! Output the \e frameVector of sample frames of the given length.
5450 An StkError is thrown if a file write error occurs.
5452 virtual void tickFrame(const MY_FLOAT
*frameVector
, unsigned int frames
= 1);
5454 public: // SWAP formerly protected
5456 // Initialize class variables.
5459 // Write data to output file;
5460 virtual void writeData( unsigned long frames
);
5462 // Write STK RAW file header.
5463 bool setRawFile( const char *fileName
);
5465 // Write WAV file header.
5466 bool setWavFile( const char *fileName
);
5468 // Close WAV file, updating the header.
5469 void closeWavFile( void );
5471 // Write SND (AU) file header.
5472 bool setSndFile( const char *fileName
);
5474 // Close SND file, updating the header.
5475 void closeSndFile( void );
5477 // Write AIFF file header.
5478 bool setAifFile( const char *fileName
);
5480 // Close AIFF file, updating the header.
5481 void closeAifFile( void );
5483 // Write MAT-file header.
5484 bool setMatFile( const char *fileName
);
5486 // Close MAT-file, updating the header.
5487 void closeMatFile( void );
5493 STK_FORMAT dataType
;
5495 unsigned int channels
;
5496 unsigned long counter
;
5497 unsigned long totalCount
;
5498 // char m_filename[1024];
5499 Chuck_String str_filename
;
5501 // char autoPrefix[1024];
5502 Chuck_String autoPrefix
;
5506 #endif // defined(__WVOUT_H)
5511 /***************************************************/
5513 \brief STK tubular bell (orchestral chime) FM
5514 synthesis instrument.
5516 This class implements two simple FM Pairs
5517 summed together, also referred to as algorithm
5521 Algorithm 5 is : 4->3--\
5526 Control Change Numbers:
5527 - Modulator Index One = 2
5528 - Crossfade of Outputs = 4
5531 - ADSR 2 & 4 Target = 128
5533 The basic Chowning/Stanford FM patent expired
5534 in 1995, but there exist follow-on patents,
5535 mostly assigned to Yamaha. If you are of the
5536 type who should worry about this (making
5539 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
5541 /***************************************************/
5543 #if !defined(__TUBEBELL_H)
5544 #define __TUBEBELL_H
5547 class TubeBell
: public FM
5550 //! Class constructor.
5553 //! Class destructor.
5556 //! Start a note with the given frequency and amplitude.
5557 void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
5558 void noteOn( MY_FLOAT amplitude
) { noteOn(baseFrequency
, amplitude
); }
5560 //! Compute one output sample.
5569 /***************************************************/
5571 \brief STK two-pole filter class.
5573 This protected Filter subclass implements
5574 a two-pole digital filter. A method is
5575 provided for creating a resonance in the
5576 frequency response while maintaining a nearly
5577 constant filter gain.
5579 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
5581 /***************************************************/
5583 #if !defined(__TWOPOLE_H)
5587 class TwoPole
: public FilterStk
// formerly protected Filter
5591 //! Default constructor creates a second-order pass-through filter.
5594 //! Class destructor.
5597 //! Clears the internal states of the filter.
5600 //! Set the b[0] coefficient value.
5601 void setB0(MY_FLOAT b0
);
5603 //! Set the a[1] coefficient value.
5604 void setA1(MY_FLOAT a1
);
5606 //! Set the a[2] coefficient value.
5607 void setA2(MY_FLOAT a2
);
5609 //! Sets the filter coefficients for a resonance at \e frequency (in Hz).
5611 This method determines the filter coefficients corresponding to
5612 two complex-conjugate poles with the given \e frequency (in Hz)
5613 and \e radius from the z-plane origin. If \e normalize is true,
5614 the coefficients are then normalized to produce unity gain at \e
5615 frequency (the actual maximum filter gain tends to be slightly
5616 greater than unity when \e radius is not close to one). The
5617 resulting filter frequency response has a resonance at the given
5618 \e frequency. The closer the poles are to the unit-circle (\e
5619 radius close to one), the narrower the resulting resonance width.
5620 An unstable filter will result for \e radius >= 1.0. For a better
5621 resonance filter, use a BiQuad filter. \sa BiQuad filter class
5623 void setResonance(MY_FLOAT frequency
, MY_FLOAT radius
, bool normalize
= FALSE
);
5629 void ck_setResNorm( bool n
) { m_resNorm
= n
; setResonance(m_resFreq
, m_resRad
, m_resNorm
); }
5630 void ck_setResFreq( MY_FLOAT n
) { m_resFreq
= n
; setResonance(m_resFreq
, m_resRad
, m_resNorm
); }
5631 void ck_setResRad( MY_FLOAT n
) { m_resRad
= n
; setResonance(m_resFreq
, m_resRad
, m_resNorm
); }
5632 //! Set the filter gain.
5634 The gain is applied at the filter input and does not affect the
5635 coefficient values. The default gain value is 1.0.
5637 void setGain(MY_FLOAT theGain
);
5639 //! Return the current filter gain.
5640 MY_FLOAT
getGain(void) const;
5642 //! Return the last computed output value.
5643 MY_FLOAT
lastOut(void) const;
5645 //! Input one sample to the filter and return one output.
5646 MY_FLOAT
tick(MY_FLOAT sample
);
5648 //! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
5649 MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
5657 /***************************************************/
5659 \brief Four formant synthesis instrument.
5661 This instrument contains an excitation singing
5662 wavetable (looping wave with random and
5663 periodic vibrato, smoothing on frequency,
5664 etc.), excitation noise, and four sweepable
5667 Measured formant data is included, and enough
5668 data is there to support either parallel or
5669 cascade synthesis. In the floating point case
5670 cascade synthesis is the most natural so
5671 that's what you'll find here.
5673 Control Change Numbers:
5674 - Voiced/Unvoiced Mix = 2
5675 - Vowel/Phoneme Selection = 4
5676 - Vibrato Frequency = 11
5678 - Loudness (Spectral Tilt) = 128
5680 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
5682 /***************************************************/
5683 #if !defined(__VOICFORM_H)
5684 #define __VOICFORM_H
5687 class VoicForm
: public Instrmnt
5690 //! Class constructor, taking the lowest desired playing frequency.
5693 //! Class destructor.
5696 //! Reset and clear all internal state.
5699 //! Set instrument parameters for a particular frequency.
5700 void setFrequency(MY_FLOAT frequency
);
5702 //! Set instrument parameters for the given phoneme. Returns FALSE if phoneme not found.
5703 bool setPhoneme(const char* phoneme
);
5705 //! Set the voiced component gain.
5706 void setVoiced(MY_FLOAT vGain
);
5708 //! Set the unvoiced component gain.
5709 void setUnVoiced(MY_FLOAT nGain
);
5711 //! Set the sweep rate for a particular formant filter (0-3).
5712 void setFilterSweepRate(int whichOne
, MY_FLOAT rate
);
5714 //! Set voiced component pitch sweep rate.
5715 void setPitchSweepRate(MY_FLOAT rate
);
5717 //! Start the voice.
5723 //! Start a note with the given frequency and amplitude.
5724 void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
5725 //! start at current frequency..
5726 void noteOn( MY_FLOAT amplitude
);
5728 //! Stop a note with the given amplitude (speed of decay).
5729 void noteOff(MY_FLOAT amplitude
);
5731 //! Compute one output sample.
5734 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
5735 void controlChange(int number
, MY_FLOAT value
);
5737 public: // SWAP formerly protected
5742 FormSwep
*filters
[4];
5745 Chuck_String str_phoneme
; // chuck data
5753 /***************************************************/
5755 \brief STK voice manager class.
5757 This class can be used to manage a group of
5758 STK instrument classes. Individual voices can
5759 be controlled via unique note tags.
5760 Instrument groups can be controlled by channel
5763 A previously constructed STK instrument class
5764 is linked with a voice manager using the
5765 addInstrument() function. An optional channel
5766 number argument can be specified to the
5767 addInstrument() function as well (default
5768 channel = 0). The voice manager does not
5769 delete any instrument instances ... it is the
5770 responsibility of the user to allocate and
5771 deallocate all instruments.
5773 The tick() function returns the mix of all
5774 sounding voices. Each noteOn returns a unique
5775 tag (credits to the NeXT MusicKit), so you can
5776 send control changes to specific voices within
5777 an ensemble. Alternately, control changes can
5778 be sent to all voices on a given channel.
5780 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
5782 /***************************************************/
5784 #if !defined(__VOICER_H)
5788 class Voicer
: public Stk
5791 //! Class constructor taking the maximum number of instruments to control and an optional note decay time (in seconds).
5792 Voicer( int maxInstruments
, MY_FLOAT decayTime
=0.2 );
5794 //! Class destructor.
5797 //! Add an instrument with an optional channel number to the voice manager.
5799 A set of instruments can be grouped by channel number and
5800 controlled via the functions which take a channel number argument.
5802 void addInstrument( Instrmnt
*instrument
, int channel
=0 );
5804 //! Remove the given instrument pointer from the voice manager's control.
5806 It is important that any instruments which are to be deleted by
5807 the user while the voice manager is running be first removed from
5808 the manager's control via this function!!
5810 void removeInstrument( Instrmnt
*instrument
);
5812 //! Initiate a noteOn event with the given note number and amplitude and return a unique note tag.
5814 Send the noteOn message to the first available unused voice.
5815 If all voices are sounding, the oldest voice is interrupted and
5816 sent the noteOn message. If the optional channel argument is
5817 non-zero, only voices on that channel are used. If no voices are
5818 found for a specified non-zero channel value, the function returns
5819 -1. The amplitude value should be in the range 0.0 - 128.0.
5821 long noteOn( MY_FLOAT noteNumber
, MY_FLOAT amplitude
, int channel
=0 );
5823 //! Send a noteOff to all voices having the given noteNumber and optional channel (default channel = 0).
5825 The amplitude value should be in the range 0.0 - 128.0.
5827 void noteOff( MY_FLOAT noteNumber
, MY_FLOAT amplitude
, int channel
=0 );
5829 //! Send a noteOff to the voice with the given note tag.
5831 The amplitude value should be in the range 0.0 - 128.0.
5833 void noteOff( long tag
, MY_FLOAT amplitude
);
5835 //! Send a frequency update message to all voices assigned to the optional channel argument (default channel = 0).
5837 The \e noteNumber argument corresponds to a MIDI note number, though it is a floating-point value and can range beyond the normal 0-127 range.
5839 void setFrequency( MY_FLOAT noteNumber
, int channel
=0 );
5841 //! Send a frequency update message to the voice with the given note tag.
5843 The \e noteNumber argument corresponds to a MIDI note number, though it is a floating-point value and can range beyond the normal 0-127 range.
5845 void setFrequency( long tag
, MY_FLOAT noteNumber
);
5847 //! Send a pitchBend message to all voices assigned to the optional channel argument (default channel = 0).
5848 void pitchBend( MY_FLOAT value
, int channel
=0 );
5850 //! Send a pitchBend message to the voice with the given note tag.
5851 void pitchBend( long tag
, MY_FLOAT value
);
5853 //! Send a controlChange to all instruments assigned to the optional channel argument (default channel = 0).
5854 void controlChange( int number
, MY_FLOAT value
, int channel
=0 );
5856 //! Send a controlChange to the voice with the given note tag.
5857 void controlChange( long tag
, int number
, MY_FLOAT value
);
5859 //! Send a noteOff message to all existing voices.
5860 void silence( void );
5862 //! Mix the output for all sounding voices.
5865 //! Compute \e vectorSize output mixes and return them in \e vector.
5866 MY_FLOAT
*tick(MY_FLOAT
*vector
, unsigned int vectorSize
);
5868 //! Return the last output value.
5869 MY_FLOAT
lastOut() const;
5871 //! Return the last left output value.
5872 MY_FLOAT
lastOutLeft() const;
5874 //! Return the last right output value.
5875 MY_FLOAT
lastOutRight() const;
5877 public: // SWAP formerly protected
5880 Instrmnt
*instrument
;
5882 MY_FLOAT noteNumber
;
5893 MY_FLOAT lastOutput
;
5894 MY_FLOAT lastOutputLeft
;
5895 MY_FLOAT lastOutputRight
;
5903 /***************************************************/
5905 \brief STK police/referee whistle instrument class.
5907 This class implements a hybrid physical/spectral
5908 model of a police whistle (a la Cook).
5910 Control Change Numbers:
5912 - Fipple Modulation Frequency = 11
5913 - Fipple Modulation Gain = 1
5914 - Blowing Frequency Modulation = 2
5917 by Perry R. Cook 1996 - 2002.
5919 /***************************************************/
5921 #if !defined(__WHISTLE_H)
5925 class Whistle
: public Instrmnt
5928 //! Class constructor.
5931 //! Class destructor.
5934 //! Reset and clear all internal state.
5937 //! Set instrument parameters for a particular frequency.
5938 void setFrequency(MY_FLOAT frequency
);
5940 //! Apply breath velocity to instrument with given amplitude and rate of increase.
5941 void startBlowing(MY_FLOAT amplitude
, MY_FLOAT rate
);
5943 //! Decrease breath velocity with given rate of decrease.
5944 void stopBlowing(MY_FLOAT rate
);
5946 //! Start a note with the given frequency and amplitude.
5947 void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
5949 //! Stop a note with the given amplitude (speed of decay).
5950 void noteOff(MY_FLOAT amplitude
);
5952 //! Compute one output sample.
5955 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
5956 void controlChange(int number
, MY_FLOAT value
);
5958 public: // SWAP formerly protected
5959 Vector3D
*tempVectorP
;
5960 Vector3D
*tempVector
;
5964 Sphere
*can
; // Declare a Spherical "can".
5965 Sphere
*pea
, *bumper
; // One spherical "pea", and a spherical "bumper".
5969 MY_FLOAT baseFrequency
;
5970 MY_FLOAT maxPressure
;
5972 MY_FLOAT fippleFreqMod
;
5973 MY_FLOAT fippleGainMod
;
5974 MY_FLOAT blowFreqMod
;
5977 int subSample
, subSampCount
;
5985 /***************************************************/
5987 \brief STK Wurlitzer electric piano FM
5988 synthesis instrument.
5990 This class implements two simple FM Pairs
5991 summed together, also referred to as algorithm
5995 Algorithm 5 is : 4->3--\
6000 Control Change Numbers:
6001 - Modulator Index One = 2
6002 - Crossfade of Outputs = 4
6005 - ADSR 2 & 4 Target = 128
6007 The basic Chowning/Stanford FM patent expired
6008 in 1995, but there exist follow-on patents,
6009 mostly assigned to Yamaha. If you are of the
6010 type who should worry about this (making
6013 by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
6015 /***************************************************/
6017 #if !defined(__WURLEY_H)
6021 class Wurley
: public FM
6024 //! Class constructor.
6027 //! Class destructor.
6030 //! Set instrument parameters for a particular frequency.
6031 void setFrequency(MY_FLOAT frequency
);
6033 //! Start a note with the given frequency and amplitude.
6034 void noteOn(MY_FLOAT frequency
, MY_FLOAT amplitude
);
6035 void noteOn(MY_FLOAT amplitude
) { noteOn ( baseFrequency
, amplitude
); }
6038 virtual void controlChange( int which
, MY_FLOAT value
);
6040 //! Compute one output sample.
6049 /***************************************************/
6051 \brief STK band-limited impulse train class.
6053 This class generates a band-limited impulse train using a
6054 closed-form algorithm reported by Stilson and Smith in "Alias-Free
6055 Digital Synthesis of Classic Analog Waveforms", 1996. The user
6056 can specify both the fundamental frequency of the impulse train
6057 and the number of harmonics contained in the resulting signal.
6059 The signal is normalized so that the peak value is +/-1.0.
6061 If nHarmonics is 0, then the signal will contain all harmonics up
6062 to half the sample rate. Note, however, that this setting may
6063 produce aliasing in the signal when the frequency is changing (no
6064 automatic modification of the number of harmonics is performed by
6065 the setFrequency() function).
6067 Original code by Robin Davies, 2005.
6068 Revisions by Gary Scavone for STK, 2005.
6070 /***************************************************/
6077 virtual void setPhase( MY_FLOAT phase
) = 0;
6078 virtual void setFrequency( MY_FLOAT freq
) = 0;
6079 virtual void setHarmonics( unsigned int harmonics
) = 0;
6081 t_CKFLOAT
getValuePhase() { return m_phase
; }
6082 t_CKFLOAT
getValueFreq() { return m_freq
; }
6083 t_CKINT
getValueHarmonics() { return m_harmonics
; }
6088 t_CKINT m_harmonics
;
6095 class Blit
: public BLT
6098 //! Default constructor that initializes BLIT frequency to 220 Hz.
6099 Blit( MY_FLOAT frequency
= 220.0 );
6101 //! Class destructor.
6104 //! Resets the oscillator state and phase to 0.
6107 //! Set the phase of the signal.
6109 Set the phase of the signal, in the range 0 to 1.
6111 virtual void setPhase( MY_FLOAT phase
) { phase_
= ONE_PI
* phase
; }
6113 //! Get the current phase of the signal.
6115 Get the phase of the signal, in the range [0 to 1.0).
6117 MY_FLOAT
getPhase() const { return phase_
/ ONE_PI
; }
6119 //! Set the impulse train rate in terms of a frequency in Hz.
6120 virtual void setFrequency( MY_FLOAT frequency
);
6122 //! Set the number of harmonics generated in the signal.
6124 This function sets the number of harmonics contained in the
6125 resulting signal. It is equivalent to (2 * M) + 1 in the BLIT
6126 algorithm. The default value of 0 sets the algorithm for maximum
6127 harmonic content (harmonics up to half the sample rate). This
6128 parameter is not checked against the current sample rate and
6129 fundamental frequency. Thus, aliasing can result if one or more
6130 harmonics for a given fundamental frequency exceeds fs / 2. This
6131 behavior was chosen over the potentially more problematic solution
6132 of automatically modifying the M parameter, which can produce
6133 audible clicks in the signal.
6135 virtual void setHarmonics( unsigned int nHarmonics
= 0 );
6137 //! Compute one output sample.
6142 void updateHarmonics( void );
6143 MY_FLOAT
computeSample( void );
6145 unsigned int nHarmonics_
;
6158 /***************************************************/
6160 \brief STK band-limited sawtooth wave class.
6162 This class generates a band-limited sawtooth waveform using a
6163 closed-form algorithm reported by Stilson and Smith in "Alias-Free
6164 Digital Synthesis of Classic Analog Waveforms", 1996. The user
6165 can specify both the fundamental frequency of the sawtooth and the
6166 number of harmonics contained in the resulting signal.
6168 If nHarmonics is 0, then the signal will contain all harmonics up
6169 to half the sample rate. Note, however, that this setting may
6170 produce aliasing in the signal when the frequency is changing (no
6171 automatic modification of the number of harmonics is performed by
6172 the setFrequency() function).
6174 Based on initial code of Robin Davies, 2005.
6175 Modified algorithm code by Gary Scavone, 2005.
6177 /***************************************************/
6179 #ifndef STK_BLITSAW_H
6180 #define STK_BLITSAW_H
6182 class BlitSaw
: public BLT
6185 //! Class constructor.
6186 BlitSaw( MY_FLOAT frequency
= 220.0 );
6188 //! Class destructor.
6191 //! Resets the oscillator state and phase to 0.
6194 //! Set the phase of the signal.
6196 Set the phase of the signal, in the range 0 to 1.
6198 virtual void setPhase( MY_FLOAT phase
) { phase_
= ONE_PI
* phase
; }
6200 //! Set the sawtooth oscillator rate in terms of a frequency in Hz.
6201 virtual void setFrequency( MY_FLOAT frequency
);
6203 //! Set the number of harmonics generated in the signal.
6205 This function sets the number of harmonics contained in the
6206 resulting signal. It is equivalent to (2 * M) + 1 in the BLIT
6207 algorithm. The default value of 0 sets the algorithm for maximum
6208 harmonic content (harmonics up to half the sample rate). This
6209 parameter is not checked against the current sample rate and
6210 fundamental frequency. Thus, aliasing can result if one or more
6211 harmonics for a given fundamental frequency exceeds fs / 2. This
6212 behavior was chosen over the potentially more problematic solution
6213 of automatically modifying the M parameter, which can produce
6214 audible clicks in the signal.
6216 virtual void setHarmonics( unsigned int nHarmonics
= 0 );
6218 //! Compute one output sample.
6223 void updateHarmonics( void );
6224 MY_FLOAT
computeSample( void );
6226 unsigned int nHarmonics_
;
6242 /***************************************************/
6243 /*! \class BlitSquare
6244 \brief STK band-limited square wave class.
6246 This class generates a band-limited square wave signal. It is
6247 derived in part from the approach reported by Stilson and Smith in
6248 "Alias-Free Digital Synthesis of Classic Analog Waveforms", 1996.
6249 The algorithm implemented in this class uses a SincM function with
6250 an even M value to achieve a bipolar bandlimited impulse train.
6251 This signal is then integrated to achieve a square waveform. The
6252 integration process has an associated DC offset but that is
6253 subtracted off the output signal.
6255 The user can specify both the fundamental frequency of the
6256 waveform and the number of harmonics contained in the resulting
6259 If nHarmonics is 0, then the signal will contain all harmonics up
6260 to half the sample rate. Note, however, that this setting may
6261 produce aliasing in the signal when the frequency is changing (no
6262 automatic modification of the number of harmonics is performed by
6263 the setFrequency() function).
6265 Based on initial code of Robin Davies, 2005.
6266 Modified algorithm code by Gary Scavone, 2005.
6268 /***************************************************/
6270 #ifndef STK_BLITSQUARE_H
6271 #define STK_BLITSQUARE_H
6273 class BlitSquare
: public BLT
6276 //! Default constructor that initializes BLIT frequency to 220 Hz.
6277 BlitSquare( MY_FLOAT frequency
= 220.0 );
6279 //! Class destructor.
6280 virtual ~BlitSquare();
6282 //! Resets the oscillator state and phase to 0.
6285 //! Set the phase of the signal.
6287 Set the phase of the signal, in the range 0 to 1.
6289 virtual void setPhase( MY_FLOAT phase
) { phase_
= ONE_PI
* phase
; }
6291 //! Get the current phase of the signal.
6293 Get the phase of the signal, in the range [0 to 1.0).
6295 MY_FLOAT
getPhase() const { return phase_
/ ONE_PI
; }
6297 //! Set the impulse train rate in terms of a frequency in Hz.
6298 virtual void setFrequency( MY_FLOAT frequency
);
6300 //! Set the number of harmonics generated in the signal.
6302 This function sets the number of harmonics contained in the
6303 resulting signal. It is equivalent to (2 * M) + 1 in the BLIT
6304 algorithm. The default value of 0 sets the algorithm for maximum
6305 harmonic content (harmonics up to half the sample rate). This
6306 parameter is not checked against the current sample rate and
6307 fundamental frequency. Thus, aliasing can result if one or more
6308 harmonics for a given fundamental frequency exceeds fs / 2. This
6309 behavior was chosen over the potentially more problematic solution
6310 of automatically modifying the M parameter, which can produce
6311 audible clicks in the signal.
6313 virtual void setHarmonics( unsigned int nHarmonics
= 0 );
6315 //! Compute one output sample.
6320 void updateHarmonics( void );
6321 MY_FLOAT
computeSample( void );
6323 unsigned int nHarmonics_
;
6340 /*********************************************************/
6342 Definition of SKINI Message Types and Special Symbols
6343 Synthesis toolKit Instrument Network Interface
6345 These symbols should have the form __SK_<name>_
6347 Where <name> is the string used in the SKINI stream.
6349 by Perry R. Cook, 1995 - 2002.
6351 /*********************************************************/
6353 /***** MIDI COMPATIBLE MESSAGES *****/
6354 /***** Status Bytes Have Channel=0 **/
6358 #define SK_DBL -32766
6359 #define SK_INT -32765
6360 #define SK_STR -32764
6362 #define __SK_NoteOff_ 128
6363 #define __SK_NoteOn_ 144
6364 #define __SK_PolyPressure_ 160
6365 #define __SK_ControlChange_ 176
6366 #define __SK_ProgramChange_ 192
6367 #define __SK_AfterTouch_ 208
6368 #define __SK_ChannelPressure_ __SK_AfterTouch_
6369 #define __SK_PitchWheel_ 224
6370 #define __SK_PitchBend_ __SK_PitchWheel_
6371 #define __SK_PitchChange_ 49
6373 #define __SK_Clock_ 248
6374 #define __SK_SongStart_ 250
6375 #define __SK_Continue_ 251
6376 #define __SK_SongStop_ 252
6377 #define __SK_ActiveSensing_ 254
6378 #define __SK_SystemReset_ 255
6380 #define __SK_Volume_ 7
6381 #define __SK_ModWheel_ 1
6382 #define __SK_Modulation_ __SK_ModWheel_
6383 #define __SK_Breath_ 2
6384 #define __SK_FootControl_ 4
6385 #define __SK_Portamento_ 65
6386 #define __SK_Balance_ 8
6387 #define __SK_Pan_ 10
6388 #define __SK_Sustain_ 64
6389 #define __SK_Damper_ __SK_Sustain_
6390 #define __SK_Expression_ 11
6392 #define __SK_AfterTouch_Cont_ 128
6393 #define __SK_ModFrequency_ __SK_Expression_
6395 #define __SK_ProphesyRibbon_ 16
6396 #define __SK_ProphesyWheelUp_ 2
6397 #define __SK_ProphesyWheelDown_ 3
6398 #define __SK_ProphesyPedal_ 18
6399 #define __SK_ProphesyKnob1_ 21
6400 #define __SK_ProphesyKnob2_ 22
6402 /*** Instrument Family Specific ***/
6404 #define __SK_NoiseLevel_ __SK_FootControl_
6406 #define __SK_PickPosition_ __SK_FootControl_
6407 #define __SK_StringDamping_ __SK_Expression_
6408 #define __SK_StringDetune_ __SK_ModWheel_
6409 #define __SK_BodySize_ __SK_Breath_
6410 #define __SK_BowPressure_ __SK_Breath_
6411 #define __SK_BowPosition_ __SK_PickPosition_
6412 #define __SK_BowBeta_ __SK_BowPosition_
6414 #define __SK_ReedStiffness_ __SK_Breath_
6415 #define __SK_ReedRestPos_ __SK_FootControl_
6417 #define __SK_FluteEmbouchure_ __SK_Breath_
6418 #define __SK_JetDelay_ __SK_FluteEmbouchure_
6420 #define __SK_LipTension_ __SK_Breath_
6421 #define __SK_SlideLength_ __SK_FootControl_
6423 #define __SK_StrikePosition_ __SK_PickPosition_
6424 #define __SK_StickHardness_ __SK_Breath_
6426 #define __SK_TrillDepth_ 1051
6427 #define __SK_TrillSpeed_ 1052
6428 #define __SK_StrumSpeed_ __SK_TrillSpeed_
6429 #define __SK_RollSpeed_ __SK_TrillSpeed_
6431 #define __SK_FilterQ_ __SK_Breath_
6432 #define __SK_FilterFreq_ 1062
6433 #define __SK_FilterSweepRate_ __SK_FootControl_
6435 #define __SK_ShakerInst_ 1071
6436 #define __SK_ShakerEnergy_ __SK_Breath_
6437 #define __SK_ShakerDamping_ __SK_ModFrequency_
6438 #define __SK_ShakerNumObjects_ __SK_FootControl_
6440 #define __SK_Strumming_ 1090
6441 #define __SK_NotStrumming_ 1091
6442 #define __SK_Trilling_ 1092
6443 #define __SK_NotTrilling_ 1093
6444 #define __SK_Rolling_ __SK_Strumming_
6445 #define __SK_NotRolling_ __SK_NotStrumming_
6447 #define __SK_PlayerSkill_ 2001
6448 #define __SK_Chord_ 2002
6449 #define __SK_ChordOff_ 2003
6451 #define __SK_SINGER_FilePath_ 3000
6452 #define __SK_SINGER_Frequency_ 3001
6453 #define __SK_SINGER_NoteName_ 3002
6454 #define __SK_SINGER_Shape_ 3003
6455 #define __SK_SINGER_Glot_ 3004
6456 #define __SK_SINGER_VoicedUnVoiced_ 3005
6457 #define __SK_SINGER_Synthesize_ 3006
6458 #define __SK_SINGER_Silence_ 3007
6459 #define __SK_SINGER_VibratoAmt_ __SK_ModWheel_
6460 #define __SK_SINGER_RndVibAmt_ 3008
6461 #define __SK_SINGER_VibFreq_ __SK_Expression_
6464 #define __SK_MaxMsgTypes_ 128