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.c62
1 files changed, 34 insertions, 28 deletions
diff --git a/src/synth_engine.c b/src/synth_engine.c
index a4d3d17..9dbf2c5 100644
--- a/src/synth_engine.c
+++ b/src/synth_engine.c
@@ -4,6 +4,7 @@
#include "filter.h"
#include "control.h"
#include "sound.h"
+#include "wavetable.h"
#include <string.h>
@@ -67,47 +68,50 @@ gen110(float f, unsigned long long phase, float x, unsigned int sample_rate)
}
float
-gen0(float f, unsigned long long phase, float x, unsigned int sample_rate)
+gen0(float f, midi_note_t * midi_note, float x, unsigned int sample_rate)
{
- return sin_sample(1, f, phase, sample_rate);
- //return chirp(phase, f);
- /* return sqr_sample(0.1, f, 0.3, phase, sample_rate) */
- /* + sqr_sample(0.1, f * 3.0 / 2.0 , 0.5, phase, sample_rate) */
- /* + saw_sample(0.3, f, phase, sample_rate) */
- /* + sin_sample(0.1, f, phase, sample_rate) */
- /* + sin_sample(0.1, f * 5, phase, sample_rate) */
- /* /\* + sin_sample(0.1, freq * 50 * 1021, phase, sample_rate) *\/ */
- /* /\* + sin_sample(0.1, freq * 50 * 3531021, phase, sample_rate) *\/ */
- /* + sin_sample(0.1, f * 7, phase, sample_rate); */
+ 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
-gen1(float f, unsigned long long phase, float x, unsigned int sample_rate)
+gen1(float f, midi_note_t * midi_note, float x, unsigned int sample_rate)
{
- //return saw_sample(1, f, phase, sample_rate);
- return sawX_sample(0.5, f, 5, phase, sample_rate)
- + saw_sample(0.3, 2 * f / 5, phase, sample_rate)
- + sin_sample(0.2, f * 5.0 / 7.0 , phase, sample_rate);
+ //return saw_sample(1, f, midi_note->elapsed, 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
-gen2(float f, unsigned long long phase, float x, unsigned int sample_rate)
+gen2(float f, midi_note_t * midi_note, float x, unsigned int sample_rate)
{
- /* return sin_sample(0.5, f * sqrt(2) , phase, sample_rate) */
- /* + sin_sample(0.5, f, phase, sample_rate); */
+ /* return sin_sample(0.5, f * sqrt(2) , midi_note->elapsed, sample_rate) */
+ /* + sin_sample(0.5, f, midi_note->elapsed, sample_rate); */
- return sawX_sample(1, f, 15, phase, sample_rate);
+ return sawX_sample(1, f, 15, midi_note->elapsed, sample_rate);
}
float
-gen3(float f, unsigned long long phase, float x, unsigned int sample_rate)
+gen3(float f, midi_note_t * midi_note, float x, unsigned int sample_rate)
{
- return sqr_sample(1, f, .5, phase, sample_rate);
- /* return sawX_sample(0.7, f, 5, phase, sample_rate) */
- /* + sin_sample(0.3, 4.0/17.0*f, phase, sample_rate); */
- /* return saw_sample(0.5, f * (1 + sqrt(5)) / 2, phase, sample_rate) */
- /* + sin_sample(0.3, f * x, phase, sample_rate) */
- /* + sqr_sample(0.2, f * x, 0.2 * x * x, phase, sample_rate); */
+ //return sqr_sample(1, f, .5, midi_note->elapsed, sample_rate);
+
+ return wvt_next(wvt_saw, f, sample_rate, &midi_note->wvt_index);
+
+ /* return sawX_sample(0.7, f, 5, midi_note->elapsed, sample_rate) */
+ /* + sin_sample(0.3, 4.0/17.0*f, midi_note->elapsed, sample_rate); */
+ /* return saw_sample(0.5, f * (1 + sqrt(5)) / 2, midi_note->elapsed, sample_rate) */
+ /* + sin_sample(0.3, f * x, midi_note->elapsed, sample_rate) */
+ /* + sqr_sample(0.2, f * x, 0.2 * x * x, midi_note->elapsed, sample_rate); */
}
float
@@ -133,6 +137,7 @@ notes_active(synth_t *synth)
synth->midi_note[i].channel = -1;
synth->midi_note[i].noteOn = -1;
synth->midi_note[i].noteOff = -1;
+ synth->midi_note[i].wvt_index = 0;
synth->midi_note[i].velocity = -1;
synth->midi_note[i].elapsed = -1;
synth->midi_note[i].active = 0;
@@ -178,7 +183,7 @@ make_sample(void *synthData, unsigned int sample_rate, int frame)
float targ_freq_with_repitch = synth->midi_note[i].freq * cc_iget(&synth->cc_pitch, frame, FRAMES_PER_BUFFER);
float synth_sample = synth->gen[synth->geni](targ_freq,
- synth->midi_note[i].elapsed,
+ &synth->midi_note[i],
synth->x,
sample_rate);
@@ -460,6 +465,7 @@ init_synth(synth_t * synth)
synth->fff2 = create_bw_band_stop_filter(8, SAMPLE_RATE, 15000, 22000);
init_sound(synth, sound_gen);
+ wvt_init();
}
void