utils/frame.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define BUFFSIZE   50000
#define DEFAULTFREQ   44100
#define FALSE   (0==1)
#define INBIN   (1+2)
#define INTEXT   (1+0)
#define IOBIN   (32)
#define MINBUFFSIZE   5000
#define NOCOMPLAIN   (16)
#define NOFILES   (0)
#define OUTBIN   (4+8)
#define OUTTEXT   (4)
#define TRUE   (0==0)

Enumerations

enum  Errornum {
  ME_NOINT, ME_NODOUBLE, ME_NOTIME, ME_NOVOL,
  ME_NOSWITCH, ME_TOOMANYFILES, ME_HEADERONTEXTFILE, ME_NOINFILE,
  ME_NOOUTFILE, ME_NOIOFILE, ME_NOSTDIN, ME_NOSTDOUT,
  ME_NOSTDIO, ME_NOTENOUGHFILES, ME_THISCANTHAPPEN
}

Functions

void argerror (char *s)
void argerrornum (char *s, Errornum code)
void argerrortxt (char *s, char *message)
int chat (const char *format,...)
void checknoargs (int argcount, char *args[])
double double2db (double value)
int error (const char *format,...)
void fatalerror (const char *format,...)
void fatalperror (const char *string)
int findoption (int argcount, char *args[], char *s)
int getremainingfilelength (FILE *anyin, long *result)
int inform (const char *format,...)
int isoptionchar (char coal)
void makewavheader (void)
char * mallocconcat (char *one, char *two)
char * malloccopy (char *string)
int myexit (int value)
void parseargs (int argcount, char *args[], int fileswitch)
int parsedoublearg (int argcount, char *args[], char *string, double *result)
char * parsefilearg (int argcount, char *args[])
int parsefreq (char *string, double *result)
int parseintarg (int argcount, char *args[], char *string, int *result)
int parseswitch (char *found, char *wanted)
int parseswitcharg (int argcount, char *args[], char *string)
int parsetime (char *string, int *result)
int parsetimearg (int argcount, char *args[], char *string, int *result)
int parsevolarg (int argcount, char *args[], char *string, double *result)
int parsevolume (char *s, double *result)
void readawaysamples (FILE *in, size_t size)
void readpkheader (FILE *anyin)
void readwavheader (FILE *anyin)
int say (const char *format,...)
void startstopwatch (void)
int workloop (FILE *theinfile, FILE *theoutfile, int(*work)(short *buffer, int length))

Variables

unsigned short channels
FILE * in
char * infilename
int iswav
FILE * out
char * outfilename
int samplefrequency
unsigned short samplewidth
char * usage
int verboselevel
char * version
int wavout


Define Documentation

#define BUFFSIZE   50000

Definition at line 54 of file utils/frame.h.

Referenced by main(), readawaysamples(), and workloop().

#define DEFAULTFREQ   44100

Definition at line 53 of file utils/frame.h.

Referenced by parseargs().

#define FALSE   (0==1)

Definition at line 36 of file utils/frame.h.

#define INBIN   (1+2)

Definition at line 28 of file utils/frame.h.

#define INTEXT   (1+0)

Definition at line 27 of file utils/frame.h.

#define IOBIN   (32)

Definition at line 33 of file utils/frame.h.

#define MINBUFFSIZE   5000

Definition at line 55 of file utils/frame.h.

#define NOCOMPLAIN   (16)

Definition at line 32 of file utils/frame.h.

Referenced by main().

#define NOFILES   (0)

Definition at line 31 of file utils/frame.h.

Referenced by main().

#define OUTBIN   (4+8)

Definition at line 30 of file utils/frame.h.

#define OUTTEXT   (4)

Definition at line 29 of file utils/frame.h.

#define TRUE   (0==0)

Definition at line 37 of file utils/frame.h.


Enumeration Type Documentation

enum Errornum

Enumerator:
ME_NOINT 
ME_NODOUBLE 
ME_NOTIME 
ME_NOVOL 
ME_NOSWITCH 
ME_TOOMANYFILES 
ME_HEADERONTEXTFILE 
ME_NOINFILE 
ME_NOOUTFILE 
ME_NOIOFILE 
ME_NOSTDIN 
ME_NOSTDOUT 
ME_NOSTDIO 
ME_NOTENOUGHFILES 
ME_THISCANTHAPPEN 

Definition at line 60 of file utils/frame.h.

00061 {
00062   ME_NOINT,
00063   ME_NODOUBLE,
00064   ME_NOTIME,
00065   ME_NOVOL,
00066   ME_NOSWITCH,
00067   ME_TOOMANYFILES,
00068   ME_HEADERONTEXTFILE,
00069   ME_NOINFILE,
00070   ME_NOOUTFILE,
00071   ME_NOIOFILE,
00072   ME_NOSTDIN,
00073   ME_NOSTDOUT,
00074   ME_NOSTDIO,
00075   ME_NOTENOUGHFILES,
00076   ME_THISCANTHAPPEN
00077 } Errornum;


Function Documentation

void argerror ( char *  s  ) 

Definition at line 625 of file utils/frame.c.

References error(), and fatalerror().

00626 {
00627   error ("Error parsing command line. Unrecognized option:\n\t-%s\n", s);
00628   fatalerror("\nTry --help for help.\n");
00629 }

void argerrornum ( char *  s,
Errornum  code 
)

Definition at line 635 of file utils/frame.c.

References error(), fatalerror(), ME_HEADERONTEXTFILE, ME_NODOUBLE, ME_NOINFILE, ME_NOINT, ME_NOIOFILE, ME_NOOUTFILE, ME_NOSTDIN, ME_NOSTDIO, ME_NOSTDOUT, ME_NOSWITCH, ME_NOTENOUGHFILES, ME_NOTIME, ME_NOVOL, ME_THISCANTHAPPEN, ME_TOOMANYFILES, and NULL.

Referenced by main(), parseargs(), parsedoublearg(), parsefreq(), parseintarg(), parseswitch(), parseswitcharg(), parsetime(), parsetimearg(), and parsevolarg().

00636 {
00637   char *message;
00638 
00639   if (code == ME_TOOMANYFILES)
00640     {
00641       error("Too many files on command line: '%s'.\n", s);
00642     }
00643   else
00644     {
00645       if (s != NULL)
00646    error ("Error parsing option -%s:\n\t", s);
00647       switch( code)
00648    {
00649    case ME_NOINT:
00650      message = "Integer expected";
00651      break;
00652    case ME_NODOUBLE:
00653      message = "Floating point number expected";
00654      break;
00655    case ME_NOTIME:
00656      message = "Time argument expected";
00657      break;
00658    case ME_NOVOL:
00659      message = "Volume argument expected";
00660      break;
00661    case ME_NOSWITCH:
00662      message = "Garbage after switch-type option";
00663      break;
00664    case ME_HEADERONTEXTFILE:
00665      message = "Option -h is not useful for text-output";
00666      break;
00667    case ME_NOINFILE:
00668      message = "No input file specified";
00669      break;
00670    case ME_NOOUTFILE:
00671      message = "No output file specified";
00672      break;
00673    case ME_NOIOFILE:
00674      message = "No input/output file specified";
00675      break;
00676    case ME_NOSTDIN:
00677      message = "Standard in not supported here";
00678      break;
00679    case ME_NOSTDOUT:
00680      message = "Standard out not supported here";
00681      break;
00682    case ME_NOSTDIO:
00683      message = "Standard in/out not supported here";
00684      break;
00685    case ME_NOTENOUGHFILES:
00686      message = "Not enough files specified";
00687      break;
00688    case ME_THISCANTHAPPEN:
00689      fatalerror("\nThis can't happen. Report this as a bug\n");
00690      /* fatalerror does not return */
00691    default:
00692      error("Error code %d not implemented. Fix me!\n", code);
00693      message = "Error message not implemented. Fix me!";
00694    }
00695       error("%s\n", message);
00696     }
00697   fatalerror("\nTry --help for help.\n");
00698 }

void argerrortxt ( char *  s,
char *  message 
)

Definition at line 704 of file utils/frame.c.

References error(), fatalerror(), and NULL.

Referenced by main(), and parseargs().

00705 {
00706   if (s != NULL)
00707     error ("Error parsing option -%s:\n\t", s);
00708   else
00709     error ("Error parsing command line:\n\t");
00710   error ("%s\n", message);
00711   fatalerror("\nTry --help for help.\n");
00712 }

int chat ( const char *  format,
  ... 
)

Definition at line 971 of file utils/frame.c.

References result, and verboselevel.

Referenced by makewavheader(), myexit(), and readwavheader().

00972 {
00973     va_list ap;
00974     int result = 0;
00975 
00976     if (verboselevel > 5)
00977     {
00978    va_start( ap, format);
00979    result = vfprintf( stderr, format, ap);
00980    va_end( ap);
00981     }
00982     return result;
00983 }

void checknoargs ( int  argcount,
char *  args[] 
)

Definition at line 717 of file utils/frame.c.

References error(), and fatalerror().

Referenced by main().

00718 {
00719   int i, errorcount = 0;
00720 
00721   for (i = 1; i < argcount; i++)
00722     {
00723       if (args[i][0] != '\0')   /* An unused argument! */
00724    {
00725      errorcount++;
00726      if (errorcount == 1)
00727        error("The following arguments were not recognized:\n");
00728      error("\t%s\n", args[i]);
00729    }
00730     }
00731   if (errorcount > 0)           /* Errors are fatal */
00732     fatalerror("\nTry --help for help.\n");
00733 
00734   return;                       /* No errors? Return. */
00735 }

double double2db ( double  value  ) 

Definition at line 1062 of file utils/frame.c.

01063 {
01064   if (value < 0)
01065     value = -value;
01066   return 6.0 * log( value / 32767) / log( 2);
01067 }

int error ( const char *  format,
  ... 
)

Definition at line 999 of file utils/frame.c.

References result.

Referenced by __ast_pbx_run(), __rtp_recvfrom(), acl_handler(), acl_handler_fn(), aco_info_init(), aco_process_ast_config(), add_calltoken_ignore(), append_string(), apply_general_options(), argerror(), argerrornum(), argerrortxt(), ast_json_vpack(), ast_odbc_find_table(), ast_parse_arg(), ast_tcptls_client_create(), ast_tcptls_server_start(), AST_TEST_DEFINE(), authenticate(), build_callno_limits(), build_peer(), cdr_handler(), checknoargs(), conf_load_config(), confbridge_cfg_alloc(), config_handler(), deliver_file(), exec(), fax_gateway_attach(), fax_gateway_detect_t38(), fax_gateway_framehook(), fax_gateway_start(), generic_fax_exec(), handle_cli_agi_show(), handle_incoming(), handle_request_invite(), handler_wait_for_message(), iax2_hangup(), iax2_write(), ip_identify_match_handler(), jingle_outgoing_hook(), jingle_send_error_response(), load_config(), load_module(), load_or_reload_lua_stuff(), lua_get_state(), message_template_build(), mgcp_devicestate(), minivm_accmess_exec(), mysql_log(), named_acl_config_alloc(), osp_check_destination(), osp_create_provider(), osp_create_transaction(), osp_finish(), osp_load(), osp_lookup(), osp_next(), osp_validate_token(), parse_uri_full(), realtime_destroy_handler(), realtime_handler(), realtime_multi_handler(), realtime_store_handler(), realtime_update2_handler(), realtime_update_handler(), receivefax_exec(), refer_progress_alloc(), reload_config(), send_packet(), sendfax_exec(), skel_config_alloc(), store_config(), t30_phase_e_handler(), test_config_alloc(), transport_localnet_handler(), unbound_config_alloc(), update2_ldap(), update_ldap(), user_event_wait_for_events(), verify_user_event_fields(), write_cdr(), write_cel(), xmpp_component_register_get_hook(), xmpp_config_alloc(), and xmpp_pubsub_handle_error().

01000 {
01001     va_list ap;
01002     int result;
01003 
01004     va_start( ap, format);
01005     result = vfprintf( stderr, format, ap);
01006     va_end( ap);
01007     return result;
01008 }

void fatalerror ( const char *  format,
  ... 
)

Definition at line 1010 of file utils/frame.c.

References myexit().

Referenced by argerror(), argerrornum(), argerrortxt(), checknoargs(), main(), and parseargs().

01011 {
01012     va_list ap;
01013 
01014     va_start( ap, format);
01015     vfprintf( stderr, format, ap);
01016     va_end( ap);
01017     myexit(1);
01018 }

void fatalperror ( const char *  string  ) 

Definition at line 1020 of file utils/frame.c.

References myexit().

Referenced by main(), parsefilearg(), readawaysamples(), and workloop().

01021 {
01022   perror( string);
01023   myexit( 1);
01024 }

int findoption ( int  argcount,
char *  args[],
char *  s 
)

Definition at line 900 of file utils/frame.c.

References isoptionchar(), and test_usage.

Referenced by parsedoublearg(), parseintarg(), parseswitcharg(), parsetimearg(), and parsevolarg().

00901 {
00902    int i;
00903 
00904    if (test_usage)
00905      printf("Checking for option -%s\n", s);
00906 
00907    for (i=1; i<argcount; i++)
00908    {
00909      if (isoptionchar (args[i][0]) &&
00910     strncmp( args[i] + 1, s, strlen( s)) == 0)
00911        {
00912     args[i][0] = '\0';
00913     return i;
00914        }
00915    }
00916    return -1;
00917 }

int getremainingfilelength ( FILE *  anyin,
long *  result 
)

Definition at line 58 of file utils/frame.c.

References FALSE, samplewidth, and TRUE.

00059 {
00060     long i;
00061 
00062     i = ftell(anyin);
00063     if (i == -1) return FALSE;
00064     if (fseek(anyin, 0, SEEK_END) == -1) return FALSE;
00065     *result = ftell(anyin);
00066     if (*result == -1) return FALSE;
00067     (*result) -= i;
00068     (*result) /= samplewidth;
00069     if (fseek(anyin, i, SEEK_SET) == -1) return FALSE;
00070     return TRUE;
00071 }

int inform ( const char *  format,
  ... 
)

Definition at line 985 of file utils/frame.c.

References result, and verboselevel.

Referenced by main(), parseargs(), and statistics().

00986 {
00987     va_list ap;
00988     int result = 0;
00989 
00990     if (verboselevel > 1)
00991     {
00992    va_start( ap, format);
00993    result = vfprintf( stderr, format, ap);
00994    va_end( ap);
00995     }
00996     return result;
00997 }

int isoptionchar ( char  coal  ) 

Definition at line 319 of file utils/frame.c.

Referenced by findoption(), and parsefilearg().

00320 {
00321    return (coal =='-');
00322 }

void makewavheader ( void   ) 

Definition at line 219 of file utils/frame.c.

References channels, chat(), out, and samplefrequency.

Referenced by main(), myexit(), and parseargs().

00220 {
00221    unsigned int tempuint, filelength;
00222    unsigned short tempushort;
00223 
00224    /* If fseek fails, don't create the header. */
00225    if (fseek(out, 0, SEEK_END) != -1)
00226    {
00227       filelength = ftell(out);
00228       chat("filelength %d, ", filelength);
00229       fseek(out, 0, SEEK_SET);
00230       if (!fwrite("RIFF", 1, 4, out)) { /* 0 */
00231          return;
00232       }
00233       tempuint = filelength - 8;
00234       if (!fwrite(&tempuint, 4, 1, out)) {    /* 4 */
00235          return;
00236       }
00237       if (!fwrite("WAVEfmt ", 1, 8, out)) {   /* 8 */
00238          return;
00239       }
00240       /* length of fmt data 16 bytes */
00241       tempuint = 16;
00242       if (!fwrite(&tempuint, 4, 1, out)) {   /* 16 */
00243          return;
00244       }
00245       /* Format tag: 1 for pcm */
00246       tempushort = 1;
00247       if (!fwrite(&tempushort, 2, 1, out)) { /* 20 */
00248          return;
00249       }
00250       chat("%d channels\n", channels);
00251       if (!fwrite(&channels, 2, 1, out)) {
00252          return;
00253       }
00254       chat("samplefrequency %d\n", samplefrequency);
00255       if (!fwrite(&samplefrequency, 4, 1, out)) {   /* 24 */
00256          return;
00257       }
00258       /* Bytes per second */
00259       tempuint = channels * samplefrequency * 2;
00260       if (!fwrite(&tempuint, 4, 1, out)) {         /* 28 */
00261          return;
00262       }
00263       /* Block align */
00264       tempushort = 2 * channels;
00265       if (!fwrite(&tempushort, 2, 1, out)) {       /* 32 */
00266          return;
00267       }
00268       /* Bits per sample */
00269       tempushort = 16;
00270       if (!fwrite(&tempushort, 2, 1, out)) {       /* 34 */
00271          return;
00272       }
00273       if (!fwrite("data", 4, 1, out)) {            /* 36 */
00274          return;
00275       }
00276       tempuint = filelength - 44;
00277       if (!fwrite(&tempuint, 4, 1, out)) {   /* 40 */
00278          return;
00279       }
00280    }
00281    return;
00282 }

char* mallocconcat ( char *  one,
char *  two 
)

Definition at line 1049 of file utils/frame.c.

References malloc, NULL, and result.

01050 {
01051     char *result;
01052 
01053     result = malloc( strlen( one) + strlen( two) + 1);
01054     if (result != NULL)
01055       {
01056    strcpy( result, one);
01057    strcat( result, two);
01058       }
01059     return result;
01060 }

char* malloccopy ( char *  string  ) 

Definition at line 1038 of file utils/frame.c.

References malloc, NULL, and result.

01039 {
01040     char *result;
01041 
01042     result = malloc( strlen( string) + 1);
01043     if (result != NULL)
01044    strcpy( result, string);
01045     return result;
01046 }

int myexit ( int  value  ) 

Definition at line 922 of file utils/frame.c.

References chat(), makewavheader(), and wavout.

Referenced by fatalerror(), fatalperror(), and main().

00923 {
00924   switch (value)
00925     {
00926     case 0:
00927       if (wavout)
00928    makewavheader();  /* Writes a fully informed .WAV header */
00929       chat("Success!\n");
00930       break;
00931     default:
00932       chat("Failure.\n");
00933       break;
00934     }
00935   exit (value);
00936 }

void parseargs ( int  argcount,
char *  args[],
int  fileswitch 
)

Definition at line 744 of file utils/frame.c.

References argerrornum(), argerrortxt(), channels, DEFAULTFREQ, errno, FALSE, fatalerror(), in, infilename, inform(), makewavheader(), ME_HEADERONTEXTFILE, ME_NOINFILE, ME_NOIOFILE, ME_NOOUTFILE, ME_NOSTDIN, ME_TOOMANYFILES, NULL, out, outfilename, parsefilearg(), parseintarg(), parseswitcharg(), readwavheader(), samplefrequency, samplewidth, standardusage, standardversion, test_usage, usage, verboselevel, version, and wavout.

Referenced by main().

00745 {
00746    char *filename;
00747    int tempint = 0;
00748 
00749    if ((fileswitch & 1) != 0)     /* If getting infile  */
00750      in = NULL;
00751    if ((fileswitch & 4) != 0)     /* If getting outfile */
00752      out = NULL;
00753    wavout = FALSE;
00754    verboselevel = 5;
00755    samplefrequency = DEFAULTFREQ;
00756    samplewidth = 2;
00757    channels = 1;
00758 
00759    /*-----------------------------------------------*
00760     * First first check testcase, usage and version *
00761     *-----------------------------------------------*/
00762    test_usage = parseswitcharg( argcount, args, "-test-usage");
00763    if (parseswitcharg( argcount, args, "-help"))
00764        {
00765     printf("%s%s", usage, standardusage);
00766     exit(0);
00767        }
00768    if (parseswitcharg( argcount, args, "-version"))
00769        {
00770     printf("%s\n(%s)\n", version, standardversion);
00771     exit(0);
00772        }
00773    /*--------------------------------------*
00774     * Set verboselevel                     *
00775     *--------------------------------------*/
00776    while (parseswitcharg( argcount, args, "V"))
00777                verboselevel = 10;
00778    while (parseswitcharg( argcount, args, "Q"))
00779                verboselevel = 1;
00780    /*-------------------------------------------------*
00781     * Get filenames and open files *
00782     *-------------------------------------------------*/
00783    if ((fileswitch & 1) != 0)        /* Infile wanted */
00784      {
00785        infilename = parsefilearg( argcount, args);
00786        if (infilename == NULL)
00787     argerrornum( NULL, ME_NOINFILE);
00788        if (strcmp( infilename, "-") == 0)
00789     {
00790       infilename = "<stdin>";
00791       in = stdin;
00792       if ((fileswitch & 2) != 0)   /* Binfile wanted */
00793         readwavheader( in);
00794     }
00795        else
00796     {
00797       if ((fileswitch & 2) == 0)   /* Textfile wanted */
00798         in = fopen(infilename, "rt");
00799       else                         /* Binfile wanted */
00800         if ((in = fopen(infilename, "rb")) != NULL)
00801           readwavheader( in);
00802     }
00803        if (in == NULL)
00804     fatalerror("Error opening input file '%s': %s\n", infilename,strerror(errno));
00805        else
00806     inform("Using file '%s' as input\n", infilename);
00807      }
00808    if ((fileswitch & 4) != 0)        /* Outfile wanted */
00809      {
00810        outfilename = parsefilearg( argcount, args);
00811        if (outfilename == NULL)
00812     argerrornum( NULL, ME_NOOUTFILE);
00813        if (strcmp( outfilename, "-") == 0)
00814     {
00815       outfilename = "<stdout>";
00816       out = stdout;
00817     }
00818        else
00819     {
00820 
00821       if ((fileswitch & 8) == 0)   /* Textfile wanted */
00822         out = fopen(outfilename, "wt");
00823       else                         /* Binfile wanted */
00824         out = fopen(outfilename, "wb");
00825     }
00826        if (out == NULL)
00827     fatalerror("Error opening output file '%s': %s\n", outfilename,strerror(errno));
00828        else
00829     inform("Using file '%s' as output\n", outfilename);
00830      }
00831    if ((fileswitch & 32) != 0)      /* In-/Outfile wanted */
00832      {
00833        assert (in == NULL && out == NULL);
00834        infilename = outfilename = parsefilearg( argcount, args);
00835        if (outfilename == NULL)
00836     argerrornum( NULL, ME_NOIOFILE);
00837        if (strcmp( infilename, "-") == 0)
00838     argerrornum( infilename, ME_NOSTDIN);
00839        inform("Using file '%s' as input/output\n", outfilename);
00840        in = out = fopen(outfilename, "r+");
00841        if (out == NULL)
00842     fatalerror("Error opening input/output file '%s': %s\n", outfilename,strerror(errno));
00843 
00844        readwavheader( in);
00845      }
00846    if ((fileswitch & 16) == 0)  /* No additional files wanted */
00847      {
00848        if ((filename = parsefilearg( argcount, args)) != NULL)
00849     argerrornum( filename, ME_TOOMANYFILES);
00850      }
00851 
00852    /*-------------------------------------------------*
00853     * Set samplefrequency, width, wavout, 
00854     *-------------------------------------------------*/
00855    parseintarg( argcount, args, "f", &samplefrequency);
00856    wavout = parseswitcharg( argcount, args, "h");
00857    if (parseintarg( argcount, args, "w", &tempint))
00858      {
00859        if (tempint != 16)
00860     argerrortxt(NULL, "Option -w is only valid "
00861            "with value 16. Sorry.");
00862        else
00863     samplewidth = tempint;
00864      }
00865    if (parseintarg( argcount, args, "c", &tempint))
00866      {
00867        if (tempint != 1 && tempint != 2)
00868     argerrortxt(NULL, "Option -c is only valid "
00869            "with values 1 or 2. Sorry.");
00870        else
00871     channels = tempint;
00872      }
00873    /*-------------------------------------------------*
00874     * Create WAV-header on output if wanted.          *
00875     *-------------------------------------------------*/
00876    if (wavout)
00877      switch (fileswitch & (12))
00878        {
00879        case 4:   /* User wants header on textfile */
00880     argerrornum( NULL, ME_HEADERONTEXTFILE);
00881        case 12:  /* User wants header on binfile  */
00882     makewavheader();
00883     break;
00884        case 0:   /* User wants header, but there is no outfile */
00885     /* Problem: what about i/o-file, 32? You might want a header
00886        on that? Better ignore this case. */
00887     break;
00888        case 8:    /* An application musn't ask for this */
00889        default:   /* This can't happen */
00890     assert( FALSE);
00891        }
00892    return;
00893 }

int parsedoublearg ( int  argcount,
char *  args[],
char *  string,
double *  result 
)

Definition at line 505 of file utils/frame.c.

References argerrornum(), end, FALSE, findoption(), ME_NODOUBLE, say(), and TRUE.

00506 {
00507   int i;
00508   double temp;
00509   char end;
00510 
00511   if ((i = findoption( argcount, args, string)) > 0)
00512     {
00513       switch (sscanf(args[i] + 1 + strlen( string), "%30lf%1c", &temp, &end))
00514    {
00515    case 0: case EOF: case 2:
00516      argerrornum(args[i]+1, ME_NODOUBLE);
00517      return FALSE;
00518    case 1:
00519      *result = temp;
00520      break;
00521    default:
00522      say("frame.c: This can't happen\n");
00523    }
00524       return TRUE;
00525     }
00526   else
00527     {
00528       return FALSE;
00529     }
00530 }

char* parsefilearg ( int  argcount,
char *  args[] 
)

Definition at line 419 of file utils/frame.c.

References fatalperror(), isoptionchar(), malloc, NULL, and result.

Referenced by main(), and parseargs().

00420 {
00421   int i;
00422   char *result = NULL;
00423 
00424    for (i = 1; i < argcount; i++)
00425    {
00426       if (args[i][0] != '\0' &&
00427      (!isoptionchar (args[i][0]) || args[i][1] == '\0' ))
00428       {
00429    /*---------------------------------------------*
00430     * The argument is a filename:                 *
00431     * it is either no dash followed by something, *
00432     * or it is a dash following by nothing.       *
00433     *---------------------------------------------*/
00434    result = malloc( strlen( args[i]) + 1);
00435    if (result == NULL)
00436        fatalperror( "Couldn't allocate memory for filename\n");
00437    strcpy( result, args[i]);
00438    args[i][0] = '\0';                    /* Mark as used up */
00439    break;
00440       }
00441    }
00442    return result;
00443 }

int parsefreq ( char *  string,
double *  result 
)

Definition at line 393 of file utils/frame.c.

References argerrornum(), end, FALSE, ME_THISCANTHAPPEN, NULL, samplefrequency, and TRUE.

00394 {
00395     int k;
00396     double temp;
00397     char m, s, end;
00398 
00399     k = sscanf(string, "%30lf%1c%1c%1c", &temp, &m, &s, &end);
00400     switch (k)
00401       {
00402       case 0: case EOF: case 2: case 4:
00403    return FALSE;
00404       case 1:
00405    *result = temp;
00406    break;
00407       case 3:
00408    if (m == 'H' && s == 'z')
00409      *result = samplefrequency / temp;
00410    else
00411      return FALSE;
00412    break;
00413       default:
00414    argerrornum(NULL, ME_THISCANTHAPPEN);
00415       }
00416     return TRUE;
00417 }

int parseintarg ( int  argcount,
char *  args[],
char *  string,
int *  result 
)

Definition at line 471 of file utils/frame.c.

References argerrornum(), c, FALSE, findoption(), ME_NOINT, say(), and TRUE.

Referenced by parseargs().

00472 {
00473   int i, temp;
00474   char c;
00475 
00476   if ((i = findoption( argcount, args, string)) > 0)
00477    {
00478       switch (sscanf(args[i] + 1 + strlen( string),
00479            "%30d%1c", &temp, &c))
00480       {
00481    case 0: case EOF: case 2:
00482             argerrornum(args[i]+1, ME_NOINT);
00483             return FALSE;
00484          case 1:
00485       *result = temp;
00486             break;
00487          default:
00488             say("frame.c: This can't happen\n");
00489       }
00490       return TRUE;
00491    }
00492   else
00493     {
00494       return FALSE;
00495     }
00496 }

int parseswitch ( char *  found,
char *  wanted 
)

Definition at line 445 of file utils/frame.c.

References argerrornum(), FALSE, ME_NOSWITCH, and TRUE.

00446 {
00447   if (strncmp( found, wanted, strlen( wanted)) == 0)
00448     {
00449       if (found[strlen( wanted)] == '\0')
00450    return TRUE;
00451       else
00452    argerrornum( found, ME_NOSWITCH);
00453     }
00454   return FALSE;
00455 }

int parseswitcharg ( int  argcount,
char *  args[],
char *  string 
)

Definition at line 457 of file utils/frame.c.

References argerrornum(), FALSE, findoption(), ME_NOSWITCH, and TRUE.

Referenced by parseargs().

00458 {
00459   int i;
00460 
00461   if ((i = findoption( argcount, args, string)) > 0)
00462     {
00463       if (args[i][strlen( string) + 1] == '\0')
00464    return TRUE;
00465       else
00466    argerrornum( args[i] + 1, ME_NOSWITCH);
00467     }
00468   return FALSE;
00469 }

int parsetime ( char *  string,
int *  result 
)

Definition at line 352 of file utils/frame.c.

References argerrornum(), end, FALSE, ME_THISCANTHAPPEN, NULL, samplefrequency, and TRUE.

Referenced by parsetimearg().

00353 {
00354     int k;
00355     double temp;
00356     char m, s, end;
00357 
00358     k = sscanf(string, "%30lf%1c%1c%1c", &temp, &m, &s, &end);
00359     switch (k)
00360       {
00361       case 0: case EOF: case 4:
00362    return FALSE;
00363       case 1:
00364    *result = temp;
00365    break;
00366       case 2:
00367    if (m == 's')
00368      *result = temp * samplefrequency;
00369    else
00370      return FALSE;
00371    break;
00372       case 3:
00373    if (m == 'm' && s == 's')
00374      *result = temp * samplefrequency / 1000;
00375    else if (m == 'H' && s == 'z')
00376      *result = samplefrequency / temp;
00377    else
00378      return FALSE;
00379    break;
00380       default:
00381    argerrornum(NULL, ME_THISCANTHAPPEN);
00382       }
00383     return TRUE;
00384 }

int parsetimearg ( int  argcount,
char *  args[],
char *  string,
int *  result 
)

Definition at line 332 of file utils/frame.c.

References argerrornum(), FALSE, findoption(), ME_NOTIME, parsetime(), and TRUE.

00333 {
00334     int i;
00335 
00336     if ((i = findoption( argcount, args, string)) > 0)
00337     {
00338    if (parsetime(args[i] + 1 + strlen( string), result))
00339        return TRUE;
00340    argerrornum(args[i]+1, ME_NOTIME);
00341     }
00342     return FALSE;
00343 }

int parsevolarg ( int  argcount,
char *  args[],
char *  string,
double *  result 
)

Definition at line 539 of file utils/frame.c.

References argerrornum(), end, FALSE, findoption(), ME_NOVOL, say(), and TRUE.

00540 {
00541   double vol = 1.0;
00542   char sbd, sbb, end;
00543   int i, weird = FALSE;
00544 
00545   if ((i = findoption( argcount, args, string)) > 0)
00546     {
00547       switch (sscanf(args[i] + 1 + strlen( string),
00548            "%30lf%1c%1c%1c", &vol, &sbd, &sbb, &end))
00549    {
00550      case 0: case EOF: case 4:
00551      weird = TRUE;
00552      break;    /* No number: error */
00553    case 1:
00554      *result = vol;
00555      break;
00556    case 2:
00557      if (sbd == '%')
00558        *result = vol / 100;
00559      else
00560        weird = TRUE;    /* One char but no percent: error */
00561      break;
00562    case 3:
00563      if (sbd =='d' && sbb == 'b')
00564        *result = pow(2, vol / 6.02);
00565      else
00566        weird = TRUE;    /* Two chars but not db: error */
00567      break;
00568    default:
00569      say("frame.c: This can't happen.\n");
00570    }
00571       if (weird)
00572    argerrornum( args[i] + 1, ME_NOVOL);
00573      /* ("Weird option: couldn't parse volume '%s'\n", args[i]+2); */
00574       return !weird;
00575     }
00576   else
00577     {
00578       return FALSE;
00579     }
00580 }

int parsevolume ( char *  s,
double *  result 
)

Definition at line 590 of file utils/frame.c.

References end, FALSE, say(), and TRUE.

00591 {
00592     int k;
00593     char sbd, sbb, end;
00594 
00595     *result = 1.0;
00596     k = sscanf(s, "%30lf%1c%1c%1c", result, &sbd, &sbb, &end);
00597     switch (k)
00598     {
00599       case 0:
00600       case EOF:
00601       case 4:
00602        return FALSE;
00603       case 1:
00604        break;
00605       case 2:
00606        if (sbd != '%')
00607       return FALSE;
00608        (*result) /=100;
00609        break;
00610       case 3:
00611        if (sbd !='d' || sbb != 'b')
00612       return FALSE;
00613        (*result) = pow(2, (*result) / 6.02);
00614        break;
00615       default:
00616        say("parsevolume: This can't happen (%d).\n", k);
00617     }
00618     return TRUE;
00619 }

void readawaysamples ( FILE *  in,
size_t  size 
)

Definition at line 1069 of file utils/frame.c.

References BUFFSIZE, fatalperror(), free, malloc, and NULL.

01070 {
01071   short *buffer;
01072   int samplesread, count;
01073 
01074   buffer = malloc( sizeof( *buffer) * BUFFSIZE);
01075   if (buffer == NULL) fatalperror("Couldn't allocate buffer");
01076 
01077   while (size > 0)
01078     {
01079       if (size > BUFFSIZE)
01080    count = BUFFSIZE;
01081       else
01082    count = size;
01083 
01084       samplesread = fread( buffer, sizeof(*buffer), count, input);
01085       if (ferror( input) != 0)
01086    fatalperror("Error reading input file");
01087       size -= samplesread;
01088     }
01089   free( buffer);
01090 }

void readpkheader ( FILE *  anyin  ) 

Definition at line 76 of file utils/frame.c.

00077 {
00078    unsigned short tempushort;
00079    int tempint, i, x;
00080    unsigned char blood[8];
00081 
00082    for (i = 0; i < 11; i++)
00083    {
00084       if (!fread( &tempint, 4, 1, anyin)) {
00085          return;
00086       }
00087       printf( "%d: %d, ", i, tempint);
00088    }
00089    printf( "\n");
00090    if (!fread( blood, 1, 8, anyin)) {
00091       return;
00092    }
00093    for (i = 0; i < 8; i++)
00094       printf( "%d ", blood[i]);
00095    printf( "\n");
00096    for (i = 0; i < 8; i++)
00097    {
00098       for (x = 128; x > 0; x /= 2)
00099          printf((blood[i] & x) == 0? "0 ":"1 ");
00100       printf(i%4==3? "\n":"| ");
00101    }
00102    printf( "\n");
00103    for (i = 0; i < 2; i++)
00104    {
00105       if (!fread( &tempint, 4, 1, anyin)) {
00106          return;
00107       }
00108       printf( "%d: %d, ", i, tempint);
00109    }
00110    printf( "\n");
00111    for (i = 0; i < 2; i++)
00112    {
00113       if (!fread( &tempushort, 2, 1, anyin)) {
00114          return;
00115       }
00116       printf( "%d: %d, ", i, tempushort);
00117    }
00118    printf( "\n");
00119 }

void readwavheader ( FILE *  anyin  ) 

Definition at line 126 of file utils/frame.c.

References channels, chat(), FALSE, iswav, samplefrequency, str, and TRUE.

Referenced by main(), and parseargs().

00127 {
00128    unsigned int tempuint, sf;
00129    unsigned short tempushort, cn;
00130    char str[9];
00131    int nowav = FALSE;
00132 
00133    iswav = FALSE;
00134 
00135    if (ftell(anyin) == -1) /* If we cannot seek this file */
00136    {
00137       nowav = TRUE;   /* -> Pretend this is no wav-file */
00138       chat("File not seekable: not checking for WAV-header.\n");
00139    }
00140    else
00141    {
00142       /* Expect four bytes "RIFF" and four bytes filelength */
00143       if (!fread(str, 1, 8, anyin)) {           /* 0 */
00144          return;
00145       }
00146       str[4] = '\0';
00147       if (strcmp(str, "RIFF") != 0) nowav = TRUE;
00148       /* Expect eight bytes "WAVEfmt " */
00149       if (!fread(str, 1, 8, anyin)) {           /* 8 */
00150          return;
00151       }
00152       str[8] = '\0';
00153       if (strcmp(str, "WAVEfmt ") != 0) nowav = TRUE;
00154       /* Expect length of fmt data, which should be 16 */
00155       if (!fread(&tempuint, 4, 1, anyin)) {  /* 16 */
00156          return;
00157       }
00158       if (tempuint != 16) nowav = TRUE;
00159       /* Expect format tag, which should be 1 for pcm */
00160       if (!fread(&tempushort, 2, 1, anyin)) { /* 20 */
00161          return;
00162       }
00163       if (tempushort != 1)
00164          nowav = TRUE;
00165       /* Expect number of channels */
00166       if (!fread(&cn, 2, 1, anyin)) { /* 20 */
00167          return;
00168       }
00169       if (cn != 1 && cn != 2) nowav = TRUE;
00170       /* Read samplefrequency */
00171       if (!fread(&sf, 4, 1, anyin)) {  /* 24 */
00172          return;
00173       }
00174       /* Read bytes per second: Should be samplefreq * channels * 2 */
00175       if (!fread(&tempuint, 4, 1, anyin)) {         /* 28 */
00176          return;
00177       }
00178       if (tempuint != sf * cn * 2) nowav = TRUE;
00179       /* read bytes per frame: Should be channels * 2 */
00180       if (!fread(&tempushort, 2, 1, anyin)) {       /* 32 */
00181          return;
00182       }
00183       if (tempushort != cn * 2) nowav = TRUE;
00184       /* Read bits per sample: Should be 16 */
00185       if (!fread(&tempushort, 2, 1, anyin)) {       /* 34 */
00186          return;
00187       }
00188       if (tempushort != 16) nowav = TRUE;
00189       if (!fread(str, 4, 1, anyin)) {            /* 36 */
00190          return;
00191       }
00192       str[4] = '\0';
00193       if (strcmp(str, "data") != 0) nowav = TRUE;
00194       if (!fread(&tempuint, 4, 1, anyin)) {   /* 40 */
00195          return;
00196       }
00197       if (nowav)
00198       {
00199          fseek(anyin, 0, SEEK_SET);   /* Back to beginning of file */
00200          chat("File has no WAV header.\n");
00201       }
00202       else
00203       {
00204          samplefrequency = sf;
00205          channels = cn;
00206          chat("Read WAV header: %d channels, samplefrequency %d.\n",
00207           channels, samplefrequency);
00208          iswav = TRUE;
00209       }
00210    }
00211    return;
00212 }

int say ( const char *  format,
  ... 
)

Definition at line 1026 of file utils/frame.c.

References result.

Referenced by parsedoublearg(), parseintarg(), parsevolarg(), and parsevolume().

01027 {
01028     va_list ap;
01029     int result;
01030 
01031     va_start( ap, format);
01032     result = vfprintf( stdout, format, ap);
01033     va_end( ap);
01034     return result;
01035 }

void startstopwatch ( void   ) 

Definition at line 307 of file utils/frame.c.

References NULL, statistics(), and stopwatch.

Referenced by main().

00308 {
00309    stopwatch = time(NULL);       /* Remember time 'now' */
00310    atexit(statistics);           /* Call function statistics() at exit. */
00311 
00312    return;
00313 }

int workloop ( FILE *  theinfile,
FILE *  theoutfile,
int(*)(short *buffer, int length)  work 
)

Definition at line 943 of file utils/frame.c.

References BUFFSIZE, FALSE, fatalperror(), malloc, NULL, and TRUE.

00945 {
00946   short *buffer;
00947   int length, nowlength;
00948 
00949   length = BUFFSIZE;
00950   if ((buffer = malloc( sizeof(short) * length)) == NULL)
00951     fatalperror ("");
00952   while (TRUE)
00953     {
00954       nowlength = fread(buffer, sizeof(short), length, theinfile);
00955       if (ferror( theinfile) != 0)
00956    fatalperror("Error reading input file");
00957       if (nowlength == 0)   /* Reached end of input file */
00958    break;
00959       /* Call the routine that does the work */
00960       if (!work (buffer, nowlength))         /* On error, stop. */
00961    return FALSE;
00962       if (!fwrite(buffer, sizeof(short), nowlength, theoutfile)) {
00963          return FALSE;
00964       }
00965       if (ferror( theoutfile) != 0)
00966    fatalperror("Error writing to output file");
00967     }
00968   return TRUE;      /* Input file done with, no errors. */
00969 }


Variable Documentation

unsigned short channels

Definition at line 30 of file utils/frame.c.

FILE* in

char* infilename

Definition at line 34 of file utils/frame.c.

Referenced by parseargs().

int iswav

Definition at line 32 of file utils/frame.c.

Referenced by main(), and readwavheader().

FILE * out

char * outfilename

Definition at line 34 of file utils/frame.c.

Referenced by main(), and parseargs().

Definition at line 28 of file utils/frame.c.

Referenced by makewavheader(), parseargs(), parsefreq(), parsetime(), and readwavheader().

unsigned short samplewidth

Definition at line 29 of file utils/frame.c.

Referenced by getremainingfilelength(), and parseargs().

char* usage

Definition at line 37 of file utils/frame.c.

Referenced by main(), parseargs(), and pbx_builtin_execiftime().

Definition at line 35 of file utils/frame.c.

Referenced by chat(), inform(), and parseargs().

char* version

Definition at line 504 of file main/security_events.c.

int wavout

Definition at line 31 of file utils/frame.c.

Referenced by main(), myexit(), and parseargs().


Generated on Thu Apr 16 06:31:09 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6