Audio plugin host https://kx.studio/carla
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.

169 lines
4.7KB

  1. #ifndef STK_SHAKERS_H
  2. #define STK_SHAKERS_H
  3. #include "Instrmnt.h"
  4. namespace stk {
  5. /***************************************************/
  6. /*! \class Shakers
  7. \brief PhISEM and PhOLIES class.
  8. PhISEM (Physically Informed Stochastic Event
  9. Modeling) is an algorithmic approach for
  10. simulating collisions of multiple independent
  11. sound producing objects. This class is a
  12. meta-model that can simulate a Maraca, Sekere,
  13. Cabasa, Bamboo Wind Chimes, Water Drops,
  14. Tambourine, Sleighbells, and a Guiro.
  15. PhOLIES (Physically-Oriented Library of
  16. Imitated Environmental Sounds) is a similar
  17. approach for the synthesis of environmental
  18. sounds. This class implements simulations of
  19. breaking sticks, crunchy snow (or not), a
  20. wrench, sandpaper, and more.
  21. Control Change Numbers:
  22. - Shake Energy = 2
  23. - System Decay = 4
  24. - Number Of Objects = 11
  25. - Resonance Frequency = 1
  26. - Shake Energy = 128
  27. - Instrument Selection = 1071
  28. - Maraca = 0
  29. - Cabasa = 1
  30. - Sekere = 2
  31. - Guiro = 3
  32. - Water Drops = 4
  33. - Bamboo Chimes = 5
  34. - Tambourine = 6
  35. - Sleigh Bells = 7
  36. - Sticks = 8
  37. - Crunch = 9
  38. - Wrench = 10
  39. - Sand Paper = 11
  40. - Coke Can = 12
  41. - Next Mug = 13
  42. - Penny + Mug = 14
  43. - Nickle + Mug = 15
  44. - Dime + Mug = 16
  45. - Quarter + Mug = 17
  46. - Franc + Mug = 18
  47. - Peso + Mug = 19
  48. - Big Rocks = 20
  49. - Little Rocks = 21
  50. - Tuned Bamboo Chimes = 22
  51. by Perry R. Cook, 1995-2011.
  52. */
  53. /***************************************************/
  54. const int MAX_FREQS = 8;
  55. const int NUM_INSTR = 24;
  56. class Shakers : public Instrmnt
  57. {
  58. public:
  59. //! Class constructor.
  60. Shakers( void );
  61. //! Class destructor.
  62. ~Shakers( void );
  63. //! Start a note with the given instrument and amplitude.
  64. /*!
  65. Use the instrument numbers above, converted to frequency values
  66. as if MIDI note numbers, to select a particular instrument.
  67. */
  68. void noteOn( StkFloat instrument, StkFloat amplitude );
  69. //! Stop a note with the given amplitude (speed of decay).
  70. void noteOff( StkFloat amplitude );
  71. //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
  72. void controlChange( int number, StkFloat value );
  73. //! Compute and return one output sample.
  74. StkFloat tick( unsigned int channel = 0 );
  75. //! Fill a channel of the StkFrames object with computed outputs.
  76. /*!
  77. The \c channel argument must be less than the number of
  78. channels in the StkFrames argument (the first channel is specified
  79. by 0). However, range checking is only performed if _STK_DEBUG_
  80. is defined during compilation, in which case an out-of-range value
  81. will trigger an StkError exception.
  82. */
  83. StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
  84. protected:
  85. int setupName( char* instr );
  86. int setupNum( int inst );
  87. int setFreqAndReson( int which, StkFloat freq, StkFloat reson );
  88. void setDecays( StkFloat sndDecay, StkFloat sysDecay );
  89. void setFinalZs( StkFloat z0, StkFloat z1, StkFloat z2 );
  90. StkFloat wuter_tick( void );
  91. StkFloat tbamb_tick( void );
  92. StkFloat ratchet_tick( void );
  93. int instType_;
  94. int ratchetPos_, lastRatchetPos_;
  95. StkFloat shakeEnergy_;
  96. StkFloat inputs_[MAX_FREQS];
  97. StkFloat outputs_[MAX_FREQS][2];
  98. StkFloat coeffs_[MAX_FREQS][2];
  99. StkFloat sndLevel_;
  100. StkFloat baseGain_;
  101. StkFloat gains_[MAX_FREQS];
  102. int nFreqs_;
  103. StkFloat t_center_freqs_[MAX_FREQS];
  104. StkFloat center_freqs_[MAX_FREQS];
  105. StkFloat resons_[MAX_FREQS];
  106. StkFloat freq_rand_[MAX_FREQS];
  107. int freqalloc_[MAX_FREQS];
  108. StkFloat soundDecay_;
  109. StkFloat systemDecay_;
  110. StkFloat nObjects_;
  111. StkFloat totalEnergy_;
  112. StkFloat ratchet_, ratchetDelta_;
  113. StkFloat finalZ_[3];
  114. StkFloat finalZCoeffs_[3];
  115. StkFloat defObjs_[NUM_INSTR];
  116. StkFloat defDecays_[NUM_INSTR];
  117. StkFloat decayScale_[NUM_INSTR];
  118. };
  119. inline StkFrames& Shakers :: tick( StkFrames& frames, unsigned int channel )
  120. {
  121. unsigned int nChannels = lastFrame_.channels();
  122. #if defined(_STK_DEBUG_)
  123. if ( channel > frames.channels() - nChannels ) {
  124. oStream_ << "Shakers::tick(): channel and StkFrames arguments are incompatible!";
  125. handleError( StkError::FUNCTION_ARGUMENT );
  126. }
  127. #endif
  128. StkFloat *samples = &frames[channel];
  129. unsigned int j, hop = frames.channels() - nChannels;
  130. if ( nChannels == 1 ) {
  131. for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
  132. *samples++ = tick();
  133. }
  134. else {
  135. for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
  136. *samples++ = tick();
  137. for ( j=1; j<nChannels; j++ )
  138. *samples++ = lastFrame_[j];
  139. }
  140. }
  141. return frames;
  142. }
  143. } // stk namespace
  144. #endif