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.

107 lines
3.1KB

  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. // Trigger to gate converter with pre-delay, duration, and repetitions.
  28. #ifndef PEAKS_PULSE_PROCESSOR_PULSE_SHAPER_H_
  29. #define PEAKS_PULSE_PROCESSOR_PULSE_SHAPER_H_
  30. #include "stmlib/stmlib.h"
  31. #include "stmlib/utils/ring_buffer.h"
  32. #include "peaks/gate_processor.h"
  33. namespace peaks {
  34. struct Pulse {
  35. uint16_t initial_delay_counter;
  36. uint16_t duration_counter;
  37. uint16_t delay_counter;
  38. uint16_t repetition_counter;
  39. };
  40. static const uint8_t kPulseBufferSize = 32;
  41. class PulseShaper {
  42. public:
  43. PulseShaper() { }
  44. ~PulseShaper() { }
  45. void Init();
  46. void FillBuffer(InputBuffer* input_buffer, OutputBuffer* output_buffer);
  47. void Configure(uint16_t* parameter, ControlMode control_mode) {
  48. if (control_mode == CONTROL_MODE_HALF) {
  49. set_initial_delay(0);
  50. set_duration(parameter[0] >> 1);
  51. set_delay((parameter[0] >> 1) + 2048);
  52. set_num_repetitions(parameter[1]);
  53. } else {
  54. set_initial_delay(parameter[0]);
  55. set_duration(parameter[1] >> 1);
  56. set_delay(parameter[2] >> 1);
  57. set_num_repetitions(parameter[3]);
  58. }
  59. }
  60. inline void set_initial_delay(uint16_t initial_delay) {
  61. initial_delay_ = initial_delay;
  62. }
  63. inline void set_duration(uint16_t duration) {
  64. duration_ = duration;
  65. }
  66. inline void set_delay(uint16_t delay) {
  67. delay_ = delay;
  68. }
  69. inline void set_num_repetitions(uint16_t num_repetitions) {
  70. num_repetitions_ = num_repetitions >> 13;
  71. }
  72. private:
  73. uint16_t delay() const;
  74. uint16_t duration() const;
  75. uint16_t initial_delay() const;
  76. uint16_t initial_delay_;
  77. uint16_t duration_;
  78. uint16_t delay_;
  79. uint16_t num_repetitions_;
  80. uint16_t previous_num_pulses_;
  81. uint16_t retrig_counter_;
  82. Pulse pulse_buffer_[kPulseBufferSize];
  83. DISALLOW_COPY_AND_ASSIGN(PulseShaper);
  84. };
  85. } // namespace peaks
  86. #endif // PEAKS_PULSE_PROCESSOR_PULSE_SHAPER_H_