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.

402 lines
12 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. (c)2019 H. Wirtz <wirtz@parasitstudio.de>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3 of the License, or
  9. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software Foundation,
  16. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef CONFIG_H_INCLUDED
  19. #define CONFIG_H_INCLUDED
  20. #include "midinotes.h"
  21. #include <Arduino.h>
  22. // ATTENTION! For better latency you have to redefine AUDIO_BLOCK_SAMPLES from
  23. // 128 to 64 in <ARDUINO-IDE-DIR>/cores/teensy3/AudioStream.h
  24. // If you want to test the system with Linux and withous any keyboard and/or audio equipment, you can do the following:
  25. // 1. In Arduino-IDE enable "Tools->USB-Type->Serial + MIDI + Audio"
  26. // 2. Build the firmware with "MIDI_DEVICE_USB" enabled in config.h.
  27. // 3. Afterconnecting to a Linux system there should be a MIDI an audio device available that is called "MicroMDAEPiano", so you can start the following:
  28. // $ aplaymidi -p 20:0 <MIDI-File> # e.g. test.mid
  29. // $ arecord -f cd -Dhw:1,0 /tmp/bla.wav
  30. //*************************************************************************************************
  31. //* DEVICE SETTINGS
  32. //*************************************************************************************************
  33. // MIDI
  34. #define MIDI_DEVICE_DIN Serial1
  35. #define MIDI_DEVICE_USB 1
  36. #define MIDI_DEVICE_USB_HOST 1
  37. //*************************************************************************************************
  38. //* MIDI SETTINGS
  39. //*************************************************************************************************
  40. #define DEFAULT_MIDI_CHANNEL MIDI_CHANNEL_OMNI
  41. #define MIDI_MERGE_THRU 1
  42. //*************************************************************************************************
  43. //* AUDIO SETTINGS
  44. //*************************************************************************************************
  45. #define AUDIO_MEM 128
  46. #define SAMPLE_RATE AUDIO_SAMPLE_RATE
  47. #define REDUCE_LOUDNESS 0
  48. #define USE_XFADE_DATA 1
  49. // CHORUS parameters
  50. #define MOD_DELAY_SAMPLE_BUFFER int32_t(TIME_MS2SAMPLES(20.0)) // 20.0 ms delay buffer.
  51. #define MOD_WAVEFORM WAVEFORM_TRIANGLE // WAVEFORM_SINE WAVEFORM_TRIANGLE WAVEFORM_SAWTOOTH WAVEFORM_SAWTOOTH_REVERSE
  52. #define MOD_FILTER_OUTPUT MOD_LINKWITZ_RILEY_FILTER_OUTPUT // MOD_LINKWITZ_RILEY_FILTER_OUTPUT MOD_BUTTERWORTH_FILTER_OUTPUT MOD_NO_FILTER_OUTPUT
  53. #define MOD_FILTER_CUTOFF_HZ 3000
  54. //*************************************************************************************************
  55. //* DEBUG OUTPUT SETTINGS
  56. //*************************************************************************************************
  57. #define SHOW_DEBUG 1
  58. #define SERIAL_SPEED 38400
  59. #define SHOW_XRUN 1
  60. #define SHOW_CPU_LOAD_MSEC 5000
  61. //#define DEBUG_AUDIO 50
  62. //*************************************************************************************************
  63. //* HARDWARE SETTINGS
  64. //*************************************************************************************************
  65. //#define USB_AUDIO 1
  66. // Teensy Audio Shield:
  67. /* Values for SGTL5000_LINEOUT_LEVEL
  68. 13: 3.16 Volts p-p
  69. 14: 2.98 Volts p-p
  70. 15: 2.83 Volts p-p
  71. 16: 2.67 Volts p-p
  72. 17: 2.53 Volts p-p
  73. 18: 2.39 Volts p-p
  74. 19: 2.26 Volts p-p
  75. 20: 2.14 Volts p-p
  76. 21: 2.02 Volts p-p
  77. 22: 1.91 Volts p-p
  78. 23: 1.80 Volts p-p
  79. 24: 1.71 Volts p-p
  80. 25: 1.62 Volts p-p
  81. 26: 1.53 Volts p-p
  82. 27: 1.44 Volts p-p
  83. 28: 1.37 Volts p-p
  84. 29: 1.29 Volts p-p (default)
  85. 30: 1.22 Volts p-p
  86. 31: 1.16 Volts p-p
  87. */
  88. #define SGTL5000_LINEOUT_LEVEL 17
  89. //#define SDCARD_CS_PIN 10
  90. //#define SDCARD_MOSI_PIN 7
  91. //#define SDCARD_SCK_PIN 14
  92. // Teensy 3.5 & 3.6 SD card
  93. #define SDCARD_CS_PIN BUILTIN_SDCARD
  94. #define SDCARD_MOSI_PIN 11 // not actually used
  95. #define SDCARD_SCK_PIN 13 // not actually used
  96. // Encoder with button
  97. #define NUM_ENCODER 2
  98. #define ENC_L_PIN_A 3
  99. #define ENC_L_PIN_B 2
  100. #define BUT_L_PIN 4
  101. #define INITIAL_ENC_L_VALUE 0
  102. #define ENC_R_PIN_A 28
  103. #define ENC_R_PIN_B 29
  104. #define BUT_R_PIN 30
  105. #define INITIAL_ENC_R_VALUE 0
  106. #define BUT_DEBOUNCE_MS 20
  107. #define LONG_BUTTON_PRESS 500
  108. // LCD display (I2C)
  109. // [I2C] SCL: Pin 19, SDA: Pin 18 (https://www.pjrc.com/teensy/td_libs_Wire.html)
  110. #define LCD_I2C_ADDRESS 0x27
  111. #define LCD_CHARS 16
  112. #define LCD_LINES 2
  113. // EEPROM address
  114. #define EEPROM_START_ADDRESS 0
  115. #define EEPROM_MASTER_VOLUME EEPROM_START_ADDRESS
  116. #define EEPROM_SOUND EEPROM_START_ADDRESS+1
  117. #define EEPROM_CONFIGURATIONS EEPROM_SOUND+1
  118. // MIDI-CC mapping
  119. // free CCs: 102-119 / 85-90 / 52-63
  120. #define MIDI_CC_PANORAMA 10
  121. #define MIDI_CC_REVERB_SEND 91
  122. #define MIDI_CC_TREMOLO_DEPTH 92
  123. #define MIDI_CC_CHORUS_SEND 93
  124. #define MIDI_CC_DETUNE_DEPTH 94
  125. #define MIDI_CC_EP_DECAY 52
  126. #define MIDI_CC_EP_RELEASE 53
  127. #define MIDI_CC_EP_HARDNESS 54
  128. #define MIDI_CC_EP_TREBLE 55
  129. #define MIDI_CC_EP_STEREO 56
  130. #define MIDI_CC_EP_TRANSPOSE 57
  131. #define MIDI_CC_EP_TUNE 58
  132. #define MIDI_CC_EP_VELOCITY_SENSE 59
  133. #define MIDI_CC_EP_TREM_FRQ 60
  134. #define MIDI_CC_EP_OVERDRIVE 61
  135. #define MIDI_CC_COMP_GAIN 102
  136. #define MIDI_CC_COMP_REPOSNE 103
  137. #define MIDI_CC_COMP_LIMIT 104
  138. #define MIDI_CC_COMP_THRESHOLD 105
  139. #define MIDI_CC_COMP_ATTACK 106
  140. #define MIDI_CC_COMP_DECAY 107
  141. #define MIDI_CC_REVERB_ROOMSIZE 108
  142. #define MIDI_CC_REVERB_DAMPING 109
  143. #define MIDI_CC_CHORUS_FREQUENCY 111
  144. #define MIDI_CC_CHORUS_INTENSITY 112
  145. #define MIDI_CC_CHORUS_WAVEFORM 113
  146. #define MIDI_CC_BASS_LR_LEVEL 114
  147. #define MIDI_CC_BASS_MONO_LEVEL 115
  148. #define MIDI_CC_EQ_BASS 116
  149. #define MIDI_CC_EQ_TREBLE 117
  150. #define MIDI_CC_MIDI_SOFT_THRU 118
  151. #define MIDI_CC_MONO 119
  152. //*************************************************************************************************
  153. //* DO NO CHANGE ANYTHING BEYOND IF YOU DON'T KNOW WHAT YOU ARE DOING !!!
  154. //*************************************************************************************************
  155. #define MICRO_MDAEPIANO_VERSION "1.0.0 alpha"
  156. /* HELPER MACROS */
  157. #define TIME_MS2SAMPLES(x) floor(uint32_t(x) * AUDIO_SAMPLE_RATE / 1000)
  158. #define SAMPLES2TIME_MS(x) float(uint32_t(x) * 1000 / AUDIO_SAMPLE_RATE)
  159. #define MOD_NO_FILTER_OUTPUT 0
  160. #define MOD_BUTTERWORTH_FILTER_OUTPUT 1
  161. #define MOD_LINKWITZ_RILEY_FILTER_OUTPUT 2
  162. #define MAX_SOUNDS min(99,int((4096-EEPROM_CONFIGURATIONS)/sizeof(config_t)))
  163. #define CONTROL_RATE_MS 100
  164. #define BACK_TO_MAIN_MS 800
  165. #define STORE_MASTER_VOLUME_MS 5000
  166. // Encoder min/max values
  167. #define ENC_DECAY_MIN 0
  168. #define ENC_DECAY_MAX 99
  169. #define ENC_DECAY_DEFAULT 50
  170. //
  171. #define ENC_RELEASE_MIN 0
  172. #define ENC_RELEASE_MAX 99
  173. #define ENC_RELEASE_DEFAULT 50
  174. //
  175. #define ENC_HARDNESS_MIN 0
  176. #define ENC_HARDNESS_MAX 99
  177. #define ENC_HARDNESS_DEFAULT 50
  178. //
  179. #define ENC_TREBLE_MIN 0
  180. #define ENC_TREBLE_MAX 99
  181. #define ENC_TREBLE_DEFAULT 50
  182. //
  183. #define ENC_STEREO_MIN 0
  184. #define ENC_STEREO_MAX 99
  185. #define ENC_STEREO_DEFAULT 64
  186. //
  187. #define ENC_TRANSPOSE_MIN -24
  188. #define ENC_TRANSPOSE_MAX 24
  189. #define ENC_TRANSPOSE_DEFAULT 0
  190. //
  191. #define ENC_TUNE_MIN -50
  192. #define ENC_TUNE_MAX 50
  193. #define ENC_TUNE_DEFAULT 0
  194. //
  195. #define ENC_DETUNE_MIN 0
  196. #define ENC_DETUNE_MAX 99
  197. #define ENC_DETUNE_DEFAULT 14
  198. //
  199. #define ENC_VELOCITY_SENSE_MIN 0
  200. #define ENC_VELOCITY_SENSE_MAX 99
  201. #define ENC_VELOCITY_SENSE_DEFAULT 24
  202. //
  203. #define ENC_PAN_TREM_FREQUENCY_MIN 0
  204. #define ENC_PAN_TREM_FREQUENCY_MAX 99
  205. #define ENC_PAN_TREM_FREQUENCY_DEFAULT 50
  206. //
  207. #define ENC_PAN_TREM_LEVEL_MIN 0
  208. #define ENC_PAN_TREM_LEVEL_MAX 99
  209. #define ENC_PAN_TREM_LEVEL_DEFAULT 50
  210. //
  211. #define ENC_OVERDRIVE_MIN 0
  212. #define ENC_OVERDRIVE_MAX 99
  213. #define ENC_OVERDRIVE_DEFAULT 15
  214. //
  215. #define ENC_COMP_GAIN_MIN 0
  216. #define ENC_COMP_GAIN_MAX 2
  217. #define ENC_COMP_GAIN_DEFAULT 0
  218. //
  219. #define ENC_COMP_RESPONSE_MIN 0
  220. #define ENC_COMP_RESPONSE_MAX 3
  221. #define ENC_COMP_RESPONSE_DEFAULT 1
  222. //
  223. #define ENC_COMP_LIMIT_MIN 0
  224. #define ENC_COMP_LIMIT_MAX 1
  225. #define ENC_COMP_LIMIT_DEFAULT 1
  226. //
  227. #define ENC_COMP_THRESHOLD_MIN 0
  228. #define ENC_COMP_THRESHOLD_MAX 96
  229. #define ENC_COMP_THRESHOLD_DEFAULT 18
  230. //
  231. #define ENC_COMP_ATTACK_MIN 0
  232. #define ENC_COMP_ATTACK_MAX 99
  233. #define ENC_COMP_ATTACK_DEFAULT 20
  234. //
  235. #define ENC_COMP_DECAY_MIN 0
  236. #define ENC_COMP_DECAY_MAX 99
  237. #define ENC_COMP_DECAY_DEFAULT 40
  238. //
  239. #define ENC_REVERB_ROOMSIZE_MIN 0
  240. #define ENC_REVERB_ROOMSIZE_MAX 99
  241. #define ENC_REVERB_ROOMSIZE_DEFAULT 40
  242. //
  243. #define ENC_REVERB_DAMPING_MIN 0
  244. #define ENC_REVERB_DAMPING_MAX 99
  245. #define ENC_REVERB_DAMPING_DEFAULT 50
  246. //
  247. #define ENC_REVERB_LEVEL_MIN 1
  248. #define ENC_REVERB_LEVEL_MAX 99
  249. #define ENC_REVERB_LEVEL_DEFAULT 15
  250. //
  251. #define ENC_CHORUS_FREQUENCY_MIN 0
  252. #define ENC_CHORUS_FREQUENCY_MAX 200
  253. #define ENC_CHORUS_FREQUENCY_DEFAULT 30
  254. //
  255. #define ENC_CHORUS_INTENSITY_MIN 0
  256. #define ENC_CHORUS_INTENSITY_MAX 100
  257. #define ENC_CHORUS_INTENSITY_DEFAULT 50
  258. //
  259. #define ENC_CHORUS_WAVEFORM_MIN 1
  260. #define ENC_CHORUS_WAVEFORM_MAX 2
  261. #define ENC_CHORUS_WAVEFORM_DEFAULT 1
  262. //
  263. #define ENC_CHORUS_LEVEL_MIN 0
  264. #define ENC_CHORUS_LEVEL_MAX 99
  265. #define ENC_CHORUS_LEVEL_DEFAULT 50
  266. //
  267. #define ENC_BASS_LR_LEVEL_MIN 0
  268. #define ENC_BASS_LR_LEVEL_MAX 99
  269. #define ENC_BASS_LR_LEVEL_DEFAULT 99
  270. //
  271. #define ENC_BASS_MONO_LEVEL_MIN 0
  272. #define ENC_BASS_MONO_LEVEL_MAX 99
  273. #define ENC_BASS_MONO_LEVEL_DEFAULT 0
  274. //
  275. #define ENC_EQ_BASS_MIN -50
  276. #define ENC_EQ_BASS_MAX 50
  277. #define ENC_EQ_BASS_DEFAULT 0
  278. //
  279. #define ENC_EQ_TREBLE_MIN -50
  280. #define ENC_EQ_TREBLE_MAX 50
  281. #define ENC_EQ_TREBLE_DEFAULT 0
  282. //
  283. #define ENC_LOUDNESS_MIN 0
  284. #define ENC_LOUDNESS_MAX 99
  285. #define ENC_LOUDNESS_DEFAULT 99
  286. //
  287. #define ENC_MIDI_CHANNEL_MIN 0
  288. #define ENC_MIDI_CHANNEL_MAX 16
  289. #define ENC_MIDI_CHANNEL_DEFAULT DEFAULT_MIDI_CHANNEL
  290. //
  291. #define ENC_MIDI_SOFT_THRU_MIN 0
  292. #define ENC_MIDI_SOFT_THRU_MAX 1
  293. #define ENC_MIDI_SOFT_THRU_DEFAULT 1
  294. //
  295. #define ENC_MAX_POLY_MIN 1
  296. #define ENC_MAX_POLY_MAX NVOICES
  297. #define ENC_MAX_POLY_DEFAULT NVOICES
  298. //
  299. #define ENC_MONO_MIN 0 // 0=stereo
  300. #define ENC_MONO_MAX 3 // 1=mono(r/l) 2=mono(r) 3=mono(l)
  301. #define ENC_MONO_DEFAULT 0
  302. //
  303. #define ENC_MASTER_VOLUME_MIN 0
  304. #define ENC_MASTER_VOLUME_MAX 99
  305. #define ENC_MASTER_VOLUME_DEFAULT 80
  306. //
  307. #define ENC_MASTER_PAN_MIN -20
  308. #define ENC_MASTER_PAN_MAX 20
  309. #define ENC_MASTER_PAN_DEFAULT 0
  310. // MIDI
  311. #ifdef MIDI_DEVICE_USB
  312. #define USBCON 1
  313. #endif
  314. #if defined(__MK66FX1M0__)
  315. // Teensy-3.6 settings
  316. #define MIDI_DEVICE_USB_HOST 1
  317. #else
  318. // Teensy-3.5 settings
  319. #undef MIDI_DEVICE_USB_HOST
  320. #endif
  321. // Engine
  322. #if defined(__MK66FX1M0__)
  323. // Teensy-3.6 settings
  324. #define NVOICES 40
  325. #else
  326. #define NVOICES 32
  327. #endif
  328. // struct for holding the current configuration
  329. struct config_t {
  330. uint32_t checksum;
  331. uint8_t decay;
  332. uint8_t release;
  333. uint8_t hardness;
  334. uint8_t treble;
  335. int8_t stereo;
  336. int8_t transpose;
  337. int8_t tune;
  338. uint8_t detune;
  339. uint8_t velocity_sense;
  340. uint8_t pan_trem_frequency;
  341. uint8_t pan_trem_level;
  342. uint8_t overdrive;
  343. uint8_t comp_gain;
  344. uint8_t comp_response;
  345. bool comp_limit;
  346. uint8_t comp_threshold;
  347. uint8_t comp_attack;
  348. uint8_t comp_decay;
  349. uint8_t reverb_roomsize;
  350. uint8_t reverb_damping;
  351. uint8_t reverb_level;
  352. uint8_t chorus_frequency;
  353. uint8_t chorus_intensity;
  354. uint8_t chorus_waveform;
  355. uint8_t chorus_level;
  356. uint8_t bass_lr_level;
  357. uint8_t bass_mono_level;
  358. int8_t eq_bass;
  359. int8_t eq_treble;
  360. uint8_t loudness;
  361. uint8_t midi_channel;
  362. bool midi_soft_thru;
  363. uint8_t max_poly;
  364. uint8_t mono;
  365. int8_t pan;
  366. };
  367. #endif