DISTRHO Plugin Framework
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.

136 lines
3.8KB

  1. /*
  2. * Simple Gain audio effect based on DISTRHO Plugin Framework (DPF)
  3. *
  4. * SPDX-License-Identifier: MIT
  5. *
  6. * Copyright (C) 2021 Jean Pierre Cimalando <jp-dev@inbox.ru>
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to
  10. * deal in the Software without restriction, including without limitation the
  11. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  12. * sell copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  23. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  24. * IN THE SOFTWARE.
  25. */
  26. #ifndef PLUGIN_SIMPLEGAIN_H
  27. #define PLUGIN_SIMPLEGAIN_H
  28. #include "DistrhoPlugin.hpp"
  29. #include "CParamSmooth.hpp"
  30. #include "extra/ScopedPointer.hpp"
  31. START_NAMESPACE_DISTRHO
  32. #ifndef MIN
  33. #define MIN(a,b) ( (a) < (b) ? (a) : (b) )
  34. #endif
  35. #ifndef MAX
  36. #define MAX(a,b) ( (a) > (b) ? (a) : (b) )
  37. #endif
  38. #ifndef CLAMP
  39. #define CLAMP(v, min, max) (MIN((max), MAX((min), (v))))
  40. #endif
  41. #ifndef DB_CO
  42. #define DB_CO(g) ((g) > -90.0f ? powf(10.0f, (g) * 0.05f) : 0.0f)
  43. #endif
  44. // -----------------------------------------------------------------------
  45. class PluginSimpleGain : public Plugin {
  46. public:
  47. enum Parameters {
  48. paramGain = 0,
  49. paramCount
  50. };
  51. PluginSimpleGain();
  52. protected:
  53. // -------------------------------------------------------------------
  54. // Information
  55. const char* getLabel() const noexcept override
  56. {
  57. return "SimpleGain";
  58. }
  59. const char* getDescription() const override
  60. {
  61. return "A simple audio volume gain plugin with ImGui for its GUI";
  62. }
  63. const char* getMaker() const noexcept override
  64. {
  65. return "Jean Pierre Cimalando, falkTX";
  66. }
  67. const char* getLicense() const noexcept override
  68. {
  69. return "MIT";
  70. }
  71. uint32_t getVersion() const noexcept override
  72. {
  73. return d_version(1, 0, 0);
  74. }
  75. int64_t getUniqueId() const noexcept override
  76. {
  77. return d_cconst('d', 'I', 'm', 'G');
  78. }
  79. // -------------------------------------------------------------------
  80. // Init
  81. void initParameter(uint32_t index, Parameter& parameter) override;
  82. // -------------------------------------------------------------------
  83. // Internal data
  84. float getParameterValue(uint32_t index) const override;
  85. void setParameterValue(uint32_t index, float value) override;
  86. // -------------------------------------------------------------------
  87. // Optional
  88. // Optional callback to inform the plugin about a sample rate change.
  89. void sampleRateChanged(double newSampleRate) override;
  90. // -------------------------------------------------------------------
  91. // Process
  92. void activate() override;
  93. void run(const float**, float** outputs, uint32_t frames) override;
  94. // -------------------------------------------------------------------
  95. private:
  96. double fSampleRate;
  97. float fGainDB;
  98. float fGainLinear;
  99. ScopedPointer<CParamSmooth> fSmoothGain;
  100. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PluginSimpleGain)
  101. };
  102. // -----------------------------------------------------------------------
  103. END_NAMESPACE_DISTRHO
  104. #endif // #ifndef PLUGIN_SIMPLEGAIN_H