DISTRHO Mini-Series
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.

169 lines
4.3KB

  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::initAudioPort(bool input, uint32_t index, AudioPort& port)
  33. {
  34. port.groupId = kPortGroupStereo;
  35. Plugin::initAudioPort(input, index, port);
  36. }
  37. void DistrhoPluginPingPongPan::initParameter(uint32_t index, Parameter& parameter)
  38. {
  39. switch (index)
  40. {
  41. case paramFreq:
  42. parameter.hints = kParameterIsAutomatable;
  43. parameter.name = "Frequency";
  44. parameter.symbol = "freq";
  45. parameter.ranges.def = 50.0f;
  46. parameter.ranges.min = 0.0f;
  47. parameter.ranges.max = 100.0f;
  48. break;
  49. case paramWidth:
  50. parameter.hints = kParameterIsAutomatable;
  51. parameter.name = "Width";
  52. parameter.symbol = "width";
  53. parameter.unit = "%";
  54. parameter.ranges.def = 75.0f;
  55. parameter.ranges.min = 0.0f;
  56. parameter.ranges.max = 100.0f;
  57. break;
  58. }
  59. }
  60. void DistrhoPluginPingPongPan::initProgramName(uint32_t index, String& programName)
  61. {
  62. if (index != 0)
  63. return;
  64. programName = "Default";
  65. }
  66. // -----------------------------------------------------------------------
  67. // Internal data
  68. float DistrhoPluginPingPongPan::getParameterValue(uint32_t index) const
  69. {
  70. switch (index)
  71. {
  72. case paramFreq:
  73. return fFreq;
  74. case paramWidth:
  75. return fWidth;
  76. default:
  77. return 0.0f;
  78. }
  79. }
  80. void DistrhoPluginPingPongPan::setParameterValue(uint32_t index, float value)
  81. {
  82. if (getSampleRate() <= 0.0)
  83. return;
  84. switch (index)
  85. {
  86. case paramFreq:
  87. fFreq = value;
  88. waveSpeed = (k2PI * fFreq / 100.0f)/(float)getSampleRate();
  89. break;
  90. case paramWidth:
  91. fWidth = value;
  92. break;
  93. }
  94. }
  95. void DistrhoPluginPingPongPan::loadProgram(uint32_t index)
  96. {
  97. if (index != 0)
  98. return;
  99. // Default values
  100. fFreq = 50.0f;
  101. fWidth = 75.0f;
  102. // reset filter values
  103. activate();
  104. }
  105. // -----------------------------------------------------------------------
  106. // Process
  107. void DistrhoPluginPingPongPan::activate()
  108. {
  109. waveSpeed = (k2PI * fFreq / 100.0f)/(float)getSampleRate();
  110. }
  111. void DistrhoPluginPingPongPan::deactivate()
  112. {
  113. wavePos = 0.0f;
  114. }
  115. void DistrhoPluginPingPongPan::run(const float** inputs, float** outputs, uint32_t frames)
  116. {
  117. const float* in1 = inputs[0];
  118. const float* in2 = inputs[1];
  119. float* out1 = outputs[0];
  120. float* out2 = outputs[1];
  121. for (uint32_t i=0; i < frames; ++i)
  122. {
  123. pan = std::fmin(std::fmax(std::sin(wavePos) * (fWidth/100.0f), -1.0f), 1.0f);
  124. if ((wavePos += waveSpeed) >= k2PI)
  125. wavePos -= k2PI;
  126. out1[i] = in1[i] * (pan > 0.0f ? 1.0f-pan : 1.0f);
  127. out2[i] = in2[i] * (pan < 0.0f ? 1.0f+pan : 1.0f);
  128. }
  129. }
  130. // -----------------------------------------------------------------------
  131. Plugin* createPlugin()
  132. {
  133. return new DistrhoPluginPingPongPan();
  134. }
  135. // -----------------------------------------------------------------------
  136. END_NAMESPACE_DISTRHO