summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2023-09-14 14:30:52 +0300
committergramanas <anastasis.gramm2@gmail.com>2023-09-14 14:30:52 +0300
commit2a2a1b0d9fc4bfffcaf23d2f66d38d6927d76bbe (patch)
treefbb51f0f79017fb11946a69e7171c4bb751b63a7 /src
parent12ef243815d409e5f4039502f378d43ecdf7abaa (diff)
downloadsynth-project-2a2a1b0d9fc4bfffcaf23d2f66d38d6927d76bbe.tar.gz
synth-project-2a2a1b0d9fc4bfffcaf23d2f66d38d6927d76bbe.tar.bz2
synth-project-2a2a1b0d9fc4bfffcaf23d2f66d38d6927d76bbe.zip
Add square wave and fix lowpass styling
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am5
-rw-r--r--src/lowpass.c278
-rw-r--r--src/lowpass.h43
-rw-r--r--src/osc.h1
-rw-r--r--src/synth_engine.c21
-rw-r--r--src/synth_gui.c79
6 files changed, 196 insertions, 231 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 933f4df..6e75352 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -20,6 +20,7 @@ common_sources = adsr.c \
osc_digisaw.c \
osc_saw.c \
osc_weird.c \
+ osc_sqr.c \
osc_sound.c \
raygui.h \
sound.c \
@@ -29,9 +30,7 @@ common_sources = adsr.c \
synth_engine.h \
synth_gui.c \
synth_gui.h \
- synth_math.h \
- wavetable.c \
- wavetable.h
+ synth_math.h
# -fwhole-program allows cross-file inlining, but only works when you put all
# the source files on one gcc command-line. -flto is another way to get the
diff --git a/src/lowpass.c b/src/lowpass.c
index 304ad9f..ccb41dd 100644
--- a/src/lowpass.c
+++ b/src/lowpass.c
@@ -1,8 +1,8 @@
/*
-Resonant low pass filter source code.
-By baltrax@hotmail.com (Zxform)
+ Resonant low pass filter source code.
+ By baltrax@hotmail.com (Zxform)
-- little changes and optimizations by Brett Paterson for FMOD example.
+ - little changes and optimizations by Brett Paterson for FMOD example.
*/
@@ -46,79 +46,79 @@ FILTER iir;
* Allocation errors cause an error message and a call to exit.
* --------------------------------------------------------------------
*/
-float LowPass_Filter(float input)
+float lpf_filter(float input)
{
- unsigned int i;
- float *hist1_ptr,*hist2_ptr,*coef_ptr;
- float output,new_hist,history1,history2;
- static float dc = (float)1E-25;
- input += dc;
- dc = -dc;
+ unsigned int i;
+ float *hist1_ptr,*hist2_ptr,*coef_ptr;
+ float output,new_hist,history1,history2;
+ static float dc = (float)1E-25;
+ input += dc;
+ dc = -dc;
- /* allocate history array if different size than last call */
+ /* allocate history array if different size than last call */
- coef_ptr = iir.coef; /* coefficient pointer */
+ coef_ptr = iir.coef; /* coefficient pointer */
- hist1_ptr = iir.history; /* first history */
- hist2_ptr = hist1_ptr + 1; /* next history */
+ hist1_ptr = iir.history; /* first history */
+ hist2_ptr = hist1_ptr + 1; /* next history */
- /* 1st number of coefficients array is overall input scale factor,
- * or filter gain */
- output = input * (*coef_ptr++);
+ /* 1st number of coefficients array is overall input scale factor,
+ * or filter gain */
+ output = input * (*coef_ptr++);
- for (i = 0 ; i < iir.length; i++)
+ for (i = 0 ; i < iir.length; i++)
{
- history1 = *hist1_ptr; /* history values */
- history2 = *hist2_ptr;
+ history1 = *hist1_ptr; /* history values */
+ history2 = *hist2_ptr;
- output = output - history1 * coef_ptr[0];
- new_hist = output - history2 * coef_ptr[1]; /* poles */
+ output = output - history1 * coef_ptr[0];
+ new_hist = output - history2 * coef_ptr[1]; /* poles */
- output = new_hist + history1 * coef_ptr[2];
- output = output + history2 * coef_ptr[3]; /* zeros */
+ output = new_hist + history1 * coef_ptr[2];
+ output = output + history2 * coef_ptr[3]; /* zeros */
- coef_ptr += 4;
- *hist2_ptr++ = *hist1_ptr;
- *hist1_ptr++ = new_hist;
- hist1_ptr++;
- hist2_ptr++;
+ coef_ptr += 4;
+ *hist2_ptr++ = *hist1_ptr;
+ *hist1_ptr++ = new_hist;
+ hist1_ptr++;
+ hist2_ptr++;
}
- return(output);
+ return(output);
}
-void LowPass_Update(float resonance, float cutoff, int samplerate)
+void lpf_update(float resonance, float cutoff, int samplerate)
{
- unsigned nInd;
- double a0, a1, a2, b0, b1, b2;
- double fs; /* Sampling frequency, cutoff frequency */
- double k; /* overall gain factor */
- float *coef;
-
- k = 1.0; /* Set overall filter gain */
- coef = iir.coef + 1; /* Skip k, or gain */
- fs = (double)samplerate; /* Sampling frequency (Hz) */
-
-/*
- * Compute z-domain coefficients for each biquad section
- * for new Cutoff Frequency and Resonance
- */
- for (nInd = 0; nInd < iir.length; nInd++)
+ unsigned nInd;
+ double a0, a1, a2, b0, b1, b2;
+ double fs; /* Sampling frequency, cutoff frequency */
+ double k; /* overall gain factor */
+ float *coef;
+
+ k = 1.0; /* Set overall filter gain */
+ coef = iir.coef + 1; /* Skip k, or gain */
+ fs = (double)samplerate; /* Sampling frequency (Hz) */
+
+ /*
+ * Compute z-domain coefficients for each biquad section
+ * for new Cutoff Frequency and Resonance
+ */
+ for (nInd = 0; nInd < iir.length; nInd++)
{
- a0 = ProtoCoef[nInd].a0;
- a1 = ProtoCoef[nInd].a1;
- a2 = ProtoCoef[nInd].a2;
-
- b0 = ProtoCoef[nInd].b0;
- b1 = ProtoCoef[nInd].b1 / resonance; /* Divide by resonance or Q */
- b2 = ProtoCoef[nInd].b2;
- szxform(&a0, &a1, &a2, &b0, &b1, &b2, cutoff, fs, &k, coef);
- coef += 4; /* Point to next filter section */
+ a0 = ProtoCoef[nInd].a0;
+ a1 = ProtoCoef[nInd].a1;
+ a2 = ProtoCoef[nInd].a2;
+
+ b0 = ProtoCoef[nInd].b0;
+ b1 = ProtoCoef[nInd].b1 / resonance; /* Divide by resonance or Q */
+ b2 = ProtoCoef[nInd].b2;
+ szxform(&a0, &a1, &a2, &b0, &b1, &b2, cutoff, fs, &k, coef);
+ coef += 4; /* Point to next filter section */
}
- /* Update overall filter gain in coef array */
- iir.coef[0] = (float)k;
+ /* Update overall filter gain in coef array */
+ iir.coef[0] = (float)k;
}
@@ -132,54 +132,54 @@ void LowPass_Update(float resonance, float cutoff, int samplerate)
* of two second order sections.
* --------------------------------------------------------------------
*/
-signed char LowPass_Init()
+signed char lpf_init()
{
-/*
- * Setup filter s-domain coefficients
- */
- /* Section 1 */
- ProtoCoef[0].a0 = 1.0;
- ProtoCoef[0].a1 = 0;
- ProtoCoef[0].a2 = 0;
- ProtoCoef[0].b0 = 1.0;
- ProtoCoef[0].b1 = 0.765367;
- ProtoCoef[0].b2 = 1.0;
+ /*
+ * Setup filter s-domain coefficients
+ */
+ /* Section 1 */
+ ProtoCoef[0].a0 = 1.0;
+ ProtoCoef[0].a1 = 0;
+ ProtoCoef[0].a2 = 0;
+ ProtoCoef[0].b0 = 1.0;
+ ProtoCoef[0].b1 = 0.765367;
+ ProtoCoef[0].b2 = 1.0;
- /* Section 2 */
- ProtoCoef[1].a0 = 1.0;
- ProtoCoef[1].a1 = 0;
- ProtoCoef[1].a2 = 0;
- ProtoCoef[1].b0 = 1.0;
- ProtoCoef[1].b1 = 1.847759;
- ProtoCoef[1].b2 = 1.0;
+ /* Section 2 */
+ ProtoCoef[1].a0 = 1.0;
+ ProtoCoef[1].a1 = 0;
+ ProtoCoef[1].a2 = 0;
+ ProtoCoef[1].b0 = 1.0;
+ ProtoCoef[1].b1 = 1.847759;
+ ProtoCoef[1].b2 = 1.0;
+
+ iir.length = FILTER_SECTIONS; /* Number of filter sections */
+
+ /*
+ * Allocate array of z-domain coefficients for each filter section
+ * plus filter gain variable
+ */
+ iir.coef = (float *) calloc(4 * iir.length + 1, sizeof(float));
+ if (!iir.coef)
+ {
+ // printf("Unable to allocate coef array, exiting\n");
+ return 0;
+ }
- iir.length = FILTER_SECTIONS; /* Number of filter sections */
+ lpf_update(1.0, 5000.0, 44100);
-/*
- * Allocate array of z-domain coefficients for each filter section
- * plus filter gain variable
- */
- iir.coef = (float *) calloc(4 * iir.length + 1, sizeof(float));
- if (!iir.coef)
- {
-// printf("Unable to allocate coef array, exiting\n");
- return 0;
- }
-
- LowPass_Update(1.0, 5000.0, 44100);
-
- /* Display filter coefficients */
-// for (nInd = 0; nInd < (iir.length * 4 + 1); nInd++)
-// printf("C[%d] = %15.10f\n", nInd, iir.coef[nInd]);
-/*
- * To process audio samples, call function iir_filter()
- * for each audio sample
- */
- return 1;
+ /* Display filter coefficients */
+ // for (nInd = 0; nInd < (iir.length * 4 + 1); nInd++)
+ // printf("C[%d] = %15.10f\n", nInd, iir.coef[nInd]);
+ /*
+ * To process audio samples, call function iir_filter()
+ * for each audio sample
+ */
+ return 1;
}
-void LowPass_Close()
+void lpf_close()
{
}
@@ -254,11 +254,11 @@ void LowPass_Close()
void prewarp(double *a0, double *a1, double *a2, double fc, double fs);
void bilinear(
- double a0, double a1, double a2, /* numerator coefficients */
- double b0, double b1, double b2, /* denominator coefficients */
- double *k, /* overall gain factor */
- double fs, /* sampling rate */
- float *coef); /* pointer to 4 iir coefficients */
+ double a0, double a1, double a2, /* numerator coefficients */
+ double b0, double b1, double b2, /* denominator coefficients */
+ double *k, /* overall gain factor */
+ double fs, /* sampling rate */
+ float *coef); /* pointer to 4 iir coefficients */
/*
@@ -269,16 +269,16 @@ void bilinear(
* ----------------------------------------------------------
*/
void prewarp(
- double *a0, double *a1, double *a2,
- double fc, double fs)
+ double *a0, double *a1, double *a2,
+ double fc, double fs)
{
- double wp, pi;
+ double wp, pi;
- pi = 4.0 * atan(1.0);
- wp = 2.0 * fs * tan(pi * fc / fs);
+ pi = 4.0 * atan(1.0);
+ wp = 2.0 * fs * tan(pi * fc / fs);
- *a2 = (*a2) / (wp * wp);
- *a1 = (*a1) / wp;
+ *a2 = (*a2) / (wp * wp);
+ *a1 = (*a1) / wp;
}
@@ -312,30 +312,30 @@ void prewarp(
* ----------------------------------------------------------
*/
void bilinear(
- double a0, double a1, double a2, /* numerator coefficients */
- double b0, double b1, double b2, /* denominator coefficients */
- double *k, /* overall gain factor */
- double fs, /* sampling rate */
- float *coef /* pointer to 4 iir coefficients */
-)
+ double a0, double a1, double a2, /* numerator coefficients */
+ double b0, double b1, double b2, /* denominator coefficients */
+ double *k, /* overall gain factor */
+ double fs, /* sampling rate */
+ float *coef /* pointer to 4 iir coefficients */
+ )
{
- double ad, bd;
+ double ad, bd;
- /* alpha (Numerator in s-domain) */
- ad = 4. * a2 * fs * fs + 2. * a1 * fs + a0;
- /* beta (Denominator in s-domain) */
- bd = 4. * b2 * fs * fs + 2. * b1* fs + b0;
+ /* alpha (Numerator in s-domain) */
+ ad = 4. * a2 * fs * fs + 2. * a1 * fs + a0;
+ /* beta (Denominator in s-domain) */
+ bd = 4. * b2 * fs * fs + 2. * b1* fs + b0;
- /* update gain constant for this section */
- *k *= ad/bd;
+ /* update gain constant for this section */
+ *k *= ad/bd;
- /* Denominator */
- *coef++ = (float)((2. * b0 - 8. * b2 * fs * fs) / bd); /* beta1 */
- *coef++ = (float)((4. * b2 * fs * fs - 2. * b1 * fs + b0) / bd); /* beta2 */
+ /* Denominator */
+ *coef++ = (float)((2. * b0 - 8. * b2 * fs * fs) / bd); /* beta1 */
+ *coef++ = (float)((4. * b2 * fs * fs - 2. * b1 * fs + b0) / bd); /* beta2 */
- /* Nominator */
- *coef++ = (float)((2. * a0 - 8. * a2 * fs * fs) / ad); /* alpha1 */
- *coef = (float)((4. * a2 * fs * fs - 2. * a1 * fs + a0) / ad); /* alpha2 */
+ /* Nominator */
+ *coef++ = (float)((2. * a0 - 8. * a2 * fs * fs) / ad); /* alpha1 */
+ *coef = (float)((4. * a2 * fs * fs - 2. * a1 * fs + a0) / ad); /* alpha2 */
}
@@ -355,17 +355,17 @@ void bilinear(
* ----------------------------------------------------------
*/
void szxform(
- double *a0, double *a1, double *a2, /* numerator coefficients */
- double *b0, double *b1, double *b2, /* denominator coefficients */
- double fc, /* Filter cutoff frequency */
- double fs, /* sampling rate */
- double *k, /* overall gain factor */
- float *coef) /* pointer to 4 iir coefficients */
+ double *a0, double *a1, double *a2, /* numerator coefficients */
+ double *b0, double *b1, double *b2, /* denominator coefficients */
+ double fc, /* Filter cutoff frequency */
+ double fs, /* sampling rate */
+ double *k, /* overall gain factor */
+ float *coef) /* pointer to 4 iir coefficients */
{
- /* Calculate a1 and a2 and overwrite the original values */
- prewarp(a0, a1, a2, fc, fs);
- prewarp(b0, b1, b2, fc, fs);
- bilinear(*a0, *a1, *a2, *b0, *b1, *b2, k, fs, coef);
+ /* Calculate a1 and a2 and overwrite the original values */
+ prewarp(a0, a1, a2, fc, fs);
+ prewarp(b0, b1, b2, fc, fs);
+ bilinear(*a0, *a1, *a2, *b0, *b1, *b2, k, fs, coef);
}
diff --git a/src/lowpass.h b/src/lowpass.h
index 6c99212..0f50683 100644
--- a/src/lowpass.h
+++ b/src/lowpass.h
@@ -4,43 +4,34 @@
/* FILTER INFORMATION STRUCTURE FOR FILTER ROUTINES */
-#define FILTER_SECTIONS 2 /* 2 filter sections for 24 db/oct filter */
+#define FILTER_SECTIONS 2 /* 2 filter sections for 24 db/oct filter */
typedef struct {
- unsigned int length; /* size of filter */
- float history[2 * FILTER_SECTIONS]; /* history in filter */
- float *coef; /* pointer to coefficients of filter */
+ unsigned int length; /* size of filter */
+ float history[2 * FILTER_SECTIONS]; /* history in filter */
+ float *coef; /* pointer to coefficients of filter */
} FILTER;
typedef struct {
- double a0, a1, a2; /* numerator coefficients */
- double b0, b1, b2; /* denominator coefficients */
+ double a0, a1, a2; /* numerator coefficients */
+ double b0, b1, b2; /* denominator coefficients */
} BIQUAD;
static BIQUAD ProtoCoef[FILTER_SECTIONS]; /* Filter prototype coefficients,
- 1 for each filter section */
+ 1 for each filter section */
-void szxform(
- double *a0, double *a1, double *a2, /* numerator coefficients */
- double *b0, double *b1, double *b2, /* denominator coefficients */
- double fc, /* Filter cutoff frequency */
- double fs, /* sampling rate */
- double *k, /* overall gain factor */
- float *coef); /* pointer to 4 iir coefficients */
+void szxform(double *a0, double *a1, double *a2, /* numerator coefficients */
+ double *b0, double *b1, double *b2, /* denominator coefficients */
+ double fc, /* Filter cutoff frequency */
+ double fs, /* sampling rate */
+ double *k, /* overall gain factor */
+ float *coef); /* pointer to 4 iir coefficients */
+signed char lpf_init();
+void lpf_close();
+float lpf_filter(float input);
+void lpf_update(float resonance, float cutoff, int samplerate);
-#ifdef __cplusplus
- extern "C" {
-#endif
-
- signed char LowPass_Init();
- void LowPass_Close();
- float LowPass_Filter(float input);
- void LowPass_Update(float resonance, float cutoff, int samplerate);
-
-#ifdef __cplusplus
- }
-#endif
#endif
diff --git a/src/osc.h b/src/osc.h
index 0dc7b81..3a48bb5 100644
--- a/src/osc.h
+++ b/src/osc.h
@@ -96,5 +96,6 @@ OSC_COMMON_H(weird)
OSC_COMMON_H(sound)
OSC_COMMON_H(saw)
OSC_COMMON_H(digisaw)
+OSC_COMMON_H(sqr)
#endif /* OSC_H */
diff --git a/src/synth_engine.c b/src/synth_engine.c
index 1e82284..5c15565 100644
--- a/src/synth_engine.c
+++ b/src/synth_engine.c
@@ -4,7 +4,6 @@
#include "filter.h"
#include "control.h"
#include "sound.h"
-#include "wavetable.h"
#include "osc.h"
#include <string.h>
@@ -104,7 +103,9 @@ gen5(float f, midi_note_t * midi_note, float x, unsigned int sample_rate)
float
gen6(float f, midi_note_t * midi_note, float x, unsigned int sample_rate)
{
- return wvt_next(wvt_sqr, f, sample_rate, &midi_note->wvt_index);
+ float sample = osc_sqr(midi_note->wvt_index);
+ midi_note->wvt_index = osc_sqr_next(f, midi_note->wvt_index);
+ return sample;
}
float
@@ -194,7 +195,7 @@ make_sample(void *synthData, unsigned int sample_rate, int frame)
synth->x,
sample_rate);
- sample += 0.2 * rms * adsr * synth_sample;
+ sample += rms * adsr * synth_sample;
}
/* filter */
@@ -205,8 +206,8 @@ make_sample(void *synthData, unsigned int sample_rate, int frame)
//cutoff = cutoff + cutoff * (synth->lfo.amp) * lfo(cc_iget(&synth->cc_lfo_freq, frame, FRAMES_PER_BUFFER), synth->lfo.elapsed, sample_rate);
if (cutoff == 0) cutoff = 0.001;
- LowPass_Update(reso, cutoff, sample_rate);
- sample = LowPass_Filter(sample);
+ lpf_update(reso, cutoff, sample_rate);
+ sample = lpf_filter(sample);
update_bw_low_pass_filter(synth->fff, SAMPLE_RATE,cutoff, reso);
sample = bw_low_pass(synth->fff, sample);
@@ -293,9 +294,6 @@ get_frame(void *outputBuffer, synth_t *synth, int i)
*out++ = s;
*out++ = s;
- if (s > 1 || s < -1) {
- printf("!! %f !!\n", s);
- }
// move time
increment_synth(synth);
@@ -431,10 +429,10 @@ init_synth(synth_t * synth)
synth->modi = 0;
- synth->gain = 1;
+ synth->gain = 0.5;
synth->x = 1;
- synth->adsr.a = 0.0;
+ synth->adsr.a = 0.00001f;
synth->adsr.peak = 1.0f;
synth->adsr.d = 0.3;
synth->adsr.s = 0.7;
@@ -487,12 +485,11 @@ init_synth(synth_t * synth)
synth->viz.sample_rate_divider = 1;
synth->viz.wi = 0;
- LowPass_Init();
+ lpf_init();
synth->fff = create_bw_low_pass_filter(2, SAMPLE_RATE, 400);
synth->fff2 = create_bw_band_stop_filter(8, SAMPLE_RATE, 15000, 22000);
init_sound(synth, sound_gen);
- wvt_init();
synth->osctri = make_tri("triangle");
}
diff --git a/src/synth_gui.c b/src/synth_gui.c
index 8aef751..35c940a 100644
--- a/src/synth_gui.c
+++ b/src/synth_gui.c
@@ -157,7 +157,7 @@ draw_bars(synth_t * synth, int x, int y, int width, int height, int offset)
int count = 0;
snprintf(buf, sizeof buf, "%.3f", synth->adsr.a);
- synth->adsr.a = GuiSlider((Rectangle){ x, y + count++ * (height + offset), width, height }, "A: ", buf, synth->adsr.a , 0.0f, 2.0f);
+ synth->adsr.a = GuiSlider((Rectangle){ x, y + count++ * (height + offset), width, height }, "A: ", buf, synth->adsr.a , 0.00001f, 2.0f);
snprintf(buf, sizeof buf, "%.3f", synth->adsr.peak);
synth->adsr.peak = GuiSlider((Rectangle){ x, y + count++ * (height + offset), width, height }, "P: ", buf, synth->adsr.peak , 0.0f, 1.0f);
snprintf(buf, sizeof buf, "%.3f", synth->adsr.d);
@@ -192,18 +192,14 @@ draw_signals(synth_t * synth, int x, int y, int width, int height)
//GuiSpinner((Rectangle){ x+ 100, y - 24 - 6, 100, 24 }, "rate divider: ", &(synth->viz.sample_rate_divider), 1, 10, 0);
for (int i = x; i < WIDTH - x; i++) {
- DrawCircle(i , y + height / 2 + floor(250 * synth->viz.wave[i - x]), point_radius, RAYWHITE);
+ if (synth->viz.wave[i - x] > 1 || synth->viz.wave[i - x] < -1)
+ DrawCircle(i , y + height / 2 + floor(50 * synth->viz.wave[i - x]), point_radius, RED);
+ else if (synth->viz.wave[i - x] >= 0.99 || synth->viz.wave[i - x] <= -0.99)
+ DrawCircle(i , y + height / 2 + floor(50 * synth->viz.wave[i - x]), point_radius, MAGENTA);
+ else
+ DrawCircle(i , y + height / 2 + floor(50 * synth->viz.wave[i - x]), point_radius, RAYWHITE);
}
-/* float adsr_duration = synth->adsr.a + synth->adsr.d + (synth->adsr.a + synth->adsr.d + synth->adsr.r) / 3.0 + synth->adsr.r; */
-/* for (int i = x; i < WIDTH - x; i++) { */
-/* for (int j = 0; j < MIDI_NOTES; j++) { */
-/* if (!synth->midi_note[j].active) */
-/* continue; */
-
-/* DrawCircle(i , y + height - 1 + 4.5*floor((WIDTH / 24) * - fix_adsr(&synth->adsr, synth->midi_note[j].noteOn, synth->midi_note[j].noteOff, (i - x) * (adsr_duration * SAMPLE_RATE) / WIDTH, synth->midi_note[j].noteOffSample)), point_radius, BLUE); */
-/* } */
-/* } */
int c = 0;
for (int i = 0; i < MIDI_NOTES; i++) {
if (!synth->midi_note[i].active) continue;
@@ -212,35 +208,25 @@ draw_signals(synth_t * synth, int x, int y, int width, int height)
int x_prev = x;
for (int i = 0; i < MIDI_NOTES; i++) {
- if (!synth->midi_note[i].active)
- continue;
-
- int rec_y = y + height - 1 +
- 4.5 * floor( (WIDTH / 24) *
- - fix_adsr(&synth->adsr,
- synth->midi_note[i].noteOn,
- synth->midi_note[i].noteOff,
- synth->midi_note[i].elapsed,
- synth->midi_note[i].noteOffSample));
-
- int rec_width = (WIDTH - x - x) / c;
- int rec_height = HEIGHT - rec_y;
-
- //DrawLine(x_prev, v, x_prev + (WIDTH - x) / c, v , WHITE);
- DrawRectangleGradientV(x_prev, rec_y, rec_width, rec_height, ColorAlpha(GREEN, .2) ,ColorAlpha(RED, .2));
- DrawRectangleLines(x_prev, rec_y, rec_width, rec_height, GRAY);
- x_prev += rec_width;
- }
-
+ if (!synth->midi_note[i].active)
+ continue;
+
+ int rec_y = y + height - 1 +
+ 4.5 * floor( (WIDTH / 24) *
+ - fix_adsr(&synth->adsr,
+ synth->midi_note[i].noteOn,
+ synth->midi_note[i].noteOff,
+ synth->midi_note[i].elapsed,
+ synth->midi_note[i].noteOffSample));
+
+ int rec_width = (WIDTH - x - x) / c;
+ int rec_height = HEIGHT - rec_y;
- /* for (int i = x; i < WIDTH - x; i++) { */
- /* for (int j = 0; j < MIDI_NOTES; j++) { */
- /* if (!synth->midi_note[j].active) */
- /* continue; */
-
- /* DrawCircle(i , y + height - 1 + 4.5*floor((WIDTH / 24) * - fix_adsr(&synth->adsr, synth->midi_note[j].noteOn, synth->midi_note[j].noteOff, synth->midi_note[j].elapsed, synth->midi_note[j].noteOffSample)), point_radius, GREEN); */
- /* } */
- /* } */
+ //DrawLine(x_prev, v, x_prev + (WIDTH - x) / c, v , WHITE);
+ DrawRectangleGradientV(x_prev, rec_y, rec_width, rec_height, ColorAlpha(GREEN, .2) ,ColorAlpha(RED, .2));
+ DrawRectangleLines(x_prev, rec_y, rec_width, rec_height, GRAY);
+ x_prev += rec_width;
+ }
}
@@ -274,22 +260,13 @@ rayrun(void *synthData){
draw_bars(synth, 33, 20, 256, 20, 4);
draw_text(synth, f, WIDTH / 2 - 108, 20);
- /* if ( GuiButton((Rectangle){ WIDTH / 2 - 108, 150 - 42 - 6 - 6, 216, 6 }, "")) { */
- /* synth->freq_offset = 0; */
- /* } */
- /* snprintf(buf, sizeof buf, "freq offset %.1f", synth->freq_offset); */
- /* DrawText(buf, WIDTH / 2 - 108, 150 - 42, 20, LIGHTGRAY); */
- /* synth->freq_offset = GuiSlider((Rectangle){ WIDTH / 2 - 108, 150 - 42, 216, 24 }, "fine", buf, synth->freq_offset , -20.0f, 20.0f); */
-
if ( GuiButton((Rectangle){ WIDTH / 2 - 108, 150 - 6 - 6 + 42, 216, 6 }, "")) {
synth->x = 1;
}
snprintf(buf, sizeof buf, "%.1f", synth->x);
synth->x = GuiSlider((Rectangle){ WIDTH / 2 - 108, 150 + 42, 216, 24 }, "x", buf, synth->x , 0.0f, 2.0f);
- //synth->multi = GuiToggle((Rectangle){ WIDTH - 100 - 50 - 100 - 50 , 50, 100, 24 }, "!MULTI!", synth->multi);
synth->filter = GuiToggle((Rectangle){ WIDTH - 100 - 50 - 100 - 50 , 50 , 100, 24 }, "FILTER", synth->filter);
- //synth->poly = GuiToggle((Rectangle){ WIDTH - 100 - 50 - 100 - 50 , 50 + 24 + 6 + 24 + 6, 100, 24 }, "POLY", synth->poly);
GuiSpinner((Rectangle){ WIDTH - 100 - 50 , 50, 100, 24 }, "oct: ", &(synth->octave), 0, 7, 0);
snprintf(buf, sizeof buf, "generator %d --> ", synth->geni);
@@ -302,9 +279,9 @@ rayrun(void *synthData){
draw_signals(synth, 20, 390, WIDTH - 2*20, 200);
//DrawText("THE SYNTH!!!!!!!!!!!!!!!!!!1", WIDTH / 2 - 100, 50, 20, LIGHTGRAY);
- DrawText("KEYBOARD: Q .. ]", WIDTH / 2 -300, HEIGHT - 300 - 50, 20, LIGHTGRAY);
- snprintf(buf, sizeof buf, "stream time: %f", Pa_GetStreamTime(synth->stream));
- DrawText(buf, WIDTH / 2 -300, HEIGHT - 300, 11, LIGHTGRAY);
+ /* DrawText("KEYBOARD: Q .. ]", WIDTH / 2 -300, HEIGHT - 300 - 50, 20, LIGHTGRAY); */
+ /* snprintf(buf, sizeof buf, "stream time: %f", Pa_GetStreamTime(synth->stream)); */
+ /* DrawText(buf, WIDTH / 2 -300, HEIGHT - 300, 11, LIGHTGRAY); */
EndDrawing();
//----------------------------------------------------------------------------------