From 89080564b4c47296fba4fd33471da2fe5d768b3a Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 11 May 2023 10:19:48 -0500 Subject: [PATCH] synthio: Fix release time of zero-sustain envelopes When there's no sustain, the release step needs to be calculated from the attack level, not the sustain level. Otherwise, contrary to intent, this leads to the actual release taking a loooonnngg time. --- shared-bindings/synthio/__init__.c | 2 +- shared-module/synthio/__init__.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shared-bindings/synthio/__init__.c b/shared-bindings/synthio/__init__.c index 2739d81e88..de1366717c 100644 --- a/shared-bindings/synthio/__init__.c +++ b/shared-bindings/synthio/__init__.c @@ -80,7 +80,7 @@ static const mp_arg_t envelope_properties[] = { //| //| :param float attack_time: The time in seconds it takes to ramp from 0 volume to attack_volume //| :param float decay_time: The time in seconds it takes to ramp from attack_volume to sustain_volume -//| :param float release_time: The time in seconds it takes to ramp from sustain_volume to release_volume. When a note is released before it has reached the sustain phase, the release is done with the same slope indicated by ``release_time`` and ``sustain_level`` +//| :param float release_time: The time in seconds it takes to ramp from sustain_volume to release_volume. When a note is released before it has reached the sustain phase, the release is done with the same slope indicated by ``release_time`` and ``sustain_level``. If the ``sustain_level`` is ``0.0`` then the release slope calculations use the ``attack_level`` instead. //| :param float attack_level: The level, in the range ``0.0`` to ``1.0`` of the peak volume of the attack phase //| :param float sustain_level: The level, in the range ``0.0`` to ``1.0`` of the volume of the sustain phase relative to the attack level //| """ diff --git a/shared-module/synthio/__init__.c b/shared-module/synthio/__init__.c index a7b2e0c25c..2bca3db439 100644 --- a/shared-module/synthio/__init__.c +++ b/shared-module/synthio/__init__.c @@ -89,7 +89,7 @@ void synthio_envelope_definition_set(synthio_envelope_definition_t *envelope, mp envelope->release_step = -convert_time_to_rate( sample_rate, fields[2], - envelope->decay_step + envelope->sustain_level ? envelope->sustain_level : envelope->attack_level); }