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.

99 lines
1.8KB

  1. #pragma once
  2. #include "bogaudio.hpp"
  3. #include "dsp/envelope.hpp"
  4. #include "dsp/filter.hpp"
  5. #include "dsp/oscillator.hpp"
  6. #include "dsp/signal.hpp"
  7. using namespace bogaudio::dsp;
  8. extern Model* modelFMOp;
  9. namespace bogaudio {
  10. struct FMOp : Module {
  11. enum ParamsIds {
  12. RATIO_PARAM,
  13. FINE_PARAM,
  14. ATTACK_PARAM,
  15. DECAY_PARAM,
  16. SUSTAIN_PARAM,
  17. RELEASE_PARAM,
  18. DEPTH_PARAM,
  19. FEEDBACK_PARAM,
  20. LEVEL_PARAM,
  21. ENV_TO_LEVEL_PARAM,
  22. ENV_TO_FEEDBACK_PARAM,
  23. ENV_TO_DEPTH_PARAM,
  24. NUM_PARAMS
  25. };
  26. enum InputsIds {
  27. SUSTAIN_INPUT,
  28. DEPTH_INPUT,
  29. FEEDBACK_INPUT,
  30. LEVEL_INPUT,
  31. PITCH_INPUT,
  32. GATE_INPUT,
  33. FM_INPUT,
  34. NUM_INPUTS
  35. };
  36. enum OutputsIds {
  37. AUDIO_OUTPUT,
  38. NUM_OUTPUTS
  39. };
  40. enum LightsIds {
  41. ENV_TO_LEVEL_LIGHT,
  42. ENV_TO_FEEDBACK_LIGHT,
  43. ENV_TO_DEPTH_LIGHT,
  44. NUM_LIGHTS
  45. };
  46. const float amplitude = 5.0f;
  47. const int modulationSteps = 100;
  48. static constexpr int oversample = 8;
  49. const float oversampleMixIncrement = 0.01f;
  50. int _steps = 0;
  51. float _feedback = 0.0f;
  52. float _feedbackDelayedSample = 0.0f;
  53. float _depth = 0.0f;
  54. float _level = 0.0f;
  55. bool _envelopeOn = false;
  56. bool _levelEnvelopeOn = false;
  57. bool _feedbackEnvelopeOn = false;
  58. bool _depthEnvelopeOn = false;
  59. float _maxFrequency = 0.0f;
  60. float _buffer[oversample];
  61. float _oversampleMix = 0.0f;
  62. dsp::ADSR _envelope;
  63. Phasor _phasor;
  64. SineTableOscillator _sineTable;
  65. CICDecimator _decimator;
  66. SchmittTrigger _gateTrigger;
  67. SlewLimiter _feedbackSL;
  68. SlewLimiter _depthSL;
  69. SlewLimiter _levelSL;
  70. SlewLimiter _sustainSL;
  71. Amplifier _amplifier;
  72. bool _linearLevel = false;
  73. FMOp()
  74. : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS)
  75. , _envelope(true)
  76. {
  77. onReset();
  78. onSampleRateChange();
  79. }
  80. void onReset() override;
  81. void onSampleRateChange() override;
  82. json_t* toJson() override;
  83. void fromJson(json_t* root) override;
  84. void step() override;
  85. };
  86. } // namespace bogaudio