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 >
Wrap
C/C++ Source or Header
|
1990-01-10
|
2KB
|
80 lines
/* sstcut.c - cut a segment out of a sound file
**
** Copyright (C) 1989 by Jef Poskanzer.
**
** Permission to use, copy, modify, and distribute this software and its
** documentation for any purpose and without fee is hereby granted, provided
** that the above copyright notice appear in all copies and that both that
** copyright notice and this permission notice appear in supporting
** documentation. This software is provided "as is" without express or
** implied warranty.
*/
#include <stdio.h>
#include "libst.h"
main( argc, argv )
int argc;
char *argv[];
{
FILE *f;
float start, length;
int sstart, slength;
int i, c;
char *usage = "usage: %s <start> <length> [file]\n";
if ( argc < 3 || argc > 4 )
{
fprintf( stderr, usage, argv[0] );
exit( 1 );
}
if ( sscanf( argv[1], "%g", &start ) != 1 )
{
fprintf( stderr, usage, argv[0] );
exit( 1 );
}
sstart = start * SAMPLES_PER_SECOND;
if ( sscanf( argv[2], "%g", &length ) != 1 )
{
fprintf( stderr, usage, argv[0] );
exit( 1 );
}
slength = length * SAMPLES_PER_SECOND;
if ( sstart < 0 )
{
fprintf( stderr, "%s: start is less than zero\n", argv[0] );
exit( 1 );
}
if ( slength < 1 )
{
fprintf( stderr, "%s: length is less than one sample\n", argv[0] );
exit( 1 );
}
if ( argc == 3 )
f = stdin;
else if ( argc == 4 )
{
f = fopen( argv[3], "r" );
if ( f == NULL )
{
perror( argv[3] );
exit( 1 );
}
}
for ( i = 0; (c = getc( f )) != EOF; ++i )
{
if ( i >= sstart )
{
if ( i >= sstart + slength )
break;
putchar( c );
}
}
exit( 0 );
}