-
Notifications
You must be signed in to change notification settings - Fork 0
/
libAdjHeartModSynth_2.h
4370 lines (3981 loc) · 151 KB
/
libAdjHeartModSynth_2.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file libAdjHeartModSynth_1.h
* @author Nahum Budin
* @date 23-Jan-2021
* @version 2.0
* 1. Code refactoring
* 2. Adding local ALSA midi device/clientss handling (not through jack connection kit)
* 3. Adding local JACK clients handling (not through jack connection kit)
* 4. Seperating JACK auto connection of audio and midi
* 5. Adding start/stop audio
*
*
* History:\n
*
* @version 1.3 9-Jan-2021
* 1. Add support in setting in focus controls using external knob/dial using sysex commands.
* 2. Add support in controloing JACK params and operation
*
* @version 1.2
* 1. Add support in Serial Port MIDI input.
* 2. Add ALSA client to support serial port input stream..*
*
* @version 1.1: 15-May-2020
* 1. Add JackAudio input client to drive signal level and output waveform display.
* 2. Activating the Pass all mode of the filter.
* 3. Add MIDI control-sequnces training to enable mapping of external midi control-keyboard\n
* controls to modSynth settings and parameters changing (e.g. kbd knob changes filter-freq)
*
* version 1.0: 5-Oct-2019
* First version (based on libAdjHeartRaspiFlSynthMultiCore_3.h
* version 3.8 8-Feb-2019)
*
* @brief A raspberry Pi multi-core polyphonic music synthesizer library api.
*
* \mainpage AdjHeart Polyphonic Synthesizer
*
* This library was writen to run over a Raspberry Pi 3B or higher version (currentlly 4).\n
* The librarry implements a modular synthesizer (ModSynth) that comprises 2 main parts:\n
* 1. FluidSynth - an open source SoundFont base synthesizer.\n
* 2. AdjHeart Synthesizer (AdjSynth), as described hereafter.\n
* It uses OpenMP to distribute the processing acrros the Pi 4 cores.\n
* It implements the DSP functions using floating point arithmetics.\n
* It implements a JackAudio client.\n
* It implements MIDI interfaces using alsaMIDI.\n
* It implements muliple Bluetooth SPP conections server serving as MIDI input channel.\n
* It was developed on VisualGDB addon for MS VisualStudio using MS Build.\n
* For best performanve: IT MUST BE COMPILED IN MAXIMUM-SPEED (-o3) OPTIMIZTION MODE!!!!
*
* Each of the polyphonic voices implements:
* - 2 VCOs (VCO1 provides multiple harmonics mixer to enable Organ like sounds).
* - 2 Filters (LPF, HPF, BPF)
* - 1 Noise generator (Multi colored)
* - 1 Karplus Strong String sound generator
* - 1 Morphed Sinuse Oscilator
* - 1 PAD synthersizer (IFFT wavetable based generator).
* - Otput Volume/Pan mixer
* - Distortion
* - 5 ADSR enevelope generators
* - 5 LFOs with delayed trigger capability
*
* It provides common control and processing modules:
* - 10 Bands graphic equilizer
* - Reverbration (Freeverb and modified Freeverb 3)
* - Split keyboard and sensitivity control.
* - Portamento (unisonic)
* - Amp-mixer with Pan control and modulation for main + 16 midi channels
*
* It provides the user with edditing, management and configuration capabilities
* - Full control and edditing mode for creating AdjSynth sound patches.
* - 3 Sketches for incremental patch development.
* - Saving and loading patches XML files.
* - MIDI mapping mode that ebables setting each MIDI channel features, including synthesizer type,\n
* AdjSynth patch / MIDI SoundFont selection, level, pan and send setting.
* - Saving /Loading mapping mode settings (described above) as XML preset files.
* - Quick select between 5 preloaded preset files.
* - Text based configuration files for setting automatic audio and MIDI connections.
*
* It provides a full API supporting all features incluuding callback functions for updates and events initiation.
*
*/
#ifndef _LIB_ADJ_SYNTH_2_0
#define _LIB_ADJ_SYNTH_2_0
#include <stdint.h>
#include <vector>
#include <string>
//#ifdef __cplusplus
//extern "C" {
//#endif
#define _SYNTH_MAX_NUM_OF_VOICES 48
#if (_SYNTH_MAX_NUM_OF_CORE_VOICES > 64)
Error - must be no more than 64
#endif
#define _SYNTH_MAX_NUM_OF_CORES 8
#if (_SYNTH_MAX_NUM_OF_CORES > 8)
Error -
must be no more than 8
#endif
#define _NUM_OF_PRESETS 5
#define _NUM_OF_HARMONIES 9
#define _AUDIO_JACK 0
#define _AUDIO_ALSA 1
#define _DEFAULT_AUDIO_DRIVER _AUDIO_JACK
#define _SAMPLE_RATE_44 44100
#define _SAMPLE_RATE_48 48000
#define _DEFAULT_SAMPLE_RATE _SAMPLE_RATE_44
#define _AUDIO_BLOCK_SIZE_256 256
#define _AUDIO_BLOCK_SIZE_512 512
#define _AUDIO_BLOCK_SIZE_1024 1024
#define _DEFAULT_BLOCK_SIZE _AUDIO_BLOCK_SIZE_512
#define _DEFAULT_ALSA_AUDIO_DEVICE { "plughw:1,0" }
#define _DEFAULT_ALSA_PERIOD_TIME_USEC 10000
#define _DEFAULT_ALSA_AUD_PERIOD_TIME_USEC ((_DEFAULT_BLOCK_SIZE*1000000)/_DEFAULT_SAMPLE_RATE + 0.5)
#define _DEFAULT_JACK_AUD_PERIOD_TIME_USEC ((_DEFAULT_BLOCK_SIZE*1000000)/_DEFAULT_SAMPLE_RATE + 0.5)
#define _JACK_MODE_APP_CONTROL 0 // application sets JACK params
#define _JACK_MODE_SERVER_CONTROL 1 // JACK server sets application params
#define _DEFAULT_JACK_MODE _JACK_MODE_SERVER_CONTROL
#define _JACK_AUTO_START_DIS false
#define _JACK_AUTO_START_EN true
#define _DEFAULT_JACK_AUTO_START _JACK_AUTO_START_EN
#define _JACK_AUTO_CONNECT_AUDIO_DIS false
#define _JACK_AUTO_CONNECT_AUDIO_EN true
#define _DEFAULT_JACK_AUTO_CONNECT_AUDIO _JACK_AUTO_CONNECT_AUDIO_EN
#define _JACK_AUTO_CONNECT_MIDI_DIS false
#define _JACK_AUTO_CONNECT_MIDI_EN true
#define _DEFAULT_JACK_AUTO_CONNECT_MIDI _JACK_AUTO_CONNECT_MIDI_DIS
#define _LEFT 0
#define _RIGHT 1
#define _SEND_LEFT 2
#define _SEND_RIGHT 3
#define _MAX_NUM_OF_JACK_AUDIO_OUT_PORTS 2
#define _MAX_NUM_OF_JACK_AUDIO_IN_PORTS 2
#define _MAX_NUM_OF_JACK_MIDI_IN_PORTS 4
#define _DEFAULT_MASTER_VOLUME 80
#define _DEFAULT_FLUID_SYNTH_VOLUME 80
#define _FLUID_CHORUS_MOD_SINE 0
#define _FLUID_CHORUS_MOD_TRIANGLE 1
#define _FLUID_DEFAULT_SOUNDFONT_FILE "/usr/share/sounds/sf2/FluidR3_GM.sf2"
#define _FLUID_DEFAULT_SOUNDFONT_DIR "/usr/share/sounds/sf2"
#define _ADJ_DEFAULT_PATCHES_DIR "/home/pi/AdjHeartModSynth_2/Settings"
#define _MAX_NUM_OF_VOICES _SYNTH_MAX_NUM_OF_VOICES
#define _PROGRAM_0 0
#define _PROGRAM_1 1
#define _PROGRAM_2 2
#define _PROGRAM_3 3
#define _PROGRAM_4 4
#define _PROGRAM_5 5
#define _PROGRAM_6 6
#define _PROGRAM_7 7
#define _PROGRAM_8 8
#define _PROGRAM_9 9
#define _PROGRAM_10 10
#define _PROGRAM_11 11
#define _PROGRAM_12 12
#define _PROGRAM_13 13
#define _PROGRAM_14 14
#define _PROGRAM_15 15
#define _PROGRAM_16 16 // Scetch 1
#define _PROGRAM_17 17
#define _PROGRAM_18 18
#define _SYNTH_MAX_NUM_OF_PROGRAMS _PROGRAM_18 + 1
#if (_SYNTH_MAX_NUM_OF_PROGRAMS > _PROGRAM_18 + 1)
Error -
must be no more than PROGRAM_18 + 1
#endif
#define _SYNTH_NUM_OF_PROGRAMS _SYNTH_MAX_NUM_OF_PROGRAMS
#define _MIDI_MIXER_CHAN_1 _PROGRAM_0
#define _MIDI_MIXER_CHAN_2 _PROGRAM_1
#define _MIDI_MIXER_CHAN_3 _PROGRAM_2
#define _MIDI_MIXER_CHAN_4 _PROGRAM_3
#define _MIDI_MIXER_CHAN_5 _PROGRAM_4
#define _MIDI_MIXER_CHAN_6 _PROGRAM_5
#define _MIDI_MIXER_CHAN_7 _PROGRAM_6
#define _MIDI_MIXER_CHAN_8 _PROGRAM_7
#define _MIDI_MIXER_CHAN_9 _PROGRAM_8
#define _MIDI_MIXER_CHAN_10 _PROGRAM_9
#define _MIDI_MIXER_CHAN_11 _PROGRAM_10
#define _MIDI_MIXER_CHAN_12 _PROGRAM_11
#define _MIDI_MIXER_CHAN_13 _PROGRAM_12
#define _MIDI_MIXER_CHAN_14 _PROGRAM_13
#define _MIDI_MIXER_CHAN_15 _PROGRAM_14
#define _MIDI_MIXER_CHAN_16 _PROGRAM_15
#define _SKETCH_PROGRAM_1 _PROGRAM_16
#define _SKETCH_PROGRAM_2 _PROGRAM_17
#define _SKETCH_PROGRAM_3 _PROGRAM_18
#define _MAX_NUM_OF_MIDI_DEVICES 16
#define _MAX_NUM_OF_MIDI_DEVICE_PORTS 16
#define _MIDI_DEVICE_INPUT 0 // an input midi device (synth)
#define _MIDI_DEVICE_OUTPUT 1 // an output midi device (keyboard)
#define _MAX_NUM_OF_JACK_CLIENTS 32
#define _MAX_NUM_OF_JACK_CLIENT_PORTS 16
#define _JACK_CLIENT_INPUT 0
#define _JACK_CLIENT_OUTPUT 1
#define _MIDI_CHAN_ASSIGNED_SYNTH_NONE 0
#define _MIDI_CHAN_ASSIGNED_SYNTH_FLUID 1
#define _MIDI_CHAN_ASSIGNED_SYNTH_ADJ 2
#define _OSC_DETUNE_MAX_OCTAVE 6
#define _OSC_DETUNE_MIN_OCTAVE -6
#define _OSC_DETUNE_MAX_SEMITONES 11
#define _OSC_DETUNE_MIN_SEMITONES -11
#define _OSC_DETUNE_MAX_CENTS 7.5f
#define _OSC_DETUNE_MIN_CENTS -7.5f
#define _OSC_DETUNE_CENTS_FACTORIAL 0.25f
#define _MOD_LFO_MIN_FREQ 0.1f
#define _MOD_LFO_MAX_FREQ 10.0f
#define _DISTORTION_MAX_DRIVE 1.f
#define _DISTORTION_MIN_DRIVE 0.f
#define _DISTORTION_MAX_RANGE 100.f
#define _DISTORTION_MIN_RANGE 1.f
#define _DISTORTION_MAX_BLEND 1.f
#define _DISTORTION_MIN_BLEND 0.f
#define _TONE_ON_DELAY_NONE 0
#define _TONE_ON_DELAY_500MS 400
#define _TONE_ON_DELAY_1000MS 800
#define _TONE_ON_DELAY_1500MS 1200
#define _TONE_ON_DELAY_2000MS 1600
#define _NUM_OF_UNISON_LEVEL_SLIDERS 9
#define _CHANGE_COMMAND_SOURCE_NONE -1
#define _CHANGE_COMMAND_SOURCE_GUI 0
#define _CHANGE_COMMAND_SOURCE_PATCH 1
#define _NUM_OF_LFOS 5
#define _NUM_OF_LFO_DELAY_OPTIONS 5
#define _NUM_OF_ENVS 5
#define _LFO_NONE 0
#define _LFO_1 1
#define _LFO_2 2
#define _LFO_3 3
#define _LFO_4 4
#define _LFO_5 5
#define _LFO_1_DELAYED_500MS 10
#define _LFO_2_DELAYED_500MS 11
#define _LFO_3_DELAYED_500MS 12
#define _LFO_4_DELAYED_500MS 13
#define _LFO_5_DELAYED_500MS 14
#define _LFO_1_DELAYED_1000MS 20
#define _LFO_2_DELAYED_1000MS 21
#define _LFO_3_DELAYED_1000MS 22
#define _LFO_4_DELAYED_1000MS 23
#define _LFO_5_DELAYED_1000MS 24
#define _LFO_1_DELAYED_1500MS 30
#define _LFO_2_DELAYED_1500MS 31
#define _LFO_3_DELAYED_1500MS 32
#define _LFO_4_DELAYED_1500MS 33
#define _LFO_5_DELAYED_1500MS 34
#define _LFO_1_DELAYED_2000MS 40
#define _LFO_2_DELAYED_2000MS 41
#define _LFO_3_DELAYED_2000MS 42
#define _LFO_4_DELAYED_2000MS 43
#define _LFO_5_DELAYED_2000MS 44
#define _ENV_NONE 0
#define _ENV_1 1
#define _ENV_2 2
#define _ENV_3 3
#define _ENV_4 4
#define _ENV_5 5
#define _NUM_OF_VCOS 2
#define _CONTROL_TYPE_DIAL 10
#define _CONTROL_TYPE_SLIDER 11
#define _CONTROL_TYPE_LIST 12
#define _CONTROL_TYPE_BUTTON 13
#define _CONTROL_TYPE_CHECK 14
#define _OSC_1_EVENT 0
#define _OSC_2_EVENT 1
#define _LFO_1_EVENT 2
#define _LFO_2_EVENT 3
#define _LFO_3_EVENT 4
#define _LFO_4_EVENT 5
#define _LFO_5_EVENT 6
#define _ENV_1_EVENT 7
#define _ENV_2_EVENT 8
#define _ENV_3_EVENT 9
#define _ENV_4_EVENT 10
#define _ENV_5_EVENT 11
#define _ENABLE ((bool)true)
#define _DISABLE ((bool)false)
#define _FILTER_1_EVENT 13
#define _FILTER_2_EVENT 14
#define _AMP_CH1_EVENT 15
#define _AMP_CH2_EVENT 16
#define _KBD_1_EVENT 20
#define _NOISE_1_EVENT 25
#define _KARPLUS_1_EVENT 30
#define _REVERB_EVENT 35
#define _DISTORTION_1_EVENT 40
#define _DISTORTION_2_EVENT 41
#define _BAND_EQUALIZER_EVENT 45
#define _MSO_1_EVENT 50
#define _MIDI_MAPPING_EVENT 55
#define _PAD_1_EVENT 60
#define _SEQUENCER_1_EVENT 65
#define _RECORDER_1_EVENT 70
#define _MIDI_MIXER_1_EVENT 75
#define _FLUID_SYNTH_1_EVENT 80
#define _MOD_SYNTH_EVENT 85
#define _AUDIO_EVENT_1 90
#define SYNC_ON true
#define SYNC_OFF false
#define TRACK_ON true
#define TRACK_OFF false
#define _OSC_PARAM_WAVEFORM 110
#define _OSC_WAVEFORM_SINE 0
#define _OSC_WAVEFORM_SQUARE 1
#define _OSC_WAVEFORM_PULSE 2
#define _OSC_WAVEFORM_TRIANGLE 3
#define _OSC_WAVEFORM_SAMPHOLD 4
#define _OSC_PWM_SYMMETRY 120
#define _OSC_DETUNE_OCTAVE 130
#define _OSC_DETUNE_SEMITONES 131
#define _OSC_DETUNE_CENTS 132
#define _OSC_FILTER_SEND_1 140
#define _OSC_FILTER_SEND_2 150
#define _OSC_UNISON_MODE 160
#define _OSC_UNISON_MODE_12345678 0
#define _OSC_UNISON_MODE_HAMMOND 1
#define _OSC_UNISON_MODE_OCTAVES 2
#define _OSC_UNISON_MODE_C_CHORD 3
#define _OSC_UNISON_MODE_Cm_CHORD 4
#define _OSC_UNISON_MODE_C7_CHORD 5
#define _OSC_UNISON_MODE_Cm7_CHORD 6
#define _OSC_UNISON_LEVEL_1 170
#define _OSC_UNISON_LEVEL_2 171
#define _OSC_UNISON_LEVEL_3 172
#define _OSC_UNISON_LEVEL_4 173
#define _OSC_UNISON_LEVEL_5 174
#define _OSC_UNISON_LEVEL_6 175
#define _OSC_UNISON_LEVEL_7 176
#define _OSC_UNISON_LEVEL_8 177
#define _OSC_UNISON_LEVEL_9 181
#define _OSC_UNISON_DISTORTION 178
#define _OSC_UNISON_DETUNE 179
#define _OSC_SYNC 180
#define _OSC_FIX_TONE 190
#define _OSC_TRACK_KBD 200
#define _OSC_1_UNISON_SQUARE 210
#define _OSC_FREQ_MOD_LFO 220
#define _OSC_FREQ_MOD_LFO_LEVEL 221
#define _OSC_FREQ_MOD_ENV 222
#define _OSC_FREQ_MOD_ENV_LEVEL 223
#define _OSC_PWM_MOD_LFO 224
#define _OSC_PWM_MOD_LFO_LEVEL 225
#define _OSC_PWM_MOD_ENV 226
#define _OSC_PWM_MOD_ENV_LEVEL 227
#define _OSC_AMP_MOD_LFO 228
#define _OSC_AMP_MOD_LFO_LEVEL 229
#define _OSC_AMP_MOD_ENV 230
#define _OSC_AMP_MOD_ENV_LEVEL 231
#define _OSC_ENABLE 232
#define _OSC_HAMMOND_PERCUSION_MODE 240
#define _HAMMOND_PERCUSION_MODE_OFF 0
#define _HAMMOND_PERCUSION_MODE_2ND_SOFT_SLOW 1
#define _HAMMOND_PERCUSION_MODE_2ND_SOFT_FAST 2
#define _HAMMOND_PERCUSION_MODE_2ND_NORM_SLOW 3
#define _HAMMOND_PERCUSION_MODE_2ND_NORM_FAST 4
#define _HAMMOND_PERCUSION_MODE_3RD_SOFT_SLOW 5
#define _HAMMOND_PERCUSION_MODE_3RD_SOFT_FAST 6
#define _HAMMOND_PERCUSION_MODE_3RD_NORM_SLOW 7
#define _HAMMOND_PERCUSION_MODE_3RD_NORM_FAST 8
#define _MOD_ADSR_ATTACK 300
#define _MOD_ADSR_DECAY 301
#define _MOD_ADSR_SUSTAIN 302
#define _MOD_ADSR_RELEASE 303
#define _MOD_LFO_WAVEFORM 310
#define _MOD_LFO_RATE 311
#define _MOD_LFO_SYMMETRY 312
#define _FILTER_FREQ 400
#define _FILTER_OCT 401
#define _FILTER_Q 402
#define _FILTER_KBD_FREQ 403
#define _FILTER_KBD_TRACK 404
#define _FILTER_BAND 405
#define _FILTER_2_TRACK_FILT_1 406
#define _FILTER_FREQ_MOD_LFO 407
#define _FILTER_FREQ_MOD_LFO_LEVEL 408
#define _FILTER_FREQ_MOD_ENV 409
#define _FILTER_FREQ_MOD_ENV_LEVEL 410
#define _FILTER_BAND_LPF 0
#define _FILTER_BAND_HPF 1
#define _FILTER_BAND_BPF 2
#define _FILTER_BAND_PASS_ALL 3
#define _AMP_LEVEL 500
#define _AMP_PAN 501
#define _AMP_ENV_MOD_ENABLE 502
#define _AMP_PAN_MOD_LFO 503
#define _AMP_PAN_MOD_LFO_LEVEL 504
#define _AMP_FIXED_LEVELS 505
#define _AMP_SEND 506
#define _AMP_FIXED_LEVELS_DISABLE 0
#define _AMP_FIXED_LEVELS_ENABLE 1
#define _MIXER_CHAN_1_LEVEL 510
#define _MIXER_CHAN_2_LEVEL 511
#define _MIXER_CHAN_3_LEVEL 512
#define _MIXER_CHAN_4_LEVEL 513
#define _MIXER_CHAN_5_LEVEL 514
#define _MIXER_CHAN_6_LEVEL 515
#define _MIXER_CHAN_7_LEVEL 516
#define _MIXER_CHAN_8_LEVEL 517
#define _MIXER_CHAN_9_LEVEL 518
#define _MIXER_CHAN_10_LEVEL 519
#define _MIXER_CHAN_11_LEVEL 520
#define _MIXER_CHAN_12_LEVEL 521
#define _MIXER_CHAN_13_LEVEL 522
#define _MIXER_CHAN_14_LEVEL 523
#define _MIXER_CHAN_15_LEVEL 524
#define _MIXER_CHAN_16_LEVEL 525
#define _MIXER_ALL_LEVEL 526
#define _MIXER_CHAN_1_PAN 530
#define _MIXER_CHAN_2_PAN 531
#define _MIXER_CHAN_3_PAN 532
#define _MIXER_CHAN_4_PAN 533
#define _MIXER_CHAN_5_PAN 534
#define _MIXER_CHAN_6_PAN 535
#define _MIXER_CHAN_7_PAN 536
#define _MIXER_CHAN_8_PAN 537
#define _MIXER_CHAN_9_PAN 538
#define _MIXER_CHAN_10_PAN 539
#define _MIXER_CHAN_11_PAN 540
#define _MIXER_CHAN_12_PAN 541
#define _MIXER_CHAN_13_PAN 542
#define _MIXER_CHAN_14_PAN 543
#define _MIXER_CHAN_15_PAN 544
#define _MIXER_CHAN_16_PAN 545
#define _MIXER_ALL_PAN 546
#define _MIXER_CHAN_1_SEND 550
#define _MIXER_CHAN_2_SEND 551
#define _MIXER_CHAN_3_SEND 552
#define _MIXER_CHAN_4_SEND 553
#define _MIXER_CHAN_5_SEND 554
#define _MIXER_CHAN_6_SEND 555
#define _MIXER_CHAN_7_SEND 556
#define _MIXER_CHAN_8_SEND 557
#define _MIXER_CHAN_9_SEND 558
#define _MIXER_CHAN_10_SEND 559
#define _MIXER_CHAN_11_SEND 560
#define _MIXER_CHAN_12_SEND 561
#define _MIXER_CHAN_13_SEND 562
#define _MIXER_CHAN_14_SEND 563
#define _MIXER_CHAN_15_SEND 564
#define _MIXER_CHAN_16_SEND 565
#define _MIXER_ALL_SEND 566
#define _KBD_PORTAMENTO_LEVEL 600
#define _KBD_PORTAMENTO_ENABLE 601
#define _KBD_SENSITIVITY_LEVEL 602
#define _KBD_POLY_MODE_LIMIT 603
#define _KBD_POLY_MODE_FIFO 604
#define _KBD_POLY_MODE_REUSE 605
#define _KBD_LOW_SENSITIVITY_LEVEL 606
#define _KBD_SPLIT_POINT 607
#define _KBD_SPLIT_POINT_NONE 0
#define _KBD_SPLIT_POINT_C2 1
#define _KBD_SPLIT_POINT_C3 2
#define _KBD_SPLIT_POINT_C4 3
#define _KBD_SPLIT_POINT_C5 4
#define _NOISE_COLOR 700
#define _WHITE_NOISE 0
#define _PINK_NOISE 1
#define _BROWN_NOISE 2
#define _NOISE_SEND_1 701
#define _NOISE_SEND_2 702
#define _NOISE_AMP_MOD_LFO 703
#define _NOISE_AMP_MOD_LFO_LEVEL 704
#define _NOISE_AMP_MOD_ENV 705
#define _NOISE_AMP_MOD_ENV_LEVEL 706
#define _NOISE_ENABLE 707
#define _KARPLUS_STRONG_EXCITATION_WAVEFORM 800
#define _KARPLUS_STRONG_EXCITATION_WHITE_NOISE 0
#define _KARPLUS_STRONG_EXCITATION_PINK_NOISE 1
#define _KARPLUS_STRONG_EXCITATION_BROWN_NOISE 2
#define _KARPLUS_STRONG_EXCITATION_SINECHIRP 3
#define _KARPLUS_STRONG_EXCITATION_DECAYEDSINE 4
#define _KARPLUS_STRONG_EXCITATION_SAWTOOTH_WAVE 5
#define _KARPLUS_STRONG_EXCITATION_SQUARE_WAVE 6
#define _KARPLUS_STRONG_STRING_DUMP_CALC_MODE 801
#define _KARPLUS_STRONG_STRING_DAMPING_CALC_DIRECT 0
#define _KARPLUS_STRONG_STRING_DAMPING_CALC_MAGIC 1
#define _KARPLUS_STRONG_STRING_DAMPING 802
#define _KARPLUS_STRONG_STRING_DAMPING_VARIATION 803
#define _KARPLUS_STRONG_PLUCK_DAMPING 804
#define _KARPLUS_STRONG_PLUCK_DAMPING_VARIATION 805
#define _KARPLUS_STRONG_ON_DECAY 806
#define _KARPLUS_STRONG_OFF_DECAY 807
#define _KARPLUS_STRONG_EXCITATION_WAVEFORM_VARIATIONS 808
#define _KARPLUS_STRONG_ENABLE 809
#define _KARPLUS_STRONG_SEND_1 812
#define _KARPLUS_STRONG_SEND_2 813
#define _SYNTH_VOICE_1 0
#define _REVERB_ROOM_SIZE 900
#define _REVERB_ENABLE 901
#define _REVERB_DAMP 902
#define _REVERB_WET 903
#define _REVERB_DRY 904
#define _REVERB_WIDTH 905
#define _REVERB_MODE 906
#define _REVERB_PRESET 907
#define _REVERB3M_ENABLE 908
#define _REVERP_PRESET_CUSTOM 0
#define _PLAY_MODE 1000
#define _PLAY_MODE_POLY 0
#define _PLAY_MODE_SOLO 1
#define _PLAY_MODE_MIDI 2
#define _MODULATOR_PREV_DESTINATION -5
#define _NO_ACTION 0
#define _DESTINATION_IN_USE 1
#define _DISCONNECTED 2
#define _CONNECTED 3
#define _CONNECTION_ERROR -1
#define _ENABLE_DISTORTION 1100
#define _DISTORTION_AUTO_GAIN 1101
#define _DISTORTION_DRIVE 1102
#define _DISTORTION_RANGE 1103
#define _DISTORTION_BLEND 1104
#define _BAND_EQUALIZER_BAND_31_LEVEL 1200
#define _BAND_EQUALIZER_BAND_62_LEVEL 1201
#define _BAND_EQUALIZER_BAND_125_LEVEL 1202
#define _BAND_EQUALIZER_BAND_250_LEVEL 1203
#define _BAND_EQUALIZER_BAND_500_LEVEL 1204
#define _BAND_EQUALIZER_BAND_1K_LEVEL 1205
#define _BAND_EQUALIZER_BAND_2K_LEVEL 1206
#define _BAND_EQUALIZER_BAND_4K_LEVEL 1207
#define _BAND_EQUALIZER_BAND_8K_LEVEL 1208
#define _BAND_EQUALIZER_BAND_16K_LEVEL 1209
#define _BAND_EQUALIZER_PRESET 1220 // 0?
#define _BAND_EQUALIZER_SET_ALL_ZERO 1221 // 1?
#define _MSO_SEGMENT_A_POSITION 1250
#define _MSO_SEGMENT_B_POSITION 1251
#define _MSO_SEGMENT_C_POSITION 1252
#define _MSO_SEGMENT_D_POSITION 1253
#define _MSO_SEGMENT_E_POSITION 1254
#define _MSO_SEGMENT_F_POSITION 1255
#define _MSO_SYMETRY 1260
#define _MSO_CALC_BASE_LUT 1270
#define _MSO_CALC_MORPHED_LUT 1271
#define _MSO_DETUNE_OCTAVE 1280
#define _MSO_DETUNE_SEMITONES 1281
#define _MSO_DETUNE_CENTS 1282
#define _MSO_FILTER_SEND_1 1283
#define _MSO_FILTER_SEND_2 1284
#define _MSO_ENABLE 1285
#define _MSO_FREQ_MOD_LFO 1290
#define _MSO_FREQ_MOD_LFO_LEVEL 1291
#define _MSO_FREQ_MOD_ENV 1292
#define _MSO_FREQ_MOD_ENV_LEVEL 1293
#define _MSO_PWM_MOD_LFO 1294
#define _MSO_PWM_MOD_LFO_LEVEL 1295
#define _MSO_PWM_MOD_ENV 1296
#define _MSO_PWM_MOD_ENV_LEVEL 1297
#define _MSO_AMP_MOD_LFO 1298
#define _MSO_AMP_MOD_LFO_LEVEL 1299
#define _MSO_AMP_MOD_ENV 1300
#define _MSO_AMP_MOD_ENV_LEVEL 1301
#define _MIDI_MAPPING_MODE 1400
#define _MIDI_MAPPING_MODE_SKETCH 0
#define _MIDI_MAPPING_MODE_MAPPING 1
#define _DEFAULT_MIDI_MAPPING_MODE _MIDI_MAPPING_MODE_SKETCH
#define _PAD_DETUNE_OCTAVE 1500
#define _PAD_DETUNE_SEMITONES 1501
#define _PAD_DETUNE_CENTS 1502
#define _PAD_FILTER_SEND_1 1503
#define _PAD_FILTER_SEND_2 1504
#define _PAD_ENABLE 1505
#define _PAD_FREQ_MOD_LFO 1506
#define _PAD_FREQ_MOD_LFO_LEVEL 1507
#define _PAD_FREQ_MOD_ENV 1508
#define _PAD_FREQ_MOD_ENV_LEVEL 1509
#define _PAD_AMP_MOD_LFO 1510
#define _PAD_AMP_MOD_LFO_LEVEL 1511
#define _PAD_AMP_MOD_ENV 1512
#define _PAD_AMP_MOD_ENV_LEVEL 1513
#define _PAD_HARMONY_LEVEL_1 1520
#define _PAD_HARMONY_LEVEL_2 1521
#define _PAD_HARMONY_LEVEL_3 1522
#define _PAD_HARMONY_LEVEL_4 1523
#define _PAD_HARMONY_LEVEL_5 1524
#define _PAD_HARMONY_LEVEL_6 1525
#define _PAD_HARMONY_LEVEL_7 1526
#define _PAD_HARMONY_LEVEL_8 1527
#define _PAD_HARMONY_LEVEL_9 1528
#define _PAD_HARMONY_LEVEL_10 1529
#define _PAD_QUALITY 1530
#define _PAD_QUALITY_32K 0
#define _PAD_QUALITY_64K 1
#define _PAD_QUALITY_128K 2
#define _PAD_QUALITY_256K 3
#define _PAD_QUALITY_512K 4
#define _PAD_QUALITY_1024K 5
#define _PAD_SHAPE 1531
#define _PAD_SHAPE_RECTANGULAR 0
#define _PAD_SHAPE_GAUSSIAN 1
#define _PAD_SHAPE_DOUBLE_EXP 2
#define _PAD_BASE_NOTE 1532
#define _PAD_BASE_NOTE_C2 0
#define _PAD_BASE_NOTE_G2 1
#define _PAD_BASE_NOTE_C3 2
#define _PAD_BASE_NOTE_G3 3
#define _PAD_BASE_NOTE_C4 4
#define _PAD_BASE_NOTE_G4 5
#define _PAD_BASE_NOTE_C5 6
#define _PAD_BASE_NOTE_G5 7
#define _PAD_BASE_NOTE_C6 8
#define _PAD_BASE_NOTE_G6 9
#define _PAD_BASE_WIDTH 1533
#define _PAD_GENERATE 1534
#define _PAD_DETUNE 1535
#define _PAD_SHAPE_CUTOFF 1540
#define _PAD_SHAPE_CUTOFF_FULL 0
#define _PAD_SHAPE_CUTOFF_UPPER 1
#define _PAD_SHAPE_CUTOFF_LOWER 2
#define _SEQUENCER_START_RECORDING 1600
#define _SEQUENCER_STOP_RECORDING 1601
#define _RECORDING_START 1700
#define _RECORDING_STOP 1701
#define _RECORDING_CLEAR 1702
#define _MESSAGE_JACK_SERV_OUTPUT_NOT_RUNNING 1800
#define _MESSAGE_JACK_SERV_OUTPUT_RUNNING 1801
#define _MESSAGE_JACK_SERV_INPUT_NOT_RUNNING 1802
#define _MESSAGE_JACK_SERV_INPUT_RUNNING 1803
#define _MASTER_VOLUME 1900
#define _FLUID_SYNTH_VOLUME 2000
#define _FLUID_SYNTH_REVERB_ROOM_SIZE 2010
#define _FLUID_SYNTH_REVERB_DAMP 2011
#define _FLUID_SYNTH_REVERB_WIDTH 2012
#define _FLUID_SYNTH_REVERB_LEVEL 2013
#define _FLUID_SYNTH_REVERB_ENABLE 2014
#define _FLUID_SYNTH_CHORUS_NUMBER 2020
#define _FLUID_SYNTH_CHORUS_LEVEL 2021
#define _FLUID_SYNTH_CHORUS_SPEED 2022
#define _FLUID_SYNTH_CHORUS_DEPTH 2023
#define _FLUID_SYNTH_CHORUS_WAVEFORM 2024
#define _FLUID_SYNTH_CHORUS_ENABLE 2025
#define _FLUID_SYNTH_ENABLE 2026
#define _AUDIO_DRIVER 2110
#define _AUDIO_SAMPLE_RATE 2120
#define _AUDIO_BLOCK_SIZE 2130
#define _AUDIO_JACK_MODE 2200
#define _AUDIO_JACK_AUTO_START 2130
#define _AUDIO_JACK_AUTO_CONNECT 2140
typedef enum
{
_SF_REVERB_PRESET_DEFAULT,
_SF_REVERB_PRESET_SMALLHALL1,
_SF_REVERB_PRESET_SMALLHALL2,
_SF_REVERB_PRESET_MEDIUMHALL1,
_SF_REVERB_PRESET_MEDIUMHALL2,
_SF_REVERB_PRESET_LARGEHALL1,
_SF_REVERB_PRESET_LARGEHALL2,
_SF_REVERB_PRESET_SMALLROOM1,
_SF_REVERB_PRESET_SMALLROOM2,
_SF_REVERB_PRESET_MEDIUMROOM1,
_SF_REVERB_PRESET_MEDIUMROOM2,
_SF_REVERB_PRESET_LARGEROOM1,
_SF_REVERB_PRESET_LARGEROOM2,
_SF_REVERB_PRESET_MEDIUMER1,
_SF_REVERB_PRESET_MEDIUMER2,
_SF_REVERB_PRESET_PLATEHIGH,
_SF_REVERB_PRESET_PLATELOW,
_SF_REVERB_PRESET_LONGREVERB1,
_SF_REVERB_PRESET_LONGREVERB2
} sf_reverb_preset;
using namespace std;
/* used for holding soundfont presets */
typedef struct _soundfont_presets_data
{
int soundFontId;
char *presetname;
int banknum;
int program;
} _soundfont_presets_data_t;
// Callback functions pointers
/* void foo(void) function pointer */
typedef void(*func_ptr_void_void_t)(void);
/* void foo(int) function pointer */
typedef void(*func_ptr_void_int_t)(int);
/* void foo(int, int) function pointer */
typedef void(*func_ptr_void_int_int_t)(int, int);
/* void foo(int, bool) function pointer */
typedef void(*func_ptr_void_int_bool_t)(int, bool);
/* void foo(int, int, int) function pointer */
typedef void(*func_ptr_void_int_int_int_t)(int, int, int);
/* void foo(float, float, int) function pointer */
typedef void(*func_ptr_void_float_ptr_float_ptr_int_t)(float*, float*, int);
/* void foo(uint32_t) function pointer */
typedef void(*func_ptr_void_uint32_t)(uint32_t);
/* void foo(string) function pointer */
typedef void(*func_ptr_void_string_t)(std::string msg);
/* bool foo(int) function pointer */
typedef bool(*func_ptr_bool_int_t)(int);
/**
* @brief Initializes the synthesizer engine.
* Must be called first before any other call.
* @param none
* @return 0 if done
*/
int mod_synth_init();
/**
* @brief Starts the audio service.
* Must be called after intializtion.
* @param none
* @return 0 if done
*/
int mod_synth_start_audio();
/**
* @brief Stops the audio service.
* @param none
* @return 0 if done
*/
int mod_synth_stop_audio();
/**
* @brief Initializes the Bluetooth services.
* @param none
* @return 0 if done
*/
int mod_synth_init_bt_services();
/**
* @brief Deinitializes the Bluetooth services.
* terminate al BT related threads
* @param none
* @return 0 if done
*/
int mod_synth_deinit_bt_services();
/**
* @brief Initializes the Serial Port services.
* @param none
* @return 0 if done
*/
int mod_synth_init_serial_port_services(int portNum = 1, int baud = 115200, const char *mode = "8N1", int flowCtl = 0); // 0=FLOW_CONTROL_DISABLED
/**
* @brief Deinitializes the Serial Port services.
* @param none
* @return 0 if done
*/
int mod_synth_deinit_serial_port_services();
/**
* @brief Initializes the MIDI streaming service.
* @param none
* @return 0 if done
*/
int mod_synth_init_midi_services();
/**
* @brief Deinitializes the MIDI streaming service.
* @param none
* @return 0 if done
*/
int mod_synth_deinit_midi_services();
/**
* @brief `Enable bt MIDI input direct (non ALSA) streaming.
* @param none
* @return void
*/
void mod_synth_connect_bt_to_midi();
/**
* @brief `Disable bt MIDI input direct (non ALSA) streaming.
* @param none
* @return void
*/
void mod_synth_disconnect_bt_to_midi();
/**
* @brief Closing and cleanup when application goes down.
* Must be called whenever terminating the application.
* @param none
* @return void
*/
void mod_synth_on_exit();
/**
* @brief Returns the synthesizer maximum number of polyiphonic voices.
* @param none
* @return int maximum number of polyiphonic voices.
*/
int mod_synth_get_synthesizer_max_num_of_polyphonic_voices();
/**
* @brief Returns the synthesizer enabled number of polyiphonic voices.
* @param none
* @return int enabled number of polyiphonic voices.
*/
int mod_synth_get_synthesizer_num_of_polyphonic_voices();
/**
* @brief Returns the synthesizer maximum number of programs.
* @param none
* @return int maximum number of programs.
*/
int mod_synth_get_synthesizer_max_num_of_programs();
/**
* @brief Returns the synthesizer enabled number of programs.
* @param none
* @return int enabled number of programs.
*/
int mod_synth_get_synthesizer_num_of_programs();
/**
* @brief Returns the number of the CPU cores.
* @param none
* @return int number of the CPU cores (1, 2, 3, 4...).
*/
int mod_synth_get_number_of_cores();
/**
* @brief Returns the total (all cores) CPU utilization.
* @param none
* @return int the total (all cores) CPU utilization in precetages (0 to 100).
*/
int mod_synth_get_cpu_utilization();
/**
* @brief Returns the audio driver type.
* @param none
* @return int _AUDIO_ALSA or _AUDIO_JACK.
*/
int mod_synth_get_audio_driver();
/**
* @brief Setss the audio driver type.
* Settings will be effective only after the next call to start_audio().
* @param driver _AUDIO_ALSA or _AUDIO_JACK
* @return int _AUDIO_ALSA or _AUDIO_JACK.
*/
int mod_synth_set_audio_driver(int driver);
/**
* @brief Returns the JACK mode of operation auto (parameters are retrived
* from JACK server), or manual (application sets JACK servers parameters).
* @param none
* @return int _JACK_MODE_MANUAL or _JACK_MODE_AUTO.
*/
int mod_synth_get_jack_mode();
/**
* @brief Set the JACK mode of operation auto (parameters are retrived
* from JACK server), or manual (application sets JACK servers parameters).
* @param int _JACK_MODE_MANUAL or _JACK_MODE_AUTO
* @return void
*/
void mod_synth_set_jack_mode(int mode);
/**
* @brief Returns the audio sample-rate.
* @param none
* @return int _SAMPLE_RATE_44 (44100KHz) or _SAMPLE_RATE_48 (48KHz).
*/
int mod_synth_get_audio_sample_rate();
/**
* @brief Sets the audio sample-rate.
* Settings will be effective only after the next call to start_audio().
* @param int _SAMPLE_RATE_44 (44100KHz/default) or _SAMPLE_RATE_48 (48KHz).
* @return sample-rate.
*/
int mod_synth_set_audio_sample_rate(int rate);
/**
* @brief Returns the audio block-size.
* @param none
* @return int _AUDIO_BLOCK_SIZE_256, _AUDIO_BLOCK_SIZE_512, _AUDIO_BLOCK_SIZE_1024.
*/
int mod_synth_get_audio_block_size();
/**