From b0128e30840dff1e7db7bcfd69e6fa4f09ed5fbe Mon Sep 17 00:00:00 2001 From: gramanas Date: Mon, 27 Nov 2023 01:03:38 +0200 Subject: wavetables --- src/midi.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/midi.c') diff --git a/src/midi.c b/src/midi.c index fbea43f..c65a298 100644 --- a/src/midi.c +++ b/src/midi.c @@ -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"); -- cgit v1.2.3