home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.lbl.gov / 2014.05.ftp.ee.lbl.gov.tar / ftp.ee.lbl.gov / sst.tar.Z / sst.tar / sst / vox.c < prev    next >
C/C++ Source or Header  |  1990-01-10  |  1KB  |  65 lines

  1. /* vox.c - simple silence-deletion filter
  2. **
  3. ** Copyright (C) 1989 by Jef Poskanzer.
  4. **
  5. ** Permission to use, copy, modify, and distribute this software and its
  6. ** documentation for any purpose and without fee is hereby granted, provided
  7. ** that the above copyright notice appear in all copies and that both that
  8. ** copyright notice and this permission notice appear in supporting
  9. ** documentation.  This software is provided "as is" without express or
  10. ** implied warranty.
  11. */
  12.  
  13. #include <stdio.h>
  14. #include "libst.h"
  15.  
  16. #define abs(a) ((a) >= 0 ? (a) : -(a))
  17.  
  18. #define Q_DELTA 100
  19. #define Q_SAMPLES 512
  20. #define MYBUFSIZ 256
  21.  
  22. main( argc, argv )
  23. int argc;
  24. char *argv[];
  25.     {
  26.     FILE *f;
  27.     char mybuf[MYBUFSIZ];
  28.     int c, lc, plc, q;
  29.  
  30.     if ( argc == 1 )
  31.     f = stdin;
  32.     else if ( argc == 2 )
  33.     {
  34.     f = fopen( argv[1], "r" );
  35.     if ( f == NULL )
  36.         {
  37.         perror( argv[1] );
  38.         exit( 1 );
  39.         }
  40.     }
  41.     else
  42.     {
  43.     fprintf( stderr, "usage:  %s [<file>]\n", argv[0] );
  44.     exit( 1 );
  45.     }
  46.     setbuffer( stdout, mybuf, MYBUFSIZ );
  47.  
  48.     q = 0;
  49.     for ( plc = 0; (c = getc( f )) != EOF; plc = lc )
  50.     {
  51.     lc = st_ulaw_to_linear( c );
  52.     if ( abs( plc - lc ) <= Q_DELTA )
  53.         q++;
  54.     else
  55.         q = 0;
  56.  
  57.     if ( q < Q_SAMPLES )
  58.         putchar( (unsigned char) c );
  59.     else if ( q == Q_SAMPLES )
  60.         fflush( stdout );
  61.     }
  62.  
  63.     exit( 0 );
  64.     }
  65.