Play "Taps"
JavaScript, 203 198 196 195 bytes
with(new AudioContext)for(t=i=0;n="301093301396202346202346202396331699464390301093"[i++];)with(createOscillator())i%2?l=n/2:(frequency.value=392+n*44,connect(destination),start(t+.1),stop(t+=l))
5 bytes saved thanks to Dendrobium and 1 thanks to @PatrickRoberts.
Explanation
with(new AudioContext) // use HTML5 audio
for( // iterate through the note pitches and lengths
t=i=0; // t = current time to place the note
n= // n = note pitch (or temporarily length)
// This string contains the values of each note alternating between length and pitch
// (l1, p1, l2, p2, etc...)
// Length value is in 16th notes (1 = 1/16th note, 2 = 1/8th, etc...)
// The longer notes are limited to 9 but I think it still sounds OK
// Pitch value 0 = G4, 3 = C5, 6 = E5, 9 = G5 (multiples of 3 saves 1 byte)
"301093301396202346202346202396331699464390301093"
[i++];)
with(createOscillator()) // create the note oscillator
i%2? // alternate between length and pitch characters
l=n/2 // l = length (stored for use in the next iteration)
// dividing it by 2 sets the speed to 60 beats per minute
// and casts it to a number
:(
frequency.value=392 // base note = G5 (392hz)
+n*44, // there is (conveniently) roughly 132hz between each note
connect(destination), // send the note's sound through the speakers
start(t // schedule the note to sound
+.1), // short delay to distinguish two notes of the same pitch
stop(t+=l) // schedule the end of the note and increment the time
)
Test it here in the browser! Works on any browser that supports the HTML5 Web Audio API.
Mathematica, 361 287 285 bytes
I went for accuracy here. Output is exactly as described in the score, played with the trumpet. You can find the file here.
"G"
e="E5";c="C5";EmitSound@Sound[SoundNote[#,5/#2,"Trumpet",SoundVolume->#3/17]&@@@{%,8,17,%,24,20,c,2,23,%,8,26,c,24,29,e,2,32,%,12,35,c,12,38,e,6,41,%,12,44,c,12,47,e,6,50,%,12,53,c,12,56,e,2,59,c,8,62,e,24,65,"G5",3,68,e,6,170/3,c,6,136/3,%,2,34,%,8,34,%,24,34,c,2,34}~Partition~3]
Thanks to @MartinBüttner for golfing suggestions.
Sonic Pi, 899 bytes
The timing is a little off, but I think it's ok.
Lightly golfed:
use_synth:blade use_synth_defaults sustain:0.70,release:0.0 play:G4,release:0.05 wait 0.75 play:G4,sustain:0.25 wait 0.25 hold=rrand_i(3,4) play:C5,sustain:hold,release:0.5 wait hold+0.5 play:G4,release:0.05 wait 0.75 play:C5,sustain:0.25 sleep 0.25 hold=rrand_i(3,4) play:E5,sustain:hold,release:1.25 sleep hold+1.25 play:G4 sleep 0.70 play:C5 sleep 0.70 2.times do play:E5,sustain:1,release:0.25 sleep 1.25 play:G4 sleep 0.7 play:C5 sleep 0.7 end hold=rrand_i(3,5) play:E5,sustain:hold,release:0.75 sleep hold+1 play:C5,release:0.05 sleep 0.75 play:E5,sustain:0.25 sleep 0.25 play:G5,sustain:2.45,release:0.05 sleep 2.5 play:E5,sustain:1,release:0.25 sleep 1.25 play:C5,sustain:1,release:0.25 sleep 1.25 hold=rrand_i(3,5) play:G4,sustain:hold,release:0.5 sleep hold+0.5 play:G4,release:0.05 sleep 0.75 play:G4,sustain:0.25 sleep 0.25 hold=rrand_i(3,5) play:C5,sustain:hold,release:1.5