Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DistrhoPluginPingPongPan.cpp 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * DISTRHO PingPongPan Plugin, based on PingPongPan by Michael Gruhn
  3. * Copyright (C) 2007 Michael Gruhn <michael-gruhn@web.de>
  4. * Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Lesser General Public License for more details.
  14. *
  15. * For a full copy of the license see the LICENSE file.
  16. */
  17. #include "DistrhoPluginPingPongPan.hpp"
  18. #include <cmath>
  19. static const float k2PI = 6.283185307f;
  20. START_NAMESPACE_DISTRHO
  21. // -----------------------------------------------------------------------
  22. DistrhoPluginPingPongPan::DistrhoPluginPingPongPan()
  23. : Plugin(paramCount, 1, 0) // 1 program, 0 states
  24. {
  25. // set default values
  26. loadProgram(0);
  27. // reset
  28. deactivate();
  29. }
  30. // -----------------------------------------------------------------------
  31. // Init
  32. void DistrhoPluginPingPongPan::initParameter(uint32_t index, Parameter& parameter)
  33. {
  34. switch (index)
  35. {
  36. case paramFreq:
  37. parameter.hints = kParameterIsAutomable;
  38. parameter.name = "Frequency";
  39. parameter.symbol = "freq";
  40. parameter.ranges.def = 50.0f;
  41. parameter.ranges.min = 0.0f;
  42. parameter.ranges.max = 100.0f;
  43. break;
  44. case paramWidth:
  45. parameter.hints = kParameterIsAutomable;
  46. parameter.name = "Width";
  47. parameter.symbol = "with";
  48. parameter.unit = "%";
  49. parameter.ranges.def = 75.0f;
  50. parameter.ranges.min = 0.0f;
  51. parameter.ranges.max = 100.0f;
  52. break;
  53. }
  54. }
  55. void DistrhoPluginPingPongPan::initProgramName(uint32_t index, String& programName)
  56. {
  57. if (index != 0)
  58. return;
  59. programName = "Default";
  60. }
  61. // -----------------------------------------------------------------------
  62. // Internal data
  63. float DistrhoPluginPingPongPan::getParameterValue(uint32_t index) const
  64. {
  65. switch (index)
  66. {
  67. case paramFreq:
  68. return fFreq;
  69. case paramWidth:
  70. return fWidth;
  71. default:
  72. return 0.0f;
  73. }
  74. }
  75. void DistrhoPluginPingPongPan::setParameterValue(uint32_t index, float value)
  76. {
  77. if (getSampleRate() <= 0.0)
  78. return;
  79. switch (index)
  80. {
  81. case paramFreq:
  82. fFreq = value;
  83. waveSpeed = (k2PI * fFreq / 100.0f)/(float)getSampleRate();
  84. break;
  85. case paramWidth:
  86. fWidth = value;
  87. break;
  88. }
  89. }
  90. void DistrhoPluginPingPongPan::loadProgram(uint32_t index)
  91. {
  92. if (index != 0)
  93. return;
  94. // Default values
  95. fFreq = 50.0f;
  96. fWidth = 75.0f;
  97. // reset filter values
  98. activate();
  99. }
  100. // -----------------------------------------------------------------------
  101. // Process
  102. void DistrhoPluginPingPongPan::activate()
  103. {
  104. waveSpeed = (k2PI * fFreq / 100.0f)/(float)getSampleRate();
  105. }
  106. void DistrhoPluginPingPongPan::deactivate()
  107. {
  108. wavePos = 0.0f;
  109. }
  110. void DistrhoPluginPingPongPan::run(const float** inputs, float** outputs, uint32_t frames)
  111. {
  112. const float* in1 = inputs[0];
  113. const float* in2 = inputs[1];
  114. float* out1 = outputs[0];
  115. float* out2 = outputs[1];
  116. for (uint32_t i=0; i < frames; ++i)
  117. {
  118. pan = std::fmin(std::fmax(std::sin(wavePos) * (fWidth/100.0f), -1.0f), 1.0f);
  119. if ((wavePos += waveSpeed) >= k2PI)
  120. wavePos -= k2PI;
  121. out1[i] = in1[i] * (pan > 0.0f ? 1.0f-pan : 1.0f);
  122. out2[i] = in2[i] * (pan < 0.0f ? 1.0f+pan : 1.0f);
  123. }
  124. }
  125. // -----------------------------------------------------------------------
  126. Plugin* createPlugin()
  127. {
  128. return new DistrhoPluginPingPongPan();
  129. }
  130. // -----------------------------------------------------------------------
  131. END_NAMESPACE_DISTRHO