home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 519b.lha / FZIFF / fziff.c < prev    next >
C/C++ Source or Header  |  1991-06-09  |  2KB  |  101 lines

  1. /* hilo - print highest and lowest sample values */
  2.  
  3. #include <stdio.h>
  4. #include <fcntl.h>
  5. #include <functions.h>
  6. #include <hackercorp/iff.h>
  7. #include <hackercorp/8svx.h>
  8.  
  9. #include "prototypes.h"
  10.  
  11. Voice8Header v8head;
  12.  
  13. short buffer[512];
  14.  
  15. char *program_name = "fziff";
  16.  
  17. long nsamples;
  18. UBYTE *bodyp;
  19.  
  20. void freebody(void)
  21. {
  22.     if (bodyp)
  23.         FreeMem(bodyp,nsamples);
  24. }
  25.  
  26. main(int argc, char *argv[])
  27. {
  28.     int fzfd, svxfd;
  29.     UBYTE *outp;
  30.     int i;
  31.  
  32.     if (argc != 3)
  33.     {
  34.         fprintf(stderr,"usage: fziff fz1dumpfilename new8svxfilename\n");
  35.         exit(1);
  36.     }
  37.  
  38.     init_libs();
  39.  
  40.     /* open the sample file read from the casio fz-1 by karl's fz-1 read stuff */
  41.     if ((fzfd = open(argv[1],O_RDONLY)) == -1)
  42.     {
  43.         perror(argv[1]);
  44.         exit(2);
  45.     }
  46.  
  47.     /* eventually get the real number from the voice parameters */
  48.     nsamples = (lseek(fzfd,0L,2) - 1024) / 2;
  49.  
  50.     /* initialize the VHDR chunk */
  51.     v8head.oneShotHiSamples = nsamples;
  52.     v8head.repeatHiSamples = 0;
  53.     v8head.samplesPerHiCycle = 0;
  54.     v8head.samplesPerSec = 17987;    /* get it out of the header eventually */
  55.     v8head.ctOctave = 0;
  56.     v8head.sCompression = 0;
  57.     v8head.volume = 65535;
  58.  
  59.     /* skip the voice parameters for now - this assumes, as the casio dumper
  60.      * does, only one voice and no banks */
  61.     if (lseek(fzfd, 1024L,0) == -1)
  62.     {
  63.         perror(argv[1]);
  64.         exit(3);
  65.     }
  66.  
  67.     /* get that IFF file open, we have to cleanup from now on */
  68.     if ((svxfd = CreateIFF(argv[2],ID_FORM,ID_8SVX)) == -1)
  69.         panic("unable to create IFF 8SVX file\n");
  70.  
  71.     if (!WriteChunk(svxfd,ID_VHDR,&v8head,sizeof(v8head)))
  72.         panic("unable to write VHDR chunk");
  73.  
  74.     if (!WriteTextChunk(svxfd,ID_NAME,argv[2]))
  75.         panic("unable to write NAME chunk");
  76.  
  77. /*
  78.     if (!WriteTextChunk(svxfd,ID_Copyright,"Copyright (C) 1989 Hackercorp.  All Rights Reserved."))
  79.         panic("unable to write Copyright chunk");
  80.  
  81.     if (!WriteTextChunk(svxfd,ID_ANNO,"sampled on a 16-bit synth and converted for the Amiga by Karl Lehenbauer/Hackercorp"));
  82.  
  83. */
  84.  
  85.     if ((bodyp = AllocMem(nsamples,0)) == NULL)
  86.         panic("unable to alloc sample memory");
  87.  
  88.     add_cleanup(freebody);
  89.     outp = bodyp;
  90.     while (read(fzfd,&buffer[0],1024) == 1024)
  91.     {
  92.         for (i = 0; i < 512; i++)
  93.             *outp++ = buffer[i] & 0xff;
  94.     }
  95.     WriteChunk(svxfd,ID_BODY,bodyp,nsamples);
  96.  
  97.     Rewrite_IFF_header(svxfd);
  98.     exit(0);
  99. }
  100.  
  101.