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.

87 lines
1.6KB

  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* modelVCO;
  8. namespace bogaudio {
  9. struct VCO : Module {
  10. enum ParamsIds {
  11. FREQUENCY_PARAM,
  12. FINE_PARAM,
  13. SLOW_PARAM,
  14. PW_PARAM,
  15. FM_PARAM,
  16. FM_TYPE_PARAM,
  17. NUM_PARAMS
  18. };
  19. enum InputsIds {
  20. PITCH_INPUT,
  21. SYNC_INPUT,
  22. PW_INPUT,
  23. FM_INPUT,
  24. NUM_INPUTS
  25. };
  26. enum OutputsIds {
  27. SQUARE_OUTPUT,
  28. SAW_OUTPUT,
  29. TRIANGLE_OUTPUT,
  30. SINE_OUTPUT,
  31. NUM_OUTPUTS
  32. };
  33. enum LightsIds {
  34. SLOW_LIGHT,
  35. NUM_LIGHTS
  36. };
  37. const int modulationSteps = 100;
  38. const float amplitude = 5.0f;
  39. static constexpr int oversample = 8;
  40. int _modulationStep = 0;
  41. float _oversampleThreshold = 0.0f;
  42. float _frequency = 0.0f;
  43. float _baseVOct = 0.0f;
  44. float _baseHz = 0.0f;
  45. bool _slowMode = false;
  46. float _fmDepth = 0.0f;
  47. bool _fmLinearMode = false;
  48. Phasor _phasor;
  49. BandLimitedSquareOscillator _square;
  50. BandLimitedSawOscillator _saw;
  51. TriangleOscillator _triangle;
  52. SineTableOscillator _sine;
  53. CICDecimator _squareDecimator;
  54. CICDecimator _sawDecimator;
  55. CICDecimator _triangleDecimator;
  56. float _squareBuffer[oversample];
  57. float _sawBuffer[oversample];
  58. float _triangleBuffer[oversample];
  59. PositiveZeroCrossing _syncTrigger;
  60. SlewLimiter _squarePulseWidthSL;
  61. VCO() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {
  62. onReset();
  63. setSampleRate(engineGetSampleRate());
  64. _saw.setQuality(12);
  65. _square.setQuality(12);
  66. }
  67. void onReset() override;
  68. void onSampleRateChange() override;
  69. void step() override;
  70. void setSampleRate(float sampleRate);
  71. void setFrequency(float frequency);
  72. };
  73. } // namespace bogaudio