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.

137 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. protected:
  38. // -------------------------------------------------------------------
  39. // Information
  40. const char* d_getLabel() const noexcept override
  41. {
  42. return "ZamSynth";
  43. }
  44. const char* d_getMaker() const noexcept override
  45. {
  46. return "Damien Zammit";
  47. }
  48. const char* d_getLicense() const noexcept override
  49. {
  50. return "GPL v2+";
  51. }
  52. uint32_t d_getVersion() const noexcept override
  53. {
  54. return 0x1000;
  55. }
  56. long d_getUniqueId() const noexcept override
  57. {
  58. return d_cconst('Z', 'S', 'T', 'H');
  59. }
  60. // -------------------------------------------------------------------
  61. // Init
  62. void d_initParameter(uint32_t index, Parameter& parameter) ;
  63. void d_initProgramName(uint32_t index, d_string& programName) ;
  64. // -------------------------------------------------------------------
  65. // Internal data
  66. float d_getParameterValue(uint32_t index) const override;
  67. void d_setParameterValue(uint32_t index, float value) override;
  68. void d_setProgram(uint32_t index) ;
  69. // -------------------------------------------------------------------
  70. // Process
  71. static inline float
  72. sanitize_denormal(float v) {
  73. if(!std::isnormal(v))
  74. return 0.f;
  75. return v;
  76. }
  77. static inline float
  78. from_dB(float gdb) {
  79. return (exp(gdb/20.f*log(10.f)));
  80. }
  81. static inline float
  82. to_dB(float g) {
  83. return (20.f*log10(g));
  84. }
  85. float wavetable(float in);
  86. void d_activate() override;
  87. void d_run(const float** inputs, float** outputs, uint32_t frames,
  88. const MidiEvent* midievent, uint32_t midicount) override;
  89. void d_setState(const char* key, const char* value) override;
  90. void d_initStateKey(unsigned int key, d_string& val) override;
  91. // -------------------------------------------------------------------
  92. private:
  93. float gain, graph, speed;
  94. int nvoices;
  95. float wave_y[AREAHEIGHT];
  96. float env_y[MAX_ENV];
  97. typedef struct v {
  98. bool playing;
  99. int notenum;
  100. int envpos;
  101. int slowcount;
  102. float curamp;
  103. float vi;
  104. float rampstate;
  105. } Voice;
  106. Voice voice[128];
  107. Voice* curvoice;
  108. };
  109. // -----------------------------------------------------------------------
  110. END_NAMESPACE_DISTRHO
  111. #endif // ZAMSYNTH_HPP_INCLUDED