home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / c / lpc05b.zip / LPCMAIN.C < prev    next >
C/C++ Source or Header  |  1992-05-22  |  4KB  |  187 lines

  1. #include <stdio.h>
  2.  
  3. #include "matrix.h"
  4. #include "lpc.h"
  5. #include "cparser.h"
  6. #include "version.h"
  7. #include "gio.h"
  8.  
  9.  
  10. /*
  11. *-------------------------------------------------------------------------
  12. *    lpc parameters:
  13. *    lpc_nsize = window size (no. of points)
  14. *    lpc_order = order of LPC 
  15. *    lpc_itype = input raw data type
  16. *    lpc_cepstrum = cepstrum flag
  17. *-------------------------------------------------------------------------
  18. */
  19. int    lpc_wsize = 256;
  20. int    lpc_wover = 0;
  21. int    lpc_order = 8;
  22. int    lpc_dtype = AUDIOPCM16;
  23. int    usestdout = 0;
  24. int    lpc_method = LPCAUTOCOR;
  25. int    acfile = 1;
  26. char    *ext = ".lpc";
  27. GIO *    gin;
  28. GIO *    gout;
  29. GIO *    gacout;
  30.  
  31. int    usage( )
  32. {
  33.     printf( "\n\n\n" );
  34.     printf( "%s %s - by %s\n", PROGNAME, VERSION, AUTHOR );
  35.     printf( "Copyright (c) 1992 All Rights Reserved. %s\n", DATE );
  36.     printf( "Synopsis: a LPC, PARCOR, LPC Cepstrum encoding program\n");
  37.     printf( "Usage: %s <switches> <files>\n", PROGNAME);
  38.     printf( "<switches> : \n" );
  39.     printf( "\t-order=#         \t;LPC order (def=%d)\n", lpc_order );
  40.     printf( "\t-wsize=#         \t;LPC window size (def=%d)\n", lpc_wsize );
  41.     printf( "\t-wover=#         \t;LPC window overlap points (def=0)\n" );
  42.     printf( "\t-dtype=ulaw8     \t;8-bit ulaw input audio data type\n" );
  43.     printf( "\t-dtype=pcm16     \t;16-bit PCM input audio data type\n" );
  44.  
  45.     /*
  46.     * not implemented yet
  47.     */
  48. /*
  49.     printf( "\t-msgqin=<key>   \t;input from message queue\n" );
  50.     printf( "\t-msgqout=<key>  \t;output to message queue\n" );
  51. */
  52.     printf( "\t-stdout          \t;use standard output only\n" );
  53.     printf( "\t-noacfile        \t;do not generate .ac file\n" );
  54.     printf( "\t                 \t;\n" );
  55.     printf( "\t-autocor         \t;generate LPC autocorr coefficients (def)\n" );
  56.     printf( "\t-covar           \t;generate LPC covariance coefficients\n" );
  57.     printf( "\t-cepstrum        \t;generate LPC cepstrum coefficients\n" );
  58.     printf( "\t-parcor          \t;generate PARCOR coefficients\n" );
  59.     printf( "\t                 \t;(default = autocorrelation method)\n" );
  60.     printf( "\n" );
  61.     printf( "<files> = input audio file name(s)\n" );
  62.     printf( "\n" );
  63.     printf( "Note: response file @ feature is supported\n" );
  64.     printf( "\te.g. %s @myfile.rsp\n", PROGNAME );
  65.     exit (0);
  66. }
  67.  
  68. int    parse( )
  69. {
  70.     int    cmd;
  71.     char    rest[128];
  72.     char    temp[128];
  73.     int    resti, i;
  74.     long    restl;
  75.  
  76.     while ((cmd = cmdget( rest ))!= -1)
  77.         {
  78.         resti = atoi(rest);
  79.         restl = atol(rest);
  80.         switch (cmd)
  81.         {
  82.         case CMD_LPCORDER:
  83.             lpc_order = resti;
  84.             break;
  85.         case CMD_LPCWSIZE:
  86.             lpc_wsize = resti;
  87.             break;
  88.         case CMD_LPCWOVER:
  89.             lpc_wover = resti;
  90.             break;
  91.         case CMD_DTYPEU8:
  92.             lpc_dtype = AUDIOULAW8;
  93.             break;
  94.         case CMD_DTYPEP16:
  95.             lpc_dtype = AUDIOPCM16;
  96.             break;
  97.         case CMD_MSGQIN:
  98.             break;
  99.         case CMD_MSGQOUT:
  100.             break;
  101.         case CMD_STDOUT:
  102.             usestdout = 1;
  103.             break;
  104.         case CMD_NOACFILE:
  105.             acfile = 0;
  106.             break;
  107.         case CMD_AUTOCOR:
  108.             ext = ".lpc";
  109.             lpc_method = LPCAUTOCOR;
  110.             break;
  111.         case CMD_COVAR:
  112.             ext = ".lpc";
  113.             lpc_method = LPCCOVAR;
  114.             break;
  115.         case CMD_CEPSTRUM:
  116.             ext = ".cep";
  117.             lpc_method = LPCCEPSTRUM;
  118.             break;
  119.         case CMD_PARCOR:
  120.             ext = ".par";
  121.             lpc_method = PARCOR;
  122.             break;
  123.         case CMD_COMMENT:
  124.             break;
  125.         case CMD_NULL:
  126.             if ((gin = gopen(GIO_FILE, rest, "rb")) == NULL)
  127.                 {
  128.                 fprintf( stderr, "file <%s> open fails\n", rest );
  129.                 break;
  130.                 }
  131.             if (!usestdout)
  132.                 {
  133.                 i = strlen(rest);
  134.                 strcpy( temp, rest );
  135.                 strcpy( temp+i, ext );
  136.                 if ((gout= gopen(GIO_FILE, temp, "w")) == NULL)
  137.                 {
  138.                 fprintf(stderr, "file <%s> open fails\n", temp );
  139.                 break;
  140.                 }
  141.                 }
  142.             else 
  143.                 gout = gopen(GIO_STDOUT, 0, 0);  
  144.  
  145.             if ((lpc_method == LPCAUTOCOR) && acfile)
  146.                 {
  147.                 i = strlen(rest);
  148.                 strcpy( temp, rest );
  149.                 strcpy( temp+i, ".ac" );
  150.                 if ((gacout = gopen(GIO_FILE, temp, "w")) == NULL)
  151.                 {
  152.                 fprintf(stderr, "file <%s> open fails\n", temp );
  153.                 break;
  154.                 }
  155.                 }
  156.             else
  157.                 gacout = NULL;
  158.  
  159.             lpc(gin, lpc_dtype, gout, gacout, lpc_order, lpc_wsize, lpc_wover, lpc_method );
  160.  
  161.             gclose(gin);
  162.             gclose(gout);
  163.             gclose(gacout);
  164.             break;
  165.             }
  166.         }
  167. }
  168.  
  169. int    main( argc, argv )
  170. int    argc;
  171. char    ** argv;
  172. {
  173.  
  174.     if (argc < 2)
  175.         {
  176.         usage();
  177.         }
  178.     else
  179.         {
  180.         cmdinit( argc, argv );
  181.         parse();
  182.         }
  183.  
  184. }
  185.  
  186.  
  187.