summaryrefslogtreecommitdiffstats
path: root/src/synth_engine.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2023-04-20 18:24:49 +0300
committergramanas <anastasis.gramm2@gmail.com>2023-04-20 18:24:49 +0300
commitc161e1016a04566a56b4858ea43502fed88dcc7f (patch)
treeb4b3086f000df6b63229dae6057f1aa253811b30 /src/synth_engine.c
parent1e374b426b4182c7b73b35219aadaca267b9623c (diff)
downloadsynth-project-c161e1016a04566a56b4858ea43502fed88dcc7f.tar.gz
synth-project-c161e1016a04566a56b4858ea43502fed88dcc7f.tar.bz2
synth-project-c161e1016a04566a56b4858ea43502fed88dcc7f.zip
Add midi
Diffstat (limited to 'src/synth_engine.c')
-rw-r--r--src/synth_engine.c43
1 files changed, 21 insertions, 22 deletions
diff --git a/src/synth_engine.c b/src/synth_engine.c
index 6bd6bf6..56ab771 100644
--- a/src/synth_engine.c
+++ b/src/synth_engine.c
@@ -152,14 +152,11 @@ make_sample(unsigned long long phase, void *synthData, unsigned int sample_rate,
//LFO!
//if (synth->adsr.elapsed > SAMPLE_RATE / 2) synth->adsr.elapsed = 0;
- if (synth->poly) {
- int n = synth->notes_active;
- for (int i = 0; i < n; i++) {
- sample += (1.0 / n) * synth->gen[synth->geni](synth->freq[i] + synth->freq_offset, synth->freq_count[i], synth->x, sample_rate);
- }
- } else {
- sample = synth->gen[synth->geni](synth->n.freq + synth->freq_offset, phase, synth->x, sample_rate);
- }
+ /* int n = synth->actual_notes_active; */
+ /* for (int i = 0; i < n; i++) { */
+ /* sample += (1.0 / n) * synth->gen[synth->geni](synth->actual_freq[i] + synth->freq_offset, synth->actual_freq_count[i], synth->x, sample_rate); */
+ /* } */
+ sample = synth->gen[synth->geni](synth->n.freq + synth->freq_offset, phase, synth->x, sample_rate);
if (!viz && synth->filter) {
// ALLL THE FILTERS
@@ -197,7 +194,7 @@ sound_gen(const void *inputBuffer, void *outputBuffer,
(void) statusFlags;
(void) inputBuffer;
- float s;
+ float s = 0.0f;
for( unsigned long i=0; i<framesPerBuffer; i++ ) {
//get_portaudio_frame(outputBuffer, synth);
if (!synth->active) {
@@ -205,29 +202,29 @@ sound_gen(const void *inputBuffer, void *outputBuffer,
*out++ = 0.0f;
continue;
}
+
if (adsr_amplitude(synth, synth->adsr.elapsed) == 0 && synth->n.noteOff != 0) {
- //printf("SYNTH OPFF\n");
synth->active = 0;
*out++ = 0.0f;
*out++ = 0.0f;
continue;
}
+
s = make_sample(synth->n.elapsed, synth, SAMPLE_RATE, 0);
*out++ = s;
*out++ = s;
+
synth->adsr.elapsed++;
synth->n.elapsed++;
- for (int j = 0; j < synth->notes_active; j++) {
- synth->freq_count[j]++;
- }
if (!synth->multi) {
- for (int j = 0; j < synth->notes_active; j++) {
- if (synth->freq_count[j] >= (1.0 / synth->freq[i]) * SAMPLE_RATE) synth->freq_count[j] = 0;
- }
if (synth->n.elapsed >= (1.0 / synth->n.freq) * SAMPLE_RATE) synth->n.elapsed = 0;
} else {
}
+ synth->viz.wi >= 1000199 ? synth->viz.wi = 0 : synth->viz.wi++;
+ synth->viz.wave[synth->viz.wi] = s;
+ synth->viz.wi >= 1000199 ? synth->viz.wi = 0 : synth->viz.wi++;
+ synth->viz.wave[synth->viz.wi] = s;
}
return paContinue;
@@ -239,12 +236,6 @@ init_synth(synth_t * synth)
synth->freq_offset = 0;
synth->gain = 1;
synth->x = 1;
-
- synth->notes_active = 0;
- for (int i = 0; i<100;i++) {
- synth->freq[i] = 0;
- synth->freq_count[i] = 0;
- }
synth->n.freq = 0;
synth->n.noteOn = 0;
@@ -277,8 +268,16 @@ init_synth(synth_t * synth)
synth->active = 0;
synth->viz.sample_rate_divider = 1;
+ synth->viz.wi = 0;
LowPass_Init();
synth->fff = create_bw_low_pass_filter(2, SAMPLE_RATE, 400);
synth->fff2 = create_bw_band_stop_filter(8, SAMPLE_RATE, 15000, 22000);
}
+
+void
+free_synth(synth_t * synth)
+{
+ free_bw_low_pass(synth->fff);
+ free_bw_band_stop(synth->fff2);
+}