Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

135 lines
3.8KB

  1. # maraca.rb -- maraca.ins -> maraca.scm -> maraca.rb
  2. # Translator: Michael Scholz <mi-scholz@users.sourceforge.net>
  3. # Created: Fri Apr 22 23:29:22 CEST 2005
  4. # Changed: Sat Feb 19 18:27:34 CET 2011
  5. # Commentary:
  6. #
  7. # Perry Cook's maraca from CMJ vol 21 no 3 (Fall 97) p 44 translated
  8. # from CLM's maraca.ins
  9. #
  10. # Code:
  11. def maraca(start, dur,
  12. amp = 0.1,
  13. sound_decay = 0.95,
  14. system_decay = 0.999,
  15. probability = 0.0625,
  16. shell_freq = 3200.0,
  17. shell_reso = 0.96)
  18. temp = 0.0
  19. shake_energy = 0.0
  20. snd_level = 0.0
  21. input = 0.0
  22. output = Vct.new(2)
  23. coeffs = Vct.new(2)
  24. num_beans = 64
  25. j = 0
  26. sndamp = amp / 16384.0
  27. srate4 = (mus_srate / 4.0).floor
  28. gain = ((log(num_beans) / log(4)) * 40.0) / num_beans
  29. coeffs[0] = -2.0 * shell_reso * cos(hz2radians(shell_freq))
  30. coeffs[1] = shell_reso * shell_reso
  31. run_instrument(start, dur) do
  32. if temp < TWO_PI
  33. temp += hz2radians(20)
  34. shake_energy += 1.0 - cos(temp)
  35. end
  36. if j == srate4
  37. temp = 0.0
  38. j = 0
  39. end
  40. j += 1
  41. shake_energy *= system_decay
  42. if random(1.0) < probability
  43. snd_level = snd_level + gain * shake_energy
  44. end
  45. input = snd_level * (random(2.0) - 1.0)
  46. snd_level *= sound_decay
  47. input = input - output[0] * coeffs[0] - output[1] * coeffs[1]
  48. output[1], output[0] = output[0], input
  49. sndamp * (output[0] - output[1])
  50. end
  51. end
  52. # maraca: vct2channel(maraca(0, 5, 0.5))
  53. # cabasa: vct2channel(maraca(0, 5, 0.5, 0.95, 0.997, 0.5, 3000.0, 0.7))
  54. def big_maraca(start, dur,
  55. amp = 0.1,
  56. sound_decay = 0.95,
  57. system_decay = 0.999,
  58. probability = 0.0625,
  59. shell_freqs = [3200.0],
  60. shell_resos = [0.96],
  61. randiff = 0.01,
  62. with_filters = true)
  63. temp = 0.0
  64. temp1 = 0.0
  65. resn = shell_freqs.length
  66. shake_energy = 0.0
  67. snd_level = 0.0
  68. input = 0.0
  69. sum = 0.0
  70. last_sum = 0.0
  71. last_diff = 0.0
  72. diff = 0.0
  73. output = Vct.new(resn * 2)
  74. coeffs = Vct.new(resn * 2)
  75. basesf = Vct.new(resn)
  76. num_beans = 64
  77. j = 0
  78. sndamp = amp / 16384.0
  79. srate4 = (mus_srate / 4.0).floor
  80. gain = ((log(num_beans) / log(4)) * 40.0) / num_beans
  81. resn.times do |i|
  82. basesf[i] = coeffs[i * 2] = -2.0 * shell_resos[i] * cos(hz2radians(shell_freqs[i]))
  83. coeffs[1 + i * 2] = shell_resos[i] * shell_resos[i]
  84. end
  85. run_instrument(start, dur) do
  86. if temp < TWO_PI
  87. temp += hz2radians(20)
  88. shake_energy += 1.0 - cos(temp)
  89. end
  90. if j == srate4
  91. temp = 0.0
  92. j = 0
  93. end
  94. j += 1
  95. shake_energy *= system_decay
  96. if random(1.0) < probability
  97. snd_level = snd_level + gain * shake_energy
  98. basesf.each_with_index do |val, i|
  99. coeffs[i * 2] = val + (random(2.0 * randiff) - randiff)
  100. end
  101. end
  102. input = snd_level * (random(2.0) - 1.0)
  103. snd_level *= sound_decay
  104. temp1 = input
  105. last_sum = sum
  106. sum = 0.0
  107. resn.times do |i|
  108. input = temp1
  109. input = input - output[i * 2] * coeffs[i * 2] - output[i * 2 + 1] * coeffs[i * 2 + 1]
  110. output[i * 2 + 1], output[i * 2] = output[i * 2], input
  111. sum += input
  112. end
  113. if with_filters
  114. last_diff, diff = diff, sum - last_sum
  115. temp1 = last_diff + diff
  116. else
  117. temp1 = sum
  118. end
  119. sndamp * temp1
  120. end
  121. end
  122. # tambourine: big_maraca(0, 1, 0.25, 0.95, 0.9985, 0.03125,
  123. # [2300, 5600, 8100], [0.96, 0.995, 0.995], 0.01)
  124. # sleighbells: big_maraca(0, 2, 0.5, 0.97, 0.9994, 0.03125,
  125. # [2500, 5300, 6500, 8300, 9800], [0.999, 0.999, 0.999, 0.999, 0.999])
  126. # sekere: big_maraca(0, 2, 0.5, 0.96, 0.999, .0625, [5500], [0.6])
  127. # windchimes: big_maraca(0, 2, 0.5, 0.99995, 0.95, 0.001,
  128. # [2200, 2800, 3400], [0.995, 0.995, 0.995], 0.01, false)
  129. # maraca.rb ends here