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.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | note |
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