summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2023-09-08 11:06:49 +0300
committergramanas <anastasis.gramm2@gmail.com>2023-09-08 11:06:49 +0300
commit70d0d8ab25a1a9e92aa3016b661b0a9fe1c3c7cb (patch)
tree7a6825afb471ee0cd6e63c192fe7363cf06779fd /src
parent1ef25d9be2b5358f3da7429bf0b27d5a9e9fa1a8 (diff)
downloadsynth-project-70d0d8ab25a1a9e92aa3016b661b0a9fe1c3c7cb.tar.gz
synth-project-70d0d8ab25a1a9e92aa3016b661b0a9fe1c3c7cb.tar.bz2
synth-project-70d0d8ab25a1a9e92aa3016b661b0a9fe1c3c7cb.zip
tmp
Diffstat (limited to 'src')
-rw-r--r--src/osc_tri.c10
-rw-r--r--src/synth_engine.c19
-rw-r--r--src/synth_gui.c47
3 files changed, 52 insertions, 24 deletions
diff --git a/src/osc_tri.c b/src/osc_tri.c
index 8dd3d41..fc3665d 100644
--- a/src/osc_tri.c
+++ b/src/osc_tri.c
@@ -3,16 +3,18 @@
osc_t OSC_tri = {
.name = "w_triangle",
.start = 0,
- .end = 2,
- .len = 2,
+ .end = 4,
+ .len = 4,
};
static float
tri(int index)
{
- if (index == 0) return -1.0f;
+ if (index == 0) return 0.0f;
else if (index == 1) return 1.0f;
- else return 0.0f;
+ else if (index == 2) return 0.0f;
+ else if (index == 3) return -1.0f;
+ //else return 0.0f;
}
float
diff --git a/src/synth_engine.c b/src/synth_engine.c
index 09c50bb..1e82284 100644
--- a/src/synth_engine.c
+++ b/src/synth_engine.c
@@ -183,8 +183,10 @@ make_sample(void *synthData, unsigned int sample_rate, int frame)
targ_freq = targ_freq + targ_freq *
cc_iget(&synth->cc_lfo_amp, frame, FRAMES_PER_BUFFER) *
// (1.05946309436/24.0) *
- (wvt_next(wvt_tri, (wvt_next(wvt_sound, 2 * cc_iget(&synth->cc_lfo_freq, frame, FRAMES_PER_BUFFER), SAMPLE_RATE, &lfo_index) / 2.0 + 0.5) * cc_iget(&synth->cc_lfo_freq, frame, FRAMES_PER_BUFFER), SAMPLE_RATE, &synth->midi_note[i].lfo_index) / 2.0 + 0.5);
+ osc_sin(synth->midi_note[i].lfo_index);
+ //(wvt_next(wvt_tri, (wvt_next(wvt_sound, 2 * cc_iget(&synth->cc_lfo_freq, frame, FRAMES_PER_BUFFER), SAMPLE_RATE, &lfo_index) / 2.0 + 0.5) * cc_iget(&synth->cc_lfo_freq, frame, FRAMES_PER_BUFFER), SAMPLE_RATE, &synth->midi_note[i].lfo_index) / 2.0 + 0.5);
+ synth->midi_note[i].lfo_index = osc_sin_next(cc_iget(&synth->cc_lfo_freq, frame, FRAMES_PER_BUFFER), synth->midi_note[i].lfo_index);
/* float synth_sample = synth->osctri->ops->sample(synth->osctri, synth->midi_note[i].wvt_index); */
/* synth->midi_note[i].wvt_index = synth->osctri->ops->next(synth->osctri, targ_freq, synth->midi_note[i].wvt_index); */
float synth_sample = synth->gen[synth->geni](targ_freq,
@@ -261,21 +263,12 @@ get_frame(void *outputBuffer, synth_t *synth, int i)
if (!synth->active) {
- /* *out++ = 0.0f; */
- /* *out++ = 0.0f; */
-
- //add_to_viz(synth, 0.0f);
lfo_index = 0;
- // return;
}
if (!notes_active(synth)) {
synth->active = 0;
- /* *out++ = 0.0f; */
- /* *out++ = 0.0f; */
- //add_to_viz(synth, 0.0f);
lfo_index = 0;
- // return;
}
if (!synth->delay) {
@@ -295,10 +288,14 @@ get_frame(void *outputBuffer, synth_t *synth, int i)
s = clamp(s + synth->del_feedback * tmp, -1, 1);
}
+
add_to_delay(synth, s);
*out++ = s;
*out++ = s;
+ if (s > 1 || s < -1) {
+ printf("!! %f !!\n", s);
+ }
// move time
increment_synth(synth);
@@ -406,7 +403,7 @@ sound_gen(const void *inputBuffer, void *outputBuffer,
get_frame(buffer, synth, i);
}
// process buffer
- if (synth->multi) process(buffer);
+ //if (synth->multi) process(buffer);
// output buffer
for( unsigned long i=0; i<framesPerBuffer * 2; i += 2 ) {
diff --git a/src/synth_gui.c b/src/synth_gui.c
index 89782ed..8aef751 100644
--- a/src/synth_gui.c
+++ b/src/synth_gui.c
@@ -165,7 +165,7 @@ draw_bars(synth_t * synth, int x, int y, int width, int height, int offset)
snprintf(buf, sizeof buf, "%.3f", synth->adsr.s);
synth->adsr.s = GuiSlider((Rectangle){ x, y + count++ * (height + offset), width, height }, "S: ", buf, synth->adsr.s , 0.0f, 1.0f);
snprintf(buf, sizeof buf, "%.3f", synth->adsr.r);
- synth->adsr.r = GuiSlider((Rectangle){ x, y + count++ * (height + offset), width, height }, "R: ", buf, synth->adsr.r , -0.001f, 3.0f);
+ synth->adsr.r = GuiSlider((Rectangle){ x, y + count++ * (height + offset), width, height }, "R: ", buf, synth->adsr.r , 0.001f, 3.0f);
snprintf(buf, sizeof buf, "%.3f", synth->cutoff);
synth->cutoff = GuiSliderBar((Rectangle){ x, y + count++ * (height + offset), width, height }, "fC: ", buf, synth->cutoff , 0.0f, 11000.0f);
/* snprintf(buf, sizeof buf, "%.3f", synth->resonance); */
@@ -189,10 +189,10 @@ draw_signals(synth_t * synth, int x, int y, int width, int height)
int point_radius = 1.5;
- GuiSpinner((Rectangle){ x+ 100, y - 24 - 6, 100, 24 }, "rate divider: ", &(synth->viz.sample_rate_divider), 1, 10, 0);
+ //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, MAGENTA);
+ DrawCircle(i , y + height / 2 + floor(250 * 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; */
@@ -204,17 +204,46 @@ draw_signals(synth_t * synth, int x, int y, int width, int height)
/* 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); */
/* } */
/* } */
- for (int i = x; i < WIDTH - x; i++) {
- for (int j = 0; j < MIDI_NOTES; j++) {
- if (!synth->midi_note[j].active)
+ int c = 0;
+ for (int i = 0; i < MIDI_NOTES; i++) {
+ if (!synth->midi_note[i].active) continue;
+ c++;
+ }
+
+ int x_prev = x;
+ for (int i = 0; i < MIDI_NOTES; i++) {
+ if (!synth->midi_note[i].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);
+ 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;
}
- }
+
+
+ /* 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); */
+ /* } */
+ /* } */
}
-#include "raystyle.h"
+
void
rayrun(void *synthData){
synth_t * synth = (synth_t *)synthData;