Skip to content
Snippets Groups Projects
frame.c 28.87 KiB
/****************************************************************************
 *
 * Programs for processing sound files in raw- or WAV-format.
 * -- Useful functions for parsing command line options and
 *    issuing errors, warnings, and chit chat.
 *
 * Name:    frame.c
 * Version: see static char *standardversion, below.
 * Author:  Mark Roberts <mark@manumark.de>
 *	    Michael Labuschke <michael@labuschke.de> sys_errlist fixes 
 *		
 ****************************************************************************/
/****************************************************************************
 *  These are useful functions that all DSP programs might find handy
 ****************************************************************************/

#include <stdio.h>
#include <math.h>
#include <stdlib.h> /* for exit and malloc */
#include <string.h>
#include <time.h>
#include <stdarg.h>
#include <errno.h>
#include <assert.h>
#include "frame.h"

time_t stopwatch;       /* will hold time at start of calculation */
int samplefrequency;
unsigned short samplewidth;
unsigned short channels;
int wavout;            /* TRUE iff out file should be a .WAV file */
int iswav;             /* TRUE iff in file was found to be a .WAV file */
FILE *in, *out;
char *infilename, *outfilename;
int verboselevel;
char *version = "";
char *usage = "";
static int test_usage;

static char *standardversion = "frame version 1.3, June 13th 2001";
static char *standardusage =
"\nOptions common to all mark-dsp programs:\n"

"-h \t\t create a WAV-header on output files.\n"
"-c#\t\t set number of channels to # (1 or 2). Default: like input.\n"
"-w#\t\t set number of bits per sample (width) to # (only 16)\n"
"-f#\t\t set sample frequency to #. Default: like input.\n"
"-V \t\t verbose: talk a lot.\n"
"-Q \t\t quiet: talk as little as possible.\n\n"
"In most cases, a filename of '-' means stdin or stdout.\n\n"
"Bug-reports: mark@manumark.de\n"
;

/* -----------------------------------------------------------------------
   Writes the number of samples to result that are yet to be read from anyin.
   Return values are TRUE on success, FALSE on failure.
   -----------------------------------------------------------------------*/
int getremainingfilelength( FILE *anyin, long *result)
{
    long i;

    i = ftell (anyin);
    if (i == -1) return FALSE;
    if (fseek (anyin, 0, SEEK_END) == -1) return FALSE;
    *result = ftell (anyin);
    if (*result == -1) return FALSE;
    (*result) -= i;
    (*result) /= samplewidth;
    if (fseek (anyin, i, SEEK_SET) == -1) return FALSE;
    return TRUE;