Distortion.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Distortion.h
  3. * ------------
  4. * Purpose: Implementation of the DMO Distortion 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 Distortion final : public IMixPlugin
  15. {
  16. protected:
  17. enum Parameters
  18. {
  19. kDistGain = 0,
  20. kDistEdge,
  21. kDistPreLowpassCutoff,
  22. kDistPostEQCenterFrequency,
  23. kDistPostEQBandwidth,
  24. kDistNumParameters
  25. };
  26. std::array<float, kDistNumParameters> m_param;
  27. // Pre-EQ coefficients
  28. float m_preEQz1[2], m_preEQb1, m_preEQa0;
  29. // Post-EQ coefficients
  30. float m_postEQz1[2], m_postEQz2[2], m_postEQa0, m_postEQb0, m_postEQb1;
  31. uint8 m_edge, m_shift;
  32. public:
  33. static IMixPlugin* Create(VSTPluginLib &factory, CSoundFile &sndFile, SNDMIXPLUGIN *mixStruct);
  34. Distortion(VSTPluginLib &factory, CSoundFile &sndFile, SNDMIXPLUGIN *mixStruct);
  35. void Release() override { delete this; }
  36. int32 GetUID() const override { return 0xEF114C90; }
  37. int32 GetVersion() const override { return 0; }
  38. void Idle() override { }
  39. uint32 GetLatency() const override { return 0; }
  40. void Process(float *pOutL, float *pOutR, uint32 numFrames) override;
  41. float RenderSilence(uint32) override { return 0.0f; }
  42. int32 GetNumPrograms() const override { return 0; }
  43. int32 GetCurrentProgram() override { return 0; }
  44. void SetCurrentProgram(int32) override { }
  45. PlugParamIndex GetNumParameters() const override { return kDistNumParameters; }
  46. PlugParamValue GetParameter(PlugParamIndex index) override;
  47. void SetParameter(PlugParamIndex index, PlugParamValue value) override;
  48. void Resume() override;
  49. void Suspend() override { m_isResumed = false; }
  50. void PositionChanged() override;
  51. bool IsInstrument() const override { return false; }
  52. bool CanRecieveMidiEvents() override { return false; }
  53. bool ShouldProcessSilence() override { return true; }
  54. #ifdef MODPLUG_TRACKER
  55. CString GetDefaultEffectName() override { return _T("Distortion"); }
  56. CString GetParamName(PlugParamIndex param) override;
  57. CString GetParamLabel(PlugParamIndex) override;
  58. CString GetParamDisplay(PlugParamIndex param) override;
  59. CString GetCurrentProgramName() override { return CString(); }
  60. void SetCurrentProgramName(const CString &) override { }
  61. CString GetProgramName(int32) override { return CString(); }
  62. bool HasEditor() const override { return false; }
  63. #endif
  64. int GetNumInputChannels() const override { return 2; }
  65. int GetNumOutputChannels() const override { return 2; }
  66. protected:
  67. static float FreqInHertz(float param) { return 100.0f + param * 7900.0f; }
  68. float GainInDecibel() const { return -60.0f + m_param[kDistGain] * 60.0f; }
  69. void RecalculateDistortionParams();
  70. };
  71. } // namespace DMO
  72. OPENMPT_NAMESPACE_END
  73. #endif // !NO_PLUGINS