home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / dmkit / flat / pend.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-31  |  3.8 KB  |  182 lines

  1. /*****************************************************************************/
  2. /* PEND.C -> Plays a digital sound effect using the PostAudioPending calls.  */
  3. /* Written by John W. Ratcliff, September 1992, needs to link to                         */
  4. /* DIGPLAY.OBJ, DOSCALLS.OBJ.                                                                                              */
  5. /*****************************************************************************/
  6. #include <conio.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10.  
  11. #include "loader.h"
  12. #include "support.h"
  13. #include "digplay.h"    // Include DIGPLAY header.
  14. #include "doscalls.h"   // Include DOS tools header.
  15. #include "video.h"      // Include header for VGA graphics tools.
  16.  
  17. int  PendingStatus(void);
  18. void PostPending(SNDSTRUC *snd);
  19.  
  20. #define SWID 320     // Width of sound data.
  21.  
  22. char *save;
  23. char *buffer;
  24. char *currentbuffer;
  25. int AUTOINITDMA;
  26. int DMALOAD;
  27.  
  28. void main(int argc,char **argv)
  29. {
  30.     char *effect;
  31.     char *sound;
  32.   long int siz;
  33.     int soundsize;
  34.     int xcon=0;
  35.     SNDSTRUC *snd;
  36.  
  37.     if ( argc != 2 )
  38.     {
  39.         printf("Usage: PEND <filename>\n");
  40.         exit(1);
  41.     }
  42.  
  43.     snd = RealAlloc(sizeof(SNDSTRUC));
  44.     buffer = realalloc(SWID*2);
  45.     save = realalloc(SWID);
  46.  
  47.     effect = floadlow(argv[1], &siz);
  48.     if ( !effect )
  49.     {
  50.         printf("File '%s' not found, or too large to play.\n",argv[1]);
  51.         exit(1);
  52.     }
  53.  
  54.     if ( !LoadDigPak("SOUNDRV.COM") )
  55.     {
  56.         printf("Failed to load sound driver.\n");
  57.         exit(1);
  58.     }
  59.  
  60.     if ( !InitDigPak() )
  61.     {
  62.         UnLoadDigPak();
  63.         printf("Failed to initialize sound driver.\n");
  64.         exit(1);
  65.     }
  66.  
  67.  
  68.     AUTOINITDMA = 0; // off by default.
  69.     sound = effect;
  70.     currentbuffer = buffer;
  71.     snd->sndlen = SWID;
  72.     snd->frequency = 11025;
  73.     soundsize = siz;
  74.  
  75.     if ( AudioCapabilities()&DMABACKFILL )
  76.     {
  77.         if ( VerifyDMA(buffer,SWID*2) )
  78.         {
  79.             AUTOINITDMA = 1;
  80.             DMALOAD = SWID; // First load time.
  81.             NullSound(buffer,SWID*2,0x80);
  82.             memorymove(buffer,sound,SWID*2);
  83.             snd->sound = RealPtr(buffer);
  84.             snd->sndlen = SWID*2;
  85.             snd->frequency = 11025;
  86.             SetBackFillMode(1);
  87.             sound += SWID*2;
  88.             siz -= SWID*2;
  89.             DigPlay(snd);  // Start auto-init dma backfill...
  90.         }
  91.         else
  92.         {
  93.             printf("DMA buffer crosses segment boundary\n");
  94.             exit(1);
  95.         }
  96.     }
  97.  
  98.     VidOn();
  99.  
  100.     do
  101.     {
  102.         if (PendingStatus() != PENDINGSOUND)
  103.         {
  104.             memorymove(currentbuffer,sound,SWID); // Move into buffer area the audio data.
  105.             snd->sound = RealPtr(currentbuffer); // Set address of play sound location.
  106.             MassageAudio(snd);
  107.             PostPending(snd);
  108.  
  109.             DrawSound(save,320,0); // Erase previous.
  110.             DrawSound(currentbuffer,320,15); // draw the new one.
  111.             memorymove(save,currentbuffer,320);
  112.  
  113.             if ( currentbuffer == buffer ) // Perform flip-flop
  114.                 currentbuffer = buffer+SWID;
  115.             else
  116.                 currentbuffer = buffer;
  117.             sound+=SWID;    // Advance source sound effect address.
  118.             siz-=SWID;    // Decrement size left to processs.
  119.             if (siz < SWID)
  120.                 xcon = 1;
  121.         }
  122.         if (keystat())
  123.             xcon = 1;
  124.     } while (!xcon);
  125.  
  126.     if (AUTOINITDMA)
  127.     {
  128.         SetBackFillMode(0);  // Turn DMA back fill mode off!
  129.     }
  130.  
  131.     VidOff();
  132.  
  133.     if ( AUTOINITDMA )
  134.         printf("The current driver played this effect IN DMABACKFILL mode.\n");
  135.     else
  136.         printf("Current sound driver NOT in DMABACKFILL mode.\n");
  137.     printf("Now playing sound effect one more time, NOT in DMA mode.\n");
  138.     snd->sndlen = soundsize;
  139.     snd->sound = RealPtr(effect);
  140.     DigPlay(snd); // Replay sound effect.
  141.  
  142.     WaitSound();
  143.     UnloadDigPak();
  144.  
  145.  
  146. }
  147.  
  148.  
  149. void PostPending(SNDSTRUC *snd)
  150. {
  151.     if ( AUTOINITDMA==0 ) PostAudioPending(snd);
  152. }
  153.  
  154. int PendingStatus(void)
  155. {
  156.     int pend;
  157.     int count;
  158.  
  159.     if (AUTOINITDMA)
  160.     {
  161.         pend = PENDINGSOUND;
  162.         count = ReportDMAC();
  163.         if ( DMALOAD && count < DMALOAD)
  164.         {
  165.             pend = PLAYINGNOTPENDING;
  166.             DMALOAD = 0;
  167.         }
  168.         else
  169.         {
  170.             if (!DMALOAD && count >= SWID )
  171.             {
  172.                 pend = PLAYINGNOTPENDING;
  173.                 DMALOAD = SWID;
  174.             }
  175.         }
  176.     }
  177.     else
  178.         pend = AudioPendingStatus();
  179.  
  180.     return(pend);
  181. }
  182.