Task

Output the 8 notes of the C major diatonic scale to the default musical sound device on the system. Specifically, pitch must be tuned to 12-tone equal temperament (12TET) with the modern standard A=440Hz.

These are the notes "C, D, E, F, G, A, B, C(1 octave higher)", or "Do, Re, Mi, Fa, Sol, La, Si/Ti, Do(1 octave higher)" on Fixed do Solfège.

For the purpose of this task, Middle C (in the case of the above tuning, around 261.63 Hz) should be used as the starting note, and any note duration is allowed.

For languages that cannot utilize a sound device, it is permissible to output to a musical score sheet (or midi file), or the task can be omitted.

(defun play-scale (freq-list dur)
  "Play a list of frequencies."
  (setq header (unibyte-string     ; AU header:
                  46 115 110 100   ;   ".snd" magic number
                  0 0 0 24         ;   start of data bytes
                  255 255 255 255  ;   file size is unknown
                  0 0 0 3          ;   16 bit PCM samples
                  0 0 172 68       ;   44,100 samples/s
                  0 0 0 1))        ;   mono
  (setq s nil)
  (dolist (freq freq-list)
    (setq v (mapcar (lambda (x)
                 (mod (round (* 32000 (sin (* 2 pi freq x (/ 44100.0))))) 65536))
                 (number-sequence 0 (* dur 44100))))
    (setq s (apply #'concat s (flatten-list (mapcar (lambda (x)
              (list (unibyte-string (ash x -8))
                    (unibyte-string (mod x 256))))
              v)))))
  (setq s (concat header s))
  (play-sound `(sound :data ,s)))
 
(play-scale '(261.63 293.66 329.63 349.23 392.00 440.00 493.88 523.25) .5)