/* * Music playing routine * Borland compilers only! */ #include void playsound(int note,int duration); void main() { /* * The song being played, "America the Beautiful," * is stored as a series of frequencies and durations * in a two-dimensional array. * * The song[][2] declaration defines the array as * a set of pairs; the compiler figures the size of * the thing. * * The first item, song[x][0], is the note's frequency. * The second item, song[x][1], is the duration in * millisonds. I've used 125 as an 8th note; 250 for * a quarter note; 375 for a dotted-quarter note; * and 750 for a dotted half note; a whole note * would have been 1000, or one second. * * A null byte ends the song. */ int song[][2] = { 392,250, 392,375, 330,125, 330,250, 392,250, 392,375, 294,125, 294,250, 330,250, 349,250, 392,250, 440,250, 494,250, 392,750, 392,250, 392,375, 330,125, 330,250, 392,250, 392,375, 294,125, 294,250, 587,250, 554,250, 587,250, 659,250, 440,250, 587,750, 392,250, 659,375, 659,125, 587,250, 523,250, 523,375, 494,125, 494,250, 523,250, 587,250, 494,250, 440,250, 392,250, 523,750, 523,250, 523,375, 440,125, 440,250, 523,250, 523,375, 392,125, 392,250, 392,250, 440,250, 523,250, 392,250, 587,250, 523,750, 0, 0 }; int x = 0; /* * The while loop continues to fetch new items * from the song[][] array until zero is read. * Variable X keeps track of the elements. * * A delay of 1/10 sec. is made after each note * is played by the playsound() function. Otherwise * the notes would all run together and sound * gross. (Comment it out to hear what I mean.) */ while(song[x++][0]) { playsound(song[x][0],song[x][1]); delay(100); } } /* * The playsound function uses Borland C's * sound and delay functions play a sound on * the PC's speaker. sound() accepts a frequency * value and delay() accepts a millisecond value * * The nosound() function turns the PC's speaker * off */ void playsound(int note,int duration) { sound(note); delay(duration); nosound(); }