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 / sstcut.c < prev    next >
C/C++ Source or Header  |  1990-01-10  |  2KB  |  80 lines

  1. /* sstcut.c - cut a segment out of a sound file
  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. main( argc, argv )
  17. int argc;
  18. char *argv[];
  19.     {
  20.     FILE *f;
  21.     float start, length;
  22.     int sstart, slength;
  23.     int i, c;
  24.     char *usage = "usage:  %s <start> <length> [file]\n";
  25.  
  26.     if ( argc < 3 || argc > 4 )
  27.     {
  28.     fprintf( stderr, usage, argv[0] );
  29.     exit( 1 );
  30.     }
  31.  
  32.     if ( sscanf( argv[1], "%g", &start ) != 1 )
  33.     {
  34.     fprintf( stderr, usage, argv[0] );
  35.     exit( 1 );
  36.     }
  37.     sstart = start * SAMPLES_PER_SECOND;
  38.     if ( sscanf( argv[2], "%g", &length ) != 1 )
  39.     {
  40.     fprintf( stderr, usage, argv[0] );
  41.     exit( 1 );
  42.     }
  43.     slength = length * SAMPLES_PER_SECOND;
  44.  
  45.     if ( sstart < 0 )
  46.     {
  47.     fprintf( stderr, "%s: start is less than zero\n", argv[0] );
  48.     exit( 1 );
  49.     }
  50.     if ( slength < 1 )
  51.     {
  52.     fprintf( stderr, "%s: length is less than one sample\n", argv[0] );
  53.     exit( 1 );
  54.     }
  55.  
  56.     if ( argc == 3 )
  57.     f = stdin;
  58.     else if ( argc == 4 )
  59.     {
  60.     f = fopen( argv[3], "r" );
  61.     if ( f == NULL )
  62.         {
  63.         perror( argv[3] );
  64.         exit( 1 );
  65.         }
  66.     }
  67.  
  68.     for ( i = 0; (c = getc( f )) != EOF; ++i )
  69.     {
  70.     if ( i >= sstart )
  71.         {
  72.         if ( i >= sstart + slength )
  73.         break;
  74.         putchar( c );
  75.         }
  76.     }
  77.  
  78.     exit( 0 );
  79.     }
  80.