diff options
author | gramanas <anastasis.gramm2@gmail.com> | 2023-04-19 04:00:08 +0300 |
---|---|---|
committer | gramanas <anastasis.gramm2@gmail.com> | 2023-04-19 04:00:08 +0300 |
commit | 1e374b426b4182c7b73b35219aadaca267b9623c (patch) | |
tree | e98b19e737c8744ca55952191e59e3d521fef68c /src/synth_engine.c | |
parent | 7cd2ef47ccf7730ada9a61deacfce6ea03b5516d (diff) | |
download | synth-project-1e374b426b4182c7b73b35219aadaca267b9623c.tar.gz synth-project-1e374b426b4182c7b73b35219aadaca267b9623c.tar.bz2 synth-project-1e374b426b4182c7b73b35219aadaca267b9623c.zip |
fake poly
Diffstat (limited to 'src/synth_engine.c')
-rw-r--r-- | src/synth_engine.c | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/src/synth_engine.c b/src/synth_engine.c index fc0a53d..6bd6bf6 100644 --- a/src/synth_engine.c +++ b/src/synth_engine.c @@ -127,10 +127,10 @@ gen1(float f, unsigned long long phase, float x, unsigned int sample_rate) float gen2(float f, unsigned long long phase, float x, unsigned int sample_rate) { - return sin_sample(0.5, f * sqrt(2) , phase, sample_rate) - + sin_sample(0.5, f, phase, sample_rate); + /* return sin_sample(0.5, f * sqrt(2) , phase, sample_rate) */ + /* + sin_sample(0.5, f, phase, sample_rate); */ - /* sawX_sample(1, synth->freq, 5, phase, sample_rate); */ + return sawX_sample(1, f, 5, phase, sample_rate); } float @@ -151,10 +151,14 @@ make_sample(unsigned long long phase, void *synthData, unsigned int sample_rate, //LFO! //if (synth->adsr.elapsed > SAMPLE_RATE / 2) synth->adsr.elapsed = 0; - - int n = 1; - for (int i = 0; i < n; i++) { - sample += (1.0 / n) * synth->gen[synth->geni](synth->n.freq + synth->freq_offset, phase, synth->x, sample_rate); + + 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); } if (!viz && synth->filter) { @@ -202,7 +206,7 @@ sound_gen(const void *inputBuffer, void *outputBuffer, continue; } if (adsr_amplitude(synth, synth->adsr.elapsed) == 0 && synth->n.noteOff != 0) { - printf("SYNTH OPFF\n"); + //printf("SYNTH OPFF\n"); synth->active = 0; *out++ = 0.0f; *out++ = 0.0f; @@ -213,7 +217,13 @@ sound_gen(const void *inputBuffer, void *outputBuffer, *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 { @@ -230,13 +240,18 @@ init_synth(synth_t * synth) 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; synth->n.noteOff = 1; synth->n.key = 0; synth->n.elapsed = 0; - synth->adsr.a = 0.0; synth->adsr.peak = 1.0f; synth->adsr.d = 0.3; @@ -246,6 +261,7 @@ init_synth(synth_t * synth) synth->octave = 3; + synth->poly = 0; synth->multi = 0; synth->filter = 0; synth->cutoff = 22000.0f; |