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.

// Rosetta Code problem: http://rosettacode.org/wiki/Musical_scale
// by Galileo, 03/2022
 
sample_rate = 44100
duration = 8
dataLength = sample_rate * duration
hdrSize = 44
fileLen = dataLength + hdrSize - 8
data 261.6, 293.6, 329.6, 349.2, 392.0, 440.0, 493.9, 523.3
 
sub int_to_bytes(dato, long)
    local dato$, esp, esp$, i
 
    esp$ = "00000000"
    dato$ = hex$(dato)
    esp = long * 2
    dato$ = right$(esp$ + dato$, esp)
    for i = esp - 1 to 1 step -2
        poke #fn, dec(mid$(dato$, i, 2))
    next
end sub
 
fn = open("notesyab.wav", "wb")
 
print #fn, "RIFF";
int_to_bytes(fileLen, 4)
print #fn, "WAVEfmt ";
int_to_bytes(16, 4)             // length of format data (= 16)
int_to_bytes(1, 2)              // type of format (= 1 (PCM))
int_to_bytes(1, 2)              // number of channels (= 1)
int_to_bytes(sample_rate, 4)    // sample rate
int_to_bytes(sample_rate, 4)    // sample rate * bps(8) * channels(1) / 8 (= sample rate)
int_to_bytes(1,2)               // bps(8) * channels(1) / 8  (= 1)
int_to_bytes(8,2)               // bits per sample (bps) (= 8)
print #fn, "data";
int_to_bytes(dataLength, 4)     // size of data section
 
for j = 1 to duration
    read f
    omega = 2 * PI * f
    for i = 0 to dataLength/duration-1 
        y = 32 * sin(omega * i / sample_rate)
        byte = and(y, 255)
        poke #fn, byte
    next
next
 
close(fn)
 
if peek$("os") = "windows" then
    system("notesyab.wav")
else // Linux
    system("aplay notesyab.wav")
endif