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
2.6KB

  1. #pragma once
  2. #include "FunVCO.h"
  3. //#define _ORIGVCO
  4. template <class TBase>
  5. class FunVCOComposite : public TBase
  6. {
  7. public:
  8. FunVCOComposite()
  9. {
  10. init();
  11. }
  12. FunVCOComposite(struct Module * module) : TBase(module)
  13. {
  14. init();
  15. }
  16. enum ParamIds
  17. {
  18. MODE_PARAM,
  19. SYNC_PARAM,
  20. FREQ_PARAM,
  21. FINE_PARAM,
  22. FM_PARAM,
  23. PW_PARAM,
  24. PWM_PARAM,
  25. NUM_PARAMS
  26. };
  27. enum InputIds
  28. {
  29. PITCH_INPUT,
  30. FM_INPUT,
  31. SYNC_INPUT,
  32. PW_INPUT,
  33. NUM_INPUTS
  34. };
  35. enum OutputIds
  36. {
  37. SIN_OUTPUT,
  38. TRI_OUTPUT,
  39. SAW_OUTPUT,
  40. SQR_OUTPUT,
  41. NUM_OUTPUTS
  42. };
  43. enum LightIds
  44. {
  45. NUM_LIGHTS
  46. };
  47. void step() override;
  48. void init()
  49. {
  50. oscillator.init();
  51. }
  52. void setSampleRate(float rate)
  53. {
  54. oscillator.sampleTime = 1.f / rate;
  55. }
  56. private:
  57. #ifdef _ORIGVCO
  58. VoltageControlledOscillatorOrig<16, 16> oscillator;
  59. #else
  60. VoltageControlledOscillator<16, 16> oscillator;
  61. #endif
  62. };
  63. template <class TBase>
  64. inline void FunVCOComposite<TBase>::step()
  65. {
  66. oscillator.analog = TBase::params[MODE_PARAM].value > 0.0f;
  67. oscillator.soft = TBase::params[SYNC_PARAM].value <= 0.0f;
  68. float pitchFine = 3.0f * quadraticBipolar(TBase::params[FINE_PARAM].value);
  69. float pitchCv = 12.0f * TBase::inputs[PITCH_INPUT].value;
  70. if (TBase::inputs[FM_INPUT].active) {
  71. pitchCv += quadraticBipolar(TBase::params[FM_PARAM].value) * 12.0f * TBase::inputs[FM_INPUT].value;
  72. }
  73. oscillator.setPitch(TBase::params[FREQ_PARAM].value, pitchFine + pitchCv);
  74. oscillator.setPulseWidth(TBase::params[PW_PARAM].value + TBase::params[PWM_PARAM].value * TBase::inputs[PW_INPUT].value / 10.0f);
  75. oscillator.syncEnabled = TBase::inputs[SYNC_INPUT].active;
  76. #ifndef _ORIGVCO
  77. oscillator.sawEnabled = TBase::outputs[SAW_OUTPUT].active;
  78. oscillator.sinEnabled = TBase::outputs[SIN_OUTPUT].active;
  79. oscillator.sqEnabled = TBase::outputs[SQR_OUTPUT].active;
  80. oscillator.triEnabled = TBase::outputs[TRI_OUTPUT].active;
  81. #endif
  82. oscillator.process(TBase::engineGetSampleTime(), TBase::inputs[SYNC_INPUT].value);
  83. // Set output
  84. if (TBase::outputs[SIN_OUTPUT].active)
  85. TBase::outputs[SIN_OUTPUT].value = 5.0f * oscillator.sin();
  86. if (TBase::outputs[TRI_OUTPUT].active)
  87. TBase::outputs[TRI_OUTPUT].value = 5.0f * oscillator.tri();
  88. if (TBase::outputs[SAW_OUTPUT].active)
  89. TBase::outputs[SAW_OUTPUT].value = 5.0f * oscillator.saw();
  90. if (TBase::outputs[SQR_OUTPUT].active)
  91. TBase::outputs[SQR_OUTPUT].value = 5.0f * oscillator.sqr();
  92. }