diff options
author | gramanas <anastasis.gramm2@gmail.com> | 2023-12-02 17:44:20 +0200 |
---|---|---|
committer | gramanas <anastasis.gramm2@gmail.com> | 2023-12-02 17:44:20 +0200 |
commit | 89b515395310c4e84a84992d3f0bd11f8ded6d03 (patch) | |
tree | 7c8554dedd0e6736a0b7db5d5f2285fbd31fe3f9 /src/synth_engine_v2.c | |
parent | 4f7de09c753ece6f2099512522d489b0104a59a8 (diff) | |
download | synth-project-89b515395310c4e84a84992d3f0bd11f8ded6d03.tar.gz synth-project-89b515395310c4e84a84992d3f0bd11f8ded6d03.tar.bz2 synth-project-89b515395310c4e84a84992d3f0bd11f8ded6d03.zip |
gui is mine
Diffstat (limited to 'src/synth_engine_v2.c')
-rw-r--r-- | src/synth_engine_v2.c | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/src/synth_engine_v2.c b/src/synth_engine_v2.c index 9beae33..bfd1d4a 100644 --- a/src/synth_engine_v2.c +++ b/src/synth_engine_v2.c @@ -178,6 +178,7 @@ make_sample(synth_t * synth, unsigned int sample_rate, int frame) //float max = get_max_sample(synth, 20); synth->adsr.a = CC_GET(adsr_a); + synth->adsr.peak = CC_GET(adsr_peak); synth->adsr.d = CC_GET(adsr_d); synth->adsr.s = CC_GET(adsr_s); synth->adsr.r = CC_GET(adsr_r); @@ -204,7 +205,7 @@ make_sample(synth_t * synth, unsigned int sample_rate, int frame) /* filter */ do_fliter(synth, &sample, sample_rate, frame); - sample = synth->gain * sample; + sample = CC_GET(gain) * sample; // band stop for high freqs //sample = bw_band_stop(synth->fff2, sample); @@ -254,8 +255,8 @@ get_frame(void *outputBuffer, synth_t *synth, int i) s = make_sample(synth, SAMPLE_RATE, i); synth->counter++; - if (synth->counter >= (int)(synth->del_time * SAMPLE_RATE * 10)) { - int idx = (synth->deli - (int)(synth->del_time * SAMPLE_RATE * 10)) % (SAMPLE_RATE * 10); + if (synth->counter >= (int)(synth->cc_del_time.target * SAMPLE_RATE)) { + int idx = (synth->deli - (int)(synth->cc_del_time.target * SAMPLE_RATE)) % (SAMPLE_RATE * 10); float tmp; if (idx >= 0) { tmp = synth->del[idx]; @@ -263,7 +264,7 @@ get_frame(void *outputBuffer, synth_t *synth, int i) tmp = synth->del[SAMPLE_RATE * 10 + idx]; } - s = clamp(s + synth->del_feedback * tmp, -1, 1); + s = clamp(s + synth->cc_del_feedback.target * tmp, -1, 1); } add_to_delay(synth, s); @@ -288,6 +289,8 @@ sound_gen(const void *inputBuffer, void *outputBuffer, synth_t *synth = (synth_t*)synthData; float *out = (float*)outputBuffer; + if (!synth->sound_active) return 0; //paContinue; + float buffer[2 * FRAMES_PER_BUFFER]; float buffer2[2 * FRAMES_PER_BUFFER]; @@ -341,20 +344,23 @@ init_synth(void) if (!synth) return NULL; synth->cci = 0; - // CC(SYNTH, NAME, MIN, MAX, STEP, DEF) - CC(synth->cc_cutoff, "cutoff", 10, 22000, 30, 5000); - CC(synth->cc_resonance, "resonance", 1, 10, .02, 1); - CC(synth->cc_lfo_freq, "lfo_freq", 1, 1000, 2, 1); - CC(synth->cc_lfo_amp, "lfo_amp", 0, 1, .01f, 0); - CC(synth->cc_pitch, "pitch", -3, 4, 0.01f, 1); - CC(synth->cc_adsr_a, "attack", 0, 3, 0.01f, 0.00); - CC(synth->cc_adsr_d, "decay", 0, 2, 0.01f, 0.3); - CC(synth->cc_adsr_s, "sustain", 0, 1.0f, 0.01f, 0.7f); - CC(synth->cc_adsr_r, "release", 0, 5, 0.01f, 0.2f); - - synth->modi = 0; - - synth->gain = 0.5; + // CC(SYNTH, NAME, MIN, MAX, STEP, DEF) + CC(synth->cc_cutoff, "cutoff", 10, 22000, 30, 5000); + CC(synth->cc_resonance, "resonance", 1, 10, .02, 1); + CC(synth->cc_lfo_freq, "lfo_freq", 1, 1000, 2, 1); + CC(synth->cc_lfo_amp, "lfo_amp", 0, 1, .01f, 0); + CC(synth->cc_pitch, "pitch", -3, 4, 0.01f, 1); + CC(synth->cc_adsr_a, "attack", 0, 3, 0.01f, 0.00); + CC(synth->cc_adsr_peak, "peak", 0, 1, 0.01f, 1.00); + CC(synth->cc_adsr_d, "decay", 0, 2, 0.01f, 0.3); + CC(synth->cc_adsr_s, "sustain", 0, 1.0f, 0.01f, 0.7f); + CC(synth->cc_adsr_r, "release", 0, 5, 0.01f, 0.2f); + CC(synth->cc_del_time, "time", 0, 3, 0.01f, 0.5f); + CC(synth->cc_del_feedback, "feedback", 0, 1, 0.01f, 0.5f); + CC(synth->cc_gain, "gain", 0, 1, 0.01f, 0.5f); + + //synth->modi = 0; + synth->x = 1; synth->adsr.a = 0.00001f; @@ -388,8 +394,6 @@ init_synth(void) synth->delay = 0; synth->del = (float *) calloc(sizeof(float), SAMPLE_RATE * 30); synth->deli = 0; - synth->del_time = .1; - synth->del_feedback = 0.5f; synth->counter; synth->filter = 1; @@ -410,10 +414,9 @@ init_synth(void) synth->fff = create_bw_low_pass_filter(2, SAMPLE_RATE, 400); synth->fff2 = create_bw_band_stop_filter(8, SAMPLE_RATE, 15000, 22000); + synth->sound_active = 0; init_sound(synth, sound_gen); - synth->osctri = make_tri("triangle"); - synth->viz.rate_divider = 15; // for (int i = 0; i < RING_SIZE; i++) synth->viz.wave_buffer_data[i] = 0; synth->viz.wave_buffer_data = (float *)calloc(sizeof(float), RING_SIZE); @@ -437,6 +440,8 @@ init_synth(void) synth->viz.tmp_index = 0; synth->wvt_pos = 0; + + return synth; } void |