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.

1119 lines
34KB

  1. /***************************************************/
  2. /*! \class Shakers
  3. \brief PhISEM and PhOLIES class.
  4. PhISEM (Physically Informed Stochastic Event
  5. Modeling) is an algorithmic approach for
  6. simulating collisions of multiple independent
  7. sound producing objects. This class is a
  8. meta-model that can simulate a Maraca, Sekere,
  9. Cabasa, Bamboo Wind Chimes, Water Drops,
  10. Tambourine, Sleighbells, and a Guiro.
  11. PhOLIES (Physically-Oriented Library of
  12. Imitated Environmental Sounds) is a similar
  13. approach for the synthesis of environmental
  14. sounds. This class implements simulations of
  15. breaking sticks, crunchy snow (or not), a
  16. wrench, sandpaper, and more.
  17. Control Change Numbers:
  18. - Shake Energy = 2
  19. - System Decay = 4
  20. - Number Of Objects = 11
  21. - Resonance Frequency = 1
  22. - Shake Energy = 128
  23. - Instrument Selection = 1071
  24. - Maraca = 0
  25. - Cabasa = 1
  26. - Sekere = 2
  27. - Guiro = 3
  28. - Water Drops = 4
  29. - Bamboo Chimes = 5
  30. - Tambourine = 6
  31. - Sleigh Bells = 7
  32. - Sticks = 8
  33. - Crunch = 9
  34. - Wrench = 10
  35. - Sand Paper = 11
  36. - Coke Can = 12
  37. - Next Mug = 13
  38. - Penny + Mug = 14
  39. - Nickle + Mug = 15
  40. - Dime + Mug = 16
  41. - Quarter + Mug = 17
  42. - Franc + Mug = 18
  43. - Peso + Mug = 19
  44. - Big Rocks = 20
  45. - Little Rocks = 21
  46. - Tuned Bamboo Chimes = 22
  47. by Perry R. Cook, 1995-2011.
  48. */
  49. /***************************************************/
  50. #include "Shakers.h"
  51. #include "SKINI.msg"
  52. #include <cstring>
  53. #include <cmath>
  54. #include <cstdlib>
  55. namespace stk {
  56. int my_random( int max ) // Return Random Int Between 0 and max
  57. {
  58. int temp = (int) ((float)max * rand() / (RAND_MAX + 1.0) );
  59. return temp;
  60. }
  61. StkFloat float_random( StkFloat max ) // Return random float between 0.0 and max
  62. {
  63. StkFloat temp = (StkFloat) (max * rand() / (RAND_MAX + 1.0) );
  64. return temp;
  65. }
  66. StkFloat noise_tick( void ) // Return random StkFloat float between -1.0 and 1.0
  67. {
  68. StkFloat temp = (StkFloat) (2.0 * rand() / (RAND_MAX + 1.0) );
  69. temp -= 1.0;
  70. return temp;
  71. }
  72. // Maraca
  73. const StkFloat MARA_SOUND_DECAY = 0.95;
  74. const StkFloat MARA_SYSTEM_DECAY = 0.999;
  75. const StkFloat MARA_GAIN = 20.0;
  76. const StkFloat MARA_NUM_BEANS = 25;
  77. const StkFloat MARA_CENTER_FREQ = 3200.0;
  78. const StkFloat MARA_RESON = 0.96;
  79. // Sekere
  80. const StkFloat SEKE_SOUND_DECAY = 0.96;
  81. const StkFloat SEKE_SYSTEM_DECAY = 0.999;
  82. const StkFloat SEKE_GAIN = 20.0;
  83. const StkFloat SEKE_NUM_BEANS = 64;
  84. const StkFloat SEKE_CENTER_FREQ = 5500.0;
  85. const StkFloat SEKE_RESON = 0.6;
  86. // Sandpaper
  87. const StkFloat SANDPAPR_SOUND_DECAY = 0.999;
  88. const StkFloat SANDPAPR_SYSTEM_DECAY = 0.999;
  89. const StkFloat SANDPAPR_GAIN = 0.5;
  90. const StkFloat SANDPAPR_NUM_GRAINS = 128;
  91. const StkFloat SANDPAPR_CENTER_FREQ = 4500.0;
  92. const StkFloat SANDPAPR_RESON = 0.6;
  93. // Cabasa
  94. const StkFloat CABA_SOUND_DECAY = 0.96;
  95. const StkFloat CABA_SYSTEM_DECAY = 0.997;
  96. const StkFloat CABA_GAIN = 40.0;
  97. const StkFloat CABA_NUM_BEADS = 512;
  98. const StkFloat CABA_CENTER_FREQ = 3000.0;
  99. const StkFloat CABA_RESON = 0.7;
  100. // Bamboo Wind Chimes
  101. const StkFloat BAMB_SOUND_DECAY = 0.95;
  102. const StkFloat BAMB_SYSTEM_DECAY = 0.9999;
  103. const StkFloat BAMB_GAIN = 2.0;
  104. const StkFloat BAMB_NUM_TUBES = 1.25;
  105. const StkFloat BAMB_CENTER_FREQ0 = 2800.0;
  106. const StkFloat BAMB_CENTER_FREQ1 = 0.8 * 2800.0;
  107. const StkFloat BAMB_CENTER_FREQ2 = 1.2 * 2800.0;
  108. const StkFloat BAMB_RESON = 0.995;
  109. // Tuned Bamboo Wind Chimes (Anklung)
  110. const StkFloat TBAMB_SOUND_DECAY = 0.95;
  111. const StkFloat TBAMB_SYSTEM_DECAY = 0.9999;
  112. const StkFloat TBAMB_GAIN = 1.0;
  113. const StkFloat TBAMB_NUM_TUBES = 1.25;
  114. const StkFloat TBAMB_CENTER_FREQ0 = 1046.6;
  115. const StkFloat TBAMB_CENTER_FREQ1 = 1174.8;
  116. const StkFloat TBAMB_CENTER_FREQ2 = 1397.0;
  117. const StkFloat TBAMB_CENTER_FREQ3 = 1568.0;
  118. const StkFloat TBAMB_CENTER_FREQ4 = 1760.0;
  119. const StkFloat TBAMB_CENTER_FREQ5 = 2093.3;
  120. const StkFloat TBAMB_CENTER_FREQ6 = 2350.0;
  121. const StkFloat TBAMB_RESON = 0.996;
  122. // Water Drops
  123. const StkFloat WUTR_SOUND_DECAY = 0.95;
  124. const StkFloat WUTR_SYSTEM_DECAY = 0.996;
  125. const StkFloat WUTR_GAIN = 1.0;
  126. const StkFloat WUTR_NUM_SOURCES = 10;
  127. const StkFloat WUTR_CENTER_FREQ0 = 450.0;
  128. const StkFloat WUTR_CENTER_FREQ1 = 600.0;
  129. const StkFloat WUTR_CENTER_FREQ2 = 750.0;
  130. const StkFloat WUTR_RESON = 0.9985;
  131. const StkFloat WUTR_FREQ_SWEEP = 1.0001;
  132. // Tambourine
  133. const StkFloat TAMB_SOUND_DECAY = 0.95;
  134. const StkFloat TAMB_SYSTEM_DECAY = 0.9985;
  135. const StkFloat TAMB_GAIN = 5.0;
  136. const StkFloat TAMB_NUM_TIMBRELS = 32;
  137. const StkFloat TAMB_SHELL_FREQ = 2300;
  138. const StkFloat TAMB_SHELL_GAIN = 0.1;
  139. const StkFloat TAMB_SHELL_RESON = 0.96;
  140. const StkFloat TAMB_CYMB_FREQ1 = 5600;
  141. const StkFloat TAMB_CYMB_FREQ2 = 8100;
  142. const StkFloat TAMB_CYMB_RESON = 0.99;
  143. // Sleighbells
  144. const StkFloat SLEI_SOUND_DECAY = 0.97;
  145. const StkFloat SLEI_SYSTEM_DECAY = 0.9994;
  146. const StkFloat SLEI_GAIN = 1.0;
  147. const StkFloat SLEI_NUM_BELLS = 32;
  148. const StkFloat SLEI_CYMB_FREQ0 = 2500;
  149. const StkFloat SLEI_CYMB_FREQ1 = 5300;
  150. const StkFloat SLEI_CYMB_FREQ2 = 6500;
  151. const StkFloat SLEI_CYMB_FREQ3 = 8300;
  152. const StkFloat SLEI_CYMB_FREQ4 = 9800;
  153. const StkFloat SLEI_CYMB_RESON = 0.99;
  154. // Guiro
  155. const StkFloat GUIR_SOUND_DECAY = 0.95;
  156. const StkFloat GUIR_GAIN = 10.0;
  157. const StkFloat GUIR_NUM_PARTS = 128;
  158. const StkFloat GUIR_GOURD_FREQ = 2500.0;
  159. const StkFloat GUIR_GOURD_RESON = 0.97;
  160. const StkFloat GUIR_GOURD_FREQ2 = 4000.0;
  161. const StkFloat GUIR_GOURD_RESON2 = 0.97;
  162. // Wrench
  163. const StkFloat WRENCH_SOUND_DECAY = 0.95;
  164. const StkFloat WRENCH_GAIN = 5;
  165. const StkFloat WRENCH_NUM_PARTS = 128;
  166. const StkFloat WRENCH_FREQ = 3200.0;
  167. const StkFloat WRENCH_RESON = 0.99;
  168. const StkFloat WRENCH_FREQ2 = 8000.0;
  169. const StkFloat WRENCH_RESON2 = 0.992;
  170. // Cokecan
  171. const StkFloat COKECAN_SOUND_DECAY = 0.97;
  172. const StkFloat COKECAN_SYSTEM_DECAY = 0.999;
  173. const StkFloat COKECAN_GAIN = 0.8;
  174. const StkFloat COKECAN_NUM_PARTS = 48;
  175. const StkFloat COKECAN_HELMFREQ = 370;
  176. const StkFloat COKECAN_HELM_RES = 0.99;
  177. const StkFloat COKECAN_METLFREQ0 = 1025;
  178. const StkFloat COKECAN_METLFREQ1 = 1424;
  179. const StkFloat COKECAN_METLFREQ2 = 2149;
  180. const StkFloat COKECAN_METLFREQ3 = 3596;
  181. const StkFloat COKECAN_METL_RES = 0.992;
  182. // PhOLIES (Physically-Oriented Library of Imitated Environmental
  183. // Sounds), Perry Cook, 1997-8
  184. // Stix1
  185. const StkFloat STIX1_SOUND_DECAY = 0.96;
  186. const StkFloat STIX1_SYSTEM_DECAY = 0.998;
  187. const StkFloat STIX1_GAIN = 30.0;
  188. const StkFloat STIX1_NUM_BEANS = 2;
  189. const StkFloat STIX1_CENTER_FREQ = 5500.0;
  190. const StkFloat STIX1_RESON = 0.6;
  191. // Crunch1
  192. const StkFloat CRUNCH1_SOUND_DECAY = 0.95;
  193. const StkFloat CRUNCH1_SYSTEM_DECAY = 0.99806;
  194. const StkFloat CRUNCH1_GAIN = 20.0;
  195. const StkFloat CRUNCH1_NUM_BEADS = 7;
  196. const StkFloat CRUNCH1_CENTER_FREQ = 800.0;
  197. const StkFloat CRUNCH1_RESON = 0.95;
  198. // Nextmug
  199. const StkFloat NEXTMUG_SOUND_DECAY = 0.97;
  200. const StkFloat NEXTMUG_SYSTEM_DECAY = 0.9995;
  201. const StkFloat NEXTMUG_GAIN = 0.8;
  202. const StkFloat NEXTMUG_NUM_PARTS = 3;
  203. const StkFloat NEXTMUG_FREQ0 = 2123;
  204. const StkFloat NEXTMUG_FREQ1 = 4518;
  205. const StkFloat NEXTMUG_FREQ2 = 8856;
  206. const StkFloat NEXTMUG_FREQ3 = 10753;
  207. const StkFloat NEXTMUG_RES = 0.997;
  208. const StkFloat PENNY_FREQ0 = 11000;
  209. const StkFloat PENNY_FREQ1 = 5200;
  210. const StkFloat PENNY_FREQ2 = 3835;
  211. const StkFloat PENNY_RES = 0.999;
  212. const StkFloat NICKEL_FREQ0 = 5583;
  213. const StkFloat NICKEL_FREQ1 = 9255;
  214. const StkFloat NICKEL_FREQ2 = 9805;
  215. const StkFloat NICKEL_RES = 0.9992;
  216. const StkFloat DIME_FREQ0 = 4450;
  217. const StkFloat DIME_FREQ1 = 4974;
  218. const StkFloat DIME_FREQ2 = 9945;
  219. const StkFloat DIME_RES = 0.9993;
  220. const StkFloat QUARTER_FREQ0 = 1708;
  221. const StkFloat QUARTER_FREQ1 = 8863;
  222. const StkFloat QUARTER_FREQ2 = 9045;
  223. const StkFloat QUARTER_RES = 0.9995;
  224. const StkFloat FRANC_FREQ0 = 5583;
  225. const StkFloat FRANC_FREQ1 = 11010;
  226. const StkFloat FRANC_FREQ2 = 1917;
  227. const StkFloat FRANC_RES = 0.9995;
  228. const StkFloat PESO_FREQ0 = 7250;
  229. const StkFloat PESO_FREQ1 = 8150;
  230. const StkFloat PESO_FREQ2 = 10060;
  231. const StkFloat PESO_RES = 0.9996;
  232. // Big Gravel
  233. const StkFloat BIGROCKS_SOUND_DECAY = 0.98;
  234. const StkFloat BIGROCKS_SYSTEM_DECAY = 0.9965;
  235. const StkFloat BIGROCKS_GAIN = 20.0;
  236. const StkFloat BIGROCKS_NUM_PARTS = 23;
  237. const StkFloat BIGROCKS_FREQ = 6460;
  238. const StkFloat BIGROCKS_RES = 0.932;
  239. // Little Gravel
  240. const StkFloat LITLROCKS_SOUND_DECAY = 0.98;
  241. const StkFloat LITLROCKS_SYSTEM_DECAY = 0.99586;
  242. const StkFloat LITLROCKS_GAIN = 20.0;
  243. const StkFloat LITLROCKS_NUM_PARTS = 1600;
  244. const StkFloat LITLROCKS_FREQ = 9000;
  245. const StkFloat LITLROCKS_RES = 0.843;
  246. // Finally ... the class code!
  247. Shakers :: Shakers( void )
  248. {
  249. int i;
  250. instType_ = 0;
  251. shakeEnergy_ = 0.0;
  252. nFreqs_ = 0;
  253. sndLevel_ = 0.0;
  254. for ( i=0; i<MAX_FREQS; i++ ) {
  255. inputs_[i] = 0.0;
  256. outputs_[i][0] = 0.0;
  257. outputs_[i][1] = 0.0;
  258. coeffs_[i][0] = 0.0;
  259. coeffs_[i][1] = 0.0;
  260. gains_[i] = 0.0;
  261. center_freqs_[i] = 0.0;
  262. resons_[i] = 0.0;
  263. freq_rand_[i] = 0.0;
  264. freqalloc_[i] = 0;
  265. }
  266. soundDecay_ = 0.0;
  267. systemDecay_ = 0.0;
  268. nObjects_ = 0.0;
  269. totalEnergy_ = 0.0;
  270. ratchet_ = 0.0;
  271. ratchetDelta_ = 0.0005;
  272. lastRatchetPos_ = 0;
  273. finalZ_[0] = 0.0;
  274. finalZ_[1] = 0.0;
  275. finalZ_[2] = 0.0;
  276. finalZCoeffs_[0] = 1.0;
  277. finalZCoeffs_[1] = 0.0;
  278. finalZCoeffs_[2] = 0.0;
  279. this->setupNum(instType_);
  280. }
  281. Shakers :: ~Shakers( void )
  282. {
  283. }
  284. const StkFloat MAX_SHAKE = 2000.0;
  285. char instrs[NUM_INSTR][10] = {
  286. "Maraca", "Cabasa", "Sekere", "Guiro",
  287. "Waterdrp", "Bamboo", "Tambourn", "Sleighbl",
  288. "Stix1", "Crunch1", "Wrench", "SandPapr",
  289. "CokeCan", "NextMug", "PennyMug", "NicklMug",
  290. "DimeMug", "QuartMug", "FrancMug", "PesoMug",
  291. "BigRocks", "LitlRoks", "TBamboo"
  292. };
  293. int Shakers :: setupName( char* instr )
  294. {
  295. int which = 0;
  296. for ( int i=0; i<NUM_INSTR; i++ ) {
  297. if ( !strcmp(instr,instrs[i]) )
  298. which = i;
  299. }
  300. return this->setupNum( which );
  301. }
  302. void Shakers :: setFinalZs( StkFloat z0, StkFloat z1, StkFloat z2 )
  303. {
  304. finalZCoeffs_[0] = z0;
  305. finalZCoeffs_[1] = z1;
  306. finalZCoeffs_[2] = z2;
  307. }
  308. void Shakers :: setDecays( StkFloat sndDecay, StkFloat sysDecay )
  309. {
  310. soundDecay_ = sndDecay;
  311. systemDecay_ = sysDecay;
  312. }
  313. int Shakers :: setFreqAndReson( int which, StkFloat freq, StkFloat reson )
  314. {
  315. if ( which < MAX_FREQS ) {
  316. resons_[which] = reson;
  317. center_freqs_[which] = freq;
  318. t_center_freqs_[which] = freq;
  319. coeffs_[which][1] = reson * reson;
  320. coeffs_[which][0] = -reson * 2.0 * cos(freq * TWO_PI / Stk::sampleRate());
  321. return 1;
  322. }
  323. else return 0;
  324. }
  325. int Shakers :: setupNum( int inst )
  326. {
  327. int i, rv = 0;
  328. StkFloat temp;
  329. if (inst == 1) { // Cabasa
  330. rv = inst;
  331. nObjects_ = CABA_NUM_BEADS;
  332. defObjs_[inst] = CABA_NUM_BEADS;
  333. setDecays(CABA_SOUND_DECAY, CABA_SYSTEM_DECAY);
  334. defDecays_[inst] = CABA_SYSTEM_DECAY;
  335. decayScale_[inst] = 0.97;
  336. nFreqs_ = 1;
  337. baseGain_ = CABA_GAIN;
  338. temp = log(nObjects_) * baseGain_ / (StkFloat) nObjects_;
  339. gains_[0] = temp;
  340. freqalloc_[0] = 0;
  341. setFreqAndReson(0,CABA_CENTER_FREQ,CABA_RESON);
  342. setFinalZs(1.0,-1.0,0.0);
  343. }
  344. else if (inst == 2) { // Sekere
  345. rv = inst;
  346. nObjects_ = SEKE_NUM_BEANS;
  347. defObjs_[inst] = SEKE_NUM_BEANS;
  348. this->setDecays(SEKE_SOUND_DECAY,SEKE_SYSTEM_DECAY);
  349. defDecays_[inst] = SEKE_SYSTEM_DECAY;
  350. decayScale_[inst] = 0.94;
  351. nFreqs_ = 1;
  352. baseGain_ = SEKE_GAIN;
  353. temp = log(nObjects_) * baseGain_ / (StkFloat) nObjects_;
  354. gains_[0] = temp;
  355. freqalloc_[0] = 0;
  356. this->setFreqAndReson(0,SEKE_CENTER_FREQ,SEKE_RESON);
  357. this->setFinalZs(1.0, 0.0, -1.0);
  358. }
  359. else if (inst == 3) { // Guiro
  360. rv = inst;
  361. nObjects_ = GUIR_NUM_PARTS;
  362. defObjs_[inst] = GUIR_NUM_PARTS;
  363. setDecays(GUIR_SOUND_DECAY,1.0);
  364. defDecays_[inst] = 0.9999;
  365. decayScale_[inst] = 1.0;
  366. nFreqs_ = 2;
  367. baseGain_ = GUIR_GAIN;
  368. temp = log(nObjects_) * baseGain_ / (StkFloat) nObjects_;
  369. gains_[0]=temp;
  370. gains_[1]=temp;
  371. freqalloc_[0] = 0;
  372. freqalloc_[1] = 0;
  373. freq_rand_[0] = 0.0;
  374. freq_rand_[1] = 0.0;
  375. setFreqAndReson(0,GUIR_GOURD_FREQ,GUIR_GOURD_RESON);
  376. setFreqAndReson(1,GUIR_GOURD_FREQ2,GUIR_GOURD_RESON2);
  377. ratchet_ = 0;
  378. ratchetPos_ = 10;
  379. }
  380. else if (inst == 4) { // Water Drops
  381. rv = inst;
  382. nObjects_ = WUTR_NUM_SOURCES;
  383. defObjs_[inst] = WUTR_NUM_SOURCES;
  384. setDecays(WUTR_SOUND_DECAY,WUTR_SYSTEM_DECAY);
  385. defDecays_[inst] = WUTR_SYSTEM_DECAY;
  386. decayScale_[inst] = 0.8;
  387. nFreqs_ = 3;
  388. baseGain_ = WUTR_GAIN;
  389. temp = log(nObjects_) * baseGain_ / (StkFloat) nObjects_;
  390. gains_[0]=temp;
  391. gains_[1]=temp;
  392. gains_[2]=temp;
  393. freqalloc_[0] = 1;
  394. freqalloc_[1] = 1;
  395. freqalloc_[2] = 1;
  396. freq_rand_[0] = 0.2;
  397. freq_rand_[1] = 0.2;
  398. freq_rand_[2] = 0.2;
  399. setFreqAndReson(0,WUTR_CENTER_FREQ0,WUTR_RESON);
  400. setFreqAndReson(1,WUTR_CENTER_FREQ0,WUTR_RESON);
  401. setFreqAndReson(2,WUTR_CENTER_FREQ0,WUTR_RESON);
  402. setFinalZs(1.0,0.0,0.0);
  403. }
  404. else if (inst == 5) { // Bamboo
  405. rv = inst;
  406. nObjects_ = BAMB_NUM_TUBES;
  407. defObjs_[inst] = BAMB_NUM_TUBES;
  408. setDecays(BAMB_SOUND_DECAY, BAMB_SYSTEM_DECAY);
  409. defDecays_[inst] = BAMB_SYSTEM_DECAY;
  410. decayScale_[inst] = 0.7;
  411. nFreqs_ = 3;
  412. baseGain_ = BAMB_GAIN;
  413. temp = log(nObjects_) * baseGain_ / (StkFloat) nObjects_;
  414. gains_[0]=temp;
  415. gains_[1]=temp;
  416. gains_[2]=temp;
  417. freqalloc_[0] = 1;
  418. freqalloc_[1] = 1;
  419. freqalloc_[2] = 1;
  420. freq_rand_[0] = 0.2;
  421. freq_rand_[1] = 0.2;
  422. freq_rand_[2] = 0.2;
  423. setFreqAndReson(0,BAMB_CENTER_FREQ0,BAMB_RESON);
  424. setFreqAndReson(1,BAMB_CENTER_FREQ1,BAMB_RESON);
  425. setFreqAndReson(2,BAMB_CENTER_FREQ2,BAMB_RESON);
  426. setFinalZs(1.0,0.0,0.0);
  427. }
  428. else if (inst == 6) { // Tambourine
  429. rv = inst;
  430. nObjects_ = TAMB_NUM_TIMBRELS;
  431. defObjs_[inst] = TAMB_NUM_TIMBRELS;
  432. setDecays(TAMB_SOUND_DECAY,TAMB_SYSTEM_DECAY);
  433. defDecays_[inst] = TAMB_SYSTEM_DECAY;
  434. decayScale_[inst] = 0.95;
  435. nFreqs_ = 3;
  436. baseGain_ = TAMB_GAIN;
  437. temp = log(nObjects_) * baseGain_ / (StkFloat) nObjects_;
  438. gains_[0]=temp*TAMB_SHELL_GAIN;
  439. gains_[1]=temp*0.8;
  440. gains_[2]=temp;
  441. freqalloc_[0] = 0;
  442. freqalloc_[1] = 1;
  443. freqalloc_[2] = 1;
  444. freq_rand_[0] = 0.0;
  445. freq_rand_[1] = 0.05;
  446. freq_rand_[2] = 0.05;
  447. setFreqAndReson(0,TAMB_SHELL_FREQ,TAMB_SHELL_RESON);
  448. setFreqAndReson(1,TAMB_CYMB_FREQ1,TAMB_CYMB_RESON);
  449. setFreqAndReson(2,TAMB_CYMB_FREQ2,TAMB_CYMB_RESON);
  450. setFinalZs(1.0,0.0,-1.0);
  451. }
  452. else if (inst == 7) { // Sleighbell
  453. rv = inst;
  454. nObjects_ = SLEI_NUM_BELLS;
  455. defObjs_[inst] = SLEI_NUM_BELLS;
  456. setDecays(SLEI_SOUND_DECAY,SLEI_SYSTEM_DECAY);
  457. defDecays_[inst] = SLEI_SYSTEM_DECAY;
  458. decayScale_[inst] = 0.9;
  459. nFreqs_ = 5;
  460. baseGain_ = SLEI_GAIN;
  461. temp = log(nObjects_) * baseGain_ / (StkFloat) nObjects_;
  462. gains_[0]=temp;
  463. gains_[1]=temp;
  464. gains_[2]=temp;
  465. gains_[3]=temp*0.5;
  466. gains_[4]=temp*0.3;
  467. for (i=0;i<nFreqs_;i++) {
  468. freqalloc_[i] = 1;
  469. freq_rand_[i] = 0.03;
  470. }
  471. setFreqAndReson(0,SLEI_CYMB_FREQ0,SLEI_CYMB_RESON);
  472. setFreqAndReson(1,SLEI_CYMB_FREQ1,SLEI_CYMB_RESON);
  473. setFreqAndReson(2,SLEI_CYMB_FREQ2,SLEI_CYMB_RESON);
  474. setFreqAndReson(3,SLEI_CYMB_FREQ3,SLEI_CYMB_RESON);
  475. setFreqAndReson(4,SLEI_CYMB_FREQ4,SLEI_CYMB_RESON);
  476. setFinalZs(1.0,0.0,-1.0);
  477. }
  478. else if (inst == 8) { // Stix1
  479. rv = inst;
  480. nObjects_ = STIX1_NUM_BEANS;
  481. defObjs_[inst] = STIX1_NUM_BEANS;
  482. setDecays(STIX1_SOUND_DECAY,STIX1_SYSTEM_DECAY);
  483. defDecays_[inst] = STIX1_SYSTEM_DECAY;
  484. decayScale_[inst] = 0.96;
  485. nFreqs_ = 1;
  486. baseGain_ = STIX1_GAIN;
  487. temp = log(nObjects_) * baseGain_ / (StkFloat) nObjects_;
  488. gains_[0]=temp;
  489. freqalloc_[0] = 0;
  490. setFreqAndReson(0,STIX1_CENTER_FREQ,STIX1_RESON);
  491. setFinalZs(1.0,0.0,-1.0);
  492. }
  493. else if (inst == 9) { // Crunch1
  494. rv = inst;
  495. nObjects_ = CRUNCH1_NUM_BEADS;
  496. defObjs_[inst] = CRUNCH1_NUM_BEADS;
  497. setDecays(CRUNCH1_SOUND_DECAY,CRUNCH1_SYSTEM_DECAY);
  498. defDecays_[inst] = CRUNCH1_SYSTEM_DECAY;
  499. decayScale_[inst] = 0.96;
  500. nFreqs_ = 1;
  501. baseGain_ = CRUNCH1_GAIN;
  502. temp = log(nObjects_) * baseGain_ / (StkFloat) nObjects_;
  503. gains_[0]=temp;
  504. freqalloc_[0] = 0;
  505. setFreqAndReson(0,CRUNCH1_CENTER_FREQ,CRUNCH1_RESON);
  506. setFinalZs(1.0,-1.0,0.0);
  507. }
  508. else if (inst == 10) { // Wrench
  509. rv = inst;
  510. nObjects_ = WRENCH_NUM_PARTS;
  511. defObjs_[inst] = WRENCH_NUM_PARTS;
  512. setDecays(WRENCH_SOUND_DECAY,1.0);
  513. defDecays_[inst] = 0.9999;
  514. decayScale_[inst] = 0.98;
  515. nFreqs_ = 2;
  516. baseGain_ = WRENCH_GAIN;
  517. temp = log(nObjects_) * baseGain_ / (StkFloat) nObjects_;
  518. gains_[0]=temp;
  519. gains_[1]=temp;
  520. freqalloc_[0] = 0;
  521. freqalloc_[1] = 0;
  522. freq_rand_[0] = 0.0;
  523. freq_rand_[1] = 0.0;
  524. setFreqAndReson(0,WRENCH_FREQ,WRENCH_RESON);
  525. setFreqAndReson(1,WRENCH_FREQ2,WRENCH_RESON2);
  526. ratchet_ = 0;
  527. ratchetPos_ = 10;
  528. }
  529. else if (inst == 11) { // Sandpapr
  530. rv = inst;
  531. nObjects_ = SANDPAPR_NUM_GRAINS;
  532. defObjs_[inst] = SANDPAPR_NUM_GRAINS;
  533. this->setDecays(SANDPAPR_SOUND_DECAY,SANDPAPR_SYSTEM_DECAY);
  534. defDecays_[inst] = SANDPAPR_SYSTEM_DECAY;
  535. decayScale_[inst] = 0.97;
  536. nFreqs_ = 1;
  537. baseGain_ = SANDPAPR_GAIN;
  538. temp = log(nObjects_) * baseGain_ / (StkFloat) nObjects_;
  539. gains_[0] = temp;
  540. freqalloc_[0] = 0;
  541. this->setFreqAndReson(0,SANDPAPR_CENTER_FREQ,SANDPAPR_RESON);
  542. this->setFinalZs(1.0, 0.0, -1.0);
  543. }
  544. else if (inst == 12) { // Cokecan
  545. rv = inst;
  546. nObjects_ = COKECAN_NUM_PARTS;
  547. defObjs_[inst] = COKECAN_NUM_PARTS;
  548. setDecays(COKECAN_SOUND_DECAY,COKECAN_SYSTEM_DECAY);
  549. defDecays_[inst] = COKECAN_SYSTEM_DECAY;
  550. decayScale_[inst] = 0.95;
  551. nFreqs_ = 5;
  552. baseGain_ = COKECAN_GAIN;
  553. temp = log(nObjects_) * baseGain_ / (StkFloat) nObjects_;
  554. gains_[0]=temp;
  555. gains_[1]=temp*1.8;
  556. gains_[2]=temp*1.8;
  557. gains_[3]=temp*1.8;
  558. gains_[4]=temp*1.8;
  559. freqalloc_[0] = 0;
  560. freqalloc_[1] = 0;
  561. freqalloc_[2] = 0;
  562. freqalloc_[3] = 0;
  563. freqalloc_[4] = 0;
  564. setFreqAndReson(0,COKECAN_HELMFREQ,COKECAN_HELM_RES);
  565. setFreqAndReson(1,COKECAN_METLFREQ0,COKECAN_METL_RES);
  566. setFreqAndReson(2,COKECAN_METLFREQ1,COKECAN_METL_RES);
  567. setFreqAndReson(3,COKECAN_METLFREQ2,COKECAN_METL_RES);
  568. setFreqAndReson(4,COKECAN_METLFREQ3,COKECAN_METL_RES);
  569. setFinalZs(1.0,0.0,-1.0);
  570. }
  571. else if (inst>12 && inst<20) { // Nextmug
  572. rv = inst;
  573. nObjects_ = NEXTMUG_NUM_PARTS;
  574. defObjs_[inst] = NEXTMUG_NUM_PARTS;
  575. setDecays(NEXTMUG_SOUND_DECAY,NEXTMUG_SYSTEM_DECAY);
  576. defDecays_[inst] = NEXTMUG_SYSTEM_DECAY;
  577. decayScale_[inst] = 0.95;
  578. nFreqs_ = 4;
  579. baseGain_ = NEXTMUG_GAIN;
  580. temp = log(nObjects_) * baseGain_ / (StkFloat) nObjects_;
  581. gains_[0]=temp;
  582. gains_[1]=temp*0.8;
  583. gains_[2]=temp*0.6;
  584. gains_[3]=temp*0.4;
  585. freqalloc_[0] = 0;
  586. freqalloc_[1] = 0;
  587. freqalloc_[2] = 0;
  588. freqalloc_[3] = 0;
  589. freqalloc_[4] = 0;
  590. freqalloc_[5] = 0;
  591. setFreqAndReson(0,NEXTMUG_FREQ0,NEXTMUG_RES);
  592. setFreqAndReson(1,NEXTMUG_FREQ1,NEXTMUG_RES);
  593. setFreqAndReson(2,NEXTMUG_FREQ2,NEXTMUG_RES);
  594. setFreqAndReson(3,NEXTMUG_FREQ3,NEXTMUG_RES);
  595. setFinalZs(1.0,0.0,-1.0);
  596. if (inst == 14) { // Mug + Penny
  597. nFreqs_ = 7;
  598. gains_[4] = temp;
  599. gains_[5] = temp*0.8;
  600. gains_[6] = temp*0.5;
  601. setFreqAndReson(4,PENNY_FREQ0,PENNY_RES);
  602. setFreqAndReson(5,PENNY_FREQ1,PENNY_RES);
  603. setFreqAndReson(6,PENNY_FREQ2,PENNY_RES);
  604. }
  605. else if (inst == 15) { // Mug + Nickel
  606. nFreqs_ = 6;
  607. gains_[4] = temp;
  608. gains_[5] = temp*0.8;
  609. gains_[6] = temp*0.5;
  610. setFreqAndReson(4,NICKEL_FREQ0,NICKEL_RES);
  611. setFreqAndReson(5,NICKEL_FREQ1,NICKEL_RES);
  612. setFreqAndReson(6,NICKEL_FREQ2,NICKEL_RES);
  613. }
  614. else if (inst == 16) { // Mug + Dime
  615. nFreqs_ = 6;
  616. gains_[4] = temp;
  617. gains_[5] = temp*0.8;
  618. gains_[6] = temp*0.5;
  619. setFreqAndReson(4,DIME_FREQ0,DIME_RES);
  620. setFreqAndReson(5,DIME_FREQ1,DIME_RES);
  621. setFreqAndReson(6,DIME_FREQ2,DIME_RES);
  622. }
  623. else if (inst == 17) { // Mug + Quarter
  624. nFreqs_ = 6;
  625. gains_[4] = temp*1.3;
  626. gains_[5] = temp*1.0;
  627. gains_[6] = temp*0.8;
  628. setFreqAndReson(4,QUARTER_FREQ0,QUARTER_RES);
  629. setFreqAndReson(5,QUARTER_FREQ1,QUARTER_RES);
  630. setFreqAndReson(6,QUARTER_FREQ2,QUARTER_RES);
  631. }
  632. else if (inst == 18) { // Mug + Franc
  633. nFreqs_ = 6;
  634. gains_[4] = temp*0.7;
  635. gains_[5] = temp*0.4;
  636. gains_[6] = temp*0.3;
  637. setFreqAndReson(4,FRANC_FREQ0,FRANC_RES);
  638. setFreqAndReson(5,FRANC_FREQ1,FRANC_RES);
  639. setFreqAndReson(6,FRANC_FREQ2,FRANC_RES);
  640. }
  641. else if (inst == 19) { // Mug + Peso
  642. nFreqs_ = 6;
  643. gains_[4] = temp;
  644. gains_[5] = temp*1.2;
  645. gains_[6] = temp*0.7;
  646. setFreqAndReson(4,PESO_FREQ0,PESO_RES);
  647. setFreqAndReson(5,PESO_FREQ1,PESO_RES);
  648. setFreqAndReson(6,PESO_FREQ2,PESO_RES);
  649. }
  650. }
  651. else if (inst == 20) { // Big Rocks
  652. nFreqs_ = 1;
  653. rv = inst;
  654. nObjects_ = BIGROCKS_NUM_PARTS;
  655. defObjs_[inst] = BIGROCKS_NUM_PARTS;
  656. setDecays(BIGROCKS_SOUND_DECAY,BIGROCKS_SYSTEM_DECAY);
  657. defDecays_[inst] = BIGROCKS_SYSTEM_DECAY;
  658. decayScale_[inst] = 0.95;
  659. baseGain_ = BIGROCKS_GAIN;
  660. temp = log(nObjects_) * baseGain_ / (StkFloat) nObjects_;
  661. gains_[0]=temp;
  662. freqalloc_[0] = 1;
  663. freq_rand_[0] = 0.11;
  664. setFreqAndReson(0,BIGROCKS_FREQ,BIGROCKS_RES);
  665. setFinalZs(1.0,0.0,-1.0);
  666. }
  667. else if (inst == 21) { // Little Rocks
  668. nFreqs_ = 1;
  669. rv = inst;
  670. nObjects_ = LITLROCKS_NUM_PARTS;
  671. defObjs_[inst] = LITLROCKS_NUM_PARTS;
  672. setDecays(LITLROCKS_SOUND_DECAY,LITLROCKS_SYSTEM_DECAY);
  673. defDecays_[inst] = LITLROCKS_SYSTEM_DECAY;
  674. decayScale_[inst] = 0.95;
  675. baseGain_ = LITLROCKS_GAIN;
  676. temp = log(nObjects_) * baseGain_ / (StkFloat) nObjects_;
  677. gains_[0]=temp;
  678. freqalloc_[0] = 1;
  679. freq_rand_[0] = 0.18;
  680. setFreqAndReson(0,LITLROCKS_FREQ,LITLROCKS_RES);
  681. setFinalZs(1.0,0.0,-1.0);
  682. }
  683. else if (inst == 22) { // Tuned Bamboo
  684. rv = inst;
  685. nObjects_ = TBAMB_NUM_TUBES;
  686. defObjs_[inst] = TBAMB_NUM_TUBES;
  687. setDecays(TBAMB_SOUND_DECAY, TBAMB_SYSTEM_DECAY);
  688. defDecays_[inst] = TBAMB_SYSTEM_DECAY;
  689. decayScale_[inst] = 0.7;
  690. nFreqs_ = 7;
  691. baseGain_ = TBAMB_GAIN;
  692. temp = log(nObjects_) * baseGain_ / (StkFloat) nObjects_;
  693. gains_[0]=temp;
  694. gains_[1]=temp;
  695. gains_[2]=temp;
  696. gains_[3]=temp;
  697. gains_[4]=temp;
  698. gains_[5]=temp;
  699. gains_[6]=temp;
  700. freqalloc_[0] = 0;
  701. freqalloc_[1] = 0;
  702. freqalloc_[2] = 0;
  703. freqalloc_[3] = 0;
  704. freqalloc_[4] = 0;
  705. freqalloc_[5] = 0;
  706. freqalloc_[6] = 0;
  707. freq_rand_[0] = 0.0;
  708. freq_rand_[1] = 0.0;
  709. freq_rand_[2] = 0.0;
  710. freq_rand_[3] = 0.0;
  711. freq_rand_[4] = 0.0;
  712. freq_rand_[5] = 0.0;
  713. freq_rand_[6] = 0.0;
  714. setFreqAndReson(0,TBAMB_CENTER_FREQ0,TBAMB_RESON);
  715. setFreqAndReson(1,TBAMB_CENTER_FREQ1,TBAMB_RESON);
  716. setFreqAndReson(2,TBAMB_CENTER_FREQ2,TBAMB_RESON);
  717. setFreqAndReson(3,TBAMB_CENTER_FREQ3,TBAMB_RESON);
  718. setFreqAndReson(4,TBAMB_CENTER_FREQ4,TBAMB_RESON);
  719. setFreqAndReson(5,TBAMB_CENTER_FREQ5,TBAMB_RESON);
  720. setFreqAndReson(6,TBAMB_CENTER_FREQ6,TBAMB_RESON);
  721. setFinalZs(1.0,0.0,-1.0);
  722. }
  723. else { // Maraca (inst == 0) or default
  724. rv = 0;
  725. nObjects_ = MARA_NUM_BEANS;
  726. defObjs_[0] = MARA_NUM_BEANS;
  727. setDecays(MARA_SOUND_DECAY,MARA_SYSTEM_DECAY);
  728. defDecays_[0] = MARA_SYSTEM_DECAY;
  729. decayScale_[inst] = 0.9;
  730. nFreqs_ = 1;
  731. baseGain_ = MARA_GAIN;
  732. temp = log(nObjects_) * baseGain_ / (StkFloat) nObjects_;
  733. gains_[0]=temp;
  734. freqalloc_[0] = 0;
  735. setFreqAndReson(0,MARA_CENTER_FREQ,MARA_RESON);
  736. setFinalZs(1.0,-1.0,0.0);
  737. }
  738. return rv;
  739. }
  740. void Shakers :: noteOn( StkFloat frequency, StkFloat amplitude )
  741. {
  742. // Yep ... pretty kludgey, but it works!
  743. int noteNum = (int) ((12*log(frequency/220.0)/log(2.0)) + 57.01) % 32;
  744. if (instType_ != noteNum) instType_ = this->setupNum(noteNum);
  745. shakeEnergy_ += amplitude * MAX_SHAKE * 0.1;
  746. if (shakeEnergy_ > MAX_SHAKE) shakeEnergy_ = MAX_SHAKE;
  747. if (instType_==10 || instType_==3) ratchetPos_ += 1;
  748. }
  749. void Shakers :: noteOff( StkFloat amplitude )
  750. {
  751. shakeEnergy_ = 0.0;
  752. if (instType_==10 || instType_==3) ratchetPos_ = 0;
  753. }
  754. const StkFloat MIN_ENERGY = 0.3;
  755. StkFloat Shakers :: tick( unsigned int )
  756. {
  757. StkFloat data;
  758. StkFloat temp_rand;
  759. int i;
  760. if (instType_ == 4) {
  761. if (shakeEnergy_ > MIN_ENERGY) {
  762. lastFrame_[0] = wuter_tick();
  763. lastFrame_[0] *= 0.0001;
  764. }
  765. else {
  766. lastFrame_[0] = 0.0;
  767. }
  768. }
  769. else if (instType_ == 22) {
  770. lastFrame_[0] = tbamb_tick();
  771. }
  772. else if (instType_ == 10 || instType_ == 3) {
  773. if (ratchetPos_ > 0) {
  774. ratchet_ -= (ratchetDelta_ + (0.002*totalEnergy_));
  775. if (ratchet_ < 0.0) {
  776. ratchet_ = 1.0;
  777. ratchetPos_ -= 1;
  778. }
  779. totalEnergy_ = ratchet_;
  780. lastFrame_[0] = ratchet_tick();
  781. lastFrame_[0] *= 0.0001;
  782. }
  783. else lastFrame_[0] = 0.0;
  784. }
  785. else { // generic_tick()
  786. if (shakeEnergy_ > MIN_ENERGY) {
  787. shakeEnergy_ *= systemDecay_; // Exponential system decay
  788. if (float_random(1024.0) < nObjects_) {
  789. sndLevel_ += shakeEnergy_;
  790. for (i=0;i<nFreqs_;i++) {
  791. if (freqalloc_[i]) {
  792. temp_rand = t_center_freqs_[i] * (1.0 + (freq_rand_[i] * noise_tick()));
  793. coeffs_[i][0] = -resons_[i] * 2.0 * cos(temp_rand * TWO_PI / Stk::sampleRate());
  794. }
  795. }
  796. }
  797. inputs_[0] = sndLevel_ * noise_tick(); // Actual Sound is Random
  798. for (i=1; i<nFreqs_; i++) {
  799. inputs_[i] = inputs_[0];
  800. }
  801. sndLevel_ *= soundDecay_; // Exponential Sound decay
  802. finalZ_[2] = finalZ_[1];
  803. finalZ_[1] = finalZ_[0];
  804. finalZ_[0] = 0;
  805. for (i=0;i<nFreqs_;i++) {
  806. inputs_[i] -= outputs_[i][0]*coeffs_[i][0]; // Do
  807. inputs_[i] -= outputs_[i][1]*coeffs_[i][1]; // resonant
  808. outputs_[i][1] = outputs_[i][0]; // filter
  809. outputs_[i][0] = inputs_[i]; // calculations
  810. finalZ_[0] += gains_[i] * outputs_[i][1];
  811. }
  812. data = finalZCoeffs_[0] * finalZ_[0]; // Extra zero(s) for shape
  813. data += finalZCoeffs_[1] * finalZ_[1]; // Extra zero(s) for shape
  814. data += finalZCoeffs_[2] * finalZ_[2]; // Extra zero(s) for shape
  815. if (data > 10000.0) data = 10000.0;
  816. if (data < -10000.0) data = -10000.0;
  817. lastFrame_[0] = data * 0.0001;
  818. }
  819. else lastFrame_[0] = 0.0;
  820. }
  821. return lastFrame_[0];
  822. }
  823. void Shakers :: controlChange( int number, StkFloat value )
  824. {
  825. #if defined(_STK_DEBUG_)
  826. if ( Stk::inRange( value, 0.0, 128.0 ) == false ) {
  827. oStream_ << "Shakers::controlChange: value (" << value << ") is out of range!";
  828. handleError( StkError::WARNING ); return;
  829. }
  830. #endif
  831. int i;
  832. StkFloat temp;
  833. StkFloat normalizedValue = value * ONE_OVER_128;
  834. if (number == __SK_Breath_) { // 2 ... energy
  835. shakeEnergy_ += normalizedValue * MAX_SHAKE * 0.1;
  836. if (shakeEnergy_ > MAX_SHAKE) shakeEnergy_ = MAX_SHAKE;
  837. if (instType_==10 || instType_==3) {
  838. ratchetPos_ = (int) fabs(value - lastRatchetPos_);
  839. ratchetDelta_ = 0.0002 * ratchetPos_;
  840. lastRatchetPos_ = (int) value;
  841. }
  842. }
  843. else if (number == __SK_ModFrequency_) { // 4 ... decay
  844. if (instType_ != 3 && instType_ != 10) {
  845. systemDecay_ = defDecays_[instType_] + ((value - 64.0) *
  846. decayScale_[instType_] *
  847. (1.0 - defDecays_[instType_]) / 64.0 );
  848. gains_[0] = log(nObjects_) * baseGain_ / (StkFloat) nObjects_;
  849. for (i=1;i<nFreqs_;i++) gains_[i] = gains_[0];
  850. if (instType_ == 6) { // tambourine
  851. gains_[0] *= TAMB_SHELL_GAIN;
  852. gains_[1] *= 0.8;
  853. }
  854. else if (instType_ == 7) { // sleighbell
  855. gains_[3] *= 0.5;
  856. gains_[4] *= 0.3;
  857. }
  858. else if (instType_ == 12) { // cokecan
  859. for (i=1;i<nFreqs_;i++) gains_[i] *= 1.8;
  860. }
  861. for (i=0;i<nFreqs_;i++) gains_[i] *= ((128-value)/100.0 + 0.36);
  862. }
  863. }
  864. else if (number == __SK_FootControl_) { // 11 ... number of objects
  865. if (instType_ == 5) // bamboo
  866. nObjects_ = (StkFloat) (value * defObjs_[instType_] / 64.0) + 0.3;
  867. else
  868. nObjects_ = (StkFloat) (value * defObjs_[instType_] / 64.0) + 1.1;
  869. gains_[0] = log(nObjects_) * baseGain_ / (StkFloat) nObjects_;
  870. for (i=1;i<nFreqs_;i++) gains_[i] = gains_[0];
  871. if (instType_ == 6) { // tambourine
  872. gains_[0] *= TAMB_SHELL_GAIN;
  873. gains_[1] *= 0.8;
  874. }
  875. else if (instType_ == 7) { // sleighbell
  876. gains_[3] *= 0.5;
  877. gains_[4] *= 0.3;
  878. }
  879. else if (instType_ == 12) { // cokecan
  880. for (i=1;i<nFreqs_;i++) gains_[i] *= 1.8;
  881. }
  882. if (instType_ != 3 && instType_ != 10) {
  883. // reverse calculate decay setting
  884. double temp = (double) (64.0 * (systemDecay_-defDecays_[instType_])/(decayScale_[instType_]*(1-defDecays_[instType_])) + 64.0);
  885. // scale gains_ by decay setting
  886. for (i=0;i<nFreqs_;i++) gains_[i] *= ((128-temp)/100.0 + 0.36);
  887. }
  888. }
  889. else if (number == __SK_ModWheel_) { // 1 ... resonance frequency
  890. for (i=0; i<nFreqs_; i++) {
  891. if (instType_ == 6 || instType_ == 2 || instType_ == 7) // limit range a bit for tambourine
  892. temp = center_freqs_[i] * pow (1.008,value-64);
  893. else
  894. temp = center_freqs_[i] * pow (1.015,value-64);
  895. t_center_freqs_[i] = temp;
  896. coeffs_[i][0] = -resons_[i] * 2.0 * cos(temp * TWO_PI / Stk::sampleRate());
  897. coeffs_[i][1] = resons_[i]*resons_[i];
  898. }
  899. }
  900. else if (number == __SK_AfterTouch_Cont_) { // 128
  901. shakeEnergy_ += normalizedValue * MAX_SHAKE * 0.1;
  902. if (shakeEnergy_ > MAX_SHAKE) shakeEnergy_ = MAX_SHAKE;
  903. if (instType_==10 || instType_==3) {
  904. ratchetPos_ = (int) fabs(value - lastRatchetPos_);
  905. ratchetDelta_ = 0.0002 * ratchetPos_;
  906. lastRatchetPos_ = (int) value;
  907. }
  908. }
  909. else if (number == __SK_ShakerInst_) { // 1071
  910. instType_ = (int) (value + 0.5); // Just to be safe
  911. this->setupNum(instType_);
  912. }
  913. #if defined(_STK_DEBUG_)
  914. else {
  915. oStream_ << "Shakers::controlChange: undefined control number (" << number << ")!";
  916. handleError( StkError::WARNING );
  917. }
  918. #endif
  919. }
  920. // KLUDGE-O-MATIC-O-RAMA
  921. StkFloat Shakers :: wuter_tick( void ) {
  922. StkFloat data;
  923. int j;
  924. shakeEnergy_ *= systemDecay_; // Exponential system decay
  925. if (my_random(32767) < nObjects_) {
  926. sndLevel_ = shakeEnergy_;
  927. j = my_random(3);
  928. if (j == 0) {
  929. center_freqs_[0] = WUTR_CENTER_FREQ1 * (0.75 + (0.25 * noise_tick()));
  930. gains_[0] = fabs(noise_tick());
  931. }
  932. else if (j == 1) {
  933. center_freqs_[1] = WUTR_CENTER_FREQ1 * (1.0 + (0.25 * noise_tick()));
  934. gains_[1] = fabs(noise_tick());
  935. }
  936. else {
  937. center_freqs_[2] = WUTR_CENTER_FREQ1 * (1.25 + (0.25 * noise_tick()));
  938. gains_[2] = fabs(noise_tick());
  939. }
  940. }
  941. gains_[0] *= resons_[0];
  942. if (gains_[0] > 0.001) {
  943. center_freqs_[0] *= WUTR_FREQ_SWEEP;
  944. coeffs_[0][0] = -resons_[0] * 2.0 *
  945. cos(center_freqs_[0] * TWO_PI / Stk::sampleRate());
  946. }
  947. gains_[1] *= resons_[1];
  948. if (gains_[1] > 0.001) {
  949. center_freqs_[1] *= WUTR_FREQ_SWEEP;
  950. coeffs_[1][0] = -resons_[1] * 2.0 *
  951. cos(center_freqs_[1] * TWO_PI / Stk::sampleRate());
  952. }
  953. gains_[2] *= resons_[2];
  954. if (gains_[2] > 0.001) {
  955. center_freqs_[2] *= WUTR_FREQ_SWEEP;
  956. coeffs_[2][0] = -resons_[2] * 2.0 *
  957. cos(center_freqs_[2] * TWO_PI / Stk::sampleRate());
  958. }
  959. sndLevel_ *= soundDecay_; // Each (all) event(s)
  960. // decay(s) exponentially
  961. inputs_[0] = sndLevel_;
  962. inputs_[0] *= noise_tick(); // Actual Sound is Random
  963. inputs_[1] = inputs_[0] * gains_[1];
  964. inputs_[2] = inputs_[0] * gains_[2];
  965. inputs_[0] *= gains_[0];
  966. inputs_[0] -= outputs_[0][0]*coeffs_[0][0];
  967. inputs_[0] -= outputs_[0][1]*coeffs_[0][1];
  968. outputs_[0][1] = outputs_[0][0];
  969. outputs_[0][0] = inputs_[0];
  970. data = gains_[0]*outputs_[0][0];
  971. inputs_[1] -= outputs_[1][0]*coeffs_[1][0];
  972. inputs_[1] -= outputs_[1][1]*coeffs_[1][1];
  973. outputs_[1][1] = outputs_[1][0];
  974. outputs_[1][0] = inputs_[1];
  975. data += gains_[1]*outputs_[1][0];
  976. inputs_[2] -= outputs_[2][0]*coeffs_[2][0];
  977. inputs_[2] -= outputs_[2][1]*coeffs_[2][1];
  978. outputs_[2][1] = outputs_[2][0];
  979. outputs_[2][0] = inputs_[2];
  980. data += gains_[2]*outputs_[2][0];
  981. finalZ_[2] = finalZ_[1];
  982. finalZ_[1] = finalZ_[0];
  983. finalZ_[0] = data * 4;
  984. data = finalZ_[2] - finalZ_[0];
  985. return data;
  986. }
  987. StkFloat Shakers :: ratchet_tick( void ) {
  988. StkFloat data;
  989. if (my_random(1024) < nObjects_) {
  990. sndLevel_ += 512 * ratchet_ * totalEnergy_;
  991. }
  992. inputs_[0] = sndLevel_;
  993. inputs_[0] *= noise_tick() * ratchet_;
  994. sndLevel_ *= soundDecay_;
  995. inputs_[1] = inputs_[0];
  996. inputs_[0] -= outputs_[0][0]*coeffs_[0][0];
  997. inputs_[0] -= outputs_[0][1]*coeffs_[0][1];
  998. outputs_[0][1] = outputs_[0][0];
  999. outputs_[0][0] = inputs_[0];
  1000. inputs_[1] -= outputs_[1][0]*coeffs_[1][0];
  1001. inputs_[1] -= outputs_[1][1]*coeffs_[1][1];
  1002. outputs_[1][1] = outputs_[1][0];
  1003. outputs_[1][0] = inputs_[1];
  1004. finalZ_[2] = finalZ_[1];
  1005. finalZ_[1] = finalZ_[0];
  1006. finalZ_[0] = gains_[0]*outputs_[0][1] + gains_[1]*outputs_[1][1];
  1007. data = finalZ_[0] - finalZ_[2];
  1008. return data;
  1009. }
  1010. StkFloat Shakers :: tbamb_tick( void ) {
  1011. StkFloat data, temp;
  1012. static int which = 0;
  1013. int i;
  1014. if (shakeEnergy_ > MIN_ENERGY) {
  1015. shakeEnergy_ *= systemDecay_; // Exponential system decay
  1016. if (float_random(1024.0) < nObjects_) {
  1017. sndLevel_ += shakeEnergy_;
  1018. which = my_random(7);
  1019. }
  1020. temp = sndLevel_ * noise_tick(); // Actual Sound is Random
  1021. for (i=0;i<nFreqs_;i++) inputs_[i] = 0;
  1022. inputs_[which] = temp;
  1023. sndLevel_ *= soundDecay_; // Exponential Sound decay
  1024. finalZ_[2] = finalZ_[1];
  1025. finalZ_[1] = finalZ_[0];
  1026. finalZ_[0] = 0;
  1027. for (i=0;i<nFreqs_;i++) {
  1028. inputs_[i] -= outputs_[i][0]*coeffs_[i][0]; // Do
  1029. inputs_[i] -= outputs_[i][1]*coeffs_[i][1]; // resonant
  1030. outputs_[i][1] = outputs_[i][0]; // filter
  1031. outputs_[i][0] = inputs_[i]; // calculations
  1032. finalZ_[0] += gains_[i] * outputs_[i][1];
  1033. }
  1034. data = finalZCoeffs_[0] * finalZ_[0]; // Extra zero(s) for shape
  1035. data += finalZCoeffs_[1] * finalZ_[1]; // Extra zero(s) for shape
  1036. data += finalZCoeffs_[2] * finalZ_[2]; // Extra zero(s) for shape
  1037. if (data > 10000.0) data = 10000.0;
  1038. if (data < -10000.0) data = -10000.0;
  1039. data = data * 0.0001;
  1040. }
  1041. else data = 0.0;
  1042. return data;
  1043. }
  1044. } // stk namespace