-
-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathsfizz.h
1252 lines (1155 loc) · 40.3 KB
/
sfizz.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
// SPDX-License-Identifier: BSD-2-Clause
// This code is part of the sfizz library and is licensed under a BSD 2-clause
// license. You should have receive a LICENSE.md file along with the code.
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
/**
* @file
* @brief sfizz public C API.
*
* sfizz is a synthesizer for SFZ instruments.
*
* The synthesizer must be operated under indicated constraints in order to
* guarantee thread-safety.
*
* At any given time, no more than 2 tasks must interact in parallel with this
* library:
* - a processing tasks @b RT for audio and MIDI, which can be real-time
* - a Control tasks @b CT
*
* The tasks RT and CT can be assumed by different threads over the lifetime, as
* long as the switch is adequately synchronized. If real-time processing is not
* required, it's acceptable for the 2 tasks can be assumed by a single thread.
*
* Where one or more following items are indicated on a function, the constraints apply.
* - @b RT: the function must be invoked from the Real-time thread
* - @b CT: the function must be invoked from the Control thread
* - @b OFF: the function cannot be invoked while a thread is calling @b RT functions
*/
#pragma once
#include "sfizz_message.h"
#include <stddef.h>
#include <stdbool.h>
#if defined SFIZZ_EXPORT_SYMBOLS
#if defined _WIN32
#define SFIZZ_EXPORTED_API __declspec(dllexport)
#else
#define SFIZZ_EXPORTED_API __attribute__ ((visibility ("default")))
#endif
#else
#define SFIZZ_EXPORTED_API
#endif
//! @cond Doxygen_Suppress
#if defined _WIN32
#define SFIZZ_DEPRECATED_API __declspec(deprecated)
#else
#define SFIZZ_DEPRECATED_API __attribute__ ((deprecated))
#endif
//! @endcond
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Synth handle.
* @since 0.2.0
*/
typedef struct sfizz_synth_t sfizz_synth_t;
/**
* @brief Oversampling factor
* @since 0.2.0
*/
typedef enum {
SFIZZ_OVERSAMPLING_X1 = 1,
SFIZZ_OVERSAMPLING_X2 = 2,
SFIZZ_OVERSAMPLING_X4 = 4,
SFIZZ_OVERSAMPLING_X8 = 8
} sfizz_oversampling_factor_t;
/**
* @brief Processing mode
* @since 0.5.0
*/
typedef enum {
SFIZZ_PROCESS_LIVE,
SFIZZ_PROCESS_FREEWHEELING,
} sfizz_process_mode_t;
/**
* @brief Creates a sfizz synth.
*
* This object has to be freed by the caller using sfizz_free().
* The synth by default is set at 48 kHz and a maximum block size of 1024.
* You should change these values if they are not correct for your application.
* @since 0.2.0
*/
SFIZZ_EXPORTED_API sfizz_synth_t* sfizz_create_synth();
/**
* @brief Frees an existing sfizz synth.
* @since 0.2.0
*
* @param synth The synth to destroy.
*/
SFIZZ_EXPORTED_API void sfizz_free(sfizz_synth_t* synth);
/**
* @brief Adds a reference to an existing sfizz synth.
* @since 1.0.0
*
* @param synth The synth to reference.
*/
SFIZZ_EXPORTED_API void sfizz_add_ref(sfizz_synth_t* synth);
/**
* @brief Loads an SFZ file.
*
* The file path can be absolute or relative. All file operations for this SFZ
* file will be relative to the parent directory of the SFZ file.
* @since 0.2.0
*
* @param synth The synth.
* @param path A null-terminated string representing a path to an SFZ file.
*
* @return @true when file loading went OK,
* @false if some error occured while loading.
*
* @par Thread-safety constraints
* - @b CT: the function must be invoked from the Control thread
* - @b OFF: the function cannot be invoked while a thread is calling @b RT functions
*/
SFIZZ_EXPORTED_API bool sfizz_load_file(sfizz_synth_t* synth, const char* path);
/**
* @brief Loads an SFZ file from textual data.
*
* This accepts a virtual path name for the imaginary sfz file, which is not
* required to exist on disk. The purpose of the virtual path is to locate
* samples with relative paths.
* @since 0.4.0
*
* @param synth The synth.
* @param path The virtual path of the SFZ file.
* @param text The contents of the virtual SFZ file.
*
* @return @true when file loading went OK,
* @false if some error occured while loading.
*
* @par Thread-safety constraints
* - @b CT: the function must be invoked from the Control thread
* - @b OFF: the function cannot be invoked while a thread is calling @b RT functions
*/
SFIZZ_EXPORTED_API bool sfizz_load_string(sfizz_synth_t* synth, const char* path, const char* text);
/**
* @brief Sets the tuning from a Scala file loaded from the file system.
* @since 0.4.0
*
* @param synth The synth.
* @param path The path to the file in Scala format.
*
* @return @true when tuning scale loaded OK,
* @false if some error occurred.
*
* @par Thread-safety constraints
* - @b CT: the function must be invoked from the Control thread
* - @b OFF: the function cannot be invoked while a thread is calling @b RT functions
*/
SFIZZ_EXPORTED_API bool sfizz_load_scala_file(sfizz_synth_t* synth, const char* path);
/**
* @brief Sets the tuning from a Scala file loaded from memory.
* @since 0.4.0
*
* @param synth The synth.
* @param text The contents of the file in Scala format.
*
* @return @true when tuning scale loaded OK,
* @false if some error occurred.
*
* @par Thread-safety constraints
* - @b CT: the function must be invoked from the Control thread
* - @b OFF: the function cannot be invoked while a thread is calling @b RT functions
*/
SFIZZ_EXPORTED_API bool sfizz_load_scala_string(sfizz_synth_t* synth, const char* text);
/**
* @brief Sets the scala root key.
* @since 0.4.0
*
* @param synth The synth.
* @param root_key The MIDI number of the Scala root key (default 60 for C4).
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_set_scala_root_key(sfizz_synth_t* synth, int root_key);
/**
* @brief Gets the scala root key.
* @since 0.4.0
*
* @param synth The synth.
*
* @return The MIDI number of the Scala root key (default 60 for C4).
*/
SFIZZ_EXPORTED_API int sfizz_get_scala_root_key(sfizz_synth_t* synth);
/**
* @brief Sets the reference tuning frequency.
* @since 0.4.0
*
* @param synth The synth.
* @param frequency The frequency which indicates where standard tuning A4 is (default 440 Hz).
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_set_tuning_frequency(sfizz_synth_t* synth, float frequency);
/**
* @brief Gets the reference tuning frequency.
* @since 0.4.0
*
* @param synth The synth.
*
* @return The frequency which indicates where standard tuning A4 is (default 440 Hz).
*/
SFIZZ_EXPORTED_API float sfizz_get_tuning_frequency(sfizz_synth_t* synth);
/**
* @brief Configure stretch tuning using a predefined parametric Railsback curve.
*
* A ratio 1/2 is supposed to match the average piano; 0 disables (the default).
* @since 0.4.0
*
* @param synth The synth.
* @param ratio The parameter in domain 0-1.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_load_stretch_tuning_by_ratio(sfizz_synth_t* synth, float ratio);
/**
* @brief Return the number of regions in the currently loaded SFZ file.
* @since 0.2.0
*
* @param synth The synth.
*/
SFIZZ_EXPORTED_API int sfizz_get_num_regions(sfizz_synth_t* synth);
/**
* @brief Return the number of groups in the currently loaded SFZ file.
* @since 0.2.0
*
* @param synth The synth.
*/
SFIZZ_EXPORTED_API int sfizz_get_num_groups(sfizz_synth_t* synth);
/**
* @brief Return the number of masters in the currently loaded SFZ file.
* @since 0.2.0
*
* @param synth The synth.
*/
SFIZZ_EXPORTED_API int sfizz_get_num_masters(sfizz_synth_t* synth);
/**
* @brief Return the number of curves in the currently loaded SFZ file.
* @since 0.2.0
*
* @param synth The synth.
*/
SFIZZ_EXPORTED_API int sfizz_get_num_curves(sfizz_synth_t* synth);
/**
* @brief Export a MIDI Name document describing the currently loaded SFZ file.
* @since 0.3.1
*
* @param synth The synth.
* @param model The model name used if a non-empty string, otherwise generated.
*
* @return A newly allocated XML string, which must be freed after use using sfizz_free_memory().
*/
SFIZZ_EXPORTED_API char* sfizz_export_midnam(sfizz_synth_t* synth, const char* model);
/**
* @brief Return the number of preloaded samples for the current SFZ file.
* @since 0.2.0
*
* @param synth The synth.
*/
SFIZZ_EXPORTED_API size_t sfizz_get_num_preloaded_samples(sfizz_synth_t* synth);
/**
* @brief Return the number of active voices.
*
* Note that this function is a basic indicator and does not aim to be perfect.
* In particular, it runs on the calling thread so voices may well start or stop
* while the function is checking which voice is active.
* @since 0.2.0
*
* @param synth The synth.
*/
SFIZZ_EXPORTED_API int sfizz_get_num_active_voices(sfizz_synth_t* synth);
/**
* @brief Set the expected number of samples per block.
*
* If unsure, give an upper bound since right now ugly things may happen if you
* go over this number.
* @since 0.2.0
*
* @param synth The synth.
* @param samples_per_block The number of samples per block.
*
* @par Thread-safety constraints
* - @b CT: the function must be invoked from the Control thread
* - @b OFF: the function cannot be invoked while a thread is calling @b RT functions
*/
SFIZZ_EXPORTED_API void sfizz_set_samples_per_block(sfizz_synth_t* synth, int samples_per_block);
/**
* @brief Set the sample rate for the synth.
*
* This is the output sample rate. This setting does not affect the internal processing.
* @since 0.2.0
*
* @param synth The synth
* @param sample_rate The sample rate.
*
* @par Thread-safety constraints
* - @b CT: the function must be invoked from the Control thread
* - @b OFF: the function cannot be invoked while a thread is calling @b RT functions
*/
SFIZZ_EXPORTED_API void sfizz_set_sample_rate(sfizz_synth_t* synth, float sample_rate);
/**
* @brief Send a note on event to the synth.
* @since 0.2.0
*
* This command should be delay-ordered with all other midi-type events
* (notes, CCs, aftertouch and pitch-wheel), otherwise the behavior of the
* synth is undefined.
*
* @param synth The synth.
* @param delay The delay of the event in the block, in samples.
* @param note_number The MIDI note number, in domain 0 to 127.
* @param velocity The MIDI velocity, in domain 0 to 127.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_send_note_on(sfizz_synth_t* synth, int delay, int note_number, int velocity);
/**
* @brief Send a high-precision on event to the synth.
* @since 1.0.0
*
* This command should be delay-ordered with all other midi-type events
* (notes, CCs, aftertouch and pitch-wheel), otherwise the behavior of the
* synth is undefined.
*
* @param synth The synth.
* @param delay The delay of the event in the block, in samples.
* @param note_number The MIDI note number, in domain 0 to 127.
* @param velocity The normalized MIDI velocity, in domain 0 to 1.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_send_hd_note_on(sfizz_synth_t* synth, int delay, int note_number, float velocity);
/**
* @brief Send a note off event to the synth.
* @since 0.2.0
*
* This command should be delay-ordered with all other midi-type events
* (notes, CCs, aftertouch and pitch-wheel), otherwise the behavior of the
* synth is undefined.
*
* As per the SFZ spec the velocity of note-off events is usually replaced by
* the note-on velocity.
*
* @param synth The synth.
* @param delay The delay of the event in the block, in samples.
* @param note_number The MIDI note number, in domain 0 to 127.
* @param velocity The MIDI velocity, in domain 0 to 127.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_send_note_off(sfizz_synth_t* synth, int delay, int note_number, int velocity);
/**
* @brief Send a high-precision note off event to the synth.
* @since 1.0.0
*
* This command should be delay-ordered with all other midi-type events
* (notes, CCs, aftertouch and pitch-wheel), otherwise the behavior of the
* synth is undefined.
*
* As per the SFZ spec the velocity of note-off events is usually replaced by
* the note-on velocity.
*
* @param synth The synth.
* @param delay The delay of the event in the block, in samples.
* @param note_number The MIDI note number, in domain 0 to 127.
* @param velocity The normalized MIDI velocity, in domain 0 to 1.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_send_hd_note_off(sfizz_synth_t* synth, int delay, int note_number, float velocity);
/**
* @brief Send a CC event to the synth.
* @since 0.2.0
*
* This command should be delay-ordered with all other midi-type events
* (notes, CCs, aftertouch and pitch-wheel), otherwise the behavior of the
* synth is undefined.
*
* @param synth The synth.
* @param delay The delay of the event in the block, in samples.
* @param cc_number The MIDI CC number, in domain 0 to 127.
* @param cc_value The MIDI CC value, in domain 0 to 127.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_send_cc(sfizz_synth_t* synth, int delay, int cc_number, int cc_value);
/**
* @brief Send a high precision CC event to the synth.
* @since 0.4.0
*
* This command should be delay-ordered with all other midi-type events
* (notes, CCs, aftertouch and pitch-wheel), otherwise the behavior of the
* synth is undefined.
*
* @param synth The synth.
* @param delay The delay of the event in the block, in samples.
* @param cc_number The MIDI CC number, in domain 0 to 127.
* @param norm_value The normalized CC value, in domain 0 to 1.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_send_hdcc(sfizz_synth_t* synth, int delay, int cc_number, float norm_value);
/**
* @brief Send a program change event to the synth.
* @since 1.2.0
*
* This command should be delay-ordered with all other midi-type events
* (notes, CCs, aftertouch and pitch-wheel), otherwise the behavior of the
* synth is undefined.
*
* @param synth The synth.
* @param delay The delay of the event in the block, in samples.
* @param program The program number, in domain 0 to 127.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_send_program_change(sfizz_synth_t* synth, int delay, int program);
/**
* @brief Send a high precision CC automation to the synth.
* @since 1.0.0
*
* This updates the CC value known to the synth, but without performing
* additional MIDI-specific interpretations. (eg. the CC 120 and up)
*
* This command should be delay-ordered with all other midi-type events
* (notes, CCs, aftertouch and pitch-wheel), otherwise the behavior of the
* synth is undefined.
*
* @param synth The synth.
* @param delay The delay of the event in the block, in samples.
* @param cc_number The MIDI CC number, in domain 0 to 127.
* @param norm_value The normalized CC value, in domain 0 to 1.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_automate_hdcc(sfizz_synth_t* synth, int delay, int cc_number, float norm_value);
/**
* @brief Send a pitch wheel event.
* @since 0.2.0
*
* This command should be delay-ordered with all other midi-type events
* (notes, CCs, aftertouch and pitch-wheel), otherwise the behavior of the
* synth is undefined.
*
* @param synth The synth.
* @param delay The delay.
* @param pitch The pitch.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_send_pitch_wheel(sfizz_synth_t* synth, int delay, int pitch);
/**
* @brief Send a high-precision pitch wheel event.
* @since 1.0.0
*
* This command should be delay-ordered with all other midi-type events
* (notes, CCs, aftertouch and pitch-wheel), otherwise the behavior of the
* synth is undefined.
*
* @param synth The synth.
* @param delay The delay.
* @param pitch The normalized pitch, in domain -1 to 1.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_send_hd_pitch_wheel(sfizz_synth_t* synth, int delay, float pitch);
/**
* @brief Send an aftertouch event.
* @since 0.2.0
*
* This command should be delay-ordered with all other midi-type events
* (notes, CCs, aftertouch and pitch-wheel), otherwise the behavior of the
* synth is undefined.
*
* @param synth The synth.
* @param delay The delay at which the event occurs; this should be lower
* than the size of the block in the next call to sfizz_render_block().
* @param aftertouch The aftertouch value, in domain 0 to 127.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API SFIZZ_DEPRECATED_API void sfizz_send_aftertouch(sfizz_synth_t* synth, int delay, int aftertouch);
/**
* @brief Send a channel aftertouch (channel pressure) event.
* @since 1.0.0
*
* This command should be delay-ordered with all other midi-type events
* (notes, CCs, aftertouch and pitch-wheel), otherwise the behavior of the
* synth is undefined.
*
* @param synth The synth.
* @param delay The delay at which the event occurs; this should be lower
* than the size of the block in the next call to sfizz_render_block().
* @param aftertouch The aftertouch value, in domain 0 to 127.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_send_channel_aftertouch(sfizz_synth_t* synth, int delay, int aftertouch);
/**
* @brief Send a high-precision aftertouch event.
* @since 1.0.0
*
* This command should be delay-ordered with all other midi-type events
* (notes, CCs, aftertouch and pitch-wheel), otherwise the behavior of the
* synth is undefined.
*
* @param synth The synth.
* @param delay The delay at which the event occurs; this should be lower
* than the size of the block in the next call to sfizz_render_block().
* @param aftertouch The normalized aftertouch value, in domain 0 to 1.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_send_hd_channel_aftertouch(sfizz_synth_t* synth, int delay, float aftertouch);
/**
* @brief Send a polyphonic aftertouch event.
* This feature is experimental and needs more testing in the internal engine.
* @since 1.0.0
*
* This command should be delay-ordered with all other midi-type events
* (notes, CCs, aftertouch and pitch-wheel), otherwise the behavior of the
* synth is undefined.
*
* @param synth The synth.
* @param delay The delay at which the event occurs; this should be lower
* than the size of the block in the next call to sfizz_render_block().
* @param note_number The note number, in domain 0 to 127.
* @param aftertouch The aftertouch value, in domain 0 to 127.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_send_poly_aftertouch(sfizz_synth_t* synth, int delay, int note_number, int aftertouch);
/**
* @brief Send a high-precision polyphonic aftertouch event.
* This feature is experimental and needs more testing in the internal engine.
* @since 1.0.0
*
* This command should be delay-ordered with all other midi-type events
* (notes, CCs, aftertouch and pitch-wheel), otherwise the behavior of the
* synth is undefined.
*
* @param synth The synth.
* @param delay The delay at which the event occurs; this should be lower
* than the size of the block in the next call to sfizz_render_block().
* @param note_number The note number, in domain 0 to 127.
* @param aftertouch The normalized aftertouch value, in domain 0 to 1.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_send_hd_poly_aftertouch(sfizz_synth_t* synth, int delay, int note_number, float aftertouch);
/**
* @brief Send a tempo event.
*
* This command should be delay-ordered with all other time/signature commands, namely
* sfizz_send_tempo(), sfizz_send_time_signature(), sfizz_send_time_position(),
* and sfizz_send_playback_state(), otherwise the behavior of the synth is undefined.
*
* @since 0.2.0
*
* @param synth The synth.
* @param delay The delay.
* @param seconds_per_beat The seconds per beat.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API SFIZZ_DEPRECATED_API void sfizz_send_tempo(sfizz_synth_t* synth, int delay, float seconds_per_beat);
/**
* @brief Send a tempo event.
*
* This command should be delay-ordered with all other time/signature commands, namely
* sfizz_send_tempo(), sfizz_send_time_signature(), sfizz_send_time_position(),
* and sfizz_send_playback_state(), otherwise the behavior of the synth is undefined.
*
* @since 1.0.0
*
* @param synth The synth.
* @param delay The delay.
* @param beats_per_minute The new tempo, in beats per minute.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_send_bpm_tempo(sfizz_synth_t* synth, int delay, float beats_per_minute);
/**
* @brief Send the time signature.
*
* This command should be delay-ordered with all other time/signature commands, namely
* sfizz_send_tempo(), sfizz_send_time_signature(), sfizz_send_time_position(),
* and sfizz_send_playback_state(), otherwise the behavior of the synth is undefined.
*
* @since 0.5.0
*
* @param synth The synth.
* @param delay The delay.
* @param beats_per_bar The number of beats per bar, or time signature numerator.
* @param beat_unit The note corresponding to one beat, or time signature denominator.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_send_time_signature(sfizz_synth_t* synth, int delay, int beats_per_bar, int beat_unit);
/**
* @brief Send the time position.
*
* This command should be delay-ordered with all other time/signature commands, namely
* sfizz_send_tempo(), sfizz_send_time_signature(), sfizz_send_time_position(),
* and sfizz_send_playback_state(), otherwise the behavior of the synth is undefined.
*
* @since 0.5.0
*
* @param synth The synth.
* @param delay The delay.
* @param bar The current bar.
* @param bar_beat The fractional position of the current beat within the bar.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_send_time_position(sfizz_synth_t* synth, int delay, int bar, double bar_beat);
/**
* @brief Send the playback state.
*
* This command should be delay-ordered with all other time/signature commands, namely
* sfizz_send_tempo(), sfizz_send_time_signature(), sfizz_send_time_position(),
* and sfizz_send_playback_state(), otherwise the behavior of the synth is undefined.
*
* @since 0.5.0
*
* @param synth The synth.
* @param delay The delay.
* @param playback_state The playback state, 1 if playing, 0 if stopped.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_send_playback_state(sfizz_synth_t* synth, int delay, int playback_state);
/**
* @brief Render a block audio data into a stereo channel.
*
* No other channel configuration is supported. The synth will gracefully ignore
* your request if you provide a value. You should pass all the relevant events
* for the block (midi notes, CCs, ...) before rendering each block.
* The synth will memorize the inputs and render sample accurates envelopes
* depending on the input events passed to it.
*
* @since 0.2.0
*
* @param synth The synth.
* @param channels Pointers to the left and right channel of the output.
* @param num_channels Number of output channels; should be a multiple of 2 as
* sfizz only handles stereo outputs.
* @param num_frames Number of frames to fill. This should be less than
* or equal to the expected samples_per_block.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_render_block(sfizz_synth_t* synth, float** channels, int num_channels, int num_frames);
/**
* @brief Get the size of the preloaded data.
*
* This returns the number of floats used in the preloading buffers.
* @since 0.2.0
*
* @param synth The synth.
*/
SFIZZ_EXPORTED_API unsigned int sfizz_get_preload_size(sfizz_synth_t* synth);
/**
* @brief Set the size of the preloaded data in number of floats (not bytes).
*
* This will disable the callbacks for the duration of the load.
* This function takes a lock ; prefer calling it out of the RT thread.
* It can also take a long time to return. If the new preload size is the same
* as the current one, it will release the lock immediately and exit.
* @since 0.2.0
*
* @param synth The synth.
* @param[in] preload_size The preload size.
*
* @par Thread-safety constraints
* - @b CT: the function must be invoked from the Control thread
* - @b OFF: the function cannot be invoked while a thread is calling @b RT functions
*/
SFIZZ_EXPORTED_API void sfizz_set_preload_size(sfizz_synth_t* synth, unsigned int preload_size);
/**
* @brief Get the internal oversampling rate.
*
* As of 1.0, This is an inactive stub for future work on oversampling in the engine.
*
* @since 0.2.0
*
* @param synth The synth.
*/
SFIZZ_EXPORTED_API sfizz_oversampling_factor_t sfizz_get_oversampling_factor(sfizz_synth_t* synth);
/**
* @brief Set the internal oversampling rate.
*
* As of 1.0, This is an inactive stub for future work on oversampling in the engine.
* @since 0.2.0
*
* @param synth The synth.
* @param[in] oversampling The oversampling factor.
*
* @return @true if the oversampling factor was correct, @false otherwise.
*
* @par Thread-safety constraints
* - @b CT: the function must be invoked from the Control thread
* - @b OFF: the function cannot be invoked while a thread is calling @b RT functions
*/
SFIZZ_EXPORTED_API bool sfizz_set_oversampling_factor(sfizz_synth_t* synth, sfizz_oversampling_factor_t oversampling);
/**
* @brief Get the default resampling quality.
*
* This is the quality setting which the engine uses when the instrument
* does not use the opcode `sample_quality`. The engine uses distinct
* default quality settings for live mode and freewheeling mode,
* which both can be accessed by the means of this function.
* @since 0.4.0
*
* @param synth The synth.
* @param[in] mode The processing mode.
*
* @return The sample quality for the given mode, in the range 0 to 10.
*/
SFIZZ_EXPORTED_API int sfizz_get_sample_quality(sfizz_synth_t* synth, sfizz_process_mode_t mode);
/**
* @brief Set the default resampling quality.
*
* This is the quality setting which the engine uses when the instrument
* does not use the opcode `sample_quality`. The engine uses distinct
* default quality settings for live mode and freewheeling mode,
* which both can be accessed by the means of this function.
* @since 0.4.0
*
* @param synth The synth.
* @param[in] mode The processing mode.
* @param[in] quality The desired sample quality, in the range 0 to 10.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_set_sample_quality(sfizz_synth_t* synth, sfizz_process_mode_t mode, int quality);
/**
* @brief Get the default oscillator quality.
*
* This is the quality setting which the engine uses when the instrument
* does not use the opcode `oscillator_quality`. The engine uses distinct
* default quality settings for live mode and freewheeling mode,
* which both can be accessed by the means of this function.
* @since 1.0.0
*
* @param synth The synth.
* @param[in] mode The processing mode.
*
* @return The oscillator quality for the given mode, in the range 0 to 10.
*/
SFIZZ_EXPORTED_API int sfizz_get_oscillator_quality(sfizz_synth_t* synth, sfizz_process_mode_t mode);
/**
* @brief Set the default oscillator quality.
*
* This is the quality setting which the engine uses when the instrument
* does not use the opcode `oscillator_quality`. The engine uses distinct
* default quality settings for live mode and freewheeling mode,
* which both can be accessed by the means of this function.
* @since 1.0.0
*
* @param synth The synth.
* @param[in] mode The processing mode.
* @param[in] quality The desired oscillator quality, in the range 0 to 10.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_set_oscillator_quality(sfizz_synth_t* synth, sfizz_process_mode_t mode, int quality);
/**
* @brief Set whether pressing the sustain pedal cancels the release stage
* @since 1.2.0
*
* @param synth The synth.
* @param value
*/
SFIZZ_EXPORTED_API void sfizz_set_sustain_cancels_release(sfizz_synth_t* synth, bool value);
/**
* @brief Set the global instrument volume.
* @since 0.2.0
*
* @param synth The synth.
* @param volume The new volume.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_set_volume(sfizz_synth_t* synth, float volume);
/**
* @brief Return the global instrument volume.
* @since 0.2.0
*
* @param synth The synth.
*/
SFIZZ_EXPORTED_API float sfizz_get_volume(sfizz_synth_t* synth);
/**
* @brief Set the number of voices used by the synth.
*
* @since 0.2.0
*
* @param synth The synth.
* @param num_voices The number of voices.
*
* @par Thread-safety constraints
* - @b CT: the function must be invoked from the Control thread
* - @b OFF: the function cannot be invoked while a thread is calling @b RT functions
*/
SFIZZ_EXPORTED_API void sfizz_set_num_voices(sfizz_synth_t* synth, int num_voices);
/**
* @brief Return the number of voices.
* @since 0.2.0
*
* @param synth The synth.
*/
SFIZZ_EXPORTED_API int sfizz_get_num_voices(sfizz_synth_t* synth);
/**
* @brief Return the number of allocated buffers from the synth.
* @since 0.2.0
*
* @param synth The synth.
*/
SFIZZ_EXPORTED_API int sfizz_get_num_buffers(sfizz_synth_t* synth);
/**
* @brief Get the number of bytes allocated from the synth.
*
* Note that this value can be less than the actual memory usage since it only
* counts the buffer objects managed by sfizz.
* @since 0.2.0
*
* @param synth The synth.
*/
SFIZZ_EXPORTED_API int sfizz_get_num_bytes(sfizz_synth_t* synth);
/**
* @brief Enable freewheeling on the synth.
* @since 0.2.0
*
* @param synth The synth.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_enable_freewheeling(sfizz_synth_t* synth);
/**
* @brief Disable freewheeling on the synth.
* @since 0.2.0
*
* @param synth The synth.
*
* @par Thread-safety constraints
* - @b RT: the function must be invoked from the Real-time thread
*/
SFIZZ_EXPORTED_API void sfizz_disable_freewheeling(sfizz_synth_t* synth);
/**
* @brief Return a comma separated list of unknown opcodes.
*
* The caller has to free() the string returned. This function allocates memory,
* do not call on the audio thread.
* @since 0.2.0
*
* @param synth The synth.
*/
SFIZZ_EXPORTED_API char* sfizz_get_unknown_opcodes(sfizz_synth_t* synth);
/**
* @brief Check if the SFZ should be reloaded.
*
* Depending on the platform this can create file descriptors.
* @since 0.2.0
*
* @param synth The synth.
*
* @return @true if any included files (including the root file)
* have been modified since the sfz file was loaded, @false otherwise.
*
* @par Thread-safety constraints
* - @b CT: the function must be invoked from the Control thread
*/
SFIZZ_EXPORTED_API bool sfizz_should_reload_file(sfizz_synth_t* synth);
/**
* @brief Check if the scala file should be reloaded.
*
* Depending on the platform this can create file descriptors.
* @since 0.4.0
*
* @param synth The synth.
*
* @return @true if the scala file has been modified since loading.
*
* @par Thread-safety constraints
* - @b CT: the function must be invoked from the Control thread
*/
SFIZZ_EXPORTED_API bool sfizz_should_reload_scala(sfizz_synth_t* synth);
/**
* @brief Enable logging of timings to sidecar CSV files.
* @since 0.3.0
*
* @note This can produce many outputs so use with caution.
* Deprecated since 1.2.0.
*
* @param synth The synth.
* @param prefix The prefix.
*
* @par Thread-safety constraints
* - TBD ?
*/
SFIZZ_EXPORTED_API SFIZZ_DEPRECATED_API void sfizz_enable_logging(sfizz_synth_t* synth, const char* prefix);