summaryrefslogtreecommitdiffstats
path: root/src/synth_engine.h
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2023-04-18 16:31:25 +0300
committergramanas <anastasis.gramm2@gmail.com>2023-04-18 16:31:25 +0300
commit9c6410cc3a43d9d1e01f853cb5a8d0f8a6d93b45 (patch)
treea4c044223d224090e54828903ae223788f97c8e6 /src/synth_engine.h
downloadsynth-project-9c6410cc3a43d9d1e01f853cb5a8d0f8a6d93b45.tar.gz
synth-project-9c6410cc3a43d9d1e01f853cb5a8d0f8a6d93b45.tar.bz2
synth-project-9c6410cc3a43d9d1e01f853cb5a8d0f8a6d93b45.zip
autotools initial...
Diffstat (limited to 'src/synth_engine.h')
-rw-r--r--src/synth_engine.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/synth_engine.h b/src/synth_engine.h
new file mode 100644
index 0000000..e35e8fb
--- /dev/null
+++ b/src/synth_engine.h
@@ -0,0 +1,77 @@
+#ifndef SYNTH_ENGINE_H
+#define SYNTH_ENGINE_H
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+#include <portaudio.h>
+
+#include "notes.h"
+#include "filter.h"
+
+#define SAMPLE_RATE (44100)
+//#define SAMPLE_RATE (48000)
+#define FRAMES_PER_BUFFER (210)
+
+#define WIDTH 1024
+#define HEIGHT 600
+
+#ifndef M_PI
+#define M_PI (3.14159265)
+#endif
+
+
+typedef struct {
+ float a;
+ float d;
+ float s;
+ float r;
+ unsigned long long elapsed;
+} adsr_t;
+
+typedef struct {
+ float freq;
+ PaTime noteOn;
+ PaTime noteOff;
+ int key;
+ unsigned long long elapsed;
+} note_t;
+
+typedef struct {
+ int sample_rate_divider;
+} viz_t;
+
+typedef struct {
+ float freq_offset;
+ float gain;
+ float x;
+
+ note_t n;
+ adsr_t adsr;
+
+ int octave;
+
+ int multi;
+ int filter;
+ float cutoff;
+ float resonance;
+ int clamp;
+
+ float (*gen[4]) (float freq, unsigned long long phase, float x, unsigned int sample_rate);
+ int geni;
+
+ BWLowPass* fff;
+
+ viz_t viz;
+} synth_t;
+
+float adsr_amplitude(void *synthData, unsigned long long elapsed);
+float make_sample(unsigned long long phase, void *synthData, unsigned int sample_rate, int viz);
+void init_synth(synth_t * synth);
+int sound_gen(const void *inputBuffer, void *outputBuffer,
+ unsigned long framesPerBuffer,
+ const PaStreamCallbackTimeInfo* timeInfo,
+ PaStreamCallbackFlags statusFlags,
+ void *synthData);
+
+#endif /* SYNTH_ENGINE_H */