DigiBoosterEcho.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * DigiBoosterEcho.h
  3. * -----------------
  4. * Purpose: Implementation of the DigiBooster Pro Echo DSP
  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. class DigiBoosterEcho final : public IMixPlugin
  13. {
  14. public:
  15. enum Parameters
  16. {
  17. kEchoDelay = 0,
  18. kEchoFeedback,
  19. kEchoMix,
  20. kEchoCross,
  21. kEchoNumParameters
  22. };
  23. // Our settings chunk for file I/O, as it will be written to files
  24. struct PluginChunk
  25. {
  26. char id[4];
  27. uint8 param[kEchoNumParameters];
  28. static PluginChunk Create(uint8 delay, uint8 feedback, uint8 mix, uint8 cross)
  29. {
  30. static_assert(sizeof(PluginChunk) == 8);
  31. PluginChunk result;
  32. memcpy(result.id, "Echo", 4);
  33. result.param[kEchoDelay] = delay;
  34. result.param[kEchoFeedback] = feedback;
  35. result.param[kEchoMix] = mix;
  36. result.param[kEchoCross] = cross;
  37. return result;
  38. }
  39. static PluginChunk Default()
  40. {
  41. return Create(80, 150, 80, 255);
  42. }
  43. };
  44. protected:
  45. std::vector<float> m_delayLine; // Echo delay line
  46. uint32 m_bufferSize = 0; // Delay line length in frames
  47. uint32 m_writePos = 0; // Current write position in the delay line
  48. uint32 m_delayTime = 0; // In frames
  49. uint32 m_sampleRate = 0;
  50. // Echo calculation coefficients
  51. float m_PMix, m_NMix;
  52. float m_PCrossPBack, m_PCrossNBack;
  53. float m_NCrossPBack, m_NCrossNBack;
  54. // Settings chunk for file I/O
  55. PluginChunk m_chunk;
  56. public:
  57. static IMixPlugin* Create(VSTPluginLib &factory, CSoundFile &sndFile, SNDMIXPLUGIN *mixStruct);
  58. DigiBoosterEcho(VSTPluginLib &factory, CSoundFile &sndFile, SNDMIXPLUGIN *mixStruct);
  59. void Release() override { delete this; }
  60. void SaveAllParameters() override;
  61. void RestoreAllParameters(int32 program) override;
  62. int32 GetUID() const override { int32le id; memcpy(&id, "Echo", 4); return id; }
  63. int32 GetVersion() const override { return 0; }
  64. void Idle() override { }
  65. uint32 GetLatency() const override { return 0; }
  66. void Process(float *pOutL, float *pOutR, uint32 numFrames) override;
  67. float RenderSilence(uint32) override { return 0.0f; }
  68. int32 GetNumPrograms() const override { return 0; }
  69. int32 GetCurrentProgram() override { return 0; }
  70. void SetCurrentProgram(int32) override { }
  71. PlugParamIndex GetNumParameters() const override { return kEchoNumParameters; }
  72. PlugParamValue GetParameter(PlugParamIndex index) override;
  73. void SetParameter(PlugParamIndex index, PlugParamValue value) override;
  74. void Resume() override;
  75. void Suspend() override { m_isResumed = false; }
  76. void PositionChanged() override;
  77. bool IsInstrument() const override { return false; }
  78. bool CanRecieveMidiEvents() override { return false; }
  79. bool ShouldProcessSilence() override { return true; }
  80. #ifdef MODPLUG_TRACKER
  81. CString GetDefaultEffectName() override { return _T("Echo"); }
  82. CString GetParamName(PlugParamIndex param) override;
  83. CString GetParamLabel(PlugParamIndex) override;
  84. CString GetParamDisplay(PlugParamIndex param) override;
  85. CString GetCurrentProgramName() override { return CString(); }
  86. void SetCurrentProgramName(const CString &) override { }
  87. CString GetProgramName(int32) override { return CString(); }
  88. bool HasEditor() const override { return false; }
  89. #endif
  90. int GetNumInputChannels() const override { return 2; }
  91. int GetNumOutputChannels() const override { return 2; }
  92. bool ProgramsAreChunks() const override { return true; }
  93. ChunkData GetChunk(bool) override;
  94. void SetChunk(const ChunkData &chunk, bool) override;
  95. protected:
  96. void RecalculateEchoParams();
  97. };
  98. OPENMPT_NAMESPACE_END
  99. #endif // NO_PLUGINS