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.

144 lines
4.1KB

  1. #ifndef STK_MANDOLIN_H
  2. #define STK_MANDOLIN_H
  3. #include "Instrmnt.h"
  4. #include "Twang.h"
  5. #include "FileWvIn.h"
  6. namespace stk {
  7. /***************************************************/
  8. /*! \class Mandolin
  9. \brief STK mandolin instrument model class.
  10. This class uses two "twang" models and "commuted
  11. synthesis" techniques to model a mandolin
  12. instrument.
  13. This is a digital waveguide model, making its
  14. use possibly subject to patents held by Stanford
  15. University, Yamaha, and others. Commuted
  16. Synthesis, in particular, is covered by patents,
  17. granted, pending, and/or applied-for. All are
  18. assigned to the Board of Trustees, Stanford
  19. University. For information, contact the Office
  20. of Technology Licensing, Stanford University.
  21. Control Change Numbers:
  22. - Body Size = 2
  23. - Pluck Position = 4
  24. - String Sustain = 11
  25. - String Detuning = 1
  26. - Microphone Position = 128
  27. by Perry R. Cook and Gary P. Scavone, 1995-2011.
  28. */
  29. /***************************************************/
  30. class Mandolin : public Instrmnt
  31. {
  32. public:
  33. //! Class constructor, taking the lowest desired playing frequency.
  34. Mandolin( StkFloat lowestFrequency );
  35. //! Class destructor.
  36. ~Mandolin( void );
  37. //! Reset and clear all internal state.
  38. void clear( void );
  39. //! Detune the two strings by the given factor. A value of 1.0 produces unison strings.
  40. void setDetune( StkFloat detune );
  41. //! Set the body size (a value of 1.0 produces the "default" size).
  42. void setBodySize( StkFloat size );
  43. //! Set the pluck or "excitation" position along the string (0.0 - 1.0).
  44. void setPluckPosition( StkFloat position );
  45. //! Set instrument parameters for a particular frequency.
  46. void setFrequency( StkFloat frequency );
  47. //! Pluck the strings with the given amplitude (0.0 - 1.0) using the current frequency.
  48. void pluck( StkFloat amplitude );
  49. //! Pluck the strings with the given amplitude (0.0 - 1.0) and position (0.0 - 1.0).
  50. void pluck( StkFloat amplitude,StkFloat position );
  51. //! Start a note with the given frequency and amplitude (0.0 - 1.0).
  52. void noteOn( StkFloat frequency, StkFloat amplitude );
  53. //! Stop a note with the given amplitude (speed of decay).
  54. void noteOff( StkFloat amplitude );
  55. //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
  56. void controlChange( int number, StkFloat value );
  57. //! Compute and return one output sample.
  58. StkFloat tick( unsigned int channel = 0 );
  59. //! Fill a channel of the StkFrames object with computed outputs.
  60. /*!
  61. The \c channel argument must be less than the number of
  62. channels in the StkFrames argument (the first channel is specified
  63. by 0). However, range checking is only performed if _STK_DEBUG_
  64. is defined during compilation, in which case an out-of-range value
  65. will trigger an StkError exception.
  66. */
  67. StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
  68. protected:
  69. Twang strings_[2];
  70. FileWvIn soundfile_[12];
  71. int mic_;
  72. StkFloat detuning_;
  73. StkFloat frequency_;
  74. StkFloat pluckAmplitude_;
  75. };
  76. inline StkFloat Mandolin :: tick( unsigned int )
  77. {
  78. StkFloat temp = 0.0;
  79. if ( !soundfile_[mic_].isFinished() )
  80. temp = soundfile_[mic_].tick() * pluckAmplitude_;
  81. lastFrame_[0] = strings_[0].tick( temp );
  82. lastFrame_[0] += strings_[1].tick( temp );
  83. lastFrame_[0] *= 0.2;
  84. return lastFrame_[0];
  85. }
  86. inline StkFrames& Mandolin :: tick( StkFrames& frames, unsigned int channel )
  87. {
  88. unsigned int nChannels = lastFrame_.channels();
  89. #if defined(_STK_DEBUG_)
  90. if ( channel > frames.channels() - nChannels ) {
  91. oStream_ << "Mandolin::tick(): channel and StkFrames arguments are incompatible!";
  92. handleError( StkError::FUNCTION_ARGUMENT );
  93. }
  94. #endif
  95. StkFloat *samples = &frames[channel];
  96. unsigned int j, hop = frames.channels() - nChannels;
  97. if ( nChannels == 1 ) {
  98. for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
  99. *samples++ = tick();
  100. }
  101. else {
  102. for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
  103. *samples++ = tick();
  104. for ( j=1; j<nChannels; j++ )
  105. *samples++ = lastFrame_[j];
  106. }
  107. }
  108. return frames;
  109. }
  110. } // stk namespace
  111. #endif