home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / BEERSRC.ZIP / SNDLIB.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-29  |  3.9 KB  |  197 lines

  1.  
  2.  
  3. #ifndef __COMPACT__
  4.    #error Memory Model must be compact
  5. #endif
  6.  
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include <conio.h>
  10. #include <stdio.h>
  11. #include <alloc.h>
  12. #include <io.h>
  13. #include <fcntl.h>
  14. #include <sys\stat.h>
  15. #include <dos.h>
  16.  
  17.  
  18. #include "sound.h"
  19.  
  20. struct filestrc {
  21.    char  name[14];        // Name of file.
  22.    long size;            // It's size.
  23.    int   flags;            // Buffering flags.
  24.    long  fptr;            // File pointer to access it's data.
  25. };
  26.  
  27.  
  28. struct sndstrc lall;
  29. int    nentries;
  30. void   *lib;
  31. long   libsize;
  32. char   *obj;
  33. long   objsize;
  34.  
  35.  
  36. int readlib(char *file)
  37. {
  38.    int  filvar;
  39.    long size;
  40.    char huge *ptr;
  41.  
  42.    filvar = open(file, O_RDONLY | O_BINARY, S_IREAD);
  43.    if (filvar == -1) {
  44.       nentries = 0; libsize = 0;
  45.       return -1;
  46.    }
  47.  
  48.    read(filvar, &nentries, 2);
  49.  
  50.    size = libsize = filelength(filvar) - 2;
  51.    ptr = lib = farmalloc(libsize);
  52.  
  53.    while(size > 65000) {
  54.       read(filvar, ptr, 65000);
  55.       ptr += 65000; size -= 65000;
  56.    }
  57.    read(filvar, ptr, size);
  58.  
  59.    close(filvar);
  60.  
  61.    return 0;
  62. }
  63.  
  64.  
  65. int readobj(char *file)
  66. {
  67.    int   filvar;
  68.    long  size;
  69.    char  huge *ptr;
  70.  
  71.    filvar = open(file, O_RDONLY | O_BINARY, S_IREAD);
  72.    if (filvar == -1) {
  73.       perror("readobj : ");
  74.       return -1;
  75.    }
  76.  
  77.    size = objsize = (filelength(filvar) - 0x21) & 0xfffffffel;
  78.    ptr = obj = farmalloc(objsize);
  79.  
  80.    lseek(filvar, 0x20, SEEK_SET);
  81.    while(size > 65000) {
  82.       read(filvar, ptr, 65000);
  83.       ptr += 65000; size -= 65000;
  84.    }
  85.    read(filvar, ptr, size);
  86.  
  87.    close(filvar);
  88.  
  89.    return 0;
  90. }
  91.  
  92.  
  93. int writelib(char *file)
  94. {
  95.    int    filvar;
  96.    int    i;
  97.    long   ptr;
  98.    struct filestrc *waff1;
  99.    long   *waff2;
  100.    long   size;
  101.    char   huge *hptr;
  102.  
  103.  
  104.    filvar = open(file, O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, S_IWRITE);
  105.    if (filvar == -1) {
  106.       perror("\nwritelib : ");
  107.       exit(1);
  108.       return -1;
  109.    }
  110.  
  111.    i = nentries + 1;
  112.    write(filvar, &i, 2);
  113.  
  114.    waff2 = (long *)lib;
  115.    for (i = 0; i < nentries; i++) {
  116.       waff2[i] += sizeof(long);
  117.       write(filvar, waff2+i, sizeof(long));
  118.    }
  119.    ptr = libsize + sizeof(long);
  120.    ptr = (ptr & 0xf) + ((ptr & 0xffff0) << 12);
  121.    write(filvar, &ptr, sizeof(long));
  122.    size = libsize - nentries*sizeof(long);
  123.    hptr = (char *)&waff2[nentries];
  124.    while (size > 65000) {
  125.       write(filvar, hptr, 65000);
  126.       hptr += 65000; size -= 65000;
  127.    }
  128.    write(filvar, hptr, size);
  129.  
  130.    write(filvar, &lall, sizeof(struct sndstrc));
  131.    hptr = obj; size = objsize;
  132.    while (size > 65000) {
  133.       write(filvar, hptr, 65000);
  134.       hptr += 65000; size -= 65000;
  135.    }
  136.    write(filvar, hptr, size);
  137.  
  138.    close(filvar);
  139.  
  140.    return 0;
  141. }
  142.  
  143.  
  144.  
  145.  
  146. void main(void)
  147. {
  148.  
  149.    char   libfile[80];
  150.    char   objfile[80];
  151.    char   text[80];
  152.    char   c;
  153.  
  154.  
  155.    printf("\n\nSound Librarian [c] 1993 by Alpha-Helix.\n\n");
  156.    printf("Library [.SND]: ");
  157.    fflush(stdin);
  158.    scanf("%s", libfile);
  159.    strcat(libfile, ".SND");
  160.    do {
  161.       printf("Sound [.VOC] : ");
  162.       fflush(stdin);
  163.       scanf("%s", objfile);
  164.       strcat(objfile, ".VOC");
  165.       if (objfile[0] != '.') {
  166.      readlib(libfile);
  167.      if (readobj(objfile) != -1 ) {
  168.         lall.len = objsize;
  169.         printf("Sampling Rate [9]: ");
  170.         fflush(stdin);
  171.         gets(text);
  172.         if (strlen(text) == 0) lall.samplerate = 9;
  173.         else lall.samplerate = atoi(text);
  174.         printf("4 bit packed [n]: ");
  175.         fflush(stdin);
  176.         gets(text);
  177.         lall.flags = 0;
  178.         if (strlen(text) != 0) {
  179.            if (text[0] == 'y') lall.flags = SND_PACKED4;
  180.         }
  181.         printf("Priority [5]: ");
  182.         fflush(stdin);
  183.         gets(text);
  184.         if (strlen(text) == 0) lall.priority = 5;
  185.         else lall.priority = atoi(text);
  186.         writelib(libfile);
  187.         farfree(obj);
  188.      }
  189.      farfree(lib);
  190.       }
  191.    } while (objfile[0] != '.');
  192.  
  193.    printf("\nDone.\n\n");
  194. }
  195.  
  196.  
  197.