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.

139 lines
3.4KB

  1. /*
  2. * ZamSynth polyphonic synthesiser
  3. * Copyright (C) 2014 Damien Zammit <damien@zamaudio.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  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 General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #ifndef ZAMSYNTHPLUGIN_HPP_INCLUDED
  18. #define ZAMSYNTHPLUGIN_HPP_INCLUDED
  19. #include <string.h>
  20. #include "DistrhoPlugin.hpp"
  21. #define MAX_VOICES 128
  22. #define AREAHEIGHT 250
  23. #define MAX_ENV AREAHEIGHT
  24. START_NAMESPACE_DISTRHO
  25. // -----------------------------------------------------------------------
  26. class ZamSynthPlugin : public Plugin
  27. {
  28. public:
  29. enum Parameters
  30. {
  31. paramGain,
  32. paramSpeed,
  33. paramGraph,
  34. paramCount
  35. };
  36. ZamSynthPlugin();
  37. ~ZamSynthPlugin() override;
  38. protected:
  39. // -------------------------------------------------------------------
  40. // Information
  41. const char* d_getLabel() const noexcept override
  42. {
  43. return "ZamSynth";
  44. }
  45. const char* d_getMaker() const noexcept override
  46. {
  47. return "Damien Zammit";
  48. }
  49. const char* d_getLicense() const noexcept override
  50. {
  51. return "GPL v2+";
  52. }
  53. uint32_t d_getVersion() const noexcept override
  54. {
  55. return 0x1000;
  56. }
  57. long d_getUniqueId() const noexcept override
  58. {
  59. return d_cconst('Z', 'S', 'T', 'H');
  60. }
  61. // -------------------------------------------------------------------
  62. // Init
  63. void d_initParameter(uint32_t index, Parameter& parameter) ;
  64. void d_initProgramName(uint32_t index, d_string& programName) ;
  65. // -------------------------------------------------------------------
  66. // Internal data
  67. float d_getParameterValue(uint32_t index) const override;
  68. void d_setParameterValue(uint32_t index, float value) override;
  69. void d_setProgram(uint32_t index) ;
  70. // -------------------------------------------------------------------
  71. // Process
  72. static inline float
  73. sanitize_denormal(float v) {
  74. if(!std::isnormal(v))
  75. return 0.f;
  76. return v;
  77. }
  78. static inline float
  79. from_dB(float gdb) {
  80. return (exp(gdb/20.f*log(10.f)));
  81. }
  82. static inline float
  83. to_dB(float g) {
  84. return (20.f*log10(g));
  85. }
  86. float wavetable(float in);
  87. void d_activate() override;
  88. void d_deactivate() override;
  89. void d_run(float** inputs, float** outputs, uint32_t frames,
  90. const MidiEvent* midievent, uint32_t midicount) override;
  91. void d_setState(const char* key, const char* value) override;
  92. void d_initStateKey(unsigned int key, d_string& val) override;
  93. // -------------------------------------------------------------------
  94. private:
  95. float gain, graph, speed;
  96. int nvoices;
  97. float wave_y[AREAHEIGHT];
  98. float env_y[MAX_ENV];
  99. typedef struct v {
  100. bool playing;
  101. int notenum;
  102. int envpos;
  103. int slowcount;
  104. float curamp;
  105. float vi;
  106. float rampstate;
  107. } Voice;
  108. Voice voice[128];
  109. Voice* curvoice;
  110. };
  111. // -----------------------------------------------------------------------
  112. END_NAMESPACE_DISTRHO
  113. #endif // ZAMSYNTH_HPP_INCLUDED