#ifndef lint
static char sccsid[] = "@(#)ulawtolin.c	1.3 (UKC) 12/3/89";
#endif
/* ulawtolin.c - convert ulaw to linear
**
** 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"

#define SBUFSIZ (BUFSIZ/sizeof(short))	/* No of entries */
static short sbuf[SBUFSIZ];

main( argc, argv )
int argc;
char *argv[];
    {
    FILE *f;
    int nsamples;
    int c;

    if ( argc == 1 )
	f = stdin;
    else if ( argc == 2 )
	{
	f = fopen( argv[1], "r" );
	if ( f == NULL )
	    {
	    perror( argv[1] );
	    exit( 1 );
	    }
	}
    else
	{
	fprintf( stderr, "usage:  %s [<file>]\n", argv[0] );
	exit( 1 );
	}

    nsamples = 0;
    while ( (c = getc( f )) != EOF )
	{
	sbuf[nsamples++] = st_ulaw_to_linear( c );
	if (nsamples >= SBUFSIZ)
	    {
	    fwrite((char *)sbuf, sizeof(sbuf[0]), nsamples, stdout);
	    nsamples = 0;
	    }
	}

    if (nsamples > 0)
	{
	fwrite((char *)sbuf, sizeof(sbuf[0]), nsamples, stdout);
	nsamples = 0;
	}

    exit( 0 );
    }
