From 42479d2ed8fcbad5fb3ffb52553dad05a329590f Mon Sep 17 00:00:00 2001 From: gramanas Date: Sun, 30 Jul 2023 20:51:05 +0300 Subject: oop --- src/synth_engine.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/synth_engine.c') diff --git a/src/synth_engine.c b/src/synth_engine.c index d17ba49..8fc8221 100644 --- a/src/synth_engine.c +++ b/src/synth_engine.c @@ -92,8 +92,8 @@ gen3(float f, midi_note_t * midi_note, float x, unsigned int sample_rate) //return sqr_sample(1, f, .5, midi_note->elapsed, sample_rate); //return wvt_next(wvt_sound, f, sample_rate, &midi_note->wvt_index); - float sample = osc_saw(midi_note->wvt_index); - midi_note->wvt_index = osc_saw_next(f, midi_note->wvt_index); + float sample = osc_sound(midi_note->wvt_index); + midi_note->wvt_index = osc_sound_next(f, midi_note->wvt_index); return sample; /* return sawX_sample(0.7, f, 5, midi_note->elapsed, sample_rate) */ @@ -103,7 +103,10 @@ gen3(float f, midi_note_t * midi_note, float x, unsigned int sample_rate) float gen4(float f, midi_note_t * midi_note, float x, unsigned int sample_rate) { - return wvt_next(wvt_tri, f, sample_rate, &midi_note->wvt_index); + float sample = osc_tri(midi_note->wvt_index); + midi_note->wvt_index = osc_tri_next(f, midi_note->wvt_index); + return sample; + //return wvt_next(wvt_tri, f, sample_rate, &midi_note->wvt_index); } float @@ -176,6 +179,9 @@ make_sample(void *synthData, unsigned int sample_rate, int frame) rms += synth->midi_note[i].velocity * synth->midi_note[i].velocity; } + // if rms == 0 we can deduce there are no notes however notes_active handles + // stopping any already playing notes and if we remove it we need to make + // sure that notes stop some other way (it laso happens every frame) rms = sqrt(rms / n); for (int i = 0; i < MIDI_NOTES; i++) { @@ -194,10 +200,12 @@ make_sample(void *synthData, unsigned int sample_rate, int frame) // (1.05946309436/24.0) * (wvt_next(wvt_tri, (wvt_next(wvt_sound, 2 * cc_iget(&synth->cc_lfo_freq, frame, FRAMES_PER_BUFFER), SAMPLE_RATE, &lfo_index) / 2.0 + 0.5) * cc_iget(&synth->cc_lfo_freq, frame, FRAMES_PER_BUFFER), SAMPLE_RATE, &synth->midi_note[i].lfo_index) / 2.0 + 0.5); - float synth_sample = synth->gen[synth->geni](targ_freq, - &synth->midi_note[i], - synth->x, - sample_rate); + float synth_sample = synth->osctri->ops->sample(synth->osctri, synth->midi_note[i].wvt_index); + synth->midi_note[i].wvt_index = synth->osctri->ops->next(synth->osctri, targ_freq, synth->midi_note[i].wvt_index); + /* float synth_sample = synth->gen[synth->geni](targ_freq, */ + /* &synth->midi_note[i], */ + /* synth->x, */ + /* sample_rate); */ sample += 0.2 * rms * adsr * synth_sample; } @@ -414,7 +422,6 @@ init_synth(synth_t * synth) synth->modi = 0; - synth->freq_offset = 0; synth->gain = 1; synth->x = 1; @@ -470,6 +477,8 @@ init_synth(synth_t * synth) init_sound(synth, sound_gen); wvt_init(); + + synth->osctri = make_tri("triangle"); } void -- cgit v1.2.3