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.

121 lines
3.4KB

  1. /***************************************************/
  2. /*! \class Tabla
  3. \brief STK tabla drum class.
  4. This class implements a drum sampling synthesizer using FileWvIn
  5. objects and one-pole filters. The drum rawwave files are sampled
  6. at 22050 Hz, but will be appropriately interpolated for other
  7. sample rates. You can specify the maximum polyphony (maximum
  8. number of simultaneous voices) in Tabla.h.
  9. by Perry R. Cook and Gary P. Scavone, 1995--2017.
  10. */
  11. /***************************************************/
  12. #include "Tabla.h"
  13. #include <cmath>
  14. #include <sstream>
  15. namespace stk {
  16. Tabla :: Tabla( void ) : Instrmnt()
  17. {
  18. // This counts the number of sounding voices.
  19. nSounding_ = 0;
  20. soundOrder_ = std::vector<int> (TABLA_POLYPHONY, -1);
  21. soundNumber_ = std::vector<int> (TABLA_POLYPHONY, -1);
  22. }
  23. Tabla :: ~Tabla( void )
  24. {
  25. }
  26. static char tablaWaves[TABLA_NUMWAVES][16] =
  27. { "Drdak2.raw",
  28. "Drdak3.raw",
  29. "Drdak4.raw",
  30. "Drddak1.raw",
  31. "Drdee1.raw",
  32. "Drdee2.raw",
  33. "Drdoo1.raw",
  34. "Drdoo2.raw",
  35. "Drdoo3.raw",
  36. "Drjun1.raw",
  37. "Drjun2.raw",
  38. "DrDoi1.raw",
  39. "DrDoi2.raw",
  40. "DrTak1.raw",
  41. "DrTak2.raw"
  42. };
  43. void Tabla :: noteOn( StkFloat instrument, StkFloat amplitude )
  44. {
  45. if ( amplitude < 0.0 || amplitude > 1.0 ) {
  46. oStream_ << "Tabla::noteOn: amplitude parameter is out of bounds!";
  47. handleError( StkError::WARNING ); return;
  48. }
  49. int noteNumber = ( (int) instrument ) % 16;
  50. // If we already have a wave of this note number loaded, just reset
  51. // it. Otherwise, look first for an unused wave or preempt the
  52. // oldest if already at maximum polyphony.
  53. int iWave;
  54. for ( iWave=0; iWave<TABLA_POLYPHONY; iWave++ ) {
  55. if ( soundNumber_[iWave] == noteNumber ) {
  56. if ( waves_[iWave].isFinished() ) {
  57. soundOrder_[iWave] = nSounding_;
  58. nSounding_++;
  59. }
  60. waves_[iWave].reset();
  61. filters_[iWave].setPole( 0.999 - (amplitude * 0.6) );
  62. filters_[iWave].setGain( amplitude );
  63. break;
  64. }
  65. }
  66. if ( iWave == TABLA_POLYPHONY ) { // This note number is not currently loaded.
  67. if ( nSounding_ < TABLA_POLYPHONY ) {
  68. for ( iWave=0; iWave<TABLA_POLYPHONY; iWave++ )
  69. if ( soundOrder_[iWave] < 0 ) break;
  70. nSounding_ += 1;
  71. }
  72. else {
  73. for ( iWave=0; iWave<TABLA_POLYPHONY; iWave++ )
  74. if ( soundOrder_[iWave] == 0 ) break;
  75. // Re-order the list.
  76. for ( int j=0; j<TABLA_POLYPHONY; j++ ) {
  77. if ( soundOrder_[j] > soundOrder_[iWave] )
  78. soundOrder_[j] -= 1;
  79. }
  80. }
  81. soundOrder_[iWave] = nSounding_ - 1;
  82. soundNumber_[iWave] = noteNumber;
  83. // Concatenate the rawwave path to the rawwave file
  84. waves_[iWave].openFile( (std::string("rawwaves/") + tablaWaves[ noteNumber ]).c_str(), true );
  85. if ( Stk::sampleRate() != 22050.0 )
  86. waves_[iWave].setRate( 22050.0 / Stk::sampleRate() );
  87. filters_[iWave].setPole( 0.999 - (amplitude * 0.6) );
  88. filters_[iWave].setGain( amplitude );
  89. }
  90. /*
  91. #if defined(_STK_DEBUG_)
  92. oStream; errorStream << "Tabla::noteOn: number sounding = " << nSounding_ << '\n';
  93. for (int i=0; i<nSounding_; i++) oStream << soundNumber_[i] << " ";
  94. oStream << '\n'; errorString_ = oStream.str();
  95. handleError( StkError::DEBUG_WARNING );
  96. #endif
  97. */
  98. }
  99. void Tabla :: noteOff( StkFloat amplitude )
  100. {
  101. // Set all sounding wave filter gains low.
  102. int i = 0;
  103. while ( i < nSounding_ ) filters_[i++].setGain( amplitude * 0.01 );
  104. }
  105. } // stk namespace