synththing/src/synths/basic.c

49 lines
902 B
C

/*
* Filename: basic.c
*
* Description:
*
*
* Version:
* Created: Wed Oct 30 17:08:31 2019
* Revision: None
* Author: Rachel Fae Fox (foxiepaws),fox@foxiepa.ws
*
*/
#include "../common.h"
#include "../utils/envelope.h"
#include <stdlib.h>
#include <math.h>
typedef enum Waveform {_waveform_sine, _waveform_saw} Waveform;
typedef struct Basic {
float freq;
Waveform shape;
int gate;
Envelope Env;
float(*process)(struct Basic *, EngineState*);
} Basic;
float basic_process(Basic *self, EngineState *t) {
float out;
switch (self->shape) {
case _waveform_saw:
out = fmod((self->freq+1) * t->t / 44100,1.0);
break;
default:
out = 0.0F;
break;
}
return out;
}
Basic* basic_new(Waveform w, Envelope e) {
Basic *b = malloc(sizeof(Envelope));
b->shape = w;
b->process = basic_process;
return b;
}