Pitch affects the melody of a song by determining the highness or lowness of each note, thus shaping the song's tune and emotional expression. It influences the contour and progression of the melody, creating unique patterns that listeners recognize and respond to emotionally.