diff options
author | gramanas <anastasis.gramm2@gmail.com> | 2023-11-27 01:03:38 +0200 |
---|---|---|
committer | gramanas <anastasis.gramm2@gmail.com> | 2023-11-27 01:03:38 +0200 |
commit | b0128e30840dff1e7db7bcfd69e6fa4f09ed5fbe (patch) | |
tree | 633be15d0e962db8fd7f2254df7a852f53b85ddc | |
parent | fb31c071fe835c5ffd1f70d3558acecee2ed7f17 (diff) | |
download | synth-project-b0128e30840dff1e7db7bcfd69e6fa4f09ed5fbe.tar.gz synth-project-b0128e30840dff1e7db7bcfd69e6fa4f09ed5fbe.tar.bz2 synth-project-b0128e30840dff1e7db7bcfd69e6fa4f09ed5fbe.zip |
wavetables
-rw-r--r-- | src/midi.c | 14 | ||||
-rw-r--r-- | src/osc.c | 10 | ||||
-rw-r--r-- | src/osc_sound.c | 12 | ||||
-rw-r--r-- | src/synth_gui.c | 13 |
4 files changed, 36 insertions, 13 deletions
@@ -92,7 +92,19 @@ void midi_decode(uint32_t msg, synth_t * synth) { printf("Channel Pressure: channel=%d, pressure=%d\n", channel, data1); break; case 0x0E: - printf("Pitch Bend: channel=%d, value=%d\n", channel, ((data2 << 7) | data1) - 8192); + int val = ((data2 << 7) | data1) - 8192; + printf("Pitch Bend: channel=%d, value=%d\n", channel, val); + float pitch; + float semitones = 2; + if (val == 0) { + pitch = 1; + } else if (val > 0) { + pitch = 1 + ((float)val / 8191) * semitones * pow(2.0, 1.0 / 12.0) / 12; + } else { + pitch = 1 + ((float)val / 8192) * semitones * pow(2.0, 1.0 / 12.0) / 12; + } + synth->cc_pitch.target = pitch; + /* cc_step(synth->cc_pitch, 1); */ break; default: printf("Unknown MIDI message\n"); @@ -21,17 +21,19 @@ osc_interpolate(float offset, float start, float end) { int osc_next_index(osc_t * osc, float offset) { - if (offset >= osc->len) offset = 0; + if (offset >= osc->len) offset = fmodf(osc->start + offset, osc->len - osc->start); + if (offset < osc->start) offset = osc->start + fmodf(osc->start + offset, osc->len - osc->start); int current_index = (int)offset; - return current_index + 1 >= osc->len ? 0 : current_index + 1; + return current_index + 1 >= osc->len ? osc->start : current_index + 1; } float osc_next_offset(osc_t * osc, float f, float offset) { - if (offset >= osc->len) offset = 0; + if (offset >= osc->len) offset = fmodf(osc->start + offset, osc->len - osc->start); + if (offset < osc->start) offset = osc->start + fmodf(osc->start + offset, osc->len - osc->start); if (osc->type == SAMPLE) { // this makes A2 be the base ??? @@ -40,7 +42,7 @@ osc_next_offset(osc_t * osc, float f, float offset) f = f / (16.35160 * pow(2, (2 + 5 / 12.0))); } - float step = f * ((float)osc->len / SAMPLE_RATE); + float step = f * ((osc->len - osc->start) / (float)SAMPLE_RATE); offset += step; if (offset >= osc->len) { diff --git a/src/osc_sound.c b/src/osc_sound.c index 2a0d519..49d9867 100644 --- a/src/osc_sound.c +++ b/src/osc_sound.c @@ -13,14 +13,20 @@ osc_t OSC_sound = { OSC_COMMON(sound) +int wvt_size = 2048; + float osc_sound(float offset) { if (!OSC_sound.len) { -// osc_load_wav(&OSC_sound, "/home/gramanas/code/synth-project/waves/test_lick.wav"); + // osc_load_wav(&OSC_sound, "/home/gramanas/code/synth-project/waves/test_lick.wav"); //osc_load_wav(&OSC_sound, "/home/gramanas/code/synth-project/waves/Free Wavetables[128]/FM Synthesis[128-44.1khz-16bit]/FM Sq- NotPM.wav"); - osc_load_wav(&OSC_sound, "/home/gramanas/code/synth-project/waves/Free Wavetables[2048]/Melda Oscillator[2048-44.1khz-32bit]/Melda CustumWave2.wav"); - OSC_sound.len = 2048; + //osc_load_wav(&OSC_sound, "/home/gramanas/code/synth-project/waves/Free Wavetables[2048]/Melda Oscillator[2048-44.1khz-32bit]/Melda SKEW.wav"); + //osc_load_wav(&OSC_sound, "/home/gramanas/code/synth-project/waves/Free Wavetables[2048]/Filter Sweep[2048-44.1khz-32bit]/SweepSaw.wav"); + //osc_load_wav(&OSC_sound, "/home/gramanas/code/synth-project/waves/Free Wavetables[2048]/Additive Synth[2048-44.1khz-32bit]/Add Synth7.wavw"); + osc_load_wav(&OSC_sound, "/home/gramanas/code/synth-project/waves/Free Wavetables[2048]/Korg Analog Synth PhaseShift[2048-44.1khz-32bit]/MS 20 Saw MPS.wav"); + OSC_sound.start = wvt_size*0; + OSC_sound.len = OSC_sound.start + wvt_size; } return osc_interpolate(offset, diff --git a/src/synth_gui.c b/src/synth_gui.c index bb394c7..dd4c75b 100644 --- a/src/synth_gui.c +++ b/src/synth_gui.c @@ -357,7 +357,8 @@ draw_fft(synth_t *synth, int x, int y, int width, int height) void draw_osc(synth_t * synth, int x, int y, int width, int height) { - DrawRectangleLines(x - 3, y - 3, width + 6, height + 6, GREEN); + DrawRectangle(x, y, width, height, BLACK); + DrawRectangleLines(x, y, width, height, WHITE); float osc_wave[width]; for (int i = 0; i < width; i++) { osc_wave[i] = 0; @@ -371,7 +372,7 @@ draw_osc(synth_t * synth, int x, int y, int width, int height) note_dup.noteOn = note->noteOn; note_dup.noteOff = note->noteOff; note_dup.velocity = note->velocity; - note_dup.wvt_index = synth->geni == 4 ? note->wvt_index : 0; + note_dup.wvt_index = 0; note_dup.lfo_index = note->lfo_index; note_dup.elapsed = note->elapsed; note_dup.noteOffSample = note->noteOffSample; @@ -442,7 +443,7 @@ draw_signals(synth_t * synth, int x, int y, int width, int height) synth->viz.osc_enabled = GuiCheckBox((Rectangle){ x + width - 170, y, 16, 16 }, "osc", synth->viz.osc_enabled); if (synth->viz.osc_enabled) { - draw_osc(synth, x + width - 170 - 40, y + 80, 80, 80); + draw_osc(synth, x + width - 80, y + height - 80, 80, 80); } } @@ -468,9 +469,11 @@ rayrun(synth_t *synth){ // GUI char buf[64]; - + osc_sound(0); snprintf(buf, sizeof buf, "%d", len); - len = GuiSlider((Rectangle){WIDTH / 2 - 108, 150 + 42 + 42, 216, 24 }, "", buf, len , 0, 99); + len = GuiSlider((Rectangle){WIDTH / 2 - 108, 150 + 42 + 42, 216, 24 }, "", buf, len , 0, 157); + set_sound_start(len*2048); + set_sound_len(len*2048 + 2048); draw_bars(synth, 33, 20, 256, 20, 4); draw_text(synth, f, WIDTH / 2 - 108, 20); |