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.

103 lines
3.0KB

  1. // Copyright 2013 Olivier Gillet.
  2. //
  3. // Author: Olivier Gillet (ol.gillet@gmail.com)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. // See http://creativecommons.org/licenses/MIT/ for more information.
  24. //
  25. // -----------------------------------------------------------------------------
  26. //
  27. // 808-style HH.
  28. #include "peaks/drums/high_hat.h"
  29. #include <cstdio>
  30. #include "stmlib/utils/dsp.h"
  31. #include "stmlib/utils/random.h"
  32. #include "peaks/resources.h"
  33. namespace peaks {
  34. using namespace stmlib;
  35. void HighHat::Init() {
  36. noise_.Init();
  37. noise_.set_frequency(105 << 7); // 8kHz
  38. noise_.set_resonance(24000);
  39. noise_.set_mode(SVF_MODE_BP);
  40. vca_coloration_.Init();
  41. vca_coloration_.set_frequency(110 << 7); // 13kHz
  42. vca_coloration_.set_resonance(0);
  43. vca_coloration_.set_mode(SVF_MODE_HP);
  44. vca_envelope_.Init();
  45. vca_envelope_.set_delay(0);
  46. vca_envelope_.set_decay(4093);
  47. }
  48. int16_t HighHat::ProcessSingleSample(uint8_t control) {
  49. if (control & CONTROL_GATE_RISING) {
  50. vca_envelope_.Trigger(32768 * 15);
  51. }
  52. phase_[0] += 48318382;
  53. phase_[1] += 71582788;
  54. phase_[2] += 37044092;
  55. phase_[3] += 54313440;
  56. phase_[4] += 66214079;
  57. phase_[5] += 93952409;
  58. int16_t noise = 0;
  59. noise += phase_[0] >> 31;
  60. noise += phase_[1] >> 31;
  61. noise += phase_[2] >> 31;
  62. noise += phase_[3] >> 31;
  63. noise += phase_[4] >> 31;
  64. noise += phase_[5] >> 31;
  65. noise <<= 12;
  66. // Run the SVF at the double of the original sample rate for stability.
  67. int32_t filtered_noise = 0;
  68. filtered_noise += noise_.Process(noise);
  69. filtered_noise += noise_.Process(noise);
  70. // The 808-style VCA amplifies only the positive section of the signal.
  71. if (filtered_noise < 0) {
  72. filtered_noise = 0;
  73. } else if (filtered_noise > 32767) {
  74. filtered_noise = 32767;
  75. }
  76. int32_t envelope = vca_envelope_.Process() >> 4;
  77. int32_t vca_noise = envelope * filtered_noise >> 14;
  78. CLIP(vca_noise);
  79. int32_t hh = 0;
  80. hh += vca_coloration_.Process(vca_noise);
  81. hh += vca_coloration_.Process(vca_noise);
  82. hh <<= 1;
  83. CLIP(hh);
  84. return hh;
  85. }
  86. } // namespace peaks