home *** CD-ROM | disk | FTP | other *** search
/ Micro R&D 1 / MicroRD-CD-ROM-Vol1-1994.iso / os30 / gfx / animdemo.lha / makeraw / audio.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-23  |  2.1 KB  |  76 lines

  1. /*******************************************************************************
  2.  *
  3.  * (c) Copyright 1993 Commodore-Amiga, Inc.  All rights reserved.
  4.  *
  5.  * This software is provided as-is and is subject to change; no warranties
  6.  * are made.  All use is at your own risk.  No liability or responsibility
  7.  * is assumed.
  8.  *
  9.  * Audio - Reads an 8SVX audio file, strips the IFF headers, and writes to the
  10.  * raw animation file.
  11.  *
  12.  ******************************************************************************/
  13.  
  14. #include <exec/types.h>
  15. #include <exec/memory.h>
  16. #include <proto/exec.h>
  17. #include <libraries/iffparse.h>
  18. #include <proto/iffparse.h>
  19. #include <dos/dos.h>
  20. #include <proto/dos.h>
  21.  
  22. #include "/playanim.h"
  23.  
  24. #define ID_8SVX MAKE_ID('8','S','V','X')
  25. #define ID_VHDR MAKE_ID('V','H','D','R')
  26. #define ID_BODY MAKE_ID('B','O','D','Y')
  27.  
  28. /* convert an 8SVX file to raw audio data. */
  29. void GetAudio(STRPTR FileName, BPTR OutFile)
  30. {
  31.     struct ContextNode *cn;
  32.     struct StoredProperty *sp;
  33.     struct IFFHandle *iff;
  34.     ULONG secsize;
  35.     UBYTE *inbuff;
  36.     struct VHDR vhdr;
  37.     struct RawAudio ra;
  38.  
  39.     if (iff = AllocIFF())
  40.     {
  41.     if (iff->iff_Stream = Open(FileName, MODE_OLDFILE))
  42.     {
  43.         InitIFFasDOS(iff);
  44.         if (OpenIFF(iff, IFFF_READ) == NULL)
  45.         {
  46.             if ((PropChunk(iff, ID_8SVX, ID_VHDR) == 0) &&
  47.                 (StopChunk(iff, ID_8SVX, ID_BODY) == 0) &&
  48.                 (ParseIFF(iff, IFFPARSE_SCAN) == 0))
  49.             {
  50.                 if (sp = FindProp(iff, ID_8SVX, ID_VHDR))
  51.                 {
  52.                     vhdr = (*(struct VHDR *)sp->sp_Data);
  53.                     ra.ra_SizeOfSample = vhdr.OneShotHiSamples;
  54.                     ra.ra_SamplesPerSecond = vhdr.SamplesPerSec;
  55.                     ra.ra_SamplesPerCycle = vhdr.SamplesPerHiCycle;
  56.                     ra.ra_Volume = vhdr.Volume;
  57.                 }
  58.                 /* we are at the BODY chunk */
  59.                 if ((cn = CurrentChunk(iff)) &&
  60.                     (secsize = (WHOLE_SECTORS(cn->cn_Size + sizeof(struct RawAudio)) * SECTORSIZE)) &&
  61.                     (inbuff = AllocVec(secsize, MEMF_CLEAR)))
  62.                 {
  63.                     ReadChunkBytes(iff, inbuff, cn->cn_Size);
  64.                     Write(OutFile, &ra, sizeof(struct RawAudio));
  65.                     Write(OutFile, inbuff, (secsize - sizeof(struct RawAudio)));
  66.                     FreeVec(inbuff);
  67.                 }
  68.             }
  69.             CloseIFF(iff);
  70.         }
  71.         Close(iff->iff_Stream);
  72.     }
  73.     FreeIFF(iff);
  74.     }
  75. }
  76.