home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / soundpla.pit / SoundPlay.c.pit / SPMain.c < prev   
Encoding:
C/C++ Source or Header  |  1985-10-01  |  3.1 KB  |  136 lines

  1. #Options Z
  2.  
  3. // SoundPlay Driver for Sounds Saved By SoundCap¬ and recorded using the
  4. //    MacNifty¬ Audio Digitizer. SoundCap¬ and MacNifty¬ Audio Digitizer
  5. //    are marketed by:     Kette Group, Inc.
  6. //                13895 Industrial Blvd.
  7. //                Minneapolis, MN 55441
  8. //                (800)-328-0184
  9. //
  10. //    (SoundCap is a Trademark of Fractal Software)
  11. //    (MacNifty is a Trademark of Kette Group, Inc.)
  12. //
  13. // SoundPlay was developed by Tom Hedges and Mark Zimmer of
  14. //    Fractal Software, San Jose, CA.
  15. //
  16. // This file was compiled with Consulair Mac C¬ Rev 2.0
  17. //
  18. // mod 9 30 85 tsh - sound play driver
  19.  
  20. #include "macdefs.h"
  21. #include "macCdefs.h"
  22. #include "MAZlib.h"
  23. #include "OSio.h"
  24. #include "packages.h"
  25. #include "pbDefs.h"
  26.  
  27.  
  28. #asm
  29.     include    SysEquX.D
  30. #endasm
  31.  
  32. extern long int huffman_readsize();
  33. extern int huffman_input();
  34. extern play_back_sound();
  35.  
  36. // IO packet
  37. extern ioParam huffIo;
  38.  
  39. // I/O buffer
  40. #define iocnt 0x2000
  41.  
  42. short iobuff[0x1010];
  43.  
  44.       
  45. // interface to standard file package      
  46. SFGetFile(where, prompt, fileFilter, numTypes, typeList, dlgHook, reply)
  47.   long *where;        // really address of a point
  48.   struct PStr *prompt;
  49.   int (*fileFilter)();
  50.   short numTypes;
  51.   SFTypeList *typeList;
  52.   int (*dlgHook)();
  53.   SFReply *reply;
  54.       {
  55. #asm
  56.       MOVE.L    D0,A0
  57.       MOVE.L    (A0),-(SP)    ; WHERE
  58.       MOVE.L    D1,-(SP)    ; PROMPT
  59.       MOVE.L    D2,-(SP)    ; FILTER PROC
  60.       MOVE.W    D3,-(SP)    ; numTypes
  61.       MOVE.L    D4,-(SP)    ; typeList
  62.       MOVE.L    D5,-(SP)    ; dlgHook
  63.       MOVE.L    D6,-(SP)    ; reply
  64.       MOVE    #2,-(SP)    ; PARM
  65.       DC.W $A9EA  ; _Pack3
  66. #endasm
  67.       };
  68.       
  69. // mainline
  70. main()
  71.     {
  72.     long count, sampling;
  73.     short compressed, errcode, refnum;
  74.     Point loc;
  75.     unsigned char *buffer;
  76.     SFReply reply;
  77.     SFTypeList typeList;
  78.     char filename[64];
  79.  
  80.     // get the name of the file to play
  81.     typeList.ftype[0] = 'FSSD';
  82.     loc.v = 80;
  83.     loc.h = 100;
  84.     SFGetFile(&loc, 0, 0, 1, &typeList, 0, &reply);
  85.     // get out if cancelled
  86.     if (reply.good == 0)
  87.     return;
  88.     // open sound file and get size
  89.     count = huffman_readsize(&reply.Namelength, reply.vRefNum);
  90.     // return if error
  91.     if (count < -1)
  92.     return;
  93.     // test for non-compressed sound
  94.     if (count == -1)
  95.     {
  96.     // flag non-compressed cound
  97.     compressed = 0;
  98.     // get size of the file
  99.     PBGetEOF(&huffIo, false);
  100.     count = huffIo.ioMisc;
  101.     }
  102.     else compressed = 1;  // compressed sound
  103.     // allocate buffer
  104.     buffer = (unsigned char *)NewPtr(count);
  105.     if (buffer == null)
  106.     {
  107.     // not enough room: close channel
  108.     huffman_close();
  109.     // and exit
  110.     return;
  111.     }
  112.     // read the sound data in
  113.     if (compressed)
  114.     {
  115.     // readin and unpack compressed sound data
  116.     errcode = huffman_input(buffer, &sampling, iobuff, iocnt);
  117.     }
  118.     else
  119.     {
  120.     // read in the uncompressed sound directly
  121.     huffIo.ioBuffer = (char *)buffer;
  122.     huffIo.ioReqCount = count;    // 2 longwords
  123.     huffIo.ioPosMode = 1;    // absolute
  124.     huffIo.ioPosOffset = 0;    // from the beginning
  125.     PBRead(&huffIo, false);
  126.     errcode = huffIo.ioResult;
  127.     // assume sampling rate is 1
  128.     sampling = 1;
  129.     }
  130.     // close channel
  131.     huffman_close();
  132.     // play the sound if there was no error reading in
  133.     if (errcode == 0)
  134.     play_back_sound(buffer, count, sampling);
  135.     }
  136.