tenv2
Files: tenv2.h, tenv2.c
Linear 2-stage Attack/Release envelope generator
This envelope takes 2 triggers. When triggered once,
the envelope will rise to 1 according to the attack time. When triggered again, it will decay to 0 according to
the decay time.
sp_tenv2_create(sp_tenv2 **tenv2)
sp_tenv2_init(sp_data *sp, sp_tenv2 *tenv2)
sp_tenv2_compute(sp_data *sp, sp_tenv2 *tenv2, SPFLOAT *trig, SPFLOAT *out)
sp_tenv2_destroy(sp_tenv2 **tenv2)
Optional Parameters
atk: Attack time (in seconds).
(Default value: 0.1)
rel: Release time (in seconds).
(Default value: 0.1)
Inputs
trig: Expects a trigger signal.
Outputs
out: Signal out (a unipolar envelope).
Example Code
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "soundpipe.h"
typedef struct {
sp_tenv2 *tenv2;
sp_osc *osc;
sp_ftbl *ft;
} UserData;
void process(sp_data *sp, void *udata) {
UserData *ud = udata;
SPFLOAT osc = 0, tenv2 = 0, tick = 0;
if(sp->pos == 0 || sp->pos == sp->sr * 1) tick = 1;
sp_osc_compute(sp, ud->osc, NULL, &osc);
sp_tenv2_compute(sp, ud->tenv2, &tick, &tenv2);
sp->out[0] = osc * tenv2;
}
int main() {
srand(1234567);
UserData ud;
sp_data *sp;
sp_create(&sp);
sp_tenv2_create(&ud.tenv2);
sp_osc_create(&ud.osc);
sp_ftbl_create(sp, &ud.ft, 2048);
sp_tenv2_init(sp, ud.tenv2);
ud.tenv2->atk = 3;
ud.tenv2->rel = 1;
sp_gen_sine(sp, ud.ft);
sp_osc_init(sp, ud.osc, ud.ft, 0);
ud.osc->amp = 0.6;
sp->len = 44100 * 5;
sp_process(sp, &ud, process);
sp_tenv2_destroy(&ud.tenv2);
sp_ftbl_destroy(&ud.ft);
sp_osc_destroy(&ud.osc);
sp_destroy(&sp);
return 0;
}