added new waveforms

master
Rachel Fae Fox (foxiepaws) 2019-10-30 22:35:20 -04:00
parent 93ef31fc7f
commit 16f7e0664f
4 changed files with 15 additions and 5 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
bin/
*.o
*.gch
.#*

View File

@ -15,12 +15,13 @@
#include "../utils/envelope.h"
#include <stdlib.h>
#include <math.h>
typedef enum Waveform {_waveform_sine, _waveform_saw} Waveform;
typedef enum Waveform {_waveform_sine, _waveform_saw, _waveform_square} Waveform;
typedef struct Basic {
float freq;
Waveform shape;
int gate;
Envelope Env;
float pwm;
float(*process)(struct Basic *, EngineState*);
} Basic;
@ -31,6 +32,12 @@ float basic_process(Basic *self, EngineState *t) {
case _waveform_saw:
out = fmod((self->freq+1) * t->t / 44100,1.0);
break;
case _waveform_sine:
out = sin(2 * M_PI * t->t * self->freq / 44100);
break;
case _waveform_square:
out = fmod((self->freq+1) * t->t / 44100,1.0) > self->pwm;
break;
default:
out = 0.0F;
break;

View File

@ -16,12 +16,13 @@
#ifndef _H_BASIC
#define _H_BASIC
typedef enum Waveform {_waveform_sine, _waveform_saw} Waveform;
typedef enum Waveform {_waveform_sine, _waveform_saw, _waveform_square} Waveform;
typedef struct Basic {
float freq;
Waveform shape;
int gate;
Envelope Env;
float pwm;
float(*process)(struct Basic *, EngineState*);
} Basic;

View File

@ -50,8 +50,8 @@ int mycallback( const void *input,
//filt.process(&filt, (saw.process(&saw,data)));
//float a = filt.low;
float a = 0.5 * saw.process(&saw,data);
filt.process(&filt,a);
a = filt.low;
//filt.process(&filt,a);
//a = filt.low;
*out++ = a;
*out++ = a;
data->t++;
@ -84,7 +84,8 @@ int main(int argc, char**argv) {
}
Envelope b = *envelope_new();
saw = *basic_new(_waveform_saw, b);
saw = *basic_new(_waveform_square, b);
saw.pwm = 0.5;
saw.freq = 440;
filt = *svf_new(7000.0f, 0.5f);
//data.sample_rate=SAMPLE_RATE;