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.

117 lines
3.5KB

  1. // Copyright 2012 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. // Macro-oscillator entry point.
  28. #ifndef BRAIDS_MACRO_OSCILLATOR_H_
  29. #define BRAIDS_MACRO_OSCILLATOR_H_
  30. #include "stmlib/stmlib.h"
  31. #include <cstring>
  32. #include "braids/analog_oscillator.h"
  33. #include "braids/digital_oscillator.h"
  34. #include "braids/resources.h"
  35. #include "braids/settings.h"
  36. namespace braids {
  37. class MacroOscillator {
  38. public:
  39. typedef void (MacroOscillator::*RenderFn)(const uint8_t*, int16_t*, size_t);
  40. MacroOscillator() { }
  41. ~MacroOscillator() { }
  42. inline void Init() {
  43. analog_oscillator_[0].Init();
  44. analog_oscillator_[1].Init();
  45. analog_oscillator_[2].Init();
  46. digital_oscillator_.Init();
  47. lp_state_ = 0;
  48. previous_parameter_[0] = 0;
  49. previous_parameter_[1] = 0;
  50. }
  51. inline void set_shape(MacroOscillatorShape shape) {
  52. if (shape != shape_) {
  53. Strike();
  54. }
  55. shape_ = shape;
  56. }
  57. inline void set_pitch(int16_t pitch) {
  58. pitch_ = pitch;
  59. }
  60. inline int16_t pitch() const { return pitch_; }
  61. inline void set_parameters(
  62. int16_t parameter_1,
  63. int16_t parameter_2) {
  64. parameter_[0] = parameter_1;
  65. parameter_[1] = parameter_2;
  66. }
  67. inline void Strike() {
  68. digital_oscillator_.Strike();
  69. }
  70. void Render(const uint8_t* sync_buffer, int16_t* buffer, size_t size);
  71. private:
  72. void RenderCSaw(const uint8_t*, int16_t*, size_t);
  73. void RenderMorph(const uint8_t*, int16_t*, size_t);
  74. void RenderSawSquare(const uint8_t*, int16_t*, size_t);
  75. void RenderDualSync(const uint8_t*, int16_t*, size_t);
  76. void RenderSineTriangle(const uint8_t*, int16_t*, size_t);
  77. void RenderBuzz(const uint8_t*, int16_t*, size_t);
  78. void RenderDigital(const uint8_t*, int16_t*, size_t);
  79. void RenderSawComb(const uint8_t*, int16_t*, size_t);
  80. void RenderTriple(const uint8_t*, int16_t*, size_t);
  81. void ConfigureTriple(AnalogOscillatorShape shape);
  82. int16_t parameter_[2];
  83. int16_t previous_parameter_[2];
  84. int16_t pitch_;
  85. uint8_t sync_buffer_[24];
  86. int16_t temp_buffer_[24];
  87. int32_t lp_state_;
  88. AnalogOscillator analog_oscillator_[3];
  89. DigitalOscillator digital_oscillator_;
  90. MacroOscillatorShape shape_;
  91. static RenderFn fn_table_[];
  92. DISALLOW_COPY_AND_ASSIGN(MacroOscillator);
  93. };
  94. } // namespace braids
  95. #endif // BRAIDS_MACRO_OSCILLATOR_H_