ADSR_level Function

private pure function ADSR_level(self, t, t1, t2)

Returns the level in [0, 1] of the ADSR envelope at time t1 < t < t2

Type Bound

ADSR_envelope

Arguments

Type IntentOptional 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

Return Value real(kind=wp)


Called by

proc~~adsr_level~~CalledByGraph proc~adsr_level ADSR_envelope%ADSR_level proc~add_noise add_noise proc~add_noise->proc~adsr_level proc~add_sawtooth_wave add_sawtooth_wave proc~add_sawtooth_wave->proc~adsr_level proc~add_sine_wave add_sine_wave proc~add_sine_wave->proc~adsr_level proc~add_square_wave add_square_wave proc~add_square_wave->proc~adsr_level proc~add_triangle_wave add_triangle_wave proc~add_triangle_wave->proc~adsr_level proc~add_weierstrass add_weierstrass proc~add_weierstrass->proc~adsr_level proc~add_note add_note proc~add_note->proc~add_sine_wave program~all_signals all_signals program~all_signals->proc~add_noise program~all_signals->proc~add_sawtooth_wave program~all_signals->proc~add_sine_wave program~all_signals->proc~add_square_wave program~all_signals->proc~add_triangle_wave program~all_signals->proc~add_weierstrass proc~add_chord add_chord proc~add_chord->proc~add_note program~chords_and_melody chords_and_melody program~chords_and_melody->proc~add_chord program~demo_effects demo_effects program~demo_effects->proc~add_chord

Source Code

    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