add_karplus_strong Subroutine

public subroutine add_karplus_strong(tape, track, t1, t2, f, Amp)

Karplus and Strong algorithm (1983), for plucked-string http://crypto.stanford.edu/~blynn/sound/karplusstrong.html https://en.wikipedia.org/wiki/Karplus%E2%80%93Strong_string_synthesis

Arguments

Type IntentOptional Attributes Name
type(tape_recorder), intent(inout) :: tape
integer, intent(in) :: track
real(kind=wp), intent(in) :: t1
real(kind=wp), intent(in) :: t2
real(kind=wp), intent(in) :: f
real(kind=wp), intent(in) :: Amp

Called by

proc~~add_karplus_strong~~CalledByGraph proc~add_karplus_strong add_karplus_strong proc~add_broken_chord add_broken_chord proc~add_broken_chord->proc~add_karplus_strong program~all_signals all_signals program~all_signals->proc~add_karplus_strong program~arpeggios arpeggios program~arpeggios->proc~add_karplus_strong program~arpeggios->proc~add_broken_chord program~blues blues program~blues->proc~add_karplus_strong program~chords_and_melody chords_and_melody program~chords_and_melody->proc~add_karplus_strong

Source Code

    subroutine add_karplus_strong(tape, track, t1, t2, f, Amp)
        type(tape_recorder), intent(inout) :: tape
        integer, intent(in)  :: track
        real(wp), intent(in) :: t1, t2, f, Amp
        real(wp) :: signal, r
        integer  :: i, P
        integer  :: i1, i2

        i1 = nint(t1*RATE)
        i2 = nint(t2*RATE) - 1

        P = nint(RATE / f) - 2

        ! Initial noise:
        do i = i1, i1 + P
            ! 0 <= r < 1
            call random_number(r)
            ! -Amp <= signal < +Amp
            signal = Amp * (2.0_wp*r - 1.0_wp)
            ! Track 0 is used as an auxiliary track:
            tape%left( 0, i) = signal
            tape%right(0, i) = signal
        end do
        ! Delay and decay:
        do i = i1 + P + 1, i2
            tape%left( 0, i) = (tape%left(0, i-P) + tape%left(0, i-P-1)) / 2.0_wp
            tape%right(0, i) = tape%left(0, i)
        end do

        ! Transfer (add) on the good track:
        tape%left( track, i1:i2) = tape%left( track, i1:i2) + tape%left( 0, i1:i2)
        tape%right(track, i1:i2) = tape%right(track, i1:i2) + tape%right(0, i1:i2)
    end subroutine add_karplus_strong