Asterisk - The Open Source Telephony Project  GIT-master-1f78ee9
Functions | Variables
utils/frame.c File Reference
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <stdarg.h>
#include <errno.h>
#include <assert.h>
#include "frame.h"

Go to the source code of this file.

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 *input, size_t size)
 
void readpkheader (FILE *anyin)
 
void readwavheader (FILE *anyin)
 
int say (const char *format,...)
 
void startstopwatch (void)
 
static void statistics (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
 
static char * standardusage
 
static char * standardversion = "frame version 1.3, June 13th 2001"
 
time_t stopwatch
 
static int test_usage
 
char * usage = ""
 
int verboselevel
 
char * version = ""
 
int wavout
 

Function Documentation

◆ argerror()

void argerror ( char *  s)

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

References error(), and fatalerror().

626 {
627  error ("Error parsing command line. Unrecognized option:\n\t-%s\n", s);
628  fatalerror("\nTry --help for help.\n");
629 }
void fatalerror(const char *format,...)
Definition: utils/frame.c:1010
int error(const char *format,...)
Definition: utils/frame.c:999

◆ argerrornum()

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().

636 {
637  char *message;
638 
639  if (code == ME_TOOMANYFILES)
640  {
641  error("Too many files on command line: '%s'.\n", s);
642  }
643  else
644  {
645  if (s != NULL)
646  error ("Error parsing option -%s:\n\t", s);
647  switch( code)
648  {
649  case ME_NOINT:
650  message = "Integer expected";
651  break;
652  case ME_NODOUBLE:
653  message = "Floating point number expected";
654  break;
655  case ME_NOTIME:
656  message = "Time argument expected";
657  break;
658  case ME_NOVOL:
659  message = "Volume argument expected";
660  break;
661  case ME_NOSWITCH:
662  message = "Garbage after switch-type option";
663  break;
664  case ME_HEADERONTEXTFILE:
665  message = "Option -h is not useful for text-output";
666  break;
667  case ME_NOINFILE:
668  message = "No input file specified";
669  break;
670  case ME_NOOUTFILE:
671  message = "No output file specified";
672  break;
673  case ME_NOIOFILE:
674  message = "No input/output file specified";
675  break;
676  case ME_NOSTDIN:
677  message = "Standard in not supported here";
678  break;
679  case ME_NOSTDOUT:
680  message = "Standard out not supported here";
681  break;
682  case ME_NOSTDIO:
683  message = "Standard in/out not supported here";
684  break;
685  case ME_NOTENOUGHFILES:
686  message = "Not enough files specified";
687  break;
688  case ME_THISCANTHAPPEN:
689  fatalerror("\nThis can't happen. Report this as a bug\n");
690  /* fatalerror does not return */
691  default:
692  error("Error code %d not implemented. Fix me!\n", code);
693  message = "Error message not implemented. Fix me!";
694  }
695  error("%s\n", message);
696  }
697  fatalerror("\nTry --help for help.\n");
698 }
#define NULL
Definition: resample.c:96
void fatalerror(const char *format,...)
Definition: utils/frame.c:1010
int error(const char *format,...)
Definition: utils/frame.c:999

◆ argerrortxt()

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().

705 {
706  if (s != NULL)
707  error ("Error parsing option -%s:\n\t", s);
708  else
709  error ("Error parsing command line:\n\t");
710  error ("%s\n", message);
711  fatalerror("\nTry --help for help.\n");
712 }
#define NULL
Definition: resample.c:96
void fatalerror(const char *format,...)
Definition: utils/frame.c:1010
int error(const char *format,...)
Definition: utils/frame.c:999

◆ chat()

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

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

References result, and verboselevel.

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

972 {
973  va_list ap;
974  int result = 0;
975 
976  if (verboselevel > 5)
977  {
978  va_start( ap, format);
979  result = vfprintf( stderr, format, ap);
980  va_end( ap);
981  }
982  return result;
983 }
static PGresult * result
Definition: cel_pgsql.c:88
static snd_pcm_format_t format
Definition: chan_alsa.c:102
int verboselevel
Definition: utils/frame.c:35

◆ checknoargs()

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

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

References error(), and fatalerror().

Referenced by main().

718 {
719  int i, errorcount = 0;
720 
721  for (i = 1; i < argcount; i++)
722  {
723  if (args[i][0] != '\0') /* An unused argument! */
724  {
725  errorcount++;
726  if (errorcount == 1)
727  error("The following arguments were not recognized:\n");
728  error("\t%s\n", args[i]);
729  }
730  }
731  if (errorcount > 0) /* Errors are fatal */
732  fatalerror("\nTry --help for help.\n");
733 
734  return; /* No errors? Return. */
735 }
const char * args
void fatalerror(const char *format,...)
Definition: utils/frame.c:1010
int error(const char *format,...)
Definition: utils/frame.c:999

◆ double2db()

double double2db ( double  value)

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

References value.

1063 {
1064  if (value < 0)
1065  value = -value;
1066  return 6.0 * log( value / 32767) / log( 2);
1067 }
int value
Definition: syslog.c:37

◆ error()

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(), append_string(), apply_general_options(), argerror(), argerrornum(), argerrortxt(), ast_channel_internal_errno_set(), ast_iostream_printf(), ast_json_vpack(), ast_odbc_find_table(), ast_parse_arg(), ast_tcptls_client_create(), ast_tcptls_server_start(), AST_TEST_DEFINE(), ast_unload_resource(), authenticate(), build_callno_limits(), build_expression_queue(), build_peer(), cdr_handler(), checknoargs(), conf_load_config(), confbridge_cfg_alloc(), config_handler(), deliver_file(), endpoint_acl_handler(), evaluate_history_entry(), exec(), fax_gateway_attach(), fax_gateway_detect_t38(), fax_gateway_framehook(), fax_gateway_start(), generic_fax_exec(), handle_cli_agi_show(), handle_cli_queue_test(), handle_incoming(), handle_request_invite(), handler_wait_for_message(), http_callback(), ip_identify_match_handler(), ip_identify_match_host_lookup(), jingle_outgoing_hook(), jingle_send_error_response(), keypad_cfg_read(), load_config(), load_module(), load_or_reload_lua_stuff(), load_pjsip(), load_values_config(), logged_dlclose(), lua_get_state(), message_template_build(), mgcp_devicestate(), minivm_accmess_exec(), mysql_log(), named_acl_config_alloc(), ogg_speex_open(), osp_check_destination(), osp_create_provider(), osp_create_transaction(), osp_finish(), osp_load(), osp_lookup(), osp_next(), osp_validate_token(), parse_uri_full(), pjsip_enable_logger_host(), pubsub_on_rx_mwi_notify_request(), realtime_destroy_handler(), realtime_handler(), realtime_multi_handler(), realtime_store_handler(), realtime_update2_handler(), realtime_update_handler(), receivefax_exec(), refer_progress_alloc(), reload_config(), rtcp_debug_test_addr(), sendfax_exec(), setup_filestack(), skel_config_alloc(), store_config(), sub_persistence_recreate(), t30_phase_e_handler(), test_config_alloc(), transport_localnet_handler(), unbound_config_alloc(), update2_ldap(), user_event_wait_for_events(), verify_user_event_fields(), wait_for_channel_callback(), wait_for_device_state_updates(), write_cel(), xmpp_component_register_get_hook(), xmpp_config_alloc(), and xmpp_pubsub_handle_error().

1000 {
1001  va_list ap;
1002  int result;
1003 
1004  va_start( ap, format);
1005  result = vfprintf( stderr, format, ap);
1006  va_end( ap);
1007  return result;
1008 }
static PGresult * result
Definition: cel_pgsql.c:88
static snd_pcm_format_t format
Definition: chan_alsa.c:102

◆ fatalerror()

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().

1011 {
1012  va_list ap;
1013 
1014  va_start( ap, format);
1015  vfprintf( stderr, format, ap);
1016  va_end( ap);
1017  myexit(1);
1018 }
int myexit(int value)
Definition: utils/frame.c:922
static snd_pcm_format_t format
Definition: chan_alsa.c:102

◆ fatalperror()

void fatalperror ( const char *  string)

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

References myexit().

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

1021 {
1022  perror( string);
1023  myexit( 1);
1024 }
int myexit(int value)
Definition: utils/frame.c:922

◆ findoption()

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().

901 {
902  int i;
903 
904  if (test_usage)
905  printf("Checking for option -%s\n", s);
906 
907  for (i=1; i<argcount; i++)
908  {
909  if (isoptionchar (args[i][0]) &&
910  strncmp( args[i] + 1, s, strlen( s)) == 0)
911  {
912  args[i][0] = '\0';
913  return i;
914  }
915  }
916  return -1;
917 }
int isoptionchar(char coal)
Definition: utils/frame.c:319
const char * args
static int test_usage
Definition: utils/frame.c:38

◆ getremainingfilelength()

int getremainingfilelength ( FILE *  anyin,
long *  result 
)

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

References FALSE, samplewidth, and TRUE.

59 {
60  long i;
61 
62  i = ftell(anyin);
63  if (i == -1) return FALSE;
64  if (fseek(anyin, 0, SEEK_END) == -1) return FALSE;
65  *result = ftell(anyin);
66  if (*result == -1) return FALSE;
67  (*result) -= i;
68  (*result) /= samplewidth;
69  if (fseek(anyin, i, SEEK_SET) == -1) return FALSE;
70  return TRUE;
71 }
#define FALSE
Definition: app_minivm.c:521
unsigned short samplewidth
Definition: utils/frame.c:29
#define TRUE
Definition: app_minivm.c:518
static PGresult * result
Definition: cel_pgsql.c:88

◆ inform()

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

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

References result, and verboselevel.

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

986 {
987  va_list ap;
988  int result = 0;
989 
990  if (verboselevel > 1)
991  {
992  va_start( ap, format);
993  result = vfprintf( stderr, format, ap);
994  va_end( ap);
995  }
996  return result;
997 }
static PGresult * result
Definition: cel_pgsql.c:88
static snd_pcm_format_t format
Definition: chan_alsa.c:102
int verboselevel
Definition: utils/frame.c:35

◆ isoptionchar()

int isoptionchar ( char  coal)

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

Referenced by findoption(), and parsefilearg().

320 {
321  return (coal =='-');
322 }

◆ makewavheader()

void makewavheader ( void  )

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

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

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

220 {
221  unsigned int tempuint, filelength;
222  unsigned short tempushort;
223 
224  /* If fseek fails, don't create the header. */
225  if (fseek(out, 0, SEEK_END) != -1)
226  {
227  filelength = ftell(out);
228  chat("filelength %d, ", filelength);
229  fseek(out, 0, SEEK_SET);
230  if (!fwrite("RIFF", 1, 4, out)) { /* 0 */
231  return;
232  }
233  tempuint = filelength - 8;
234  if (!fwrite(&tempuint, 4, 1, out)) { /* 4 */
235  return;
236  }
237  if (!fwrite("WAVEfmt ", 1, 8, out)) { /* 8 */
238  return;
239  }
240  /* length of fmt data 16 bytes */
241  tempuint = 16;
242  if (!fwrite(&tempuint, 4, 1, out)) { /* 16 */
243  return;
244  }
245  /* Format tag: 1 for pcm */
246  tempushort = 1;
247  if (!fwrite(&tempushort, 2, 1, out)) { /* 20 */
248  return;
249  }
250  chat("%d channels\n", channels);
251  if (!fwrite(&channels, 2, 1, out)) {
252  return;
253  }
254  chat("samplefrequency %d\n", samplefrequency);
255  if (!fwrite(&samplefrequency, 4, 1, out)) { /* 24 */
256  return;
257  }
258  /* Bytes per second */
259  tempuint = channels * samplefrequency * 2;
260  if (!fwrite(&tempuint, 4, 1, out)) { /* 28 */
261  return;
262  }
263  /* Block align */
264  tempushort = 2 * channels;
265  if (!fwrite(&tempushort, 2, 1, out)) { /* 32 */
266  return;
267  }
268  /* Bits per sample */
269  tempushort = 16;
270  if (!fwrite(&tempushort, 2, 1, out)) { /* 34 */
271  return;
272  }
273  if (!fwrite("data", 4, 1, out)) { /* 36 */
274  return;
275  }
276  tempuint = filelength - 44;
277  if (!fwrite(&tempuint, 4, 1, out)) { /* 40 */
278  return;
279  }
280  }
281  return;
282 }
int samplefrequency
Definition: utils/frame.c:28
unsigned short channels
Definition: utils/frame.c:30
int chat(const char *format,...)
Definition: utils/frame.c:971
FILE * out
Definition: utils/frame.c:33

◆ mallocconcat()

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

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

References malloc(), NULL, and result.

1050 {
1051  char *result;
1052 
1053  result = malloc( strlen( one) + strlen( two) + 1);
1054  if (result != NULL)
1055  {
1056  strcpy( result, one);
1057  strcat( result, two);
1058  }
1059  return result;
1060 }
#define NULL
Definition: resample.c:96
char * malloc()
static PGresult * result
Definition: cel_pgsql.c:88

◆ malloccopy()

char* malloccopy ( char *  string)

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

References malloc(), NULL, and result.

1039 {
1040  char *result;
1041 
1042  result = malloc( strlen( string) + 1);
1043  if (result != NULL)
1044  strcpy( result, string);
1045  return result;
1046 }
#define NULL
Definition: resample.c:96
char * malloc()
static PGresult * result
Definition: cel_pgsql.c:88

◆ myexit()

int myexit ( int  value)

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

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

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

923 {
924  switch (value)
925  {
926  case 0:
927  if (wavout)
928  makewavheader(); /* Writes a fully informed .WAV header */
929  chat("Success!\n");
930  break;
931  default:
932  chat("Failure.\n");
933  break;
934  }
935  exit (value);
936 }
void makewavheader(void)
Definition: utils/frame.c:219
int value
Definition: syslog.c:37
int wavout
Definition: utils/frame.c:31
int chat(const char *format,...)
Definition: utils/frame.c:971

◆ parseargs()

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().

745 {
746  char *filename;
747  int tempint = 0;
748 
749  if ((fileswitch & 1) != 0) /* If getting infile */
750  in = NULL;
751  if ((fileswitch & 4) != 0) /* If getting outfile */
752  out = NULL;
753  wavout = FALSE;
754  verboselevel = 5;
756  samplewidth = 2;
757  channels = 1;
758 
759  /*-----------------------------------------------*
760  * First first check testcase, usage and version *
761  *-----------------------------------------------*/
762  test_usage = parseswitcharg( argcount, args, "-test-usage");
763  if (parseswitcharg( argcount, args, "-help"))
764  {
765  printf("%s%s", usage, standardusage);
766  exit(0);
767  }
768  if (parseswitcharg( argcount, args, "-version"))
769  {
770  printf("%s\n(%s)\n", version, standardversion);
771  exit(0);
772  }
773  /*--------------------------------------*
774  * Set verboselevel *
775  *--------------------------------------*/
776  while (parseswitcharg( argcount, args, "V"))
777  verboselevel = 10;
778  while (parseswitcharg( argcount, args, "Q"))
779  verboselevel = 1;
780  /*-------------------------------------------------*
781  * Get filenames and open files *
782  *-------------------------------------------------*/
783  if ((fileswitch & 1) != 0) /* Infile wanted */
784  {
785  infilename = parsefilearg( argcount, args);
786  if (infilename == NULL)
788  if (strcmp( infilename, "-") == 0)
789  {
790  infilename = "<stdin>";
791  in = stdin;
792  if ((fileswitch & 2) != 0) /* Binfile wanted */
793  readwavheader( in);
794  }
795  else
796  {
797  if ((fileswitch & 2) == 0) /* Textfile wanted */
798  in = fopen(infilename, "rt");
799  else /* Binfile wanted */
800  if ((in = fopen(infilename, "rb")) != NULL)
801  readwavheader( in);
802  }
803  if (in == NULL)
804  fatalerror("Error opening input file '%s': %s\n", infilename,strerror(errno));
805  else
806  inform("Using file '%s' as input\n", infilename);
807  }
808  if ((fileswitch & 4) != 0) /* Outfile wanted */
809  {
810  outfilename = parsefilearg( argcount, args);
811  if (outfilename == NULL)
813  if (strcmp( outfilename, "-") == 0)
814  {
815  outfilename = "<stdout>";
816  out = stdout;
817  }
818  else
819  {
820 
821  if ((fileswitch & 8) == 0) /* Textfile wanted */
822  out = fopen(outfilename, "wt");
823  else /* Binfile wanted */
824  out = fopen(outfilename, "wb");
825  }
826  if (out == NULL)
827  fatalerror("Error opening output file '%s': %s\n", outfilename,strerror(errno));
828  else
829  inform("Using file '%s' as output\n", outfilename);
830  }
831  if ((fileswitch & 32) != 0) /* In-/Outfile wanted */
832  {
833  assert (in == NULL && out == NULL);
834  infilename = outfilename = parsefilearg( argcount, args);
835  if (outfilename == NULL)
837  if (strcmp( infilename, "-") == 0)
839  inform("Using file '%s' as input/output\n", outfilename);
840  in = out = fopen(outfilename, "r+");
841  if (out == NULL)
842  fatalerror("Error opening input/output file '%s': %s\n", outfilename,strerror(errno));
843 
844  readwavheader( in);
845  }
846  if ((fileswitch & 16) == 0) /* No additional files wanted */
847  {
848  if ((filename = parsefilearg( argcount, args)) != NULL)
849  argerrornum( filename, ME_TOOMANYFILES);
850  }
851 
852  /*-------------------------------------------------*
853  * Set samplefrequency, width, wavout,
854  *-------------------------------------------------*/
855  parseintarg( argcount, args, "f", &samplefrequency);
856  wavout = parseswitcharg( argcount, args, "h");
857  if (parseintarg( argcount, args, "w", &tempint))
858  {
859  if (tempint != 16)
860  argerrortxt(NULL, "Option -w is only valid "
861  "with value 16. Sorry.");
862  else
863  samplewidth = tempint;
864  }
865  if (parseintarg( argcount, args, "c", &tempint))
866  {
867  if (tempint != 1 && tempint != 2)
868  argerrortxt(NULL, "Option -c is only valid "
869  "with values 1 or 2. Sorry.");
870  else
871  channels = tempint;
872  }
873  /*-------------------------------------------------*
874  * Create WAV-header on output if wanted. *
875  *-------------------------------------------------*/
876  if (wavout)
877  switch (fileswitch & (12))
878  {
879  case 4: /* User wants header on textfile */
881  case 12: /* User wants header on binfile */
882  makewavheader();
883  break;
884  case 0: /* User wants header, but there is no outfile */
885  /* Problem: what about i/o-file, 32? You might want a header
886  on that? Better ignore this case. */
887  break;
888  case 8: /* An application musn't ask for this */
889  default: /* This can't happen */
890  assert( FALSE);
891  }
892  return;
893 }
#define FALSE
Definition: app_minivm.c:521
static char * standardversion
Definition: utils/frame.c:40
int samplefrequency
Definition: utils/frame.c:28
void makewavheader(void)
Definition: utils/frame.c:219
unsigned short samplewidth
Definition: utils/frame.c:29
const char * args
#define NULL
Definition: resample.c:96
int parseswitcharg(int argcount, char *args[], char *string)
Definition: utils/frame.c:457
int inform(const char *format,...)
Definition: utils/frame.c:985
char * infilename
Definition: utils/frame.c:34
char * version
Definition: utils/frame.c:36
FILE * in
Definition: utils/frame.c:33
void fatalerror(const char *format,...)
Definition: utils/frame.c:1010
static int test_usage
Definition: utils/frame.c:38
int parseintarg(int argcount, char *args[], char *string, int *result)
Definition: utils/frame.c:471
char * usage
Definition: utils/frame.c:37
int wavout
Definition: utils/frame.c:31
int errno
static char * standardusage
Definition: utils/frame.c:41
unsigned short channels
Definition: utils/frame.c:30
void argerrortxt(char *s, char *message)
Definition: utils/frame.c:704
void readwavheader(FILE *anyin)
Definition: utils/frame.c:126
FILE * out
Definition: utils/frame.c:33
#define DEFAULTFREQ
Definition: utils/frame.h:53
char * outfilename
Definition: utils/frame.c:34
void argerrornum(char *s, Errornum code)
Definition: utils/frame.c:635
char * parsefilearg(int argcount, char *args[])
Definition: utils/frame.c:419
int verboselevel
Definition: utils/frame.c:35

◆ parsedoublearg()

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.

506 {
507  int i;
508  double temp;
509  char end;
510 
511  if ((i = findoption( argcount, args, string)) > 0)
512  {
513  switch (sscanf(args[i] + 1 + strlen( string), "%30lf%1c", &temp, &end))
514  {
515  case 0: case EOF: case 2:
517  return FALSE;
518  case 1:
519  *result = temp;
520  break;
521  default:
522  say("frame.c: This can't happen\n");
523  }
524  return TRUE;
525  }
526  else
527  {
528  return FALSE;
529  }
530 }
#define FALSE
Definition: app_minivm.c:521
const char * args
char * end
Definition: eagi_proxy.c:73
int findoption(int argcount, char *args[], char *s)
Definition: utils/frame.c:900
int say(const char *format,...)
Definition: utils/frame.c:1026
#define TRUE
Definition: app_minivm.c:518
static PGresult * result
Definition: cel_pgsql.c:88
void argerrornum(char *s, Errornum code)
Definition: utils/frame.c:635

◆ parsefilearg()

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().

420 {
421  int i;
422  char *result = NULL;
423 
424  for (i = 1; i < argcount; i++)
425  {
426  if (args[i][0] != '\0' &&
427  (!isoptionchar (args[i][0]) || args[i][1] == '\0' ))
428  {
429  /*---------------------------------------------*
430  * The argument is a filename: *
431  * it is either no dash followed by something, *
432  * or it is a dash following by nothing. *
433  *---------------------------------------------*/
434  result = malloc( strlen( args[i]) + 1);
435  if (result == NULL)
436  fatalperror( "Couldn't allocate memory for filename\n");
437  strcpy( result, args[i]);
438  args[i][0] = '\0'; /* Mark as used up */
439  break;
440  }
441  }
442  return result;
443 }
void fatalperror(const char *string)
Definition: utils/frame.c:1020
int isoptionchar(char coal)
Definition: utils/frame.c:319
const char * args
#define NULL
Definition: resample.c:96
char * malloc()
static PGresult * result
Definition: cel_pgsql.c:88

◆ parsefreq()

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.

394 {
395  int k;
396  double temp;
397  char m, s, end;
398 
399  k = sscanf(string, "%30lf%1c%1c%1c", &temp, &m, &s, &end);
400  switch (k)
401  {
402  case 0: case EOF: case 2: case 4:
403  return FALSE;
404  case 1:
405  *result = temp;
406  break;
407  case 3:
408  if (m == 'H' && s == 'z')
409  *result = samplefrequency / temp;
410  else
411  return FALSE;
412  break;
413  default:
415  }
416  return TRUE;
417 }
#define FALSE
Definition: app_minivm.c:521
int samplefrequency
Definition: utils/frame.c:28
#define NULL
Definition: resample.c:96
char * end
Definition: eagi_proxy.c:73
#define TRUE
Definition: app_minivm.c:518
static PGresult * result
Definition: cel_pgsql.c:88
void argerrornum(char *s, Errornum code)
Definition: utils/frame.c:635

◆ parseintarg()

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().

472 {
473  int i, temp;
474  char c;
475 
476  if ((i = findoption( argcount, args, string)) > 0)
477  {
478  switch (sscanf(args[i] + 1 + strlen( string),
479  "%30d%1c", &temp, &c))
480  {
481  case 0: case EOF: case 2:
482  argerrornum(args[i]+1, ME_NOINT);
483  return FALSE;
484  case 1:
485  *result = temp;
486  break;
487  default:
488  say("frame.c: This can't happen\n");
489  }
490  return TRUE;
491  }
492  else
493  {
494  return FALSE;
495  }
496 }
#define FALSE
Definition: app_minivm.c:521
static struct test_val c
const char * args
int findoption(int argcount, char *args[], char *s)
Definition: utils/frame.c:900
int say(const char *format,...)
Definition: utils/frame.c:1026
#define TRUE
Definition: app_minivm.c:518
static PGresult * result
Definition: cel_pgsql.c:88
void argerrornum(char *s, Errornum code)
Definition: utils/frame.c:635

◆ parseswitch()

int parseswitch ( char *  found,
char *  wanted 
)

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

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

446 {
447  if (strncmp( found, wanted, strlen( wanted)) == 0)
448  {
449  if (found[strlen( wanted)] == '\0')
450  return TRUE;
451  else
452  argerrornum( found, ME_NOSWITCH);
453  }
454  return FALSE;
455 }
#define FALSE
Definition: app_minivm.c:521
#define TRUE
Definition: app_minivm.c:518
void argerrornum(char *s, Errornum code)
Definition: utils/frame.c:635

◆ parseswitcharg()

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().

458 {
459  int i;
460 
461  if ((i = findoption( argcount, args, string)) > 0)
462  {
463  if (args[i][strlen( string) + 1] == '\0')
464  return TRUE;
465  else
466  argerrornum( args[i] + 1, ME_NOSWITCH);
467  }
468  return FALSE;
469 }
#define FALSE
Definition: app_minivm.c:521
const char * args
int findoption(int argcount, char *args[], char *s)
Definition: utils/frame.c:900
#define TRUE
Definition: app_minivm.c:518
void argerrornum(char *s, Errornum code)
Definition: utils/frame.c:635

◆ parsetime()

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().

353 {
354  int k;
355  double temp;
356  char m, s, end;
357 
358  k = sscanf(string, "%30lf%1c%1c%1c", &temp, &m, &s, &end);
359  switch (k)
360  {
361  case 0: case EOF: case 4:
362  return FALSE;
363  case 1:
364  *result = temp;
365  break;
366  case 2:
367  if (m == 's')
368  *result = temp * samplefrequency;
369  else
370  return FALSE;
371  break;
372  case 3:
373  if (m == 'm' && s == 's')
374  *result = temp * samplefrequency / 1000;
375  else if (m == 'H' && s == 'z')
376  *result = samplefrequency / temp;
377  else
378  return FALSE;
379  break;
380  default:
382  }
383  return TRUE;
384 }
#define FALSE
Definition: app_minivm.c:521
int samplefrequency
Definition: utils/frame.c:28
#define NULL
Definition: resample.c:96
char * end
Definition: eagi_proxy.c:73
#define TRUE
Definition: app_minivm.c:518
static PGresult * result
Definition: cel_pgsql.c:88
void argerrornum(char *s, Errornum code)
Definition: utils/frame.c:635

◆ parsetimearg()

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.

333 {
334  int i;
335 
336  if ((i = findoption( argcount, args, string)) > 0)
337  {
338  if (parsetime(args[i] + 1 + strlen( string), result))
339  return TRUE;
340  argerrornum(args[i]+1, ME_NOTIME);
341  }
342  return FALSE;
343 }
#define FALSE
Definition: app_minivm.c:521
const char * args
int findoption(int argcount, char *args[], char *s)
Definition: utils/frame.c:900
int parsetime(char *string, int *result)
Definition: utils/frame.c:352
#define TRUE
Definition: app_minivm.c:518
static PGresult * result
Definition: cel_pgsql.c:88
void argerrornum(char *s, Errornum code)
Definition: utils/frame.c:635

◆ parsevolarg()

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.

540 {
541  double vol = 1.0;
542  char sbd, sbb, end;
543  int i, weird = FALSE;
544 
545  if ((i = findoption( argcount, args, string)) > 0)
546  {
547  switch (sscanf(args[i] + 1 + strlen( string),
548  "%30lf%1c%1c%1c", &vol, &sbd, &sbb, &end))
549  {
550  case 0: case EOF: case 4:
551  weird = TRUE;
552  break; /* No number: error */
553  case 1:
554  *result = vol;
555  break;
556  case 2:
557  if (sbd == '%')
558  *result = vol / 100;
559  else
560  weird = TRUE; /* One char but no percent: error */
561  break;
562  case 3:
563  if (sbd =='d' && sbb == 'b')
564  *result = pow(2, vol / 6.02);
565  else
566  weird = TRUE; /* Two chars but not db: error */
567  break;
568  default:
569  say("frame.c: This can't happen.\n");
570  }
571  if (weird)
572  argerrornum( args[i] + 1, ME_NOVOL);
573  /* ("Weird option: couldn't parse volume '%s'\n", args[i]+2); */
574  return !weird;
575  }
576  else
577  {
578  return FALSE;
579  }
580 }
#define FALSE
Definition: app_minivm.c:521
const char * args
char * end
Definition: eagi_proxy.c:73
int findoption(int argcount, char *args[], char *s)
Definition: utils/frame.c:900
int say(const char *format,...)
Definition: utils/frame.c:1026
#define TRUE
Definition: app_minivm.c:518
static PGresult * result
Definition: cel_pgsql.c:88
void argerrornum(char *s, Errornum code)
Definition: utils/frame.c:635

◆ parsevolume()

int parsevolume ( char *  s,
double *  result 
)

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

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

591 {
592  int k;
593  char sbd, sbb, end;
594 
595  *result = 1.0;
596  k = sscanf(s, "%30lf%1c%1c%1c", result, &sbd, &sbb, &end);
597  switch (k)
598  {
599  case 0:
600  case EOF:
601  case 4:
602  return FALSE;
603  case 1:
604  break;
605  case 2:
606  if (sbd != '%')
607  return FALSE;
608  (*result) /=100;
609  break;
610  case 3:
611  if (sbd !='d' || sbb != 'b')
612  return FALSE;
613  (*result) = pow(2, (*result) / 6.02);
614  break;
615  default:
616  say("parsevolume: This can't happen (%d).\n", k);
617  }
618  return TRUE;
619 }
#define FALSE
Definition: app_minivm.c:521
char * end
Definition: eagi_proxy.c:73
int say(const char *format,...)
Definition: utils/frame.c:1026
#define TRUE
Definition: app_minivm.c:518
static PGresult * result
Definition: cel_pgsql.c:88

◆ readawaysamples()

void readawaysamples ( FILE *  input,
size_t  size 
)

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

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

1070 {
1071  short *buffer;
1072  int samplesread, count;
1073 
1074  buffer = malloc( sizeof( *buffer) * BUFFSIZE);
1075  if (buffer == NULL) fatalperror("Couldn't allocate buffer");
1076 
1077  while (size > 0)
1078  {
1079  if (size > BUFFSIZE)
1080  count = BUFFSIZE;
1081  else
1082  count = size;
1083 
1084  samplesread = fread( buffer, sizeof(*buffer), count, input);
1085  if (ferror( input) != 0)
1086  fatalperror("Error reading input file");
1087  size -= samplesread;
1088  }
1089  free( buffer);
1090 }
void fatalperror(const char *string)
Definition: utils/frame.c:1020
#define NULL
Definition: resample.c:96
static int input(yyscan_t yyscanner)
Definition: ast_expr2f.c:1584
char * malloc()
void free()
#define BUFFSIZE
Definition: utils/frame.h:54

◆ readpkheader()

void readpkheader ( FILE *  anyin)

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

77 {
78  unsigned short tempushort;
79  int tempint, i, x;
80  unsigned char blood[8];
81 
82  for (i = 0; i < 11; i++)
83  {
84  if (!fread( &tempint, 4, 1, anyin)) {
85  return;
86  }
87  printf( "%d: %d, ", i, tempint);
88  }
89  printf( "\n");
90  if (!fread( blood, 1, 8, anyin)) {
91  return;
92  }
93  for (i = 0; i < 8; i++)
94  printf( "%d ", blood[i]);
95  printf( "\n");
96  for (i = 0; i < 8; i++)
97  {
98  for (x = 128; x > 0; x /= 2)
99  printf((blood[i] & x) == 0? "0 ":"1 ");
100  printf(i%4==3? "\n":"| ");
101  }
102  printf( "\n");
103  for (i = 0; i < 2; i++)
104  {
105  if (!fread( &tempint, 4, 1, anyin)) {
106  return;
107  }
108  printf( "%d: %d, ", i, tempint);
109  }
110  printf( "\n");
111  for (i = 0; i < 2; i++)
112  {
113  if (!fread( &tempushort, 2, 1, anyin)) {
114  return;
115  }
116  printf( "%d: %d, ", i, tempushort);
117  }
118  printf( "\n");
119 }

◆ readwavheader()

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().

127 {
128  unsigned int tempuint, sf;
129  unsigned short tempushort, cn;
130  char str[9];
131  int nowav = FALSE;
132 
133  iswav = FALSE;
134 
135  if (ftell(anyin) == -1) /* If we cannot seek this file */
136  {
137  nowav = TRUE; /* -> Pretend this is no wav-file */
138  chat("File not seekable: not checking for WAV-header.\n");
139  }
140  else
141  {
142  /* Expect four bytes "RIFF" and four bytes filelength */
143  if (!fread(str, 1, 8, anyin)) { /* 0 */
144  return;
145  }
146  str[4] = '\0';
147  if (strcmp(str, "RIFF") != 0) nowav = TRUE;
148  /* Expect eight bytes "WAVEfmt " */
149  if (!fread(str, 1, 8, anyin)) { /* 8 */
150  return;
151  }
152  str[8] = '\0';
153  if (strcmp(str, "WAVEfmt ") != 0) nowav = TRUE;
154  /* Expect length of fmt data, which should be 16 */
155  if (!fread(&tempuint, 4, 1, anyin)) { /* 16 */
156  return;
157  }
158  if (tempuint != 16) nowav = TRUE;
159  /* Expect format tag, which should be 1 for pcm */
160  if (!fread(&tempushort, 2, 1, anyin)) { /* 20 */
161  return;
162  }
163  if (tempushort != 1)
164  nowav = TRUE;
165  /* Expect number of channels */
166  if (!fread(&cn, 2, 1, anyin)) { /* 20 */
167  return;
168  }
169  if (cn != 1 && cn != 2) nowav = TRUE;
170  /* Read samplefrequency */
171  if (!fread(&sf, 4, 1, anyin)) { /* 24 */
172  return;
173  }
174  /* Read bytes per second: Should be samplefreq * channels * 2 */
175  if (!fread(&tempuint, 4, 1, anyin)) { /* 28 */
176  return;
177  }
178  if (tempuint != sf * cn * 2) nowav = TRUE;
179  /* read bytes per frame: Should be channels * 2 */
180  if (!fread(&tempushort, 2, 1, anyin)) { /* 32 */
181  return;
182  }
183  if (tempushort != cn * 2) nowav = TRUE;
184  /* Read bits per sample: Should be 16 */
185  if (!fread(&tempushort, 2, 1, anyin)) { /* 34 */
186  return;
187  }
188  if (tempushort != 16) nowav = TRUE;
189  if (!fread(str, 4, 1, anyin)) { /* 36 */
190  return;
191  }
192  str[4] = '\0';
193  if (strcmp(str, "data") != 0) nowav = TRUE;
194  if (!fread(&tempuint, 4, 1, anyin)) { /* 40 */
195  return;
196  }
197  if (nowav)
198  {
199  fseek(anyin, 0, SEEK_SET); /* Back to beginning of file */
200  chat("File has no WAV header.\n");
201  }
202  else
203  {
204  samplefrequency = sf;
205  channels = cn;
206  chat("Read WAV header: %d channels, samplefrequency %d.\n",
208  iswav = TRUE;
209  }
210  }
211  return;
212 }
#define FALSE
Definition: app_minivm.c:521
int samplefrequency
Definition: utils/frame.c:28
const char * str
Definition: app_jack.c:147
int iswav
Definition: utils/frame.c:32
unsigned short channels
Definition: utils/frame.c:30
int chat(const char *format,...)
Definition: utils/frame.c:971
#define TRUE
Definition: app_minivm.c:518

◆ say()

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

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

References result.

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

1027 {
1028  va_list ap;
1029  int result;
1030 
1031  va_start( ap, format);
1032  result = vfprintf( stdout, format, ap);
1033  va_end( ap);
1034  return result;
1035 }
static PGresult * result
Definition: cel_pgsql.c:88
static snd_pcm_format_t format
Definition: chan_alsa.c:102

◆ startstopwatch()

void startstopwatch ( void  )

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

References NULL, statistics(), and stopwatch.

Referenced by main().

308 {
309  stopwatch = time(NULL); /* Remember time 'now' */
310  atexit(statistics); /* Call function statistics() at exit. */
311 
312  return;
313 }
static void statistics(void)
Definition: utils/frame.c:287
time_t stopwatch
Definition: utils/frame.c:27
#define NULL
Definition: resample.c:96

◆ statistics()

static void statistics ( void  )
static

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

References inform(), NULL, and stopwatch.

Referenced by internal_stasis_subscribe(), publish_msg(), rtp_transport_wide_cc_feedback_produce(), startstopwatch(), stasis_subscription_cb_noop(), subscription_invoke(), and topic_dtor().

288 {
289  int temp;
290 
291  temp = time(NULL) - stopwatch;
292  if (temp != 1)
293  {
294  inform ("\nTime: %d seconds\n", temp);
295  }
296  else
297  {
298  inform ("\nTime: 1 second\n");
299  }
300  return;
301 }
time_t stopwatch
Definition: utils/frame.c:27
#define NULL
Definition: resample.c:96
int inform(const char *format,...)
Definition: utils/frame.c:985

◆ workloop()

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.

945 {
946  short *buffer;
947  int length, nowlength;
948 
949  length = BUFFSIZE;
950  if ((buffer = malloc( sizeof(short) * length)) == NULL)
951  fatalperror ("");
952  while (TRUE)
953  {
954  nowlength = fread(buffer, sizeof(short), length, theinfile);
955  if (ferror( theinfile) != 0)
956  fatalperror("Error reading input file");
957  if (nowlength == 0) /* Reached end of input file */
958  break;
959  /* Call the routine that does the work */
960  if (!work (buffer, nowlength)) /* On error, stop. */
961  return FALSE;
962  if (!fwrite(buffer, sizeof(short), nowlength, theoutfile)) {
963  return FALSE;
964  }
965  if (ferror( theoutfile) != 0)
966  fatalperror("Error writing to output file");
967  }
968  return TRUE; /* Input file done with, no errors. */
969 }
#define FALSE
Definition: app_minivm.c:521
void fatalperror(const char *string)
Definition: utils/frame.c:1020
#define NULL
Definition: resample.c:96
char * malloc()
#define TRUE
Definition: app_minivm.c:518
#define BUFFSIZE
Definition: utils/frame.h:54

Variable Documentation

◆ channels

unsigned short channels

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

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

◆ in

FILE* in

◆ infilename

char* infilename

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

Referenced by parseargs().

◆ iswav

int iswav

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

Referenced by main(), and readwavheader().

◆ out

FILE * out

◆ outfilename

char * outfilename

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

Referenced by main(), and parseargs().

◆ samplefrequency

int samplefrequency

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

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

◆ samplewidth

unsigned short samplewidth

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

Referenced by getremainingfilelength(), and parseargs().

◆ standardusage

char* standardusage
static

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

Referenced by parseargs().

◆ standardversion

char* standardversion = "frame version 1.3, June 13th 2001"
static

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

Referenced by parseargs().

◆ stopwatch

time_t stopwatch

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

Referenced by startstopwatch(), and statistics().

◆ test_usage

int test_usage
static

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

Referenced by findoption(), and parseargs().

◆ usage

char* usage = ""

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

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

◆ verboselevel

int verboselevel

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

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

◆ version

char* version = ""

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

Referenced by parseargs().

◆ wavout

int wavout

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

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