Returns the level in [0, 1] of the ADSR envelope at time t1 < t < t2
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(ADSR_envelope), | intent(in) | :: | self | |||
real(kind=wp), | intent(in) | :: | t | |||
real(kind=wp), | intent(in) | :: | t1 | |||
real(kind=wp), | intent(in) | :: | t2 |
pure real(wp) function ADSR_level(self, t, t1, t2) class(ADSR_envelope), intent(in) :: self real(wp), intent(in) :: t, t1, t2 integer :: i, i1, i2, i3, i4, i5 i = nint(t * RATE) ! First part (Attack): i1 = nint(t1 * RATE) i2 = nint((t1 + (t2-t1) * self%attack / 100.0_wp) * RATE) if ((i >= i1) .and. (i < i2)) then ADSR_level = (i-i1) / real(i2-i1, wp) else i3 = nint((t1 + (t2-t1) * (self%attack+self%decay) / 100.0_wp) * RATE) if ((i >= i2) .and. (i < i3)) then ADSR_level = (100.0_wp - (i-i2)/real(i3-i2, wp) * & & (100.0_wp-self%sustain)) / 100.0_wp else i4 = nint((t2 - (t2-t1) * self%release / 100.0_wp) * RATE) if ((i >= i3) .and. (i < i4)) then ADSR_level = (self%sustain / 100.0_wp) else i5 = nint(t2 * RATE) if ((i >= i4) .and. (i <= i5)) then ADSR_level = (self%sustain - (i-i4)/real(i5-i4, wp) * & & self%sustain) / 100.0_wp else ! ERROR ADSR_level: t outside [t1, t2] ADSR_level = 1.0_wp end if end if end if end if end function ADSR_level