NO-OP: whitespace

This commit is contained in:
Robin Gareus 2019-03-01 15:59:41 +01:00
parent 63200eab05
commit 6064c75fd5
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04

View File

@ -22,9 +22,9 @@
#endif
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#ifndef COMPILER_MSVC
#include <stdbool.h>
@ -148,8 +148,7 @@ adsr_env(RSSynthChannel *sc, const uint8_t note)
const float d = sc->adsr.vol[0] - sc->adsr_amp[note];
return sc->adsr_amp[note] + (p / (float)sc->adsr.tme[0]) * d;
}
}
else if (sc->adsr_cnt[note] < sc->adsr.off[1]) {
} else if (sc->adsr_cnt[note] < sc->adsr.off[1]) {
// decay
const uint32_t p = ++sc->adsr_cnt[note] - sc->adsr.off[0];
if (p == sc->adsr.tme[1]) {
@ -159,12 +158,10 @@ adsr_env(RSSynthChannel *sc, const uint8_t note)
const float d = sc->adsr.vol[1] - sc->adsr_amp[note];
return sc->adsr_amp[note] + (p / (float)sc->adsr.tme[1]) * d;
}
}
else if (sc->adsr_cnt[note] == sc->adsr.off[1]) {
} else if (sc->adsr_cnt[note] == sc->adsr.off[1]) {
// sustain
return sc->adsr.vol[1];
}
else if (sc->adsr_cnt[note] < sc->adsr.off[2]) {
} else if (sc->adsr_cnt[note] < sc->adsr.off[2]) {
// release
const uint32_t p = ++sc->adsr_cnt[note] - sc->adsr.off[1];
if (p == sc->adsr.tme[2]) {
@ -174,8 +171,7 @@ adsr_env(RSSynthChannel *sc, const uint8_t note)
const float d = 0 - sc->adsr_amp[note];
return sc->adsr_amp[note] + (p / (float)sc->adsr.tme[2]) * d;
}
}
else {
} else {
sc->adsr_cnt[note] = 0;
return 0;
}
@ -193,7 +189,9 @@ synthesize_sineP (RSSynthChannel* sc,
for (i = 0; i < n_samples; ++i) {
float env = adsr_env (sc, note);
if (sc->adsr_cnt[note] == 0) break;
if (sc->adsr_cnt[note] == 0) {
break;
}
const float amp = vol * env;
if (amp > 1e-10) {
left[i] += amp * sinf (2.0 * M_PI * phase);
@ -214,7 +212,8 @@ synthesize_sineP (RSSynthChannel* sc,
} else {
phase += fq;
}
if (phase > 1.0) phase -= 2.0;
if (phase > 1.0)
phase -= 2.0;
}
sc->phase[note] = phase;
}
@ -223,7 +222,6 @@ static const ADSRcfg piano_adsr = {{ 5, 800, 100}, { 1.0, 0.0}, {0, 0, 0}};
/*****************************************************************************/
/* process note - move through ADSR states, count active keys,.. */
static void
process_key (void* synth,
@ -249,8 +247,7 @@ process_key (void *synth,
sc->phase[note] = 0;
sc->keycomp++;
//printf("[On] Now %d keys active on chn %d\n", sc->keycomp, chn);
}
else if (phase >= -1.0 && phase <= 1.0 && vel > 0) {
} else if (phase >= -1.0 && phase <= 1.0 && vel > 0) {
// sustain note or re-start note while adsr in progress:
if (sc->adsr_cnt[note] > sc->adsr.off[1] || msg == 3 || msg == 5 || msg == 7) {
sc->midimsgs[note] &= ~4;
@ -258,8 +255,7 @@ process_key (void *synth,
sc->adsr_amp[note] = adsr_env (sc, note);
sc->adsr_cnt[note] = 0;
}
}
else if (phase >= -1.0 && phase <= 1.0 && vel < 0) {
} else if (phase >= -1.0 && phase <= 1.0 && vel < 0) {
sc->midimsgs[note] |= 4;
// note off
if (sc->adsr_cnt[note] <= sc->adsr.off[1] && !sus) {
@ -268,12 +264,10 @@ process_key (void *synth,
sc->adsr_amp[note] = adsr_env (sc, note);
}
sc->adsr_cnt[note] = sc->adsr.off[1] + 1;
}
else if (sus && sc->adsr_cnt[note] == sc->adsr.off[1]) {
} else if (sus && sc->adsr_cnt[note] == sc->adsr.off[1]) {
sc->adsr_cnt[note] = sc->adsr.off[1] + 1;
}
}
else {
} else {
//printf("FORCE NOTE OFF: %d %d\n", vel, sus);
/* note-on + off in same cycle */
sc->miditable[note] = 0;
@ -310,7 +304,9 @@ synth_fragment (void *synth, const size_t n_samples, float *left, float *right)
for (c = 0; c < 16; ++c) {
for (k = 0; k < 128; ++k) {
if (rs->sc[c].miditable[k] == 0) continue;
if (rs->sc[c].miditable[k] == 0) {
continue;
}
process_key (synth, c, k, n_samples, left, right);
}
keycomp += rs->sc[c].keycomp;
@ -320,6 +316,7 @@ synth_fragment (void *synth, const size_t n_samples, float *left, float *right)
float kctgt = 8.0 / (float)(keycomp + 7.0);
if (kctgt < .5) kctgt = .5;
if (kctgt > 1.0) kctgt = 1.0;
const float _w = rs->kcfilt;
for (i = 0; i < n_samples; ++i) {
rs->kcgain += _w * (kctgt - rs->kcgain);
@ -456,9 +453,11 @@ synth_sound (void *synth, uint32_t written, const uint32_t nframes, float **out)
static void
synth_parse_midi (void* synth, const uint8_t* data, const size_t size)
{
if (size < 2 || size > 3) return;
if (size < 2 || size > 3)
return;
// All messages need to be 3 bytes; except program-changes: 2bytes.
if (size == 2 && (data[0] & 0xf0) != 0xC0) return;
if (size == 2 && (data[0] & 0xf0) != 0xC0)
return;
struct rmidi_event_t ev;
@ -498,9 +497,11 @@ static void
synth_parse_xmas (void* synth, const uint8_t* data, const size_t size)
{
RSSynthesizer* rs = (RSSynthesizer*)synth;
if (size < 2 || size > 3) return;
if (size < 2 || size > 3)
return;
// All messages need to be 3 bytes; except program-changes: 2bytes.
if (size == 2 && (data[0] & 0xf0) != 0xC0) return;
if (size == 2 && (data[0] & 0xf0) != 0xC0)
return;
struct rmidi_event_t ev;
@ -510,13 +511,15 @@ synth_parse_xmas(void *synth, const uint8_t *data, const size_t size)
ev.type = NOTE_OFF;
ev.d.tone.note = jingle[rs->xmas_off++];
ev.d.tone.velocity = data[2] & 0x7f;
if (rs->xmas_off >= sizeof(jingle)) rs->xmas_off = 0;
if (rs->xmas_off >= sizeof (jingle))
rs->xmas_off = 0;
break;
case 0x90:
ev.type = NOTE_ON;
ev.d.tone.note = jingle[rs->xmas_on++];
ev.d.tone.velocity = data[2] & 0x7f;
if (rs->xmas_on >= sizeof(jingle)) rs->xmas_on = 0;
if (rs->xmas_on >= sizeof (jingle))
rs->xmas_on = 0;
break;
case 0xB0:
ev.type = CONTROL_CHANGE;
@ -541,7 +544,8 @@ synth_parse_xmas(void *synth, const uint8_t *data, const size_t size)
* @param rate sample-rate
*/
static void
synth_init(void* synth, double rate) {
synth_init (void* synth, double rate)
{
RSSynthesizer* rs = (RSSynthesizer*)synth;
rs->rate = rate;
rs->boffset = BUFFER_SIZE_SAMPLES;