synththing/src/utils/seq.c

40 lines
692 B
C

/*
* Filename: seq.h
*
* Description:
*
*
* Version:
* Created: Thu Oct 31 15:39:38 2019
* Revision: None
* Author: Rachel Fae Fox (foxiepaws),fox@foxiepa.ws
*
*/
#include "seq.h"
#include <math.h>
#include <stdlib.h>
float get_freq(midinote n) {
return pow(2.0,(((float)n-69.0)/12.0)) * 440.0;
}
Seq* seq_new() {
Seq *s = malloc(sizeof(Seq));
s->step = 0;
s->run = seq_run;
s->t = 0;
return s;
}
void seq_run(Seq *self) {
__asm("nop");
if (self->t < self->wait) {
self->t++;
} else {
self->t = 0;
self->step = (self->step < self->steps) ? self->step+1 : 0;
}
self->out = get_freq(self->notes[self->step]);
}