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
Type | Intent | Optional | 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 |
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