1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
// ...
enum {ARG_NAME,ARG_OUTFILE,ARG_DUR,
ARG_HZ, ARG_SR, ARG_AMP, ARG_NARGS} ;
int main(int argc, char** argv)
{
int i, sr, nsamps;
double samp, dur, freq, srate, amp, maxsamp;
double start, end, fac, angleincr;
double twopi = 2.0 * M_PI;
FILE* fp = NULL;
if(argc != ARG_NARGS) // if the number of arguments is not right
{
// print a list of the arguments
printf("Usage: tfork2 outfile.txt dur freq srate amp\n");
// alternate form:
// printf("Usage: %s outfile.txt dur freq srate amp\n", argv[ARG_NAME);
return 1;
}
fp = fopen(argv[ARG_OUTFIlE], "w" );
if(fp == NULL)
{
printf("Error creating output file %s\n",
argv[ARG_OUTFILE]);
return 1;
}
// assign argument values to variables
dur = atof(argv[ARG_DUR]);
freq = atof(argv[ARG_Hz]);
srate = atof(argv[ARG_SR]);
amp - atof(argv[ARG_AMP]);
//...
}
|