home *** CD-ROM | disk | FTP | other *** search
- /* Noise Maker Main Program
- */
-
- #define FALSE 0
- #define TRUE 1
-
- /* main()
-
- Function: Produce sound-effect. Repeatedly ask the user what
- sound to make, and then make it.
-
- Algorithm: Loop, asking the user for which sound and how many
- times to make it. Then repeat the sound generation code the
- number of times requested. To generate the sound, switch on the
- type of sound to generate. Each sound is generated by sweeping
- through a set of frequencies in a particular order at a particular
- rate.
- */
-
- main()
-
- {
- int snd; /* Which sound to produce. */
- int cnt; /* Number of times to repeat sound. */
- int note; /* Current note, when sweeping frequencies. */
- int adj100; /* A delay of 100, adjusted for processor speed. */
- int adj200; /* Delay of 200, adjusted for processor speed. */
- int adj700; /* Delay of 700, adjusted for processor speed. */
-
- /* Calculate the delays needed for this processor. */
- adj100 = calib();
- adj200 = 2*adj100;
- adj700 = 7*adj100;
-
- while (TRUE) {
- /* Make sure any previous sounds are turned off. */
- sndOff();
- /* Ask the user for which type of sound. */
- printf("1-siren; 2-overload; 3-whoop; 4-phaser; 0-exit: ");
- /* Read the answer. */
- scanf("%d",&snd);
- /* If the answer is to exit, do so. */
- if (snd == 0) break;
- /* Ask how many times to repeat the sound. */
- printf("Number of times: ");
- /* Get the answer. */
- scanf("%d",&cnt);
- /* Repeat the sound the number of time specified. */
- while (cnt--) {
- /* Switch on type of sound to produce. */
- switch (snd) {
- case 1:
- /* Do a siren: sweep up. */
- for (note = 1000; note > 150;
- note -= 10) {
- sound(note); delay(adj200);
- };
- /* Sweep down. */
- for (; note < 1000; note += 10) {
- sound(note); delay(adj200);
- };
- break;
- case 2:
- /* Do an overload: sweep up. */
- for (note = 4000; note > 10;
- note -= 10) {
- sound(note); delay(adj700);
- };
- break;
- case 3:
- /* Do a whoop: sweep up. */
- for (note = 1000; note > 10;
- note -= 10) {
- sound(note); delay(adj200);
- };
- break;
- case 4:
- /* Do a phaser: sweep down. */
- for (note = 60; note < 2000;
- note += 10) {
- sound(note); delay(adj100);
- };
- break;
- default:
- /* Unknown, ask again. */
- printf("Invalid entry; try again.\n");
- break;
- };
- };
- };
- }
-
- /* delay(cnt)
-
- Function: Delay for an amount of time proportional to cnt.
-
- Algorithm: Just waste time in a for loop.
- */
-
- delay(cnt)
-
- {
- int i;
-
- /* Loop to burn time... */
- for (i = 0; i < cnt; i++);
- }
-