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.

145 lines
3.8 KiB

  1. /*
  2. MicroMDAEPiano
  3. MicroMDAEPiano is a port of the MDA-EPiano sound engine
  4. (https://sourceforge.net/projects/mda-vst/) for the Teensy-3.5/3.6 with audio shield.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  16. */
  17. #ifndef __mdaEPiano__
  18. #define __mdaEPiano__
  19. #include <Audio.h>
  20. #include <Arduino.h>
  21. #include <string.h>
  22. #include "config.h"
  23. #define NPARAMS 12 //number of parameters
  24. #define NPROGS 1 //number of programs
  25. #define NOUTS 2 //number of outputs
  26. #define SUSTAIN 128
  27. #define SILENCE 0.0001f //voice choking
  28. #define WAVELEN 422414 //wave data bytes
  29. // MDAEPiano parameter mapping
  30. #define MDA_EP_DECAY 0
  31. #define MDA_EP_RELEASE 1
  32. #define MDA_EP_HARDNESS 2
  33. #define MDA_EP_TREBLE 3
  34. #define MDA_EP_PAN_TREM 4
  35. #define MDA_EP_LFO_RATE 5
  36. #define MDA_EP_VELOCITY_SENSE 6
  37. #define MDA_EP_STEREO 7
  38. #define MDA_EP_MAX_POLY 8
  39. #define MDA_EP_TUNE 9
  40. #define MDA_EP_DETUNE 10
  41. #define MDA_EP_OVERDRIVE 11
  42. class mdaEPianoProgram
  43. {
  44. friend class mdaEPiano;
  45. private:
  46. float param[NPARAMS];
  47. };
  48. struct VOICE //voice state
  49. {
  50. int32_t delta; //sample playback
  51. int32_t frac;
  52. int32_t pos;
  53. int32_t end;
  54. int32_t loop;
  55. float env; //envelope
  56. float dec;
  57. float f0; //first-order LPF
  58. float f1;
  59. float ff;
  60. float outl;
  61. float outr;
  62. int32_t note; //remember what note triggered this
  63. };
  64. struct KGRP //keygroup
  65. {
  66. int32_t root; //MIDI root note
  67. int32_t high; //highest note
  68. int32_t pos;
  69. int32_t end;
  70. int32_t loop;
  71. };
  72. class mdaEPiano
  73. {
  74. public:
  75. mdaEPiano();
  76. ~mdaEPiano();
  77. virtual void process(int16_t *outputs_r, int16_t *outputs_l);
  78. void noteOn(int32_t note, int32_t velocity);
  79. virtual bool processMidiController(uint8_t data1, uint8_t data2);
  80. //virtual void setProgram(int32_t program);
  81. //virtual float getParameter(int32_t index);
  82. virtual void resume();
  83. void reset_voices(void);
  84. void reset_controllers(void);
  85. void stop_voices(void);
  86. void setDecay(float value);
  87. void setRelease(float value);
  88. void setHardness(float value);
  89. void setTreble(float value);
  90. void setPanTremolo(float value);
  91. void setPanLFO(float value);
  92. void setVelocitySense(float value);
  93. void setStereo(float value);
  94. void setMaxPolyphony(uint8_t value);
  95. void setTune(float value);
  96. void setDetune(float value);
  97. void setOverdrive(float value);
  98. void setLoudness(float value);
  99. int32_t getActiveVoices(void);
  100. private:
  101. void update(); //my parameter update
  102. void fillpatch(int32_t p, char *name, float p0, float p1, float p2, float p3, float p4,
  103. float p5, float p6, float p7, float p8, float p9, float p10, float p11);
  104. void setParameter(int32_t index, float value);
  105. mdaEPianoProgram* programs;
  106. float Fs, iFs;
  107. ///global internal variables
  108. uint8_t max_polyphony;
  109. KGRP kgrp[34];
  110. VOICE voice[NVOICES];
  111. int32_t activevoices;
  112. short *waves;
  113. float width;
  114. int32_t size, sustain;
  115. float lfo0, lfo1, dlfo, lmod, rmod;
  116. float treb, tfrq, tl, tr;
  117. float tune, fine, random, stretch, overdrive;
  118. float muff, muffvel, sizevel, velsens, modwhl;
  119. float volume;
  120. float vol;
  121. //uint8_t curProgram;
  122. };
  123. #endif