42"\nOptions common to all mark-dsp programs:\n"
44"-h \t\t create a WAV-header on output files.\n"
45"-c#\t\t set number of channels to # (1 or 2). Default: like input.\n"
46"-w#\t\t set number of bits per sample (width) to # (only 16)\n"
47"-f#\t\t set sample frequency to #. Default: like input.\n"
48"-V \t\t verbose: talk a lot.\n"
49"-Q \t\t quiet: talk as little as possible.\n\n"
50"In most cases, a filename of '-' means stdin or stdout.\n\n"
51"Bug-reports: mark@manumark.de\n"
63 if (i == -1)
return FALSE;
64 if (fseek(anyin, 0, SEEK_END) == -1)
return FALSE;
69 if (fseek(anyin, i, SEEK_SET) == -1)
return FALSE;
78 unsigned short tempushort;
80 unsigned char blood[8];
82 for (i = 0; i < 11; i++)
84 if (!fread( &tempint, 4, 1, anyin)) {
87 printf(
"%d: %d, ", i, tempint);
90 if (!fread( blood, 1, 8, anyin)) {
93 for (i = 0; i < 8; i++)
94 printf(
"%d ", blood[i]);
96 for (i = 0; i < 8; i++)
98 for (x = 128; x > 0; x /= 2)
99 printf((blood[i] & x) == 0?
"0 ":
"1 ");
100 printf(i%4==3?
"\n":
"| ");
103 for (i = 0; i < 2; i++)
105 if (!fread( &tempint, 4, 1, anyin)) {
108 printf(
"%d: %d, ", i, tempint);
111 for (i = 0; i < 2; i++)
113 if (!fread( &tempushort, 2, 1, anyin)) {
116 printf(
"%d: %d, ", i, tempushort);
128 unsigned int tempuint, sf;
129 unsigned short tempushort, cn;
135 if (ftell(anyin) == -1)
138 chat(
"File not seekable: not checking for WAV-header.\n");
143 if (!fread(
str, 1, 8, anyin)) {
147 if (strcmp(
str,
"RIFF") != 0) nowav =
TRUE;
149 if (!fread(
str, 1, 8, anyin)) {
153 if (strcmp(
str,
"WAVEfmt ") != 0) nowav =
TRUE;
155 if (!fread(&tempuint, 4, 1, anyin)) {
158 if (tempuint != 16) nowav =
TRUE;
160 if (!fread(&tempushort, 2, 1, anyin)) {
166 if (!fread(&cn, 2, 1, anyin)) {
169 if (cn != 1 && cn != 2) nowav =
TRUE;
171 if (!fread(&sf, 4, 1, anyin)) {
175 if (!fread(&tempuint, 4, 1, anyin)) {
178 if (tempuint != sf * cn * 2) nowav =
TRUE;
180 if (!fread(&tempushort, 2, 1, anyin)) {
183 if (tempushort != cn * 2) nowav =
TRUE;
185 if (!fread(&tempushort, 2, 1, anyin)) {
188 if (tempushort != 16) nowav =
TRUE;
189 if (!fread(
str, 4, 1, anyin)) {
193 if (strcmp(
str,
"data") != 0) nowav =
TRUE;
194 if (!fread(&tempuint, 4, 1, anyin)) {
199 fseek(anyin, 0, SEEK_SET);
200 chat(
"File has no WAV header.\n");
206 chat(
"Read WAV header: %d channels, samplefrequency %d.\n",
221 unsigned int tempuint, filelength;
222 unsigned short tempushort;
225 if (fseek(
out, 0, SEEK_END) != -1)
227 filelength = ftell(
out);
228 chat(
"filelength %d, ", filelength);
229 fseek(
out, 0, SEEK_SET);
230 if (!fwrite(
"RIFF", 1, 4,
out)) {
233 tempuint = filelength - 8;
234 if (!fwrite(&tempuint, 4, 1,
out)) {
237 if (!fwrite(
"WAVEfmt ", 1, 8,
out)) {
242 if (!fwrite(&tempuint, 4, 1,
out)) {
247 if (!fwrite(&tempushort, 2, 1,
out)) {
260 if (!fwrite(&tempuint, 4, 1,
out)) {
265 if (!fwrite(&tempushort, 2, 1,
out)) {
270 if (!fwrite(&tempushort, 2, 1,
out)) {
273 if (!fwrite(
"data", 4, 1,
out)) {
276 tempuint = filelength - 44;
277 if (!fwrite(&tempuint, 4, 1,
out)) {
294 inform (
"\nTime: %d seconds\n", temp);
298 inform (
"\nTime: 1 second\n");
358 k = sscanf(
string,
"%30lf%1c%1c%1c", &temp, &m, &s, &
end);
361 case 0:
case EOF:
case 4:
373 if (m ==
'm' && s ==
's')
375 else if (m ==
'H' && s ==
'z')
399 k = sscanf(
string,
"%30lf%1c%1c%1c", &temp, &m, &s, &
end);
402 case 0:
case EOF:
case 2:
case 4:
408 if (m ==
'H' && s ==
'z')
424 for (i = 1; i < argcount; i++)
426 if (
args[i][0] !=
'\0' &&
436 fatalperror(
"Couldn't allocate memory for filename\n");
447 if (strncmp( found, wanted, strlen( wanted)) == 0)
449 if (found[strlen( wanted)] ==
'\0')
463 if (
args[i][strlen(
string) + 1] ==
'\0')
478 switch (sscanf(
args[i] + 1 + strlen(
string),
479 "%30d%1c", &temp, &
c))
481 case 0:
case EOF:
case 2:
488 say(
"frame.c: This can't happen\n");
513 switch (sscanf(
args[i] + 1 + strlen(
string),
"%30lf%1c", &temp, &
end))
515 case 0:
case EOF:
case 2:
522 say(
"frame.c: This can't happen\n");
543 int i, weird =
FALSE;
547 switch (sscanf(
args[i] + 1 + strlen(
string),
548 "%30lf%1c%1c%1c", &vol, &sbd, &sbb, &
end))
550 case 0:
case EOF:
case 4:
563 if (sbd ==
'd' && sbb ==
'b')
564 *
result = pow(2, vol / 6.02);
569 say(
"frame.c: This can't happen.\n");
596 k = sscanf(s,
"%30lf%1c%1c%1c",
result, &sbd, &sbb, &
end);
611 if (sbd !=
'd' || sbb !=
'b')
613 (*result) = pow(2, (*
result) / 6.02);
616 say(
"parsevolume: This can't happen (%d).\n", k);
627 error (
"Error parsing command line. Unrecognized option:\n\t-%s\n", s);
641 error(
"Too many files on command line: '%s'.\n", s);
646 error (
"Error parsing option -%s:\n\t", s);
653 message =
"Floating point number expected";
656 message =
"Time argument expected";
659 message =
"Volume argument expected";
662 message =
"Garbage after switch-type option";
665 message =
"Option -h is not useful for text-output";
668 message =
"No input file specified";
671 message =
"No output file specified";
674 message =
"No input/output file specified";
677 message =
"Standard in not supported here";
680 message =
"Standard out not supported here";
683 message =
"Standard in/out not supported here";
686 message =
"Not enough files specified";
689 fatalerror(
"\nThis can't happen. Report this as a bug\n");
692 error(
"Error code %d not implemented. Fix me!\n", code);
693 message =
"Error message not implemented. Fix me!";
707 error (
"Error parsing option -%s:\n\t", s);
709 error (
"Error parsing command line:\n\t");
719 int i, errorcount = 0;
721 for (i = 1; i < argcount; i++)
723 if (
args[i][0] !=
'\0')
727 error(
"The following arguments were not recognized:\n");
749 if ((fileswitch & 1) != 0)
751 if ((fileswitch & 4) != 0)
783 if ((fileswitch & 1) != 0)
792 if ((fileswitch & 2) != 0)
797 if ((fileswitch & 2) == 0)
808 if ((fileswitch & 4) != 0)
821 if ((fileswitch & 8) == 0)
831 if ((fileswitch & 32) != 0)
846 if ((fileswitch & 16) == 0)
861 "with value 16. Sorry.");
867 if (tempint != 1 && tempint != 2)
869 "with values 1 or 2. Sorry.");
877 switch (fileswitch & (12))
905 printf(
"Checking for option -%s\n", s);
907 for (i=1; i<argcount; i++)
910 strncmp(
args[i] + 1, s, strlen( s)) == 0)
944 int (*work)(
short *buffer,
int length) )
947 int length, nowlength;
950 if ((buffer =
malloc(
sizeof(
short) * length)) ==
NULL)
954 nowlength = fread(buffer,
sizeof(
short), length, theinfile);
955 if (ferror( theinfile) != 0)
960 if (!work (buffer, nowlength))
962 if (!fwrite(buffer,
sizeof(
short), nowlength, theoutfile)) {
965 if (ferror( theoutfile) != 0)
971int __attribute__((format(printf,1,2)))
chat( const
char *format, ...)
978 va_start( ap, format);
979 result = vfprintf( stderr, format, ap);
985int __attribute__((format(printf,1,2)))
inform( const
char *format, ...)
992 va_start( ap, format);
993 result = vfprintf( stderr, format, ap);
999int __attribute__((format(printf,1,2)))
error( const
char *format, ...)
1004 va_start( ap, format);
1005 result = vfprintf( stderr, format, ap);
1010void __attribute__((format(printf,1,2)))
fatalerror( const
char *format, ...)
1014 va_start( ap, format);
1015 vfprintf( stderr, format, ap);
1026int __attribute__((format(printf,1,2)))
say( const
char *format, ...)
1031 va_start( ap, format);
1032 result = vfprintf( stdout, format, ap);
1066 return 6.0 * log(
value / 32767) / log( 2);
1072 int samplesread, count;
1084 samplesread = fread( buffer,
sizeof(*buffer), count,
input);
1085 if (ferror(
input) != 0)
1087 size -= samplesread;
static int input(yyscan_t yyscanner)
Time-related functions and macros.
char * mallocconcat(char *one, char *two)
double double2db(double value)
void argerrornum(char *s, Errornum code)
void fatalperror(const char *string)
int say(const char *format,...)
char * malloccopy(char *string)
static char * standardversion
int parsetimearg(int argcount, char *args[], char *string, int *result)
int error(const char *format,...)
void readwavheader(FILE *anyin)
int getremainingfilelength(FILE *anyin, long *result)
void argerrortxt(char *s, char *message)
int parsetime(char *string, int *result)
static char * standardusage
void readawaysamples(FILE *input, size_t size)
int parsevolarg(int argcount, char *args[], char *string, double *result)
int findoption(int argcount, char *args[], char *s)
static void statistics(void)
void fatalerror(const char *format,...)
int parseswitch(char *found, char *wanted)
int isoptionchar(char coal)
int chat(const char *format,...)
int parsevolume(char *s, double *result)
int inform(const char *format,...)
void checknoargs(int argcount, char *args[])
int workloop(FILE *theinfile, FILE *theoutfile, int(*work)(short *buffer, int length))
int parsedoublearg(int argcount, char *args[], char *string, double *result)
int parsefreq(char *string, double *result)
unsigned short samplewidth
int parseintarg(int argcount, char *args[], char *string, int *result)
void readpkheader(FILE *anyin)
int parseswitcharg(int argcount, char *args[], char *string)
char * parsefilearg(int argcount, char *args[])
void parseargs(int argcount, char *args[], int fileswitch)
void startstopwatch(void)