Chorus.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Chorus.h
  3. * --------
  4. * Purpose: Implementation of the DMO Chorus DSP (for non-Windows platforms)
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #pragma once
  10. #include "openmpt/all/BuildSettings.hpp"
  11. #ifndef NO_PLUGINS
  12. #include "../PlugInterface.h"
  13. OPENMPT_NAMESPACE_BEGIN
  14. namespace DMO
  15. {
  16. class Chorus : public IMixPlugin
  17. {
  18. protected:
  19. enum Parameters
  20. {
  21. kChorusWetDryMix = 0,
  22. kChorusDepth,
  23. kChorusFrequency,
  24. kChorusWaveShape,
  25. kChorusPhase,
  26. kChorusFeedback,
  27. kChorusDelay,
  28. kChorusNumParameters
  29. };
  30. std::array<float, kChorusNumParameters> m_param;
  31. // Calculated parameters
  32. float m_waveShapeMin, m_waveShapeMax, m_waveShapeVal;
  33. float m_depthDelay;
  34. float m_frequency;
  35. int32 m_delayOffset;
  36. const bool m_isFlanger = false;
  37. // State
  38. std::vector<float> m_bufferL, m_bufferR; // Only m_bufferL is used in case of !m_isFlanger
  39. std::array<float, 3> m_DryBufferL, m_DryBufferR;
  40. int32 m_bufPos = 0, m_bufSize = 0;
  41. int32 m_delayL = 0, m_delayR = 0;
  42. int32 m_dryWritePos = 0;
  43. public:
  44. static IMixPlugin* Create(VSTPluginLib &factory, CSoundFile &sndFile, SNDMIXPLUGIN *mixStruct);
  45. Chorus(VSTPluginLib &factory, CSoundFile &sndFile, SNDMIXPLUGIN *mixStruct, bool stereoBuffers = false);
  46. void Release() override { delete this; }
  47. int32 GetUID() const override { return 0xEFE6629C; }
  48. int32 GetVersion() const override { return 0; }
  49. void Idle() override { }
  50. uint32 GetLatency() const override { return 0; }
  51. void Process(float *pOutL, float *pOutR, uint32 numFrames) override;
  52. float RenderSilence(uint32) override { return 0.0f; }
  53. int32 GetNumPrograms() const override { return 0; }
  54. int32 GetCurrentProgram() override { return 0; }
  55. void SetCurrentProgram(int32) override { }
  56. PlugParamIndex GetNumParameters() const override { return kChorusNumParameters; }
  57. PlugParamValue GetParameter(PlugParamIndex index) override;
  58. void SetParameter(PlugParamIndex index, PlugParamValue value) override;
  59. void Resume() override;
  60. void Suspend() override { m_isResumed = false; }
  61. void PositionChanged() override;
  62. bool IsInstrument() const override { return false; }
  63. bool CanRecieveMidiEvents() override { return false; }
  64. bool ShouldProcessSilence() override { return true; }
  65. #ifdef MODPLUG_TRACKER
  66. CString GetDefaultEffectName() override { return _T("Chorus"); }
  67. CString GetParamName(PlugParamIndex param) override;
  68. CString GetParamLabel(PlugParamIndex) override;
  69. CString GetParamDisplay(PlugParamIndex param) override;
  70. CString GetCurrentProgramName() override { return CString(); }
  71. void SetCurrentProgramName(const CString &) override { }
  72. CString GetProgramName(int32) override { return CString(); }
  73. bool HasEditor() const override { return false; }
  74. #endif
  75. void BeginSetProgram(int32) override { }
  76. void EndSetProgram() override { }
  77. int GetNumInputChannels() const override { return 2; }
  78. int GetNumOutputChannels() const override { return 2; }
  79. protected:
  80. int32 GetBufferIntOffset(int32 fpOffset) const;
  81. virtual float WetDryMix() const { return m_param[kChorusWetDryMix]; }
  82. virtual bool IsTriangle() const { return m_param[kChorusWaveShape] < 1; }
  83. virtual float Depth() const { return m_param[kChorusDepth]; }
  84. virtual float Feedback() const { return -99.0f + m_param[kChorusFeedback] * 198.0f; }
  85. virtual float Delay() const { return m_param[kChorusDelay] * 20.0f; }
  86. virtual float FrequencyInHertz() const { return m_param[kChorusFrequency] * 10.0f; }
  87. virtual int Phase() const { return mpt::saturate_round<uint32>(m_param[kChorusPhase] * 4.0f); }
  88. void RecalculateChorusParams();
  89. };
  90. } // namespace DMO
  91. OPENMPT_NAMESPACE_END
  92. #endif // !NO_PLUGINS