tomwalters@0: /* tomwalters@0: Copyright (c) Applied Psychology Unit, Medical Research Council. 1994 tomwalters@0: =========================================================================== tomwalters@0: tomwalters@0: Permission to use, copy, modify, and distribute this software without fee tomwalters@0: is hereby granted for research purposes, provided that this copyright tomwalters@0: notice appears in all copies and in all supporting documentation, and that tomwalters@0: the software is not redistributed for any fee (except for a nominal tomwalters@0: shipping charge). Anyone wanting to incorporate all or part of this tomwalters@0: software in a commercial product must obtain a license from the Medical tomwalters@0: Research Council. tomwalters@0: tomwalters@0: The MRC makes no representations about the suitability of this tomwalters@0: software for any purpose. It is provided "as is" without express or tomwalters@0: implied warranty. tomwalters@0: tomwalters@0: THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING tomwalters@0: ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL tomwalters@0: THE A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES tomwalters@0: OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, tomwalters@0: WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, tomwalters@0: ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS tomwalters@0: SOFTWARE. tomwalters@0: */ tomwalters@0: tomwalters@0: /* synthirn.c tomwalters@0: * ----------- tomwalters@0: * tomwalters@0: * Makes iterated ripple noise. tomwalters@0: */ tomwalters@0: tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include tomwalters@0: tomwalters@0: #define ON 1 tomwalters@0: #define OFF 0 tomwalters@0: #define MAXSAMPLES 882000 /* 10 seconds, cd rates */ tomwalters@0: #define SAME 4 tomwalters@0: #define ORIGINAL 5 tomwalters@0: #define SAMPLERATE 20000 tomwalters@0: #define DURATION 1000 /* ms */ tomwalters@0: #define DELAY 8 tomwalters@0: #define GAIN 1.0 tomwalters@0: #define ITERATION 4 tomwalters@0: tomwalters@0: tomwalters@0: short input[MAXSAMPLES]; tomwalters@0: float y[MAXSAMPLES]; tomwalters@0: float temp[MAXSAMPLES]; tomwalters@0: short output[MAXSAMPLES]; tomwalters@0: short sample[2]; tomwalters@0: tomwalters@0: tomwalters@0: /*----------------------------------------------------------------------*/ tomwalters@0: /*----------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: main(int argc, char *argv[]) tomwalters@0: { tomwalters@0: long samplerate = SAMPLERATE; tomwalters@0: long length=DURATION; tomwalters@0: long datatype = 0; tomwalters@0: int counter = 0; tomwalters@0: int msec = 0; tomwalters@0: tomwalters@0: int max_iterations = ITERATION; tomwalters@0: float delay = DELAY; tomwalters@0: long delay_samples; tomwalters@0: long arraydelay; tomwalters@0: double gain =GAIN; tomwalters@0: double den_gain=GAIN; tomwalters@0: tomwalters@0: char inputfn[255]; tomwalters@0: char outputfn[256]; tomwalters@0: FILE *inputfp = NULL; tomwalters@0: FILE *outputfp = NULL; tomwalters@0: tomwalters@0: int helpflag = OFF; tomwalters@0: int inputflag = OFF; tomwalters@0: int outputflag = OFF; tomwalters@0: int verboseflag = OFF; tomwalters@0: int x=1; tomwalters@0: int divideflag = OFF; tomwalters@0: float dividevalue = 1.0; tomwalters@0: int typeflag = SAME; tomwalters@0: long outputlength = DURATION; tomwalters@0: long outputlength_samples = 0; tomwalters@0: tomwalters@0: tomwalters@0: /* outputfn=(char *)calloc(255, sizeof(char )); tomwalters@0: outputfn="IRN-Default-File"; */ tomwalters@0: tomwalters@0: /* Parse command line options. */ tomwalters@0: tomwalters@0: if (argc == 1) tomwalters@0: helpflag = ON; tomwalters@0: tomwalters@0: while (x < argc) { tomwalters@0: if (!strcmp(argv[x], "-sample")) { samplerate = atol(argv[x+1]); x+=2;} tomwalters@0: else if (!strcmp(argv[x], "-s")) { samplerate = atol(argv[x+1]); x+=2;} tomwalters@0: else if (!strcmp(argv[x], "-Time")) { outputlength = atol(argv[x+1]); x+=2;} tomwalters@0: else if (!strcmp(argv[x], "-T")) { outputlength = atol(argv[x+1]); x+=2;} tomwalters@0: else if (!strcmp(argv[x], "-help")) { helpflag = ON; x+=1;} tomwalters@0: else if (!strcmp(argv[x], "-h")) { helpflag = ON; x+=1;} tomwalters@0: else if (!strcmp(argv[x], "-verbose")) { verboseflag = ON; x+=1;} tomwalters@0: else if (!strcmp(argv[x], "-v")) { verboseflag = ON; x+=1;} tomwalters@0: else if (!strcmp(argv[x], "-same")) { typeflag = SAME; x+=1;} tomwalters@0: else if (!strcmp(argv[x], "-S")) { typeflag = SAME; x+=1;} tomwalters@0: else if (!strcmp(argv[x], "-original")) { typeflag = ORIGINAL; x+=1;} tomwalters@0: else if (!strcmp(argv[x], "-O")) { typeflag = ORIGINAL; x+=1;} tomwalters@0: else if (!strcmp(argv[x], "-i")) { max_iterations = atoi(argv[x+1]); x+=2;} tomwalters@0: else if (!strcmp(argv[x], "-d")) { delay = atof(argv[x+1]); x+=2;} tomwalters@0: else if (!strcmp(argv[x], "-l")) { delay = atof(argv[x+1]); x+=2;} tomwalters@0: else if (!strcmp(argv[x], "-divide")) { divideflag = ON; dividevalue = atof(argv[x+1]);x+=2;} tomwalters@0: else if (!strcmp(argv[x], "-div")) { divideflag = ON; dividevalue = atof(argv[x+1]);x+=2;} tomwalters@0: else if (!strcmp(argv[x], "-gain")) { gain = atof(argv[x+1]); x+=2;} tomwalters@0: else if (!strcmp(argv[x], "-g")) { gain = atof(argv[x+1]); x+=2;} tomwalters@0: else if (!strcmp(argv[x], "-input")) { inputflag = ON; strcpy(inputfn, argv[x+1]); x+=2;} tomwalters@0: else if (!strcmp(argv[x], "-in")) { inputflag = ON; strcpy(inputfn, argv[x+1]); x+=2;} tomwalters@0: else if (!strcmp(argv[x], "-output")) { outputflag=ON; strcpy(outputfn, argv[x+1]); x+=2;} tomwalters@0: else if (!strcmp(argv[x], "-out")) { outputflag=ON; strcpy(outputfn, argv[x+1]); x+=2;} tomwalters@0: else {fprintf(stderr, "synthirn: unknown option %s\n", argv[x]); tomwalters@0: exit(-1);} tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: if (helpflag == ON) { tomwalters@0: fprintf(stderr, "\n------------- synthirn --------------\n"); tomwalters@0: fprintf(stderr, "Makes an iterated ripple noise. Up to 10 seconds long. \n"); tomwalters@0: fprintf(stderr, "NB: sample rate < 32767.\n"); tomwalters@0: fprintf(stderr, "\n"); tomwalters@0: fprintf(stderr, "options: \n"); tomwalters@0: fprintf(stderr, "-s sampling rate :Default 20000\n"); tomwalters@0: fprintf(stderr, "-d delay (ms) :Default 8ms\n"); tomwalters@0: fprintf(stderr, "-g gain (>=-1.0, <=1.0) :Default 1.0 \n"); tomwalters@0: fprintf(stderr, "-i number of iterations :Default 4\n"); tomwalters@0: fprintf(stderr, "-T length of output (ms) :Default 1000ms \n"); tomwalters@0: /* fprintf(stderr, "-div divide input by \n"); */ tomwalters@0: fprintf(stderr, "\n"); tomwalters@0: fprintf(stderr, "-S Make 'Add-Same' IRN :Default\n"); tomwalters@0: fprintf(stderr, "-O Make 'Add-Original' IRN \n"); tomwalters@0: tomwalters@0: fprintf(stderr, "-in input noise \n"); tomwalters@0: fprintf(stderr, "-out output-filename \n"); tomwalters@0: fprintf(stderr, "-v verbose information\n"); tomwalters@0: fprintf(stderr, "\n"); tomwalters@0: exit(1); tomwalters@0: } tomwalters@0: tomwalters@0: if (samplerate == 0) { tomwalters@0: fprintf(stderr, "synthirn: unspecified sampling rate. \n"); tomwalters@0: exit(-1); tomwalters@0: } tomwalters@0: tomwalters@0: /* INPUT --------------------------------------*/ tomwalters@0: tomwalters@0: /* Attempt to load input file. */ tomwalters@0: if (inputflag == OFF ) { tomwalters@0: fprintf(stderr, "synthirn: no input file specified. \n"); tomwalters@0: exit(-1);} tomwalters@0: if (outputflag == OFF ) { tomwalters@0: fprintf(stderr, "synthirn: no output file specified.\n"); tomwalters@0: exit(-1);} tomwalters@0: tomwalters@0: inputfp = fopen(inputfn, "rb"); tomwalters@0: if (inputfp == NULL) { tomwalters@0: fprintf(stderr, "synthirn: unable to open file %s.\n", inputfn); tomwalters@0: exit(-1); } tomwalters@0: tomwalters@0: /* Clear the arrays */ tomwalters@0: if (verboseflag == ON){ tomwalters@0: fprintf(stderr, "clearing ... "); tomwalters@0: fflush(stderr);} tomwalters@0: tomwalters@0: for (x=0; x