incr

Files: incr.h, incr.c

Trigger-based Incrementor When triggered, this module will increment and decrement a value bounded between a min and max. Initially, this was designed for the specific use case of interfacing with the griffin knob.

Functions

sp_incr_create(sp_incr **incr)
sp_incr_init(sp_data *sp, sp_incr *incr, SPFLOAT val)
sp_incr_compute(sp_data *sp, sp_incr *incr, SPFLOAT *trig, SPFLOAT *out)
sp_incr_destroy(sp_incr **incr)

Mandatory Parameters

val: Initial value
(Recommended value: 0.5)

Optional Parameters

step: Step value to increment by.
(Default value: 0.1)
min: Minimum value
(Default value: 0)
max: Maximum value
(Default value: 1)

Inputs

trig: Trigger signal. When positive, the value will increase. When negative, the value will decrease.

Outputs

out: incr output.

Example Code

/*
 * This is a dummy example.
 * Please implement a small and simple working example of your module, and then
 * remove this header.
 * Don't be clever.
 * Bonus points for musicality. 
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "soundpipe.h"

typedef struct {
    sp_metro *met;
    sp_incr *incr;
    sp_osc *osc;
    sp_ftbl *ft; 
} UserData;

void process(sp_data *sp, void *udata) 
{
    UserData *ud = udata;
    SPFLOAT osc = 0, incr = 0, met = 0;
    sp_metro_compute(sp, ud->met, NULL, &met);
    sp_incr_compute(sp, ud->incr, &met, &incr);
    ud->osc->freq = incr;
    sp_osc_compute(sp, ud->osc, NULL, &osc);
    sp->out[0] = osc;
}

int main() 
{
    UserData ud;
    sp_data *sp;
    sp_create(&sp);
    sp_srand(sp, 1234567);

    sp_metro_create(&ud.met);
    sp_incr_create(&ud.incr);
    sp_osc_create(&ud.osc);
    sp_ftbl_create(sp, &ud.ft, 2048);

    sp_metro_init(sp, ud.met);
    ud.met->freq = 3;
    sp_incr_init(sp, ud.incr, 300);
    ud.incr->min = 300;
    ud.incr->max = 900;
    ud.incr->step = 30;
    sp_gen_sine(sp, ud.ft);
    sp_osc_init(sp, ud.osc, ud.ft, 0);
    ud.osc->amp = 0.5;

    sp->len = 44100 * 5;
    sp_process(sp, &ud, process);

    sp_incr_destroy(&ud.incr);
    sp_ftbl_destroy(&ud.ft);
    sp_osc_destroy(&ud.osc);
    sp_metro_destroy(&ud.met);

    sp_destroy(&sp);
    return 0;
}