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.

114 lines
2.8KB

  1. #pragma once
  2. #include "FunVCO3.h"
  3. template <class TBase>
  4. class KSComposite : public TBase
  5. {
  6. public:
  7. KSComposite()
  8. {
  9. init();
  10. }
  11. KSComposite(struct Module * module) : TBase(module)
  12. {
  13. init();
  14. }
  15. enum ParamIds
  16. {
  17. OCTAVE_PARAM,
  18. SEMI_PARAM,
  19. FINE_PARAM,
  20. FM_PARAM,
  21. PW_PARAM,
  22. PWM_PARAM,
  23. NUM_PARAMS
  24. };
  25. enum InputIds
  26. {
  27. PITCH_INPUT,
  28. FM_INPUT,
  29. SYNC_INPUT,
  30. PW_INPUT,
  31. NUM_INPUTS
  32. };
  33. enum OutputIds
  34. {
  35. SIN_OUTPUT,
  36. TRI_OUTPUT,
  37. SAW_OUTPUT,
  38. SQR_OUTPUT,
  39. NUM_OUTPUTS
  40. };
  41. enum LightIds
  42. {
  43. NUM_LIGHTS
  44. };
  45. void step() override;
  46. void init()
  47. {
  48. oscillator.init();
  49. }
  50. #if 0
  51. void setSampleRate(float rate)
  52. {
  53. oscillator.sampleTime = 1.f / rate;
  54. }
  55. #endif
  56. private:
  57. KSOscillator <16, 16> oscillator;
  58. };
  59. template <class TBase>
  60. inline void KSComposite<TBase>::step()
  61. {
  62. // TODO: tune these
  63. /* from functional
  64. float pitchFine = 3.0f * quadraticBipolar(TBase::params[FINE_PARAM].value);
  65. float pitchCv = 12.0f * TBase::inputs[PITCH_INPUT].value;
  66. if (TBase::inputs[FM_INPUT].active) {
  67. pitchCv += quadraticBipolar(TBase::params[FM_PARAM].value) * 12.0f * TBase::inputs[FM_INPUT].value;
  68. }
  69. */
  70. // const float cv = getInput(osc, CV1_INPUT, CV2_INPUT, CV3_INPUT);
  71. const float cv = TBase::inputs[PITCH_INPUT].value;
  72. const float finePitch = TBase::params[FINE_PARAM].value / 12.0f;
  73. const float semiPitch = TBase::params[SEMI_PARAM].value / 12.0f;
  74. // const float fm = getInput(osc, FM1_INPUT, FM2_INPUT, FM3_INPUT);
  75. float pitch = 1.0f + roundf(TBase::params[OCTAVE_PARAM].value) +
  76. semiPitch +
  77. finePitch;
  78. pitch += cv;
  79. oscillator.setPitch(pitch);
  80. oscillator.setPulseWidth(TBase::params[PW_PARAM].value + TBase::params[PWM_PARAM].value * TBase::inputs[PW_INPUT].value / 10.0f);
  81. oscillator.syncEnabled = TBase::inputs[SYNC_INPUT].active;
  82. oscillator.sawEnabled = TBase::outputs[SAW_OUTPUT].active;
  83. oscillator.sinEnabled = TBase::outputs[SIN_OUTPUT].active;
  84. oscillator.sqEnabled = TBase::outputs[SQR_OUTPUT].active;
  85. oscillator.triEnabled = TBase::outputs[TRI_OUTPUT].active;
  86. oscillator.process(TBase::engineGetSampleTime(), TBase::inputs[SYNC_INPUT].value, TBase::engineGetSampleTime());
  87. // Set output
  88. if (TBase::outputs[SIN_OUTPUT].active)
  89. TBase::outputs[SIN_OUTPUT].value = 5.0f * oscillator.sin();
  90. if (TBase::outputs[TRI_OUTPUT].active)
  91. TBase::outputs[TRI_OUTPUT].value = 5.0f * oscillator.tri();
  92. if (TBase::outputs[SAW_OUTPUT].active)
  93. TBase::outputs[SAW_OUTPUT].value = 5.0f * oscillator.saw();
  94. if (TBase::outputs[SQR_OUTPUT].active)
  95. TBase::outputs[SQR_OUTPUT].value = 5.0f * oscillator.sqr();
  96. }