Flanger.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * Flanger.cpp
  3. * -----------
  4. * Purpose: Implementation of the DMO Flanger 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. #include "stdafx.h"
  10. #ifndef NO_PLUGINS
  11. #include "../../Sndfile.h"
  12. #include "Flanger.h"
  13. #endif // !NO_PLUGINS
  14. OPENMPT_NAMESPACE_BEGIN
  15. #ifndef NO_PLUGINS
  16. namespace DMO
  17. {
  18. IMixPlugin* Flanger::Create(VSTPluginLib &factory, CSoundFile &sndFile, SNDMIXPLUGIN *mixStruct)
  19. {
  20. return new (std::nothrow) Flanger(factory, sndFile, mixStruct, false);
  21. }
  22. IMixPlugin* Flanger::CreateLegacy(VSTPluginLib &factory, CSoundFile &sndFile, SNDMIXPLUGIN *mixStruct)
  23. {
  24. return new(std::nothrow) Flanger(factory, sndFile, mixStruct, true);
  25. }
  26. Flanger::Flanger(VSTPluginLib &factory, CSoundFile &sndFile, SNDMIXPLUGIN *mixStruct, const bool legacy)
  27. : Chorus(factory, sndFile, mixStruct, !legacy)
  28. {
  29. m_param[kFlangerWetDryMix] = 0.5f;
  30. m_param[kFlangerWaveShape] = 1.0f;
  31. m_param[kFlangerFrequency] = 0.025f;
  32. m_param[kFlangerDepth] = 1.0f;
  33. m_param[kFlangerPhase] = 0.5f;
  34. m_param[kFlangerFeedback] = (-50.0f + 99.0f) / 198.0f;
  35. m_param[kFlangerDelay] = 0.5f;
  36. // Already done in Chorus constructor
  37. //m_mixBuffer.Initialize(2, 2);
  38. //InsertIntoFactoryList();
  39. }
  40. void Flanger::SetParameter(PlugParamIndex index, PlugParamValue value)
  41. {
  42. if(index < kFlangerNumParameters)
  43. {
  44. value = mpt::safe_clamp(value, 0.0f, 1.0f);
  45. if(index == kFlangerWaveShape)
  46. {
  47. value = mpt::round(value);
  48. if(m_param[index] != value)
  49. {
  50. m_waveShapeMin = 0.0f;
  51. m_waveShapeMax = 0.5f + value * 0.5f;
  52. }
  53. } else if(index == kFlangerPhase)
  54. {
  55. value = mpt::round(value * 4.0f) / 4.0f;
  56. }
  57. m_param[index] = value;
  58. RecalculateChorusParams();
  59. }
  60. }
  61. #ifdef MODPLUG_TRACKER
  62. CString Flanger::GetParamName(PlugParamIndex param)
  63. {
  64. switch(param)
  65. {
  66. case kFlangerWetDryMix: return _T("WetDryMix");
  67. case kFlangerWaveShape: return _T("WaveShape");
  68. case kFlangerFrequency: return _T("Frequency");
  69. case kFlangerDepth: return _T("Depth");
  70. case kFlangerPhase: return _T("Phase");
  71. case kFlangerFeedback: return _T("Feedback");
  72. case kFlangerDelay: return _T("Delay");
  73. }
  74. return CString();
  75. }
  76. CString Flanger::GetParamLabel(PlugParamIndex param)
  77. {
  78. switch(param)
  79. {
  80. case kFlangerWetDryMix:
  81. case kFlangerDepth:
  82. case kFlangerFeedback:
  83. return _T("%");
  84. case kFlangerFrequency:
  85. return _T("Hz");
  86. case kFlangerPhase:
  87. return mpt::ToCString(MPT_UTF8("\xC2\xB0")); // U+00B0 DEGREE SIGN
  88. case kFlangerDelay:
  89. return _T("ms");
  90. }
  91. return CString();
  92. }
  93. CString Flanger::GetParamDisplay(PlugParamIndex param)
  94. {
  95. CString s;
  96. float value = m_param[param];
  97. switch(param)
  98. {
  99. case kFlangerWetDryMix:
  100. case kFlangerDepth:
  101. value *= 100.0f;
  102. break;
  103. case kFlangerFrequency:
  104. value = FrequencyInHertz();
  105. break;
  106. case kFlangerWaveShape:
  107. return (value < 1) ? _T("Triangle") : _T("Sine");
  108. break;
  109. case kFlangerPhase:
  110. switch(Phase())
  111. {
  112. case 0: return _T("-180");
  113. case 1: return _T("-90");
  114. case 2: return _T("0");
  115. case 3: return _T("90");
  116. case 4: return _T("180");
  117. }
  118. break;
  119. case kFlangerFeedback:
  120. value = Feedback();
  121. break;
  122. case kFlangerDelay:
  123. value = Delay();
  124. }
  125. s.Format(_T("%.2f"), value);
  126. return s;
  127. }
  128. #endif // MODPLUG_TRACKER
  129. } // namespace DMO
  130. #else
  131. MPT_MSVC_WORKAROUND_LNK4221(Flanger)
  132. #endif // !NO_PLUGINS
  133. OPENMPT_NAMESPACE_END