blob: 16c2135467b86d636641a1fdbb0b7e11ccc49cc1 (
plain) (
blame)
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
|
#ifndef SYNTH_ENGINE_H
#define SYNTH_ENGINE_H
#include <math.h>
#include <portaudio.h>
#include "synth_common.h"
#include "filter.h"
#include "adsr.h"
#include "control.h"
#include "pa_ringbuffer.h"
#ifndef M_PI
#define M_PI (3.14159265)
#endif
#define RING_SIZE 65536
typedef struct lfo_t {
float freq;
float amp;
unsigned long long elapsed;
} lfo_t;
typedef struct midi_note_t {
float freq;
int channel;
PaTime noteOn;
PaTime noteOff;
float velocity; // normalized
float wvt_index;
float lfo_index;
unsigned long long elapsed;
unsigned long long noteOffSample;
adsr_t * adsr;
int active;
} midi_note_t;
typedef struct {
int spectrum_enabled;
int wave_enabled;
int adsr_enabled;
int adsr_graph_enabled;
int osc_enabled;
int freeze;
int rate_divider;
float *wave_buffer_data;
PaUtilRingBuffer wave_buffer;
float *fft_buffer_data;
PaUtilRingBuffer fft_buffer;
float *tmp_buffer;
float *wave_viz_buffer;
float *fft_input_buffer;
float *fft_output_buffer;
float *fft_smooth_buffer;
int tmp_index;
} synth_viz;
struct midi_t;
typedef struct {
PaStream *stream;
int wvt_pos;
cc_t * ccs[128];
int cci;
cc_t cc_pitch;
cc_t cc_cutoff;
cc_t cc_resonance;
cc_t cc_lfo_freq;
cc_t cc_lfo_amp;
cc_t cc_adsr_a;
cc_t cc_adsr_peak;
cc_t cc_adsr_d;
cc_t cc_adsr_s;
cc_t cc_adsr_r;
cc_t cc_gain;
cc_t cc_f_adsr_a;
cc_t cc_f_adsr_peak;
cc_t cc_f_adsr_d;
cc_t cc_f_adsr_s;
cc_t cc_f_adsr_r;
int autogain;
float x;
midi_note_t midi_note[MIDI_NOTES];
midi_note_t * midi_active[MIDI_NOTES];
int midi_active_n;
adsr_t adsr;
adsr_t f_adsr;
lfo_t lfo;
int octave;
int delay;
float * del;
int deli;
cc_t cc_del_time;
cc_t cc_del_feedback;
unsigned long long counter;
int f_adsr_enabled;
int filter;
int biquad;
char biquad_type;
int clamp;
int modifiers[16];
int modi;
float (*gen[7]) (float freq, midi_note_t * midi_note, float x, unsigned int sample_rate);
int geni;
BWLowPass* fff;
BWBandStop* fff2;
int active;
int sound_active;
int soundcard_id;
int midi_device_id;
synth_viz viz;
struct midi_t * midi;
} synth_t;
synth_t * init_synth();
void free_synth(synth_t *synth);
void change_soundcard(synth_t *synth);
void change_midi_device(synth_t *synth);
int save_synth(synth_t *synth, const char *path);
int load_synth(synth_t *synth, const char *path);
#endif /* SYNTH_ENGINE_H */
|