diff options
-rw-r--r-- | src/osc_tri.c | 10 | ||||
-rw-r--r-- | src/synth_engine.c | 19 | ||||
-rw-r--r-- | src/synth_gui.c | 47 | ||||
-rw-r--r-- | tetris.mid | bin | 0 -> 16647 bytes |
4 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; diff --git a/tetris.mid b/tetris.mid Binary files differnew file mode 100644 index 0000000..5b3a038 --- /dev/null +++ b/tetris.mid |