fr Function

public function fr(note)

Returns the frequency of the note. The note name is composed of two or three characters, for example "A4", "A#4", "Ab4", where the final character is the octave.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: note

Return Value real(kind=wp)


Called by

proc~~fr~~CalledByGraph proc~fr fr program~all_signals all_signals program~all_signals->proc~fr program~arpeggios arpeggios program~arpeggios->proc~fr program~blues blues program~blues->proc~fr program~chords_and_melody chords_and_melody program~chords_and_melody->proc~fr program~demo_effects demo_effects program~demo_effects->proc~fr program~misc_sounds misc_sounds program~misc_sounds->proc~fr

Source Code

    real(wp) function fr(note)
        character(*), intent(in) :: note
        ! 0 <= octave <=9
        integer :: octave
        ! Gap relative to PITCH, in semitones:
        integer :: gap
        ! ASCII code of the 0 character:
        integer, parameter :: zero = iachar('0')

        select case (note(1:1))
            case ('C')
                gap = -9
            case ('D')
                gap = -7
            case ('E')
                gap = -5
            case ('F')
                gap = -4
            case ('G')
                gap = -2
            case ('A')
                gap = 0
            case ('B')
                gap = +2
            case default
                print*, "ERROR! Note name unknown..."
                stop
        end select

        ! Treating accidentals (sharp, flat) and computing the octave:
        select case (note(2:2))
            case ('b')
                gap = gap - 1
                octave = iachar(note(3:3)) - zero
            case ('#')
                gap = gap + 1
                octave = iachar(note(3:3)) - zero
            case default
                octave = iachar(note(2:2)) - zero
        end select

        if ((octave >= 0) .and. (octave <= 9)) then
            gap = gap + (octave - 4) * 12
        else
            print *, "ERROR! Octave out of bounds [0; 9]"
            stop
        end if

        ! Computing the frequency of the note:
        fr = PITCH * SEMITONE**(real(gap, wp))
    end function fr