Compressor.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Compressor.h
  3. * -------------
  4. * Purpose: Implementation of the DMO Compressor 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. #ifndef NO_PLUGINS
  10. #include "../PlugInterface.h"
  11. OPENMPT_NAMESPACE_BEGIN
  12. namespace DMO
  13. {
  14. class Compressor final : public IMixPlugin
  15. {
  16. protected:
  17. enum Parameters
  18. {
  19. kCompGain = 0,
  20. kCompAttack,
  21. kCompRelease,
  22. kCompThreshold,
  23. kCompRatio,
  24. kCompPredelay,
  25. kCompNumParameters
  26. };
  27. std::array<float, kCompNumParameters> m_param;
  28. // Calculated parameters and coefficients
  29. float m_gain;
  30. float m_attack;
  31. float m_release;
  32. float m_threshold;
  33. float m_ratio;
  34. int32 m_predelay;
  35. // State
  36. std::vector<float> m_buffer;
  37. int32 m_bufPos, m_bufSize;
  38. float m_peak;
  39. public:
  40. static IMixPlugin* Create(VSTPluginLib &factory, CSoundFile &sndFile, SNDMIXPLUGIN *mixStruct);
  41. Compressor(VSTPluginLib &factory, CSoundFile &sndFile, SNDMIXPLUGIN *mixStruct);
  42. void Release() override { delete this; }
  43. int32 GetUID() const override { return 0xEF011F79; }
  44. int32 GetVersion() const override { return 0; }
  45. void Idle() override { }
  46. uint32 GetLatency() const override { return 0; }
  47. void Process(float *pOutL, float *pOutR, uint32 numFrames) override;
  48. float RenderSilence(uint32) override { return 0.0f; }
  49. int32 GetNumPrograms() const override { return 0; }
  50. int32 GetCurrentProgram() override { return 0; }
  51. void SetCurrentProgram(int32) override { }
  52. PlugParamIndex GetNumParameters() const override { return kCompNumParameters; }
  53. PlugParamValue GetParameter(PlugParamIndex index) override;
  54. void SetParameter(PlugParamIndex index, PlugParamValue value) override;
  55. void Resume() override;
  56. void Suspend() override { m_isResumed = false; }
  57. void PositionChanged() override;
  58. bool IsInstrument() const override { return false; }
  59. bool CanRecieveMidiEvents() override { return false; }
  60. bool ShouldProcessSilence() override { return true; }
  61. #ifdef MODPLUG_TRACKER
  62. CString GetDefaultEffectName() override { return _T("Compressor"); }
  63. CString GetParamName(PlugParamIndex param) override;
  64. CString GetParamLabel(PlugParamIndex) override;
  65. CString GetParamDisplay(PlugParamIndex param) override;
  66. CString GetCurrentProgramName() override { return CString(); }
  67. void SetCurrentProgramName(const CString &) override { }
  68. CString GetProgramName(int32) override { return CString(); }
  69. bool HasEditor() const override { return false; }
  70. #endif
  71. int GetNumInputChannels() const override { return 2; }
  72. int GetNumOutputChannels() const override { return 2; }
  73. protected:
  74. float GainInDecibel() const { return -60.0f + m_param[kCompGain] * 120.0f; }
  75. float AttackTime() const { return 0.01f + m_param[kCompAttack] * 499.99f; }
  76. float ReleaseTime() const { return 50.0f + m_param[kCompRelease] * 2950.0f; }
  77. float ThresholdInDecibel() const { return -60.0f + m_param[kCompThreshold] * 60.0f; }
  78. float CompressorRatio() const { return 1.0f + m_param[kCompRatio] * 99.0f; }
  79. float PreDelay() const { return m_param[kCompPredelay] * 4.0f; }
  80. void RecalculateCompressorParams();
  81. };
  82. } // namespace DMO
  83. OPENMPT_NAMESPACE_END
  84. #endif // !NO_PLUGINS