-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathflsynth.h
128 lines (106 loc) · 3.15 KB
/
flsynth.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
#ifndef FLSYNTH_LIBRARY_H
#define FLSYNTH_LIBRARY_H
#include <stdbool.h>
// Howmany frames are processed in one cycle,
// if this is greater you will have more latency, but more stable sound
#define FRAME_PER_CYCLE 256
typedef struct {
unsigned int sample_rate;
unsigned char channels;
void* settings;
void* fluid_synth;
unsigned int last_sfid;
void *buff;
#ifndef __ANDROID__
unsigned int audio_device;
#else
void *audio_device;
#endif
void *synth_thread;
void *synth_sem;
void *cb_sem;
bool playing;
} synth_t;
/**
* Create synthesizer
* @return A struct contains the state of the synth object
*/
synth_t *flsynth_create(unsigned int sample_rate, unsigned char channels);
/**
* Free the synth object
* @param synth A synth object to be free
*/
void flsynth_free(synth_t *synth);
/**
* Load soundfont
* Soundfont can be sf2 and sf3 (ogg vorbis) format
* @param synth Synth object
* @param filename Path of soundfont file
* @param program_reset
* @return The soundfont ID
*/
int flsynth_sfload(synth_t *synth, const char *filename, bool program_reset);
/**
* Start synthesizer
* Start the audio engine, the synthesis in the background, and send the result of the synth to the audio output.
* @param synth Synth object
* @return
*/
bool flsynth_start(synth_t *synth);
/**
* Stop the synthesis thread and audio engine.
* @param synth Synth object
*/
bool flsynth_stop(synth_t *synth);
/**
* Select program for channel
* @param synth Synth object
* @param chan Channel where we want to change program
* @param bank The sounont bank where the pereset is
* @param preset The instrument preset
* @return
*/
bool flsynth_program_select(synth_t *synth, int chan, unsigned int bank, unsigned int preset);
/**
* The same as flsynth_program_select, but you can specify soundfont id as well, if you loaded multiple fonts
* @param synth Synth object
* @param chan Channel where we want to change program
* @param sfid The soundfont id which is returned by sfload call
* @param bank The sounont bank where the pereset is
* @param preset The instrument preset
* @return
*/
bool flsynth_program_select_sfid(synth_t *synth, int chan, unsigned int sfid, unsigned int bank, unsigned int preset);
/**
* Play a note on the specified channel
* @param synth Synth object
* @param chan Channel where the note should be played
* @param key The key of the note (60 is the middle C)
* @param velocity Velociy value of the note (0-127)
* @return
*/
bool flsynth_noteon(synth_t *synth, int chan, int key, int velocity);
/**
* Stop a previously playing note on a channel
* @param synth Synth object
* @param chan Channel where the not is playing
* @param key Key of the note
* @return
*/
bool flsynth_noteoff(synth_t *synth, int chan, int key);
/**
* Big red panic button
* @param synth Synth object
* @return
*/
bool flsynth_system_reset(synth_t *synth);
/**
* Send a MIDI controller event on a MIDI channel.
* @param synth Synth object
* @param chan Channel number
* @param ctrl MIDI controller number
* @param val MIDI controller value
* @return
*/
bool flsynth_cc(synth_t *synth, int chan, int ctrl, int val);
#endif