From 801ea22d3eb9e622b5fe96a4bcfdd6e48c830f3a Mon Sep 17 00:00:00 2001 From: Anachronaut Date: Sat, 14 Mar 2026 09:23:08 -0400 Subject: [PATCH] Mapped oscillator pulse width to modulation wheel. --- include/synth.h | 2 +- source/midi.c | 6 ++++++ source/soundThing.c | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/synth.h b/include/synth.h index 9e16732..cac8cc8 100644 --- a/include/synth.h +++ b/include/synth.h @@ -3,7 +3,7 @@ #include -#define VOICE_COUNT 8 +#define VOICE_COUNT 16 typedef enum { WAVE_SINE, diff --git a/source/midi.c b/source/midi.c index db28f44..3db930e 100644 --- a/source/midi.c +++ b/source/midi.c @@ -96,12 +96,18 @@ void *midiThread(void *arg) synthNoteOff(m->synth, ev->data.note.note); break; case SND_SEQ_EVENT_CONTROLLER: + // This are controller parameter changes. + // Map the Mod Wheel to PWM: + if (ev->data.control.param == 1) + m->synth->dutyCycle = 0.05f + (ev->data.control.value / 127.0f) * 0.90f; + // This naively maps parameter 70 to the waveform in a way that does not play so nice with real pots. if (ev->data.control.param == 70) m->synth->waveform = ev->data.control.value % WAVE_COUNT; break; case SND_SEQ_EVENT_PITCHBEND: m->synth->pitchBend = ev->data.control.value / 8191.0f; break; + } snd_seq_free_event(ev); ev = NULL; diff --git a/source/soundThing.c b/source/soundThing.c index 2a8c442..cdc09cf 100644 --- a/source/soundThing.c +++ b/source/soundThing.c @@ -79,6 +79,8 @@ int main(void) 20, 55, 20, RAYWHITE); DrawText(TextFormat("MIDI: client %d port %d", gMidi.client, gMidi.port), 20, 90, 20, GRAY); + if (gSynth.waveform == WAVE_PULSE) + DrawText(TextFormat("Duty Cycle: %.2f", gSynth.dutyCycle), 20, 280, 20, GREEN); EndDrawing(); }