home *** CD-ROM | disk | FTP | other *** search
/ C++ Games Programming / CPPGAMES.ISO / digmid / real / test16.c < prev    next >
C/C++ Source or Header  |  1994-01-03  |  4KB  |  158 lines

  1. /**** TEST16.C        Demonstrate all DIGPAK capable play modes.                *******/
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <malloc.h>
  5.  
  6. #include "doscalls.h"
  7. #include "loader.h"
  8. #include "digplay.h"
  9. #include "t16.h"
  10.  
  11. // Define memory allocation functions.  If using DOS memory allocation
  12. // functions, provided through DOSCALLS, then set the conditional compilation
  13. // 'DOSALLOC' to true.  If using C compiler library function memory allocation
  14. // set 'DOSALLOC' to zero.
  15.  
  16. #define DOSALLOC 0
  17. // Redirect memory allocation to either DOS memory allocate functions located
  18. // in DOSCALLS or to C library far memory allocation functions.
  19. unsigned char far * far memalloc(long int siz)
  20. {
  21.     #if DOSALLOC
  22.         return(fmalloc(siz));  // DOS far memory allocation functions
  23.     #else
  24.         return(farmalloc(siz)); // C's far memory allocation functions.
  25.     #endif
  26. }
  27.  
  28. void far memfree(char far *memory)
  29. {
  30.     #if DOSALLOC
  31.         ffree(memory);
  32.     #else
  33.         farfree(memory);
  34.     #endif
  35. }
  36.  
  37. void main(void)
  38. {
  39.     int cap;
  40.     SNDSTRUC snd;
  41.     long int siz;
  42.     char far *music;
  43.     char far *sound;
  44.     char far *workspace;
  45.  
  46.     if ( !LoadDigPak("SOUNDRV.COM") )
  47.     {
  48.         printf("Unable to load SOUNDRV.COM\n");
  49.         exit(1);
  50.     }
  51.     if ( !InitDigPak() )
  52.     {
  53.         UnLoadDigPak();
  54.         printf("Unable to initialize digitized sound hardware.\n");
  55.         exit(1);
  56.     }
  57.     sound = fload("TEST.SND", &siz);
  58.     if ( sound )
  59.     {
  60.         cap = AudioCapabilities();
  61.         workspace = memalloc(64000); //allocate lots of memory for workspace.
  62.         if ( siz*4 > 64000L ) siz = 64000/4;
  63.         printf("Press a key to play test sound effect in 8 bit mono mode.\n");
  64.         printf("Press ESC to go to next step in the test suite.\n");
  65.  
  66.         farmov(workspace,sound,siz);
  67.         snd.sound = workspace;
  68.         snd.frequency = 11000;
  69.         snd.sndlen = siz;
  70.         MassageAudio(&snd);
  71.  
  72.         do
  73.         {
  74.             DigPlay2(&snd);
  75.         } while ( getkey() != 27 );
  76.         if ( cap & STEREOPLAY )
  77.         {
  78.             printf("Press a key to play test sound effect in 8 bit stereo mode.\n");
  79.             printf("JUST out of the LEFT speaker.\n");
  80.             printf("Press ESC to go to next step in the test suite.\n");
  81.             Left8(sound,workspace,siz);
  82.             snd.sound = workspace;
  83.             snd.frequency = 11000;
  84.             snd.sndlen = siz*2;
  85.  
  86.             SetPlayMode(PCM_8_STEREO);
  87.             MassageAudio(&snd);
  88.             do
  89.             {
  90.                 DigPlay2(&snd);
  91.             } while ( getkey() != 27 );
  92.  
  93.             printf("Press a key to play test sound effect in 8 bit stereo mode.\n");
  94.             printf("JUST out of the RIGHT speaker.\n");
  95.             printf("Press ESC to go to next step in the test suite.\n");
  96.             Right8(sound,workspace,siz);
  97.             snd.sound = workspace;
  98.             snd.frequency = 11000;
  99.             snd.sndlen = siz*2;
  100.             SetPlayMode(PCM_8_STEREO);
  101.             MassageAudio(&snd);
  102.             do
  103.             {
  104.                 DigPlay2(&snd);
  105.             } while ( getkey() != 27 );
  106.         }
  107.         if ( cap&PCM16 )
  108.         {
  109.             printf("Press a key to play test sound effect in 16 bit MONO mode.\n");
  110.             printf("Press ESC to go to next step in the test suite.\n");
  111.             Mono16(sound,workspace,siz);
  112.             snd.sound = workspace;
  113.             snd.frequency = 11000;
  114.             snd.sndlen = siz*2;
  115.             SetPlayMode(PCM_16_MONO);
  116.             do
  117.             {
  118.                 DigPlay2(&snd);
  119.             } while ( getkey() != 27 );
  120.         }
  121.  
  122.  
  123.         if ( cap&PCM16STEREO )
  124.         {
  125.             printf("Press a key to play test sound effect in 16 bit STEREO mode.\n");
  126.             printf("Will play 16 bit sound effect, just out of LEFT channel.\n");
  127.             printf("Press ESC to go to next step in the test suite.\n");
  128.             Left16(sound,workspace,siz);
  129.             snd.sound = workspace;
  130.             snd.frequency = 11000;
  131.             snd.sndlen = siz*4;
  132.             SetPlayMode(PCM_16_STEREO);
  133.             do
  134.             {
  135.                 DigPlay2(&snd);
  136.             } while ( getkey() != 27 );
  137.  
  138.             printf("Press a key to play test sound effect in 16 bit STEREO mode.\n");
  139.             printf("Will play 16 bit sound effect, just out of RIGHT channel.\n");
  140.             printf("Press ESC to go to next step in the test suite.\n");
  141.             Right16(sound,workspace,siz);
  142.             snd.sound = workspace;
  143.             snd.frequency = 11000;
  144.             snd.sndlen = siz*4;
  145.             SetPlayMode(PCM_16_STEREO);
  146.             do
  147.             {
  148.                 DigPlay2(&snd);
  149.             } while ( getkey() != 27 );
  150.         }
  151.         SetPlayMode(PCM_8_MONO);
  152.     }
  153.     else
  154.         printf("Unable to load test sound effect 'TEST.SND'.\n");
  155.  
  156.     UnLoadDigPak();
  157. }
  158.