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.

package require sound
 
# Encapsulate the tone generation
set filter [snack::filter generator 1 20000 0.5 sine -1]
set sound  [snack::sound -rate 22050]
proc play {frequency length} {
    global filter sound
 
    $filter configure $frequency
    $sound play -filter $filter
 
    # Need to run event loop; Snack uses it internally
    after $length {set donePlay 1}
    vwait donePlay
 
    $sound stop
}
 
# Major scale up, then down; extra delay at ends of scale
set tonicFrequency 261.63; # C4
foreach i {0 2 4 5 7 9 11 12 11 9 7 5 4 2 0} {
    play [expr {$tonicFrequency*2**($i/12.0)}] [expr {$i%12?250:500}]
}