MicroDexed is a compatible 6-operator-FM-synth based on the Teensy(-3.6/-4.0) Microcontroller. https://www.parasitstudio.de
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.

204 lines
7.3KB

  1. /*
  2. MicroDexed
  3. MicroDexed is a port of the Dexed sound engine
  4. (https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield.
  5. Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android
  6. (c)2018,2019 H. Wirtz <wirtz@parasitstudio.de>
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 3 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software Foundation,
  17. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #ifndef DEXED_H_INCLUDED
  20. #define DEXED_H_INCLUDED
  21. #include <Arduino.h>
  22. #include "controllers.h"
  23. #include "dx7note.h"
  24. #include "lfo.h"
  25. #include "synth.h"
  26. #include "fm_core.h"
  27. #include "EngineMkI.h"
  28. #include "EngineOpl.h"
  29. #include "PluginFx.h"
  30. #include <Audio.h>
  31. #include "config.h"
  32. extern uint32_t overload;
  33. extern bool load_sysex(uint8_t bank, uint8_t voice_number);
  34. extern AudioControlSGTL5000 sgtl5000_1;
  35. extern float vol;
  36. extern float vol_right;
  37. extern float vol_left;
  38. extern void set_volume(float master_volume, float volume_right, float volume_left);
  39. extern char voice_name[11];
  40. struct ProcessorVoice {
  41. uint8_t midi_note;
  42. uint8_t velocity;
  43. bool keydown;
  44. bool sustained;
  45. bool live;
  46. Dx7Note *dx7_note;
  47. };
  48. enum DexedEngineResolution {
  49. DEXED_ENGINE_MODERN, // 0
  50. DEXED_ENGINE_MARKI, // 1
  51. DEXED_ENGINE_OPL // 2
  52. };
  53. enum DexedVoiceOPParameters {
  54. DEXED_OP_EG_R1, // 0
  55. DEXED_OP_EG_R2, // 1
  56. DEXED_OP_EG_R3, // 2
  57. DEXED_OP_EG_R4, // 3
  58. DEXED_OP_EG_L1, // 4
  59. DEXED_OP_EG_L2, // 5
  60. DEXED_OP_EG_L3, // 6
  61. DEXED_OP_EG_L4, // 7
  62. DEXED_OP_LEV_SCL_BRK_PT, // 8
  63. DEXED_OP_SCL_LEFT_DEPTH, // 9
  64. DEXED_OP_SCL_RGHT_DEPTH, // 10
  65. DEXED_OP_SCL_LEFT_CURVE, // 11
  66. DEXED_OP_SCL_RGHT_CURVE, // 12
  67. DEXED_OP_OSC_RATE_SCALE, // 13
  68. DEXED_OP_AMP_MOD_SENS, // 14
  69. DEXED_OP_KEY_VEL_SENS, // 15
  70. DEXED_OP_OUTPUT_LEV, // 16
  71. DEXED_OP_OSC_MODE, // 17
  72. DEXED_OP_FREQ_COARSE, // 18
  73. DEXED_OP_FREQ_FINE, // 19
  74. DEXED_OP_OSC_DETUNE // 20
  75. };
  76. #define DEXED_VOICE_OFFSET 126
  77. enum DexedVoiceParameters {
  78. DEXED_PITCH_EG_R1, // 0
  79. DEXED_PITCH_EG_R2, // 1
  80. DEXED_PITCH_EG_R3, // 2
  81. DEXED_PITCH_EG_R4, // 3
  82. DEXED_PITCH_EG_L1, // 4
  83. DEXED_PITCH_EG_L2, // 5
  84. DEXED_PITCH_EG_L3, // 6
  85. DEXED_PITCH_EG_L4, // 7
  86. DEXED_ALGORITHM, // 8
  87. DEXED_FEEDBACK, // 9
  88. DEXED_OSC_KEY_SYNC, // 10
  89. DEXED_LFO_SPEED, // 11
  90. DEXED_LFO_DELAY, // 12
  91. DEXED_LFO_PITCH_MOD_DEP, // 13
  92. DEXED_LFO_AMP_MOD_DEP, // 14
  93. DEXED_LFO_SYNC, // 15
  94. DEXED_LFO_WAVE, // 16
  95. DEXED_LFO_PITCH_MOD_SENS, // 17
  96. DEXED_TRANSPOSE, // 18
  97. DEXED_NAME // 19
  98. };
  99. #define DEXED_GLOBAL_PARAMETER_OFFSET 155
  100. enum DexedGlobalParameters {
  101. DEXED_PITCHBEND_RANGE, // 0
  102. DEXED_PITCHBEND_STEP, // 1
  103. DEXED_MODWHEEL_RANGE, // 2
  104. DEXED_MODWHEEL_ASSIGN, // 3
  105. DEXED_FOOTCTRL_RANGE, // 4
  106. DEXED_FOOTCTRL_ASSIGN, // 5
  107. DEXED_BREATHCTRL_RANGE, // 6
  108. DEXED_BREATHCTRL_ASSIGN, // 7
  109. DEXED_AT_RANGE, // 8
  110. DEXED_AT_ASSIGN, // 9
  111. DEXED_MASTER_TUNE, // 10
  112. DEXED_OP1_ENABLE, // 11
  113. DEXED_OP2_ENABLE, // 12
  114. DEXED_OP3_ENABLE, // 13
  115. DEXED_OP4_ENABLE, // 14
  116. DEXED_OP5_ENABLE, // 15
  117. DEXED_OP6_ENABLE, // 16
  118. DEXED_MAX_NOTES, // 17
  119. DEXED_VOICE_VOLUME // 18
  120. };
  121. // GLOBALS
  122. //==============================================================================
  123. class Dexed
  124. {
  125. public:
  126. Dexed(int rate);
  127. ~Dexed();
  128. void activate(void);
  129. void deactivate(void);
  130. uint8_t getEngineType();
  131. void setEngineType(uint8_t tp);
  132. bool isMonoMode(void);
  133. void setMonoMode(bool mode);
  134. void getSamples(uint16_t n_samples, int16_t* buffer);
  135. void panic(void);
  136. void notesOff(void);
  137. void resetControllers(void);
  138. void setMaxNotes(uint8_t n);
  139. uint8_t getMaxNotes(void);
  140. void doRefreshVoice(void);
  141. void setOPs(uint8_t ops);
  142. bool loadSysexVoice(uint8_t* data);
  143. void keyup(uint8_t pitch);
  144. void keydown(uint8_t pitch, uint8_t velo);
  145. void setSustain(bool sustain);
  146. bool getSustain(void);
  147. uint8_t getNumNotesPlaying(void);
  148. ProcessorVoice voices[MAX_NOTES];
  149. Controllers controllers;
  150. PluginFx fx;
  151. uint8_t data[173] = {
  152. 95, 29, 20, 50, 99, 95, 00, 00, 41, 00, 19, 00, 00, 03, 00, 06, 79, 00, 01, 00, 14, // OP6 eg_rate_1-4, level_1-4, kbd_lev_scl_brk_pt, kbd_lev_scl_lft_depth, kbd_lev_scl_rht_depth, kbd_lev_scl_lft_curve, kbd_lev_scl_rht_curve, kbd_rate_scaling, amp_mod_sensitivity, key_vel_sensitivity, operator_output_level, osc_mode, osc_freq_coarse, osc_freq_fine, osc_detune
  153. 95, 20, 20, 50, 99, 95, 00, 00, 00, 00, 00, 00, 00, 03, 00, 00, 99, 00, 01, 00, 00, // OP5
  154. 95, 29, 20, 50, 99, 95, 00, 00, 00, 00, 00, 00, 00, 03, 00, 06, 89, 00, 01, 00, 07, // OP4
  155. 95, 20, 20, 50, 99, 95, 00, 00, 00, 00, 00, 00, 00, 03, 00, 02, 99, 00, 01, 00, 07, // OP3
  156. 95, 50, 35, 78, 99, 75, 00, 00, 00, 00, 00, 00, 00, 03, 00, 07, 58, 00, 14, 00, 07, // OP2
  157. 96, 25, 25, 67, 99, 75, 00, 00, 00, 00, 00, 00, 00, 03, 00, 02, 99, 00, 01, 00, 10, // OP1
  158. 94, 67, 95, 60, 50, 50, 50, 50, // 4 * pitch EG rates, 4 *pitch EG level
  159. 04, 06, 00, // algorithm, feedback, osc sync
  160. 34, 33, 00, 00, 00, 04, // lfo speed, lfo delay, lfo pitch_mod_depth, lfo_amp_mod_depth, lfo_sync, lfo_waveform
  161. 03, 24, // pitch_mod_sensitivity, transpose
  162. 69, 68, 80, 56, 85 , 76, 84, 00, 00, 00, // 10 * char for name ("DEFAULT ")
  163. 01, 00, 99, 00, 99, 00, 99, 00, 99, 00, // pitch_bend_range, pitch_bend_step, mod_wheel_range, mod_wheel_assign, foot_ctrl_range, foot_ctrl_assign, breath_ctrl_range, breath_ctrl_assign, aftertouch_range, aftertouch_assign
  164. 00, // master tune
  165. 01, 01, 01, 01, 01, 01, // OP1-6 enable
  166. 16 // number of voices
  167. }; // FM-Piano
  168. protected:
  169. static const uint8_t MAX_ACTIVE_NOTES = MAX_NOTES;
  170. uint8_t max_notes = MAX_ACTIVE_NOTES;
  171. uint8_t currentNote;
  172. bool sustain;
  173. bool monoMode;
  174. bool refreshVoice;
  175. uint8_t engineType;
  176. VoiceStatus voiceStatus;
  177. Lfo lfo;
  178. FmCore* engineMsfa;
  179. EngineMkI* engineMkI;
  180. EngineOpl* engineOpl;
  181. };
  182. #endif // PLUGINPROCESSOR_H_INCLUDED