tgate

tgate

Overview

A triggerable gate generator. Takes in a trigger signal, and produces a gate whose duration is measured in seconds.

Tangled Files

<<tgate.h>>=
#ifndef SK_TGATE_H
#define SK_TGATE_H

#ifndef SKFLT
#define SKFLT float
#endif

<<typedefs>>

#ifdef SK_TGATE_PRIV
<<structs>>
#endif

<<funcdefs>>
#endif

<<tgate.c>>=
#define SK_TGATE_PRIV
#include "tgate.h"
<<funcs>>

Struct And Initialization

<<typedefs>>=
typedef struct sk_tgate sk_tgate;

<<structs>>=
struct sk_tgate {
    SKFLT dur;
    unsigned long timer;
    int sr;
};

<<funcdefs>>=
void sk_tgate_init(sk_tgate *tg, int sr);

<<funcs>>=
void sk_tgate_init(sk_tgate *tg, int sr)
{
    tg->sr = sr;
    tg->dur = 0;
    tg->timer = 0;
}

Gate Time

<<funcdefs>>=
void sk_tgate_dur(sk_tgate *tg, SKFLT dur);

<<funcs>>=
void sk_tgate_dur(sk_tgate *tg, SKFLT dur)
{
    tg->dur = dur;
}

Computation

sk_tgate_tick expects a trigger input signal.

<<funcdefs>>=
SKFLT sk_tgate_tick(sk_tgate *tg, SKFLT trig);

<<funcs>>=
SKFLT sk_tgate_tick(sk_tgate *tg, SKFLT trig)
{
    SKFLT out;

    out = 0;

    if (trig != 0) {
        tg->timer = tg->dur * tg->sr;
    }

    if (tg->timer != 0) {
        out = 1.0;
        tg->timer--;
    }

    return out;
}