add_sine_wave Subroutine

public subroutine add_sine_wave(tape, track, t1, t2, f, Amp, envelope)

Adds on the track a sine wave with an ADSR envelope:

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
type(ADSR_envelope), intent(in), optional :: envelope

Calls

proc~~add_sine_wave~~CallsGraph proc~add_sine_wave add_sine_wave proc~adsr_level ADSR_envelope%ADSR_level proc~add_sine_wave->proc~adsr_level

Called by

proc~~add_sine_wave~~CalledByGraph proc~add_sine_wave add_sine_wave proc~add_note add_note proc~add_note->proc~add_sine_wave program~all_signals all_signals program~all_signals->proc~add_sine_wave 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

    subroutine add_sine_wave(tape, track, t1, t2, f, Amp, envelope)
        type(tape_recorder), intent(inout) :: tape
        integer, intent(in)  :: track
        real(wp), intent(in) :: t1, t2, f, Amp
        type(ADSR_envelope), optional, intent(in) :: envelope
        ! Phase at t=0 s, radians:
        real(wp), parameter  :: phi = 0.0_wp
        ! Pulsation (radians/second):
        real(wp) :: omega
        ! Time in seconds:
        real(wp) :: t
        ! ADSR Envelope value:
        real(wp) :: env
        real(wp) :: signal
        integer  :: i

        env = 1._wp     ! Default value if no envelope is passed
        omega = 2.0_wp * PI * f

        do concurrent(i = nint(t1*RATE) : nint(t2*RATE)-1)
            t = (i - nint(t1*RATE)) * dt

            if (present(envelope)) env = envelope%get_level(t1+t, t1, t2)

            signal = Amp * sin(omega*t + phi) * env

            tape%left(track, i)  = tape%left(track, i)  + signal
            tape%right(track, i) = tape%right(track, i) + signal
        end do
    end subroutine add_sine_wave