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.

137 lines
3.0KB

  1. #pragma once
  2. #include "bogaudio.hpp"
  3. #include "dsp/filter.hpp"
  4. #include "dsp/oscillator.hpp"
  5. #include "dsp/signal.hpp"
  6. using namespace bogaudio::dsp;
  7. extern Model* modelXCO;
  8. namespace bogaudio {
  9. struct XCO : Module {
  10. enum ParamsIds {
  11. FREQUENCY_PARAM,
  12. FINE_PARAM,
  13. SLOW_PARAM,
  14. FM_DEPTH_PARAM,
  15. FM_TYPE_PARAM,
  16. SQUARE_PW_PARAM,
  17. SQUARE_PHASE_PARAM,
  18. SQUARE_MIX_PARAM,
  19. SAW_SATURATION_PARAM,
  20. SAW_PHASE_PARAM,
  21. SAW_MIX_PARAM,
  22. TRIANGLE_SAMPLE_PARAM,
  23. TRIANGLE_PHASE_PARAM,
  24. TRIANGLE_MIX_PARAM,
  25. SINE_FEEDBACK_PARAM,
  26. SINE_PHASE_PARAM,
  27. SINE_MIX_PARAM,
  28. NUM_PARAMS
  29. };
  30. enum InputsIds {
  31. FM_INPUT,
  32. FM_DEPTH_INPUT,
  33. SQUARE_PW_INPUT,
  34. SQUARE_PHASE_INPUT,
  35. SQUARE_MIX_INPUT,
  36. SAW_SATURATION_INPUT,
  37. SAW_PHASE_INPUT,
  38. SAW_MIX_INPUT,
  39. TRIANGLE_SAMPLE_INPUT,
  40. TRIANGLE_PHASE_INPUT,
  41. TRIANGLE_MIX_INPUT,
  42. SINE_FEEDBACK_INPUT,
  43. SINE_PHASE_INPUT,
  44. SINE_MIX_INPUT,
  45. PITCH_INPUT,
  46. SYNC_INPUT,
  47. NUM_INPUTS
  48. };
  49. enum OutputsIds {
  50. SQUARE_OUTPUT,
  51. SAW_OUTPUT,
  52. TRIANGLE_OUTPUT,
  53. SINE_OUTPUT,
  54. MIX_OUTPUT,
  55. NUM_OUTPUTS
  56. };
  57. enum LightsIds {
  58. SLOW_LIGHT,
  59. NUM_LIGHTS
  60. };
  61. const int modulationSteps = 100;
  62. const float amplitude = 5.0f;
  63. static constexpr int oversample = 8;
  64. const float sineOversampleMixIncrement = 0.01f;
  65. int _modulationStep = 0;
  66. float _oversampleThreshold = 0.0f;
  67. float _frequency = 0.0f;
  68. float _baseVOct = 0.0f;
  69. float _baseHz = 0.0f;
  70. bool _slowMode = false;
  71. float _fmDepth = 0.0f;
  72. bool _fmLinearMode = false;
  73. float _triangleSampleWidth = 0.0f;
  74. float _sineFeedback = 0.0f;
  75. float _sineOMix = 0.0f;
  76. float _sineFeedbackDelayedSample = 0.0f;
  77. Phasor::phase_delta_t _squarePhaseOffset = 0.0f;
  78. Phasor::phase_delta_t _sawPhaseOffset = 0.0f;
  79. Phasor::phase_delta_t _trianglePhaseOffset = 0.0f;
  80. Phasor::phase_delta_t _sinePhaseOffset = 0.0f;
  81. float _squareMix = 1.0f;
  82. float _sawMix = 1.0f;
  83. float _triangleMix = 1.0f;
  84. float _sineMix = 1.0f;
  85. Phasor _phasor;
  86. BandLimitedSquareOscillator _square;
  87. BandLimitedSawOscillator _saw;
  88. TriangleOscillator _triangle;
  89. SineTableOscillator _sine;
  90. CICDecimator _squareDecimator;
  91. CICDecimator _sawDecimator;
  92. CICDecimator _triangleDecimator;
  93. CICDecimator _sineDecimator;
  94. float _squareBuffer[oversample];
  95. float _sawBuffer[oversample];
  96. float _triangleBuffer[oversample];
  97. float _sineBuffer[oversample];
  98. PositiveZeroCrossing _syncTrigger;
  99. SlewLimiter _fmDepthSL;
  100. SlewLimiter _squarePulseWidthSL;
  101. SlewLimiter _sawSaturationSL;
  102. SlewLimiter _triangleSampleWidthSL;
  103. SlewLimiter _sineFeedbackSL;
  104. SlewLimiter _squareMixSL;
  105. SlewLimiter _sawMixSL;
  106. SlewLimiter _triangleMixSL;
  107. SlewLimiter _sineMixSL;
  108. XCO() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {
  109. onReset();
  110. setSampleRate(engineGetSampleRate());
  111. _saw.setQuality(12);
  112. _square.setQuality(12);
  113. }
  114. void onReset() override;
  115. void onSampleRateChange() override;
  116. void step() override;
  117. Phasor::phase_delta_t phaseOffset(Param& param, Input& input);
  118. float level(Param& param, Input& input);
  119. void setSampleRate(float sampleRate);
  120. void setFrequency(float frequency);
  121. };
  122. } // namespace bogaudio