From 0cceb2057e382129ae24565fdefff87e91b076ab Mon Sep 17 00:00:00 2001 From: gramanas Date: Sat, 29 Apr 2023 14:34:48 +0300 Subject: self contained adsr --- src/synth_engine.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/synth_engine.c') diff --git a/src/synth_engine.c b/src/synth_engine.c index 6710ff6..8587001 100644 --- a/src/synth_engine.c +++ b/src/synth_engine.c @@ -138,8 +138,11 @@ make_sample(unsigned long long phase, void *synthData, unsigned int sample_rate, continue; sample += 0.2 * rms - * adsr_amplitude(&synth->adsr, (float)synth->midi_note[i].noteOn, (float)synth->midi_note[i].noteOff, (float)synth->midi_note[i].elapsed) - * synth->gen[synth->geni](synth->midi_note[i].freq + synth->midi_note[i].freq * synth->freq_offset, synth->midi_note[i].elapsed, synth->x, sample_rate); + * adsr_amplitude(&synth->adsr, + synth->midi_note[i].noteOn, + synth->midi_note[i].noteOff, + synth->midi_note[i].elapsed) + * synth->gen[synth->geni](synth->midi_note[i].freq + synth->freq_offset, synth->midi_note[i].elapsed, synth->x, sample_rate); } /* filter */ @@ -204,7 +207,6 @@ sound_gen(const void *inputBuffer, void *outputBuffer, } if (!notes_active(synth)) { - //if (adsr_amplitude(synth, synth->adsr.elapsed, synth->n.noteOn, synth->n.noteOff) == 0 && synth->n.noteOff != 0) { synth->active = 0; *out++ = 0.0f; *out++ = 0.0f; @@ -219,11 +221,6 @@ sound_gen(const void *inputBuffer, void *outputBuffer, synth->lfo.elapsed++; synth->adsr.elapsed++; synth->n.elapsed++; - /* if (!synth->multi) { */ - /* if (synth->n.elapsed >= (1.0 / synth->n.freq) * SAMPLE_RATE) synth->n.elapsed = 0; */ - /* } else { */ - - /* } */ for (int i = 0; i < MIDI_NOTES; i++) { if (!synth->midi_note[i].active) @@ -318,7 +315,7 @@ init_synth(synth_t * synth) PaStreamParameters outputParameters; - outputParameters.device = i; Pa_GetDefaultOutputDevice(); /* default output device */ + outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */ printf("-------\nSelected device: %s\n-------\n", Pa_GetDeviceInfo(outputParameters.device)->name); outputParameters.channelCount = 2; /* stereo output */ outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */ -- cgit v1.2.3