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.

119 lines
3.4KB

  1. // Copyright 2014 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. // Group of voices.
  28. #ifndef ELEMENTS_DSP_PART_H_
  29. #define ELEMENTS_DSP_PART_H_
  30. #include "stmlib/stmlib.h"
  31. #include "elements/dsp/fx/reverb.h"
  32. #include "elements/dsp/ominous_voice.h"
  33. #include "elements/dsp/patch.h"
  34. #include "elements/dsp/voice.h"
  35. namespace elements {
  36. struct PerformanceState {
  37. bool gate;
  38. float note;
  39. float modulation;
  40. float strength;
  41. };
  42. // Polyphony is actually possible, but you have to reduce the number of modes
  43. // to 16, and this doesn't sound very good...
  44. const size_t kNumVoices = 1;
  45. class Part {
  46. public:
  47. Part() { }
  48. ~Part() { }
  49. void Init(uint16_t* reverb_buffer);
  50. void Process(
  51. const PerformanceState& performance_state,
  52. const float* blow_in,
  53. const float* strike_in,
  54. float* main,
  55. float* aux,
  56. size_t n);
  57. inline Patch* mutable_patch() { return &patch_; }
  58. void Seed(uint32_t* seed, size_t size);
  59. void Panic();
  60. // For metering.
  61. inline float exciter_level() const { return scaled_exciter_level_; }
  62. inline float resonator_level() const { return scaled_resonator_level_; }
  63. inline bool gate() const { return previous_gate_; }
  64. inline bool bypass() const { return bypass_; }
  65. inline void set_bypass(bool bypass) { bypass_ = bypass; }
  66. inline bool easter_egg() const { return easter_egg_; }
  67. inline void set_easter_egg(bool easter_egg) { easter_egg_ = easter_egg; }
  68. inline ResonatorModel resonator_model() const { return resonator_model_; }
  69. inline void set_resonator_model(ResonatorModel r) { resonator_model_ = r; }
  70. private:
  71. Patch patch_;
  72. Voice voice_[kNumVoices];
  73. OminousVoice ominous_voice_[kNumVoices];
  74. bool panic_;
  75. bool bypass_;
  76. bool easter_egg_;
  77. bool previous_gate_;
  78. float note_[kNumVoices];
  79. size_t num_voices_;
  80. size_t active_voice_;
  81. float silence_[kMaxBlockSize];
  82. float raw_buffer_[kMaxBlockSize];
  83. float center_buffer_[kMaxBlockSize];
  84. float sides_buffer_[kMaxBlockSize];
  85. float scaled_exciter_level_;
  86. float scaled_resonator_level_;
  87. float resonator_level_;
  88. Reverb reverb_;
  89. ResonatorModel resonator_model_;
  90. DISALLOW_COPY_AND_ASSIGN(Part);
  91. };
  92. } // namespace elements
  93. #endif // ELEMENTS_DSP_PART_H_