In Listing 8.2, we put all of the pieces together.
Notice the use of named constants to represent the notes. Also, notice the use of the
named constant BEAT to set the duration of notes and rests. Finally, using the reserved
boolean variable bSoundActive, we can introduce holds to allow notes to nish. The sound
queue is limited to just 10 requests, so it is a good idea to wait for the queue to empty at the
end of each measure or after 10 requests whichever comes rst. While sounds are playing
from the sound queue bSoundActive is true. When all requested sounds are nished playing
bSoundActive is false. Also, PlayTone() requests are made instantly, so it is important
to wait for tones to nish before rests. Otherwise, the rests will occur while the notes are
playing!

No comments:
Post a Comment