summaryrefslogtreecommitdiffstats
path: root/src/synth_engine.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/synth_engine.c')
-rw-r--r--src/synth_engine.c63
1 files changed, 42 insertions, 21 deletions
diff --git a/src/synth_engine.c b/src/synth_engine.c
index 4a4fd03..09c50bb 100644
--- a/src/synth_engine.c
+++ b/src/synth_engine.c
@@ -49,9 +49,6 @@ gen10(float f, unsigned long long phase, float x, unsigned int sample_rate)
float
gen110(float f, unsigned long long phase, float x, unsigned int sample_rate)
{
- /* return sawX_sample(0.5, f, 5, midi_note->elapsed, sample_rate) */
- /* + saw_sample(0.3, 2 * f / 5, midi_note->elapsed, sample_rate) */
- /* + sin_sample(0.2, f * 5.0 / 7.0 , midi_note->elapsed, sample_rate); */
float a = fmodf(phase, sample_rate/f);
return a > (sample_rate/f) / 2.0f ? 0.9999f : -0.9999f;
}
@@ -62,16 +59,6 @@ gen0(float f, midi_note_t * midi_note, float x, unsigned int sample_rate)
float sample = osc_sin(midi_note->wvt_index);
midi_note->wvt_index = osc_sin_next(f, midi_note->wvt_index);
return sample;
- /* return sin_sample(1, f, midi_note->elapsed, sample_rate); */
- //return chirp(midi_note->elapsed, f);
- /* return sqr_sample(0.1, f, 0.3, midi_note->elapsed, sample_rate) */
- /* + sqr_sample(0.1, f * 3.0 / 2.0 , 0.5, midi_note->elapsed, sample_rate) */
- /* + saw_sample(0.3, f, midi_note->elapsed, sample_rate) */
- /* + sin_sample(0.1, f, midi_note->elapsed, sample_rate) */
- /* + sin_sample(0.1, f * 5, midi_note->elapsed, sample_rate) */
- /* /\* + sin_sample(0.1, freq * 50 * 1021, midi_note->elapsed, sample_rate) *\/ */
- /* /\* + sin_sample(0.1, freq * 50 * 3531021, midi_note->elapsed, sample_rate) *\/ */
- /* + sin_sample(0.1, f * 7, midi_note->elapsed, sample_rate); */
}
float
@@ -244,6 +231,16 @@ add_to_viz(synth_t *synth, float sample)
}
void
+add_to_delay(synth_t *synth, float sample)
+{
+ synth->del[synth->deli++] = sample;
+
+ if (synth->deli >= SAMPLE_RATE * 10) {
+ synth->deli = 0;
+ }
+}
+
+void
increment_synth(synth_t *synth)
{
synth->lfo.elapsed++;
@@ -264,24 +261,41 @@ get_frame(void *outputBuffer, synth_t *synth, int i)
if (!synth->active) {
- *out++ = 0.0f;
- *out++ = 0.0f;
+ /* *out++ = 0.0f; */
+ /* *out++ = 0.0f; */
- add_to_viz(synth, 0.0f);
+ //add_to_viz(synth, 0.0f);
lfo_index = 0;
- return;
+ // return;
}
if (!notes_active(synth)) {
synth->active = 0;
- *out++ = 0.0f;
- *out++ = 0.0f;
- add_to_viz(synth, 0.0f);
+ /* *out++ = 0.0f; */
+ /* *out++ = 0.0f; */
+ //add_to_viz(synth, 0.0f);
lfo_index = 0;
- return;
+ // return;
+ }
+
+ if (!synth->delay) {
+ synth->counter = 0;
}
s = make_sample(synth, SAMPLE_RATE, i);
+ synth->counter++;
+ if (synth->counter >= (int)(synth->del_time * SAMPLE_RATE * 10)) {
+ int idx = (synth->deli - (int)(synth->del_time * SAMPLE_RATE * 10)) % (SAMPLE_RATE * 10);
+ float tmp;
+ if (idx >= 0) {
+ tmp = synth->del[idx];
+ } else {
+ tmp = synth->del[SAMPLE_RATE * 10 + idx];
+ }
+
+ s = clamp(s + synth->del_feedback * tmp, -1, 1);
+ }
+ add_to_delay(synth, s);
*out++ = s;
*out++ = s;
@@ -449,6 +463,13 @@ init_synth(synth_t * synth)
synth->octave = 3;
+ synth->delay = 0;
+ synth->del[SAMPLE_RATE * 10];
+ synth->deli = 0;
+ synth->del_time = .1;
+ synth->del_feedback = 0.5f;
+ synth->counter;
+
synth->poly = 0;
synth->multi = 0;
synth->filter = 1;