I3DL2Reverb.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * I3DL2Reverb.h
  3. * -------------
  4. * Purpose: Implementation of the DMO I3DL2Reverb 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 I3DL2Reverb final : public IMixPlugin
  17. {
  18. protected:
  19. enum Parameters
  20. {
  21. kI3DL2ReverbRoom = 0,
  22. kI3DL2ReverbRoomHF,
  23. kI3DL2ReverbRoomRolloffFactor, // Doesn't actually do anything :)
  24. kI3DL2ReverbDecayTime,
  25. kI3DL2ReverbDecayHFRatio,
  26. kI3DL2ReverbReflections,
  27. kI3DL2ReverbReflectionsDelay,
  28. kI3DL2ReverbReverb,
  29. kI3DL2ReverbReverbDelay,
  30. kI3DL2ReverbDiffusion,
  31. kI3DL2ReverbDensity,
  32. kI3DL2ReverbHFReference,
  33. kI3DL2ReverbQuality,
  34. kI3DL2ReverbNumParameters
  35. };
  36. enum QualityFlags
  37. {
  38. kMoreDelayLines = 0x01,
  39. kFullSampleRate = 0x02,
  40. };
  41. class DelayLine : private std::vector<float>
  42. {
  43. int32 m_length;
  44. int32 m_position;
  45. int32 m_delayPosition;
  46. public:
  47. void Init(int32 ms, int32 padding, uint32 sampleRate, int32 delayTap = 0);
  48. void SetDelayTap(int32 delayTap);
  49. void Advance();
  50. void Set(float value);
  51. float Get(int32 offset) const;
  52. float Get() const;
  53. };
  54. std::array<float, kI3DL2ReverbNumParameters> m_param;
  55. int32 m_program = 0;
  56. // Calculated parameters
  57. uint32 m_quality;
  58. float m_effectiveSampleRate;
  59. float m_diffusion;
  60. float m_roomFilter;
  61. float m_ERLevel;
  62. float m_ReverbLevelL;
  63. float m_ReverbLevelR;
  64. int32 m_delayTaps[15]; // 6*L + 6*R + LR + Early L + Early R
  65. int32 m_earlyTaps[2][6];
  66. float m_delayCoeffs[13][2];
  67. // State
  68. DelayLine m_delayLines[19];
  69. float m_filterHist[19];
  70. // Remaining frame for downsampled reverb
  71. float m_prevL;
  72. float m_prevR;
  73. bool m_remain = false;
  74. bool m_ok = false, m_recalcParams = true;
  75. public:
  76. static IMixPlugin* Create(VSTPluginLib &factory, CSoundFile &sndFile, SNDMIXPLUGIN *mixStruct);
  77. I3DL2Reverb(VSTPluginLib &factory, CSoundFile &sndFile, SNDMIXPLUGIN *mixStruct);
  78. void Release() override { delete this; }
  79. int32 GetUID() const override { return 0xEF985E71; }
  80. int32 GetVersion() const override { return 0; }
  81. void Idle() override { }
  82. uint32 GetLatency() const override { return 0; }
  83. void Process(float *pOutL, float *pOutR, uint32 numFrames) override;
  84. float RenderSilence(uint32) override { return 0.0f; }
  85. int32 GetNumPrograms() const override;
  86. int32 GetCurrentProgram() override { return m_program; }
  87. // cppcheck-suppress virtualCallInConstructor
  88. void SetCurrentProgram(int32) override;
  89. PlugParamIndex GetNumParameters() const override { return kI3DL2ReverbNumParameters; }
  90. PlugParamValue GetParameter(PlugParamIndex index) override;
  91. void SetParameter(PlugParamIndex index, PlugParamValue value) override;
  92. void Resume() override;
  93. void Suspend() override { m_isResumed = false; }
  94. void PositionChanged() override;
  95. bool IsInstrument() const override { return false; }
  96. bool CanRecieveMidiEvents() override { return false; }
  97. bool ShouldProcessSilence() override { return true; }
  98. #ifdef MODPLUG_TRACKER
  99. CString GetDefaultEffectName() override { return _T("I3DL2Reverb"); }
  100. CString GetParamName(PlugParamIndex param) override;
  101. CString GetParamLabel(PlugParamIndex) override;
  102. CString GetParamDisplay(PlugParamIndex param) override;
  103. CString GetCurrentProgramName() override;
  104. void SetCurrentProgramName(const CString &) override { }
  105. CString GetProgramName(int32 program) override;
  106. bool HasEditor() const override { return false; }
  107. #endif
  108. void BeginSetProgram(int32) override { }
  109. void EndSetProgram() override { }
  110. int GetNumInputChannels() const override { return 2; }
  111. int GetNumOutputChannels() const override { return 2; }
  112. protected:
  113. float Room() const { return -10000.0f + m_param[kI3DL2ReverbRoom] * 10000.0f; }
  114. float RoomHF() const { return -10000.0f + m_param[kI3DL2ReverbRoomHF] * 10000.0f; }
  115. float RoomRolloffFactor() const { return m_param[kI3DL2ReverbRoomRolloffFactor] * 10.0f; }
  116. float DecayTime() const { return 0.1f + m_param[kI3DL2ReverbDecayTime] * 19.9f; }
  117. float DecayHFRatio() const { return 0.1f + m_param[kI3DL2ReverbDecayHFRatio] * 1.9f; }
  118. float Reflections() const { return -10000.0f + m_param[kI3DL2ReverbReflections] * 11000.0f; }
  119. float ReflectionsDelay() const { return m_param[kI3DL2ReverbReflectionsDelay] * 0.3f; }
  120. float Reverb() const { return -10000.0f + m_param[kI3DL2ReverbReverb] * 12000.0f; }
  121. float ReverbDelay() const { return m_param[kI3DL2ReverbReverbDelay] * 0.1f; }
  122. float Diffusion() const { return m_param[kI3DL2ReverbDiffusion] * 100.0f; }
  123. float Density() const { return m_param[kI3DL2ReverbDensity] * 100.0f; }
  124. float HFReference() const { return 20.0f + m_param[kI3DL2ReverbHFReference] * 19980.0f; }
  125. uint32 Quality() const { return mpt::saturate_round<uint32>(m_param[kI3DL2ReverbQuality] * 3.0f); }
  126. void RecalculateI3DL2ReverbParams();
  127. void SetDelayTaps();
  128. void SetDecayCoeffs();
  129. float CalcDecayCoeffs(int32 index);
  130. };
  131. } // namespace DMO
  132. OPENMPT_NAMESPACE_END
  133. #endif // !NO_PLUGINS