ParamEq.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * ParamEq.h
  3. * ---------
  4. * Purpose: Implementation of the DMO Parametric Equalizer 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 ParamEq final : public IMixPlugin
  15. {
  16. protected:
  17. enum Parameters
  18. {
  19. kEqCenter = 0,
  20. kEqBandwidth,
  21. kEqGain,
  22. kEqNumParameters
  23. };
  24. std::array<float, kEqNumParameters> m_param;
  25. // Equalizer coefficients
  26. float b0DIVa0, b1DIVa0, b2DIVa0, a1DIVa0, a2DIVa0;
  27. // Equalizer memory
  28. float x1[2], x2[2];
  29. float y1[2], y2[2];
  30. float m_maxFreqParam;
  31. public:
  32. static IMixPlugin* Create(VSTPluginLib &factory, CSoundFile &sndFile, SNDMIXPLUGIN *mixStruct);
  33. ParamEq(VSTPluginLib &factory, CSoundFile &sndFile, SNDMIXPLUGIN *mixStruct);
  34. void Release() override { delete this; }
  35. int32 GetUID() const override { return 0x120CED89; }
  36. int32 GetVersion() const override { return 0; }
  37. void Idle() override { }
  38. uint32 GetLatency() const override { return 0; }
  39. void Process(float *pOutL, float *pOutR, uint32 numFrames) override;
  40. float RenderSilence(uint32) override { return 0.0f; }
  41. int32 GetNumPrograms() const override { return 0; }
  42. int32 GetCurrentProgram() override { return 0; }
  43. void SetCurrentProgram(int32) override { }
  44. PlugParamIndex GetNumParameters() const override { return kEqNumParameters; }
  45. PlugParamValue GetParameter(PlugParamIndex index) override;
  46. void SetParameter(PlugParamIndex index, PlugParamValue value) override;
  47. void Resume() override;
  48. void Suspend() override { m_isResumed = false; }
  49. void PositionChanged() override;
  50. bool IsInstrument() const override { return false; }
  51. bool CanRecieveMidiEvents() override { return false; }
  52. bool ShouldProcessSilence() override { return true; }
  53. #ifdef MODPLUG_TRACKER
  54. CString GetDefaultEffectName() override { return _T("ParamEq"); }
  55. CString GetParamName(PlugParamIndex param) override;
  56. CString GetParamLabel(PlugParamIndex) override;
  57. CString GetParamDisplay(PlugParamIndex param) override;
  58. CString GetCurrentProgramName() override { return CString(); }
  59. void SetCurrentProgramName(const CString &) override { }
  60. CString GetProgramName(int32) override { return CString(); }
  61. bool HasEditor() const override { return false; }
  62. #endif
  63. int GetNumInputChannels() const override { return 2; }
  64. int GetNumOutputChannels() const override { return 2; }
  65. protected:
  66. float BandwidthInSemitones() const { return 1.0f + m_param[kEqBandwidth] * 35.0f; }
  67. float FreqInHertz() const { return 80.0f + m_param[kEqCenter] * 15920.0f; }
  68. float GainInDecibel() const { return (m_param[kEqGain] - 0.5f) * 30.0f; }
  69. void RecalculateEqParams();
  70. };
  71. } // namespace DMO
  72. OPENMPT_NAMESPACE_END
  73. #endif // !NO_PLUGINS