diff --git a/src/Performance.c b/src/Performance.c index 54a24d0..d860b3d 100644 --- a/src/Performance.c +++ b/src/Performance.c @@ -585,6 +585,14 @@ static void DmPerformance_playPattern(DmPerformance* slf, DmPattern* pttn) { int16_t start = curve.start_value; int16_t end = curve.end_value; + // Some MIDI control curves have invalid ranges (e.g. -22000 to 127) + bool start_in_range = start >= 0 && start <= 127; + bool end_in_range = end >= 0 && end <= 127; + if (curve.event_type == DmCurveType_CONTROL_CHANGE && !(start_in_range && end_in_range)) { + Dm_report(DmLogLevel_DEBUG, "DmPerformance: Curve is out-of-range"); + continue; + } + float prev_value = start; // TODO(lmichaelis): Check whether this is actually correct! for (uint32_t k = 0; k < (duration / DmInt_CURVE_SPACING); ++k) { diff --git a/src/Synth.c b/src/Synth.c index e309745..cbd4f8a 100644 --- a/src/Synth.c +++ b/src/Synth.c @@ -241,10 +241,17 @@ size_t DmSynth_render(DmSynth* slf, void* buf, size_t len, DmRenderOptions fmt) tsf_set_output(slf->channels[i].synth, TSF_MONO, 44100, 0); } + float vol = slf->channels[i].volume; + if (vol < 0) { + vol = 0; + } else if (vol > 1) { + vol = 1; + } + if (fmt & DmRender_FLOAT) { - tsf_render_float(slf->channels[i].synth, buf, (int) len / channels, true, slf->channels[i].volume); + tsf_render_float(slf->channels[i].synth, buf, (int) len / channels, true, vol); } else { - tsf_render_short(slf->channels[i].synth, buf, (int) len / channels, true, slf->channels[i].volume); + tsf_render_short(slf->channels[i].synth, buf, (int) len / channels, true, vol); } }