Skip to content

Commit cf81781

Browse files
committed
misc
1 parent 8cca5b8 commit cf81781

File tree

5 files changed

+37
-17
lines changed

5 files changed

+37
-17
lines changed

src/midi.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const CCMapping cc_map[] = {
2626
{11, "osc1.pulse_width", 0.0f, 1.0f}, // CC 11: Expression → OSC 1 Pulse Width
2727
{12, "osc2.pitch", -24.0f, 24.0f}, // CC 12: Effect Control 1 → OSC 2 Pitch Bend
2828
{13, "osc2.detune", -1.0f, 1.0f}, // CC 13: Effect Control 2 → OSC 2 Detune
29-
{14, "osc3.gain", 0.0f, 1.0f}, // CC 14: (Undefined/Unused) → OSC 3 Gain
29+
{14, "osc2.gain", 0.0f, 1.0f}, // CC 14: (Undefined/Unused) → OSC 2 Gain
30+
{15, "osc3.gain", 0.0f, 1.0f}, // CC 15: (Undefined/Unused) → OSC 3 Gain
3031
{15, "osc3.waveform", 0.0f, 4.0f}, // CC 15: (Undefined/Unused) → OSC 3 Waveform Select
3132
{16, "osc4.pitch", -24.0f, 24.0f}, // CC 16: General Purpose Controller 1 → OSC 4 Pitch Bend
3233
{17, "osc4.detune", -1.0f, 1.0f}, // CC 17: General Purpose Controller 2 → OSC 4 Detune
@@ -46,9 +47,10 @@ const CCMapping cc_map[] = {
4647
{30, "fx.delay.mix", 0.0f, 1.0f}, // CC 30: (Undefined) → Delay Mix
4748

4849
// STANDARD MIDI CONTROLLERS (CC 32-63)
50+
{33, "osc4.gain", 0.0f, 1.0f}, // CC 33: (Undefined) → OSC 4 Gain
4951
{34, "osc4.waveform", 0.0f, 4.0f}, // CC 34: LSB of Bank Select → OSC 4 Waveform
50-
{35, "osc4.waveform", 0.0f, 4.0f}, // CC 35: LSB of Bank Select → OSC 4 Waveform
51-
{36, "osc3.waveform", 0.0f, 4.0f}, // CC 36: LSB of Bank Select → OSC 3 Waveform
52+
{35, "osc3.waveform", 0.0f, 4.0f}, // CC 35: LSB of Bank Select → OSC 3 Waveform
53+
{36, "osc2.waveform", 0.0f, 4.0f}, // CC 36: LSB of Bank Select → OSC 2 Waveform
5254
{37, "osc2.waveform", 0.0f, 4.0f}, // CC 37: LSB of Bank Select → OSC 2 Waveform
5355
{38, "osc1.waveform", 0.0f, 4.0f}, // CC 38: LSB of Bank Select → OSC 1 Waveform
5456
{39, "mixer.comp.threshold", -24.0f, 0.0f}, // CC 39: LSB of Bank Select → Compressor Threshold

src/mixer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ static void calculate_coefficients(BusCompressor *comp, float attack_ms, float r
7979
void mixer_init(Mixer *mixer) {
8080
// Set oscillator gains
8181
mixer->osc_gain[0] = 1.0f; // OSC 1 - full volume
82-
mixer->osc_gain[1] = 0.0f; // OSC 2 - muted
83-
mixer->osc_gain[2] = 0.0f; // OSC 3 - muted
84-
mixer->osc_gain[3] = 0.0f; // OSC 4 - muted
82+
mixer->osc_gain[1] = 1.0f; // OSC 2 - full volume
83+
mixer->osc_gain[2] = 1.0f; // OSC 3 - full volume
84+
mixer->osc_gain[3] = 1.0f; // OSC 4 - full volume
8585

8686
mixer->master = 0.25f; // Reduced from 1.0f to 0.25f
8787
mixer->master_pan = 0.0f; // Center pan by default

src/osc.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,33 @@ void osc_set_param(Oscillator *osc, const char *param, float value) {
4040

4141
float osc_process(Oscillator *osc, float note, float *phase_acc) {
4242
float output = 0.0f;
43+
float unison_phase_acc = 0.0f; // Local phase accumulator for unison calculation
4344

4445
// Process unison voices
4546
for (int voice = 0; voice < osc->unison_voices; ++voice) {
4647
// Calculate frequency with unison detuning
4748
float voice_detune = 0.0f;
4849
if (osc->unison_voices > 1 && osc->unison_detune > 0.0f) {
4950
// Spread voices symmetrically around center frequency
50-
float spread = (float)(voice - (osc->unison_voices - 1) * 0.5f) / (osc->unison_voices - 1);
51+
float spread = (float)(voice - (osc->unison_voices - 1) * 0.5f) / (float)(osc->unison_voices - 1);
5152
voice_detune = spread * osc->unison_detune;
5253
}
5354

5455
float freq = 440.0f * powf(2.0f, (note + osc->pitch + osc->detune + voice_detune - 69.0f) / 12.0f);
55-
*phase_acc += freq / osc->samplerate;
56-
if (*phase_acc >= 1.0f)
57-
*phase_acc -= 1.0f;
56+
57+
// Update the main phase accumulator for the first voice, use local for others
58+
if (voice == 0) {
59+
*phase_acc += freq / osc->samplerate;
60+
if (*phase_acc >= 1.0f)
61+
*phase_acc -= 1.0f;
62+
unison_phase_acc = *phase_acc;
63+
} else {
64+
unison_phase_acc += freq / osc->samplerate;
65+
if (unison_phase_acc >= 1.0f)
66+
unison_phase_acc -= 1.0f;
67+
}
5868

59-
float p = *phase_acc + osc->phase;
69+
float p = unison_phase_acc + osc->phase;
6070
if (p >= 1.0f)
6171
p -= 1.0f;
6272

src/synth.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ void synth_audio_callback(void *userdata, Uint8 *stream, int len) {
275275
memset(vbuf, 0, sizeof(float) * frames * 2);
276276
voice_render(&synth->voices[v], synth->osc, synth->lfos, synth->mixer.osc_gain, vbuf, frames);
277277
for (int i = 0; i < frames * 2; ++i)
278-
out[i] += vbuf[i] * synth->voices[v].velocity;
278+
out[i] += vbuf[i];
279279
}
280280
free(vbuf);
281281

@@ -324,8 +324,16 @@ void synth_handle_cc(Synth *synth, int cc, int value) {
324324
void synth_set_param(Synth *synth, const char *param, float value) {
325325
if (strncmp(param, "osc", 3) == 0) {
326326
int i = param[3] - '1';
327-
if (i >= 0 && i < 4)
328-
osc_set_param(&synth->osc[i], param + 5, value);
327+
if (i >= 0 && i < 4) {
328+
// Handle gain parameter specially - route to mixer instead of oscillator
329+
if (strncmp(param + 5, "gain", 4) == 0) {
330+
// Set mixer gain for this oscillator
331+
synth->mixer.osc_gain[i] = value;
332+
} else {
333+
// Set other oscillator parameters normally
334+
osc_set_param(&synth->osc[i], param + 5, value);
335+
}
336+
}
329337
} else if (strncmp(param, "fx.", 3) == 0) {
330338
fx_set_param(&synth->fx, param + 3, value);
331339
} else if (strncmp(param, "mixer.", 6) == 0) {

src/voice.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ void voice_render(Voice *v, const Oscillator *osc, const LFO *lfo, const float *
7575
left *= v->velocity * adsr_value;
7676
right *= v->velocity * adsr_value;
7777

78-
// Average across oscillators and add to stereo buffer
79-
stereo[n * 2 + 0] += left * (1.0f / 4.0f); // Left channel
80-
stereo[n * 2 + 1] += right * (1.0f / 4.0f); // Right channel
78+
// Add to stereo buffer (no averaging - oscillator gains handle mixing)
79+
stereo[n * 2 + 0] += left; // Left channel
80+
stereo[n * 2 + 1] += right; // Right channel
8181
}
8282
}
8383

0 commit comments

Comments
 (0)