GTick
Overview
The GTick
algorithm has but one purpose: take in a
gate signal, and return a tick signal.
Gate signals, such as those generated by tgate, are signals that are either off (0) or on (1, or non-zero). Tick signals, such as those generated by metro or phsclk, can be thought of as impulse streams, and produce "tick" values, single-sample non-zero impulses, that can be used as clock sources to trigger things like tenv, trand, or tgate.
In many situations, it can be very difficult to produce a tick signal that is guaranteed to be 1 sample long. Meanwhile, a gate signal is a much more approachable kind of signal to make.
Tangled Files
#ifndef SK_GTICK_H
#define SK_GTICK_H
#ifndef SKFLT
#define SKFLT float
#endif
<<typedefs>>
#ifdef SK_GTICK_PRIV
<<structs>>
#endif
<<funcdefs>>
#endif
#define SK_GTICK_PRIV
#include "gtick.h"
<<funcs>>
Struct
sk_gtick
.
typedef struct sk_gtick sk_gtick;
struct sk_gtick {
SKFLT prev;
};
Init
sk_gtick_init
.
void sk_gtick_init(sk_gtick *gt);
void sk_gtick_init(sk_gtick *gt)
{
gt->prev = 0;
}
Compute
A single sample of gtick
is computed with
sk_gtick_tick
. It expects as an input a gate signal.
SKFLT sk_gtick_tick(sk_gtick *gt, SKFLT in);
A tick signal is only produced what a gate transitions from off to on (in Electrical Engineering terms, they sometimes might say it goes from LOW to HIGH). It does this by keeping track of the previous sample.
A gate signal must transition from on to off before it can be ready to produce another tick again.
SKFLT sk_gtick_tick(sk_gtick *gt, SKFLT gate)
{
SKFLT out;
out = 0;
if (gate > 0 && gt->prev <= 0) {
out = 1;
}
gt->prev = gate;
return out;
}