home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / mus / dsound-1.50.lha / DSound / DSound.c < prev    next >
C/C++ Source or Header  |  1994-07-18  |  28KB  |  1,051 lines

  1.  
  2. /**************************************************************************/
  3. /*                 DSound V1.50                  */
  4. /*    Copyright 1991-1994 by Dave Schreiber, All Rights Reserved.      */
  5. /*                                      */
  6. /* To compile with SAS/C version 6, type:                  */
  7. /*    smake                                  */
  8. /*                                      */
  9. /* Revision history:                              */
  10. /*    V1.50  - Fixed a bug that caused DSound's window to have the wrong  */
  11. /*           height in some instances.  Also extended DSound's Workbench*/
  12. /*           support:  DSound now recognizes a number of tool types      */
  13. /*           which give the user the same level of control as when      */
  14. /*           DSound is used from the Shell.                  */
  15. /*           July 18, 1994                          */
  16. /*    V1.40  - Fixed a bug that caused slowdowns with floptical drives,   */
  17. /*           added some Workbench support (a project with "DSound" as   */
  18. /*           its default tool can now be run by double-clicking on its  */
  19. /*           icon), and added an ARexx port so now one can quit DSound  */
  20. /*           via an ARexx command.  In addition, DSound is no longer      */
  21. /*           pure (i.e. can not be made resident), due to conflicts     */
  22. /*           with MinRexx.                          */
  23. /*           July 2, 1994                          */
  24. /*    V1.31  - Fixed some bugs that caused some samples (esp. ones        */
  25. /*           without a CHAN chunk) to not play.              */
  26. /*           March 6, 1994                          */
  27. /*    V1.30  - DSound now displays the name of the sound sample being      */
  28. /*           played, the number of seconds of the sample that have been */
  29. /*           played, and the total number of seconds in the sample.      */
  30. /*           A bug that prevent DSound from being aborted from the      */
  31. /*           window when a stereo sample is played has also been fixed. */
  32. /*           July 17, 1993                          */
  33. /*    V1.20  - Added the ability to stop DSound by typing CTRL-C, and      */
  34. /*           added the switch '-w', which keeps the DSound window from  */
  35. /*           opening.                           */
  36. /*           August 23, 1992                          */
  37. /*    V1.10  - Added the ability to play a sound sample repeatedly (in a  */
  38. /*           loop).                              */
  39. /*           July 11, 1992                          */
  40. /*    V1.00  - Added a new module (Mem.c) which allows a sample to be     */
  41. /*           loaded entirely into memory, so samples can be played from */
  42. /*           floppy disk without first copying to a hard or RAM drive.  */
  43. /*           DSound also can now play a single channel of a stereo      */
  44. /*           out of two speakers.  The small window, used to let the      */
  45. /*           user abort a playing sample, as been redone (DSound also   */
  46. /*           now responds instantly when the user clicks on the Close   */
  47. /*           gadget).  DSound now checks a given 8SVX sample to make      */
  48. /*           sure that it is actually a valid sample.  Finally, DSound  */
  49. /*           has been made pure (residentiable).                        */
  50. /*           Second release (April 16, 1992)                            */
  51. /*    V0.94a - Can now play a mono sample out of both speakers at the      */
  52. /*           same time (using the -2 switch).                           */
  53. /*           March 27, 1992 (a little later)                            */
  54. /*    V0.93a - Now handles stereo sound samples.  Either the right or      */
  55. /*           left, or both, stereo channels can be played.  Also split  */
  56. /*           off the code that actually plays the sound sample into a   */
  57. /*           separate source file (Play.c).                             */
  58. /*           March 27, 1992                          */
  59. /*    V0.92a - Now gets the length of the sound sample from the head of   */
  60. /*           the BODY chunk, instead of the VHDR (a workaround to a bug */
  61. /*           in the Perfect Sound software that would sometimes store   */
  62. /*           an incorrect length in the VHDR chunk of a sound sample).  */
  63. /*           November 4, 1991                       */
  64. /*    V0.91a - First release (September 11, 1991)                         */
  65. /**************************************************************************/
  66.  
  67. #include <exec/types.h>
  68. #include <exec/exec.h>
  69. #include <devices/audio.h>
  70. #include <dos/dos.h>
  71. #include <intuition/intuition.h>
  72. #include <intuition/intuitionbase.h>
  73. #include <graphics/gfxbase.h>
  74. #include <workbench/startup.h>
  75. #include <stdlib.h>
  76. #include <stdio.h>
  77. #include <string.h>
  78.  
  79. #include "dsound.h"
  80. #include "arexx.h"
  81. #include "minrexx.h"
  82.  
  83. #include <proto/intuition.h>
  84. #include <proto/graphics.h>
  85. #include <proto/exec.h>
  86. #include <proto/dos.h>
  87. #include <proto/icon.h>
  88.  
  89. #include <pragmas/intuition_pragmas.h>
  90. #include <pragmas/graphics_pragmas.h>
  91. #include <pragmas/exec_pragmas.h>
  92. #include <pragmas/dos_pragmas.h>
  93.  
  94. char filename[256];
  95.  
  96. #define DEF_BUF_SIZE 0xFFFFFFFF
  97.  
  98. void InterpretArgs(int argc,char *argv[]);
  99. void InterpretWBArgs(struct WBArg *wbArgs);
  100. BOOL LoopAndNoWindow_WB(void);
  101. void showAboutWindow(void);
  102. BOOL noFilter=FALSE;
  103. UBYTE volume=0;
  104. UWORD speed=0;
  105. ULONG bufSize=DEF_BUF_SIZE;
  106.  
  107. void filter_on(void);
  108. void filter_off(void);
  109. char *getDoubleDigit(unsigned int value,char *buf);
  110.  
  111. char *version="$VER: DSound V1.50 (18.7.94)";
  112. char *copyright="Copyright 1991-1994 by Dave Schreiber, All Rights Reserved";
  113.  
  114. extern struct IntuitionBase *IntuitionBase;
  115. struct GfxBase *GfxBase=NULL;
  116. extern struct Library *IconBase;
  117.  
  118. struct Window *window=NULL;
  119.  
  120. BPTR file=NULL;
  121.  
  122. channel audioChannel=UNSPECIFIED;
  123. BOOL bothChan=FALSE;
  124. BOOL readAll=FALSE;
  125. BOOL loop=FALSE;
  126. BOOL titleBarName=TRUE;
  127. BOOL titleBarTime=TRUE;
  128.  
  129. /*The window definition*/
  130. struct NewWindow newWindow = {
  131.     0,0,
  132.     60,56,
  133.     0,1,
  134.     CLOSEWINDOW,
  135.     SMART_REFRESH|WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE,
  136.     NULL,
  137.     NULL,
  138.     "DSound V1.50",
  139.     NULL,
  140.     NULL,
  141.     5,5,
  142.     640,200,
  143.     WBENCHSCREEN
  144. };
  145.  
  146. /*This determines whether or not the window will be opened*/
  147. BOOL openTheWdw=TRUE;
  148. ULONG signalMask=SIGBREAKF_CTRL_C;
  149.  
  150. struct TextFont *titleBarFont=NULL;
  151. long arexxSigBit=0;
  152.  
  153. extern struct WBStartup *WBenchMsg;
  154.  
  155. main(int argc,char *argv[])
  156. {
  157.    struct Voice8Header vhdr;
  158.    UBYTE foo2[5];
  159.    UBYTE foo[5];
  160.    ULONG chan;
  161.    ULONG sampleLength;
  162.    ULONG lock;
  163.    ULONG titleLength,nameLength,timeLength,colonLength,finalDelta;
  164.    char *chanStr;
  165.  
  166.    filename[0]=NULL;
  167.  
  168.    /*If run from the CLI*/
  169.    if(WBenchMsg==NULL)
  170.    {
  171.       /*Get and interpret the command-line arguments*/
  172.       InterpretArgs(argc,argv);
  173.    }
  174.    else
  175.    {
  176.       if(WBenchMsg->sm_NumArgs>0)
  177.      InterpretWBArgs(&WBenchMsg->sm_ArgList[0]);
  178.  
  179.       if(WBenchMsg->sm_NumArgs>1)
  180.       {
  181.      CurrentDir(WBenchMsg->sm_ArgList[1].wa_Lock);
  182.      InterpretWBArgs(&WBenchMsg->sm_ArgList[1]);
  183.      if(loop && openTheWdw==FALSE)
  184.         if(!LoopAndNoWindow_WB())
  185.            exit(0);
  186.      strcpy(filename,WBenchMsg->sm_ArgList[1].wa_Name);
  187.       }
  188.       else
  189.       {
  190.      showAboutWindow();
  191.      exit(0);
  192.       }
  193.    }
  194.  
  195.    /*Exit if there was no sound sample specified*/
  196.    if(filename[0]==NULL)
  197.    {
  198.       WriteMsg("Please specify the name of a sound sample\n");
  199.       cleanup(75);
  200.    }
  201.  
  202.    /*Open the file*/
  203.    file=Open(filename,MODE_OLDFILE);
  204.    if(file==NULL)
  205.    {
  206.       WriteMsg("Couldn't open the file\n");
  207.       cleanup(100);
  208.    }
  209.  
  210.    arexxSigBit=initRexxPort();
  211.  
  212.    /*If the user hasn't told us not to open the window*/
  213.    if(openTheWdw)
  214.    {
  215.       char temp[256];
  216.       int yDelta=0;
  217.       /*Open libraries*/
  218.       GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0L);
  219.  
  220.       if(GfxBase==NULL || IntuitionBase==NULL)
  221.       {
  222.      WriteMsg("A shared library could not be opened\n");
  223.      cleanup(50);
  224.       }
  225.  
  226.       /*Get the size of the title bar font in a rather illegal way        */
  227.       /*Note:  programmers at C= should put a GetDefTitleBarFontHeight()    */
  228.       /*function into Intuition before complaining to me about the following*/
  229.       /*code.                                    */
  230.  
  231.       lock=LockIBase(0L);
  232.       newWindow.Height=IntuitionBase->ActiveScreen->Font->ta_YSize+3;
  233.       UnlockIBase(lock);
  234.  
  235.       window=OpenWindow(&newWindow);
  236.  
  237.       if(window->WScreen->Font->ta_YSize+3!=window->Height)
  238.      yDelta=window->WScreen->Font->ta_YSize+3-window->Height;
  239. /*       SizeWindow(window,0,window->WScreen->Font->ta_YSize+3-window->Height);*/
  240.  
  241.       if(window==NULL)
  242.      cleanup(110);
  243.       signalMask|=1<<window->UserPort->mp_SigBit;
  244.  
  245.       titleBarFont=OpenFont(IntuitionBase->ActiveScreen->Font);
  246.       if(titleBarFont==NULL)
  247.      cleanup(115);
  248.  
  249.       SetFont(window->RPort,titleBarFont);
  250.       finalDelta=t