You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
4.2KB

  1. #ifndef STK_BANDEDWG_H
  2. #define STK_BANDEDWG_H
  3. #include "Instrmnt.h"
  4. #include "DelayL.h"
  5. #include "BowTable.h"
  6. #include "ADSR.h"
  7. #include "BiQuad.h"
  8. namespace stk {
  9. /***************************************************/
  10. /*! \class BandedWG
  11. \brief Banded waveguide modeling class.
  12. This class uses banded waveguide techniques to
  13. model a variety of sounds, including bowed
  14. bars, glasses, and bowls. For more
  15. information, see Essl, G. and Cook, P. "Banded
  16. Waveguides: Towards Physical Modelling of Bar
  17. Percussion Instruments", Proceedings of the
  18. 1999 International Computer Music Conference.
  19. Control Change Numbers:
  20. - Bow Pressure = 2
  21. - Bow Motion = 4
  22. - Strike Position = 8 (not implemented)
  23. - Vibrato Frequency = 11
  24. - Gain = 1
  25. - Bow Velocity = 128
  26. - Set Striking = 64
  27. - Instrument Presets = 16
  28. - Uniform Bar = 0
  29. - Tuned Bar = 1
  30. - Glass Harmonica = 2
  31. - Tibetan Bowl = 3
  32. by Georg Essl, 1999 - 2004.
  33. Modified for STK 4.0 by Gary Scavone.
  34. */
  35. /***************************************************/
  36. const int MAX_BANDED_MODES = 20;
  37. class BandedWG : public Instrmnt
  38. {
  39. public:
  40. //! Class constructor.
  41. BandedWG( void );
  42. //! Class destructor.
  43. ~BandedWG( void );
  44. //! Reset and clear all internal state.
  45. void clear( void );
  46. //! Set strike position (0.0 - 1.0).
  47. void setStrikePosition( StkFloat position );
  48. //! Select a preset.
  49. void setPreset( int preset );
  50. //! Set instrument parameters for a particular frequency.
  51. void setFrequency( StkFloat frequency );
  52. //! Apply bow velocity/pressure to instrument with given amplitude and rate of increase.
  53. void startBowing( StkFloat amplitude, StkFloat rate );
  54. //! Decrease bow velocity/breath pressure with given rate of decrease.
  55. void stopBowing( StkFloat rate );
  56. //! Pluck the instrument with given amplitude.
  57. void pluck( StkFloat amp );
  58. //! Start a note with the given frequency and amplitude.
  59. void noteOn( StkFloat frequency, StkFloat amplitude );
  60. //! Stop a note with the given amplitude (speed of decay).
  61. void noteOff( StkFloat amplitude );
  62. //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
  63. void controlChange( int number, StkFloat value );
  64. //! Compute and return one output sample.
  65. StkFloat tick( unsigned int channel = 0 );
  66. //! Fill a channel of the StkFrames object with computed outputs.
  67. /*!
  68. The \c channel argument must be less than the number of
  69. channels in the StkFrames argument (the first channel is specified
  70. by 0). However, range checking is only performed if _STK_DEBUG_
  71. is defined during compilation, in which case an out-of-range value
  72. will trigger an StkError exception.
  73. */
  74. StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
  75. protected:
  76. bool doPluck_;
  77. bool trackVelocity_;
  78. int nModes_;
  79. int presetModes_;
  80. BowTable bowTable_;
  81. ADSR adsr_;
  82. BiQuad bandpass_[MAX_BANDED_MODES];
  83. DelayL delay_[MAX_BANDED_MODES];
  84. StkFloat maxVelocity_;
  85. StkFloat modes_[MAX_BANDED_MODES];
  86. StkFloat frequency_;
  87. StkFloat baseGain_;
  88. StkFloat gains_[MAX_BANDED_MODES];
  89. StkFloat basegains_[MAX_BANDED_MODES];
  90. StkFloat excitation_[MAX_BANDED_MODES];
  91. StkFloat integrationConstant_;
  92. StkFloat velocityInput_;
  93. StkFloat bowVelocity_;
  94. StkFloat bowTarget_;
  95. StkFloat bowPosition_;
  96. StkFloat strikeAmp_;
  97. int strikePosition_;
  98. };
  99. inline StkFrames& BandedWG :: tick( StkFrames& frames, unsigned int channel )
  100. {
  101. unsigned int nChannels = lastFrame_.channels();
  102. #if defined(_STK_DEBUG_)
  103. if ( channel > frames.channels() - nChannels ) {
  104. oStream_ << "BandedWG::tick(): channel and StkFrames arguments are incompatible!";
  105. handleError( StkError::FUNCTION_ARGUMENT );
  106. }
  107. #endif
  108. StkFloat *samples = &frames[channel];
  109. unsigned int j, hop = frames.channels() - nChannels;
  110. if ( nChannels == 1 ) {
  111. for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
  112. *samples++ = tick();
  113. }
  114. else {
  115. for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
  116. *samples++ = tick();
  117. for ( j=1; j<nChannels; j++ )
  118. *samples++ = lastFrame_[j];
  119. }
  120. }
  121. return frames;
  122. }
  123. } // stk namespace
  124. #endif