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.

166 lines
4.0KB

  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-2013 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 LGPL.txt file
  16. */
  17. #include "DistrhoPluginPingPongPan.hpp"
  18. #include <cmath>
  19. static const float cf2PI = 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. d_setProgram(0);
  27. // reset
  28. d_deactivate();
  29. }
  30. DistrhoPluginPingPongPan::~DistrhoPluginPingPongPan()
  31. {
  32. }
  33. // -------------------------------------------------
  34. // Init
  35. void DistrhoPluginPingPongPan::d_initParameter(uint32_t index, Parameter& parameter)
  36. {
  37. switch (index)
  38. {
  39. case paramFreq:
  40. parameter.hints = PARAMETER_IS_AUTOMABLE;
  41. parameter.name = "Frequency";
  42. parameter.symbol = "freq";
  43. parameter.ranges.def = 50.0f;
  44. parameter.ranges.min = 0.0f;
  45. parameter.ranges.max = 100.0f;
  46. break;
  47. case paramWidth:
  48. parameter.hints = PARAMETER_IS_AUTOMABLE;
  49. parameter.name = "Width";
  50. parameter.symbol = "with";
  51. parameter.unit = "%";
  52. parameter.ranges.def = 75.0f;
  53. parameter.ranges.min = 0.0f;
  54. parameter.ranges.max = 100.0f;
  55. break;
  56. }
  57. }
  58. void DistrhoPluginPingPongPan::d_initProgramName(uint32_t index, d_string& programName)
  59. {
  60. if (index != 0)
  61. return;
  62. programName = "Default";
  63. }
  64. // -------------------------------------------------
  65. // Internal data
  66. float DistrhoPluginPingPongPan::d_parameterValue(uint32_t index)
  67. {
  68. switch (index)
  69. {
  70. case paramFreq:
  71. return fFreq;
  72. case paramWidth:
  73. return fWidth;
  74. default:
  75. return 0.0f;
  76. }
  77. }
  78. void DistrhoPluginPingPongPan::d_setParameterValue(uint32_t index, float value)
  79. {
  80. if (d_sampleRate() <= 0.0)
  81. return;
  82. switch (index)
  83. {
  84. case paramFreq:
  85. fFreq = value;
  86. waveSpeed = (cf2PI * fFreq / 100.0f)/(float)d_sampleRate();
  87. break;
  88. case paramWidth:
  89. fWidth = value;
  90. break;
  91. }
  92. }
  93. void DistrhoPluginPingPongPan::d_setProgram(uint32_t index)
  94. {
  95. if (index != 0)
  96. return;
  97. // Default values
  98. fFreq = 50.0f;
  99. fWidth = 75.0f;
  100. // reset filter values
  101. d_activate();
  102. }
  103. // -------------------------------------------------
  104. // Process
  105. void DistrhoPluginPingPongPan::d_activate()
  106. {
  107. waveSpeed = (cf2PI * fFreq / 100.0f)/(float)d_sampleRate();
  108. }
  109. void DistrhoPluginPingPongPan::d_deactivate()
  110. {
  111. wavePos = 0.0f;
  112. }
  113. void DistrhoPluginPingPongPan::d_run(float** inputs, float** outputs, uint32_t frames, uint32_t, const MidiEvent*)
  114. {
  115. float* in1 = inputs[0];
  116. float* in2 = inputs[1];
  117. float* out1 = outputs[0];
  118. float* out2 = outputs[1];
  119. for (uint32_t i=0; i < frames; i++)
  120. {
  121. pan = std::fmin(std::fmax(std::sin(wavePos) * (fWidth/100.0f), -1.0f), 1.0f);
  122. if ((wavePos += waveSpeed) >= cf2PI)
  123. wavePos -= cf2PI;
  124. out1[i] = in1[i] * (pan > 0.0f ? 1.0f-pan : 1.0f);
  125. out2[i] = in2[i] * (pan < 0.0f ? 1.0f+pan : 1.0f);
  126. }
  127. }
  128. // -------------------------------------------------
  129. Plugin* createPlugin()
  130. {
  131. return new DistrhoPluginPingPongPan();
  132. }
  133. // -------------------------------------------------
  134. END_NAMESPACE_DISTRHO