home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / SOUNDSYS / SOUNDS.C next >
Text File  |  1989-04-09  |  2KB  |  137 lines

  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <time.h>
  4. #include <stdlib.h>
  5. #include <dos.h>
  6. #include "sounds.h"
  7. #include "soundsys.h"
  8. #include "keyboard.h"
  9.  
  10. void GunSound(void)
  11. {
  12.   int i,j;
  13.  
  14.   for (j=0;j<5;j++)
  15.         for (i=40; i>=10; i--)
  16.         {
  17.                 submit_sound((i*10),0);
  18.                 submit_sound(0,0);
  19.         }
  20. }
  21.  
  22. void ExplSound(void)
  23. {
  24.   explode(400,300,0);
  25. }
  26.  
  27. void explode(int freq, int iterations,int delayfactor)
  28. {
  29.   int i;
  30.  
  31.   for (i=1; i<iterations; i++)
  32.   {
  33.     submit_sound(random(freq),(delayfactor*5));
  34.     submit_sound(random(freq),(delayfactor*5));
  35.   }
  36. }
  37.  
  38. int between(int low, int high)
  39. {
  40.   if (high > low)
  41.     return (random(high - low + 1) + high);
  42.   else
  43.   {
  44.     if (high == low)
  45.       return high;
  46.     else
  47.       return (random(low-high+1) + 1);
  48.   }
  49. }
  50.  
  51. void siren(int i, int j, int k)
  52. {
  53.   while (i != j)
  54.   {
  55.     submit_sound(i,k);
  56.     if (i>j)
  57.       i-=5;
  58.     else
  59.       i+=5;
  60.   }
  61. }
  62.  
  63. void whine(void)
  64. {
  65.   int i,ii;
  66.  
  67.   for (i=1; i<=8; i++)
  68.   {
  69.     ii = 100*i;
  70.     siren(1000-ii,1100-ii,1);
  71.     siren(1100-ii,900-ii,1);
  72.   }
  73.   nosound();
  74. }
  75.  
  76. void fallsound(void)
  77. {
  78.   siren(2000,500,1);
  79.   explode(400,200,0);
  80. }
  81.  
  82. void DropSound(void)
  83. {
  84.   siren(2000,500,1);
  85. }
  86.  
  87. void JetEngineStart(void)
  88. {
  89.   siren(40,5000,3);
  90.   submit_sound(5000,1000);
  91. }
  92.  
  93. void JetEngineOff(void)
  94. {
  95.   siren(5000,40,4);
  96. }
  97.  
  98. void main(void)
  99. {
  100.   int i;
  101.  
  102.   clrscr();
  103.   printf("Background Sound System Demo - by J.Jimenez\n\n");
  104.   init_sound();
  105.   printf("Background noise on...\n");
  106.   frequency = 40;
  107.   back_sound = ON;
  108.   sleep(5);
  109.   printf("Explosion...\n");
  110.   ExplSound();
  111.   sleep(5);
  112.   printf("Machine Gun...\n");
  113.   for (i=0;i<3;i++) GunSound();
  114.   sleep(5);
  115.   printf("Whine??\n");
  116.   whine();
  117.   sleep(5);
  118.   printf("Drop bomb...\n");
  119.   DropSound();
  120.   sleep(5);
  121.   printf("Drop bomb w/explosion...\n");
  122.   fallsound();
  123.   sleep(5);
  124.   printf("Jet engine start...\n");
  125.   JetEngineStart();
  126.   sleep(10);
  127.   printf("Jet engine shutdown...\n");
  128.   JetEngineOff();
  129.   sleep(10);
  130.   printf("Background noise off...\n");
  131.   back_sound = OFF;
  132.   sleep(2);
  133.   printf("Done!\n");
  134.   restore_sound();
  135.   exit(0);
  136. }
  137.