summaryrefslogtreecommitdiffstats
path: root/src/synth_engine.h
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2023-04-29 14:34:36 +0300
committergramanas <anastasis.gramm2@gmail.com>2023-04-29 14:34:36 +0300
commit402f6791150d503fc29ed75a7b8be9abfdd3867f (patch)
tree1061ae5cd2f9e1728b59a1ae6fbe0dfe8582c849 /src/synth_engine.h
parente919ad41b01595d2cd8fb0771bd3542817ec1058 (diff)
downloadsynth-project-402f6791150d503fc29ed75a7b8be9abfdd3867f.tar.gz
synth-project-402f6791150d503fc29ed75a7b8be9abfdd3867f.tar.bz2
synth-project-402f6791150d503fc29ed75a7b8be9abfdd3867f.zip
midi cc
Diffstat (limited to 'src/synth_engine.h')
-rw-r--r--src/synth_engine.h46
1 files changed, 31 insertions, 15 deletions
diff --git a/src/synth_engine.h b/src/synth_engine.h
index b88f3d5..a434b53 100644
--- a/src/synth_engine.h
+++ b/src/synth_engine.h
@@ -8,29 +8,30 @@
#include "notes.h"
#include "filter.h"
+#include "adsr.h"
-#define SAMPLE_RATE (44100)
-//#define SAMPLE_RATE (48000)
+//#define SAMPLE_RATE (44100)
+#define SAMPLE_RATE (48000)
#define FRAMES_PER_BUFFER (210)
+#define VIZ_BUF 1024
+
#define WIDTH 1024
#define HEIGHT 600
+#define MIDI_NOTES 128
+
#ifndef M_PI
#define M_PI (3.14159265)
#endif
-
-typedef struct {
- float a;
- float peak;
- float d;
- float s;
- float r;
+typedef struct lfo_t {
+ float freq;
+ float amp;
unsigned long long elapsed;
-} adsr_t;
+} lfo_t;
-typedef struct {
+typedef struct note_t {
float freq;
PaTime noteOn;
PaTime noteOff;
@@ -38,9 +39,20 @@ typedef struct {
unsigned long long elapsed;
} note_t;
-typedef struct {
+typedef struct midi_note_t {
+ float freq;
+ int channel;
+ PaTime noteOn;
+ PaTime noteOff;
+ float velocity; // normalized
+ unsigned long long elapsed;
+ adsr_t * adsr;
+ int active;
+} midi_note_t;
+
+typedef struct viz_t {
int sample_rate_divider;
- float wave[1000200];
+ float wave[VIZ_BUF];
int wi;
} viz_t;
@@ -51,9 +63,13 @@ typedef struct {
float gain;
float x;
+ midi_note_t midi_note[MIDI_NOTES];
+
note_t n;
adsr_t adsr;
+ lfo_t lfo;
+
int octave;
int poly;
@@ -75,11 +91,11 @@ typedef struct {
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);
void free_synth(synth_t * synth);
-int sound_gen(const void *inputBuffer, void *outputBuffer,
+int sound_gen(const void *inputBuffer,
+ void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,