Bladeren bron

clear compiler warnings

richarddobson 3 jaren geleden
bovenliggende
commit
d29c0085ae
8 gewijzigde bestanden met toevoegingen van 5812 en 5619 verwijderingen
  1. 896 872
      dev/science/crystal.c
  2. 454 428
      dev/science/cubicspline.c
  3. 740 716
      dev/science/dvdwind.c
  4. 662 638
      dev/science/newscales.c
  5. 770 746
      dev/science/repeater.c
  6. 781 757
      dev/science/sorter.c
  7. 750 726
      dev/science/verges.c
  8. 759 736
      dev/science/waveform.c

File diff suppressed because it is too large
+ 896 - 872
dev/science/crystal.c


+ 454 - 428
dev/science/cubicspline.c

@@ -1,3 +1,28 @@
+
+/*
+ * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
+ * http://www.trevorwishart.co.uk
+ * http://www.composersdesktop.com
+ *
+ This file is part of the CDP System.
+ 
+ The CDP System is free software; you can redistribute it
+ and/or modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+ 
+ The CDP System is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU Lesser General Public License for more details.
+ 
+ You should have received a copy of the GNU Lesser General Public
+ License along with the CDP System; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA
+ *
+ */
+
 /*
  * Take a set of amp-frq data in the correct range,
  * and use cubic spline to replot curve to cover
@@ -6,7 +31,7 @@
  * use chan centre frqs.
  */
 
-#define PSEUDOCENT	(1.0009)	// approx 1/64th of a tone
+#define PSEUDOCENT  (1.0009)    // approx 1/64th of a tone
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -28,7 +53,7 @@
 #include <string.h>
 #include <srates.h>
 
-int	sloom = 0;
+int sloom = 0;
 int sloombatch = 0;
 
 const char* cdp_version = "6.1.0";
@@ -36,7 +61,7 @@ const char* cdp_version = "6.1.0";
 char errstr[2400];  //RWD added
 //CDP LIB REPLACEMENTS
 static int allocate_output_array(double **outarray, int *outcnt, double chwidth, double halfchwidth, double nyquist);
-static int get_tk_cmdline_word(int *cmdlinecnt,char ***cmdline,char *q);
+//static int get_tk_cmdline_word(int *cmdlinecnt,char ***cmdline,char *q);
 static int handle_the_special_data(FILE *fpi, double **parray, double **secondderiv, double **x, double **y, int *itemcnt);
 static int test_the_special_data(double *parray, int itemcnt, double nyquist);
 static int smooth(double *x,double *y,double *secondderiv,double *outarray,int *outcnt,double chwidth,double halfchwidth,double nyquist,int arraycnt);
@@ -50,98 +75,98 @@ static int  get_float_with_e_from_within_string(char **str,double *val);
 
 int main(int argc,char *argv[])
 {
-	FILE *fpi, *fpo;
-	int k, OK = 0, dovetail = 0;
-	int exit_status, srate, pointcnt, clength;
-	double chwidth, halfchwidth, nyquist, *parray, *secondderiv, *x, *y, *outarray;
-	int itemcnt, outcnt, arraycnt;
-	char temp[200], temp2[200];
-	if(argc < 5 || argc > 6) {
-		usage1();	
-		return(FAILED);
-	}
-	if((fpi = fopen(argv[1],"r")) == NULL) {
-		fprintf(stdout,"CANNOT OPEN DATAFILE %s\n",argv[1]);
-		fflush(stdout);
-		return(FAILED);
-	}
-	if((exit_status = handle_the_special_data(fpi,&parray,&secondderiv,&x,&y,&itemcnt))<0) {
-		return(FAILED);
-	}
-	arraycnt = itemcnt/2;
-	if(sscanf(argv[3],"%d",&pointcnt) != 1) {
-		fprintf(stdout,"CANNOT READ POINTCNT (%s)\n",argv[3]);
-		fflush(stdout);
-		return(FAILED);
-	}
-	OK = 0;
-	k = 1;
-	while(k < pointcnt) {
-		k *= 2;
-		if(k == pointcnt){
-			OK= 1;
-			break;
-		}
-	}
-	if(!OK) {
-		fprintf(stdout,"ANALYSIS POINTS PARAMETER MUST BE A POWER OF TWO.\n");
-		fflush(stdout);
-		return(FAILED);
-	}
-	if(sscanf(argv[4],"%d",&srate) != 1) {
-		fprintf(stdout,"CANNOT READ SAMPLE RATE (%s)\n",argv[3]);
-		fflush(stdout);
-		return(FAILED);
-	}
- 	if(srate < 44100 || BAD_SR(srate)) {
-		fprintf(stdout,"INVALID SAMPLE RATE ENTERED (44100,48000,88200,96000 only).\n");
-		fflush(stdout);
-		return(DATA_ERROR);
-	}
-	if(argc == 6) {
-		if(strcmp(argv[5],"-s")) {
-			fprintf(stdout,"UNKNOWN FINAL PARAMETER (%s).\n",argv[5]);
-			fflush(stdout);
-			return(DATA_ERROR);
-		}
-		dovetail = 1;
-	}
-	clength	 = (pointcnt + 2)/2;
-	nyquist	 = (double)(srate / 2);		
-	chwidth	 = nyquist/(double)clength;
-	halfchwidth = chwidth / 2;
-
-	if((exit_status = test_the_special_data(parray,itemcnt,nyquist))<0)
-		return(FAILED);
-	if((exit_status = 	allocate_output_array(&outarray,&outcnt,chwidth,halfchwidth,nyquist))<0)
-		return(FAILED);
-	if((fpo = fopen(argv[2],"w")) == NULL) {
-		fprintf(stdout,"CANNOT OPEN OUTPUT DATAFILE %s\n",argv[2]);
-		fflush(stdout);
-		return(FAILED);
-	}
-	if((exit_status = spline(parray,itemcnt,secondderiv,x,y))<0)
-		return(FAILED);
-	if((exit_status = smooth(x,y,secondderiv,outarray,&outcnt,chwidth,halfchwidth,nyquist,arraycnt)) < 0)
-		return(FAILED);
-	if(dovetail) {
-		if((exit_status = dove(parray,itemcnt,outarray,outcnt)) < 0)
-			return(FAILED);
-	}
-	k = 0;
-	for(k = 0;k < outcnt;k+=2) {
-		sprintf(temp,"%lf",outarray[k]);
-		sprintf(temp2,"%lf",outarray[k+1]);
-		strcat(temp2,"\n");
-		strcat(temp,"\t");
-		strcat(temp,temp2);
-		fputs(temp,fpo);
-	}
-	if(fclose(fpo)<0) {
-		fprintf(stdout,"WARNING: Failed to close output data file %s.\n",argv[2]);
-		fflush(stdout);
-	}
-	return(SUCCEEDED);
+    FILE *fpi, *fpo;
+    int k, OK = 0, dovetail = 0;
+    int exit_status, srate, pointcnt, clength;
+    double chwidth, halfchwidth, nyquist, *parray, *secondderiv, *x, *y, *outarray;
+    int itemcnt, outcnt, arraycnt;
+    char temp[200], temp2[200];
+    if(argc < 5 || argc > 6) {
+        usage1();   
+        return(FAILED);
+    }
+    if((fpi = fopen(argv[1],"r")) == NULL) {
+        fprintf(stdout,"CANNOT OPEN DATAFILE %s\n",argv[1]);
+        fflush(stdout);
+        return(FAILED);
+    }
+    if((exit_status = handle_the_special_data(fpi,&parray,&secondderiv,&x,&y,&itemcnt))<0) {
+        return(FAILED);
+    }
+    arraycnt = itemcnt/2;
+    if(sscanf(argv[3],"%d",&pointcnt) != 1) {
+        fprintf(stdout,"CANNOT READ POINTCNT (%s)\n",argv[3]);
+        fflush(stdout);
+        return(FAILED);
+    }
+    OK = 0;
+    k = 1;
+    while(k < pointcnt) {
+        k *= 2;
+        if(k == pointcnt){
+            OK= 1;
+            break;
+        }
+    }
+    if(!OK) {
+        fprintf(stdout,"ANALYSIS POINTS PARAMETER MUST BE A POWER OF TWO.\n");
+        fflush(stdout);
+        return(FAILED);
+    }
+    if(sscanf(argv[4],"%d",&srate) != 1) {
+        fprintf(stdout,"CANNOT READ SAMPLE RATE (%s)\n",argv[3]);
+        fflush(stdout);
+        return(FAILED);
+    }
+    if(srate < 44100 || BAD_SR(srate)) {
+        fprintf(stdout,"INVALID SAMPLE RATE ENTERED (44100,48000,88200,96000 only).\n");
+        fflush(stdout);
+        return(DATA_ERROR);
+    }
+    if(argc == 6) {
+        if(strcmp(argv[5],"-s")) {
+            fprintf(stdout,"UNKNOWN FINAL PARAMETER (%s).\n",argv[5]);
+            fflush(stdout);
+            return(DATA_ERROR);
+        }
+        dovetail = 1;
+    }
+    clength  = (pointcnt + 2)/2;
+    nyquist  = (double)(srate / 2);     
+    chwidth  = nyquist/(double)clength;
+    halfchwidth = chwidth / 2;
+
+    if((exit_status = test_the_special_data(parray,itemcnt,nyquist))<0)
+        return(FAILED);
+    if((exit_status =   allocate_output_array(&outarray,&outcnt,chwidth,halfchwidth,nyquist))<0)
+        return(FAILED);
+    if((fpo = fopen(argv[2],"w")) == NULL) {
+        fprintf(stdout,"CANNOT OPEN OUTPUT DATAFILE %s\n",argv[2]);
+        fflush(stdout);
+        return(FAILED);
+    }
+    if((exit_status = spline(parray,itemcnt,secondderiv,x,y))<0)
+        return(FAILED);
+    if((exit_status = smooth(x,y,secondderiv,outarray,&outcnt,chwidth,halfchwidth,nyquist,arraycnt)) < 0)
+        return(FAILED);
+    if(dovetail) {
+        if((exit_status = dove(parray,itemcnt,outarray,outcnt)) < 0)
+            return(FAILED);
+    }
+    k = 0;
+    for(k = 0;k < outcnt;k+=2) {
+        sprintf(temp,"%lf",outarray[k]);
+        sprintf(temp2,"%lf",outarray[k+1]);
+        strcat(temp2,"\n");
+        strcat(temp,"\t");
+        strcat(temp,temp2);
+        fputs(temp,fpo);
+    }
+    if(fclose(fpo)<0) {
+        fprintf(stdout,"WARNING: Failed to close output data file %s.\n",argv[2]);
+        fflush(stdout);
+    }
+    return(SUCCEEDED);
 }
 
 
@@ -149,170 +174,171 @@ int main(int argc,char *argv[])
 
 int usage1(void)
 {
-	fprintf(stderr,
-	"USAGE: cubicspline datafile outdatafile pointcnt srate [-s]\n"
-	"\n"
-	"Generate smoothed curve from input data re spectrum.\n"
-	"\n"
-	"DATAFILE     textfile of frq/amp pairs.\n"
-	"OUTDATAFILE  textfile of smoothed data.\n"
-	"POINTCNT     no of analysis points required in handling data.\n"
-	"SRATE        samplerate of eventual sound output.\n"
-	"-s           if spectral amp falls to zero before the nyquist,\n"
-	"             keep zeroed end of spectrum at zero.\n."
-	"\n");
-	return(USAGE_ONLY);
+    fprintf(stderr,
+    "USAGE: cubicspline datafile outdatafile pointcnt srate [-s]\n"
+    "\n"
+    "Generate smoothed curve from input data re spectrum.\n"
+    "\n"
+    "DATAFILE     textfile of frq/amp pairs.\n"
+    "OUTDATAFILE  textfile of smoothed data.\n"
+    "POINTCNT     no of analysis points required in handling data.\n"
+    "SRATE        samplerate of eventual sound output.\n"
+    "-s           if spectral amp falls to zero before the nyquist,\n"
+    "             keep zeroed end of spectrum at zero.\n."
+    "\n");
+    return(USAGE_ONLY);
 }
 
 /************************** HANDLE_THE_SPECIAL_DATA **********************************/
 
 int handle_the_special_data(FILE *fpi, double **parray, double **secondderiv, double **x, double **y,int *itemcnt)
 {
-	int cnt, linecnt;
-	int arraycnt;
-	double *p, dummy;
-	char temp[200], *q;
-	cnt = 0;
-	p = &dummy;
-	while(fgets(temp,200,fpi)==temp) {
-		q = temp;
-		if(*q == ';')	//	Allow comments in file
-			continue;
-		while(get_float_with_e_from_within_string(&q,p))
-			cnt++;
-	}
-	if(ODD(cnt)) {
-		fprintf(stdout,"Data not paired correctly in input data file\n");
-		fflush(stdout);
-		return(DATA_ERROR);
-	}
-	if(cnt == 0) {
-		fprintf(stdout,"No data in input data file\n");
-		fflush(stdout);
-		return(DATA_ERROR);
-	}
-	if((*parray = (double *)malloc(cnt * sizeof(double)))==NULL) {
-		fprintf(stdout,"INSUFFICIENT MEMORY for input data.\n");
-		fflush(stdout);
-		return(MEMORY_ERROR);
-	}
-	arraycnt = cnt/2;
-	if((*secondderiv = (double *)malloc(cnt/2 * sizeof(double)))==NULL) {
-		fprintf(stdout,"INSUFFICIENT MEMORY for storing slope of input data.\n");
-		fflush(stdout);
-		return(MEMORY_ERROR);
-	}
-	if((*x = (double *)malloc(cnt/2 * sizeof(double)))==NULL) {
-		fprintf(stdout,"INSUFFICIENT MEMORY for storing x-coords of input data.\n");
-		fflush(stdout);
-		return(MEMORY_ERROR);
-	}
-	if((*y = (double *)malloc(cnt/2 * sizeof(double)))==NULL) {
-		fprintf(stdout,"INSUFFICIENT MEMORY for storing y-coords of input data.\n");
-		fflush(stdout);
-		return(MEMORY_ERROR);
-	}
-	fseek(fpi,0,0);
-	linecnt = 1;
-	p = *parray;
-	while(fgets(temp,200,fpi)==temp) {
-		q = temp;
-		if(*q == ';')	//	Allow comments in file
-			continue;
-		while(get_float_with_e_from_within_string(&q,p)) {
-			p++;
-		}
-		linecnt++;
-	}
-	if(fclose(fpi)<0) {
-		fprintf(stdout,"WARNING: Failed to close input data file.\n");
-		fflush(stdout);
-	}
-	*itemcnt = cnt;
-	return(FINISHED);
+    int cnt, linecnt;
+    int arraycnt;
+    double *p, dummy;
+    char temp[200], *q;
+    cnt = 0;
+    p = &dummy;
+    while(fgets(temp,200,fpi)==temp) {
+        q = temp;
+        if(*q == ';')   //  Allow comments in file
+            continue;
+        while(get_float_with_e_from_within_string(&q,p))
+            cnt++;
+    }
+    if(ODD(cnt)) {
+        fprintf(stdout,"Data not paired correctly in input data file\n");
+        fflush(stdout);
+        return(DATA_ERROR);
+    }
+    if(cnt == 0) {
+        fprintf(stdout,"No data in input data file\n");
+        fflush(stdout);
+        return(DATA_ERROR);
+    }
+    if((*parray = (double *)malloc(cnt * sizeof(double)))==NULL) {
+        fprintf(stdout,"INSUFFICIENT MEMORY for input data.\n");
+        fflush(stdout);
+        return(MEMORY_ERROR);
+    }
+    arraycnt = cnt/2;
+    if((*secondderiv = (double *)malloc(cnt/2 * sizeof(double)))==NULL) {
+        fprintf(stdout,"INSUFFICIENT MEMORY for storing slope of input data.\n");
+        fflush(stdout);
+        return(MEMORY_ERROR);
+    }
+    if((*x = (double *)malloc(cnt/2 * sizeof(double)))==NULL) {
+        fprintf(stdout,"INSUFFICIENT MEMORY for storing x-coords of input data.\n");
+        fflush(stdout);
+        return(MEMORY_ERROR);
+    }
+    if((*y = (double *)malloc(cnt/2 * sizeof(double)))==NULL) {
+        fprintf(stdout,"INSUFFICIENT MEMORY for storing y-coords of input data.\n");
+        fflush(stdout);
+        return(MEMORY_ERROR);
+    }
+    fseek(fpi,0,0);
+    linecnt = 1;
+    p = *parray;
+    while(fgets(temp,200,fpi)==temp) {
+        q = temp;
+        if(*q == ';')   //  Allow comments in file
+            continue;
+        while(get_float_with_e_from_within_string(&q,p)) {
+            p++;
+        }
+        linecnt++;
+    }
+    if(fclose(fpi)<0) {
+        fprintf(stdout,"WARNING: Failed to close input data file.\n");
+        fflush(stdout);
+    }
+    *itemcnt = cnt;
+    return(FINISHED);
 }
 
 /************************** TEST_THE_SPECIAL_DATA **********************************/
 
 int test_the_special_data(double *parray, int itemcnt, double nyquist)
 {
-	double *p;
-	int isamp = 0, linecnt = 1;
-	p = parray;
-	while(linecnt <= itemcnt/2) {
-		if(isamp) {
-			if(*p < 0.0 || *p > 1.0) {
-				fprintf(stdout,"Amp (%lf) out of range (0-1) at line %d in datafile.\n",*p,linecnt);
-				fflush(stdout);
-				return(DATA_ERROR);
-			}
-		} else {
-			if(*p < 0.0 || *p > nyquist) {
-				fprintf(stdout,"Frq (%lf) out of range (0 - %lf) at line %d in datafile.\n",*p,nyquist,linecnt);
-				fflush(stdout);
-				return(DATA_ERROR);
-			}
-		}
-		if(!isamp)
-			linecnt++;
-		isamp = !isamp;
-		p++;
-	}
-	return(FINISHED);
+    double *p;
+    int isamp = 0, linecnt = 1;
+    p = parray;
+    while(linecnt <= itemcnt/2) {
+        if(isamp) {
+            if(*p < 0.0 || *p > 1.0) {
+                fprintf(stdout,"Amp (%lf) out of range (0-1) at line %d in datafile.\n",*p,linecnt);
+                fflush(stdout);
+                return(DATA_ERROR);
+            }
+        } else {
+            if(*p < 0.0 || *p > nyquist) {
+                fprintf(stdout,"Frq (%lf) out of range (0 - %lf) at line %d in datafile.\n",*p,nyquist,linecnt);
+                fflush(stdout);
+                return(DATA_ERROR);
+            }
+        }
+        if(!isamp)
+            linecnt++;
+        isamp = !isamp;
+        p++;
+    }
+    return(FINISHED);
 }
 
 /************************** ALLOCATE_OUTPUT_ARRAY **********************************/
 
 int allocate_output_array(double **outarray,int *outcnt,double chwidth,double halfchwidth,double nyquist)
 {
-	int outsize = 1;  // Count initial halfwidht channel
-	double lastlofrq, lofrq = halfchwidth;
-	while(lofrq <= nyquist) {
-		outsize++;
-		lastlofrq = lofrq;	
-		lofrq *= PSEUDOCENT;
-		if(lofrq - lastlofrq >= chwidth)	//	Once chan separation is > chwidth
-			lofrq = lastlofrq + chwidth;	//	Just set 1 value per channel
-	}
-	outsize += 64;  //	SAFETY
-	outsize *= 2;
-	if((*outarray = (double *)malloc(outsize * sizeof(double)))==NULL) {
-		fprintf(stdout,"INSUFFICIENT MEMORY for input data.\n");
-		fflush(stdout);
-		return(MEMORY_ERROR);
-	}
-	*outcnt = outsize;
-	return(	FINISHED);
+    int outsize = 1;  // Count initial halfwidht channel
+    double lastlofrq, lofrq = halfchwidth;
+    while(lofrq <= nyquist) {
+        outsize++;
+        lastlofrq = lofrq;  
+        lofrq *= PSEUDOCENT;
+        if(lofrq - lastlofrq >= chwidth)    //  Once chan separation is > chwidth
+            lofrq = lastlofrq + chwidth;    //  Just set 1 value per channel
+    }
+    outsize += 64;  //  SAFETY
+    outsize *= 2;
+    if((*outarray = (double *)malloc(outsize * sizeof(double)))==NULL) {
+        fprintf(stdout,"INSUFFICIENT MEMORY for input data.\n");
+        fflush(stdout);
+        return(MEMORY_ERROR);
+    }
+    *outcnt = outsize;
+    return( FINISHED);
 }
 
 /************************** SMOOTH **********************************
 
 static int smooth(double *parray,double *outarray,int *outcnt,double chwidth,double halfchwidth,double nyquist)
 {
-	int k = 0;
-	double lastlofrq, lofrq = halfchwidth;
-	outarray[k] = 1.0;
-	outarray[k+1] = 0.0;
-	k = 2;
-	while(lofrq <= nyquist) {
-		k += 2;
-		if(k > *outcnt) {
-			fprintf(stdout,"OUT OF MEMORY IN OUTPUT ARRAY.\n");
-			fflush(stdout);
-			return(MEMORY_ERROR);
-		}
-		outarray[k] = 0.0;
-		outarray[k+1] = lofrq;
-		lastlofrq = lofrq;	
-		lofrq *= PSEUDOCENT;
-		if(lofrq - lastlofrq >= chwidth) {	//	Once chan separation is < HEREH
-			lofrq = lastlofrq + chwidth;	//	Just set 1 value per channel
-			outarray[k] = 1.0;
-		}
-	}
-	*outcnt = k;
-	return(	FINISHED);
+    int k = 0;
+    double lastlofrq, lofrq = halfchwidth;
+    outarray[k] = 1.0;
+    outarray[k+1] = 0.0;
+    k = 2;
+    while(lofrq <= nyquist) {
+        k += 2;
+        if(k > *outcnt) {
+            fprintf(stdout,"OUT OF MEMORY IN OUTPUT ARRAY.\n");
+            fflush(stdout);
+            return(MEMORY_ERROR);
+        }
+        outarray[k] = 0.0;
+        outarray[k+1] = lofrq;
+        lastlofrq = lofrq;  
+        lofrq *= PSEUDOCENT;
+        if(lofrq - lastlofrq >= chwidth) {  //  Once chan separation is < HEREH
+            lofrq = lastlofrq + chwidth;    //  Just set 1 value per channel
+            outarray[k] = 1.0;
+        }
+    }
+    *outcnt = k;
+    return( FINISHED);
 }
+*/
 
 /************************************ SPLINE ************************************
  *
@@ -323,37 +349,37 @@ static int smooth(double *parray,double *outarray,int *outcnt,double chwidth,dou
 
 int spline(double *parray,int itemcnt,double *secondderiv,double *x,double *y)
 {
-	double firstderivstt = 0.0, firstderivend = 0.0; 
-	double *u, sig, ppp, qend, uend;
-	int i, k, arraylen = itemcnt/2;
-	if((u = (double *)malloc(arraylen * sizeof(double)))==NULL) {
-		fprintf(stdout,"INSUFFICIENT MEMORY for slope calculations 1.\n");
-		fflush(stdout);
-		return(MEMORY_ERROR);
-	}
-	for(i=0,k=0;k<itemcnt;k+=2,i++) {
-		x[i] = parray[k];	// FRQ is the independent, monotonically increasing variable
-		y[i] = parray[k+1];
-	}
-	secondderiv[0] = -0.5;
-	u[0] = (3.0/(x[1] - x[0])) * (((y[1] - y[0])/(x[1] - x[0])) - firstderivstt);
-
-	for(i = 1;i < arraylen-1; i++) {
-		sig = (x[i] - x[i-1])/(x[i+1] - x[i-1]);
-		ppp = (sig * secondderiv[i-1]) + 2.0;
-		secondderiv[i] = (sig - 1.0)/ppp;
-		u[i] = ((y[i+1] - y[i])/(x[i+1] - x[i])) - ((y[i] - y[i-1])/(x[i] - x[i-1]));
-		u[i] = (((6.0 * u[i])/(x[i+1] - x[i-1])) - (sig * u[i-1]))/ppp;
-	}
-	// i = arraylen-1; = last entry in array
-	qend = 0.5;
-	uend = (3.0/(x[i] - x[i-1])) * (firstderivend - ((y[i] - y[i-1])/(x[i] - x[i-1])));
-	secondderiv[i] = (uend - (qend * u[i-1]))/((qend * secondderiv[i-1]) + 1.0);
-	for(k = i-1;k >= 0;k--) {
-		secondderiv[k] = (secondderiv[k] * secondderiv[k+1]) + u[k];
-	}
-	free(u);
-	return(FINISHED);
+    double firstderivstt = 0.0, firstderivend = 0.0; 
+    double *u, sig, ppp, qend, uend;
+    int i, k, arraylen = itemcnt/2;
+    if((u = (double *)malloc(arraylen * sizeof(double)))==NULL) {
+        fprintf(stdout,"INSUFFICIENT MEMORY for slope calculations 1.\n");
+        fflush(stdout);
+        return(MEMORY_ERROR);
+    }
+    for(i=0,k=0;k<itemcnt;k+=2,i++) {
+        x[i] = parray[k];   // FRQ is the independent, monotonically increasing variable
+        y[i] = parray[k+1];
+    }
+    secondderiv[0] = -0.5;
+    u[0] = (3.0/(x[1] - x[0])) * (((y[1] - y[0])/(x[1] - x[0])) - firstderivstt);
+
+    for(i = 1;i < arraylen-1; i++) {
+        sig = (x[i] - x[i-1])/(x[i+1] - x[i-1]);
+        ppp = (sig * secondderiv[i-1]) + 2.0;
+        secondderiv[i] = (sig - 1.0)/ppp;
+        u[i] = ((y[i+1] - y[i])/(x[i+1] - x[i])) - ((y[i] - y[i-1])/(x[i] - x[i-1]));
+        u[i] = (((6.0 * u[i])/(x[i+1] - x[i-1])) - (sig * u[i-1]))/ppp;
+    }
+    // i = arraylen-1; = last entry in array
+    qend = 0.5;
+    uend = (3.0/(x[i] - x[i-1])) * (firstderivend - ((y[i] - y[i-1])/(x[i] - x[i-1])));
+    secondderiv[i] = (uend - (qend * u[i-1]))/((qend * secondderiv[i-1]) + 1.0);
+    for(k = i-1;k >= 0;k--) {
+        secondderiv[k] = (secondderiv[k] * secondderiv[k+1]) + u[k];
+    }
+    free(u);
+    return(FINISHED);
 }
 
 /************************************ SPLINT ************************************
@@ -363,143 +389,143 @@ int spline(double *parray,int itemcnt,double *secondderiv,double *x,double *y)
 
 int splint(double thisfrq,double *thisamp,int *hi,int arraycnt,double *secondderiv, double *x, double *y)
 {
-	int klo, khi = *hi;
-	double fullstep, a, b, amp, jjj, kkk;
-
-	/* Establish which input values bracket 'thisfrq' */
-
-	while(x[khi] <= thisfrq) {
-		khi++;
-		if(khi >= arraycnt) {
-			*thisamp = y[arraycnt - 1];
-			return(FINISHED);
-		}
-	}
-	klo = khi - 1;
-	if(klo < 0) {
-		*thisamp = y[0];
-		return(FINISHED);
-	}
-	fullstep = x[khi] - x[klo];
-	a = (x[khi] - thisfrq)/fullstep;
-	b = (thisfrq - x[klo])/fullstep;
-	amp  = a * y[klo];
-	amp += b * y[khi];
-
-	jjj  = a * a * a;
-	jjj -= a;
-	jjj *= secondderiv[klo];
-
-	kkk  = b * b * b;
-	kkk -= b;
-	kkk *= secondderiv[khi];
-
-	jjj += kkk;
-	jjj *= fullstep * fullstep;
-	jjj /= 6.0;
-	
-	amp += jjj;
-	if(amp < 0.0)
-		amp = 0.0;
-	if(amp > 1.0) {
-		fprintf(stdout,"INFO: SMOOTHED DATA CLIPPED\n");
-		fflush(stdout);
-		amp = 1.0;
-	}
-	*thisamp = amp;
-	*hi = khi;
-	return(FINISHED);
+    int klo, khi = *hi;
+    double fullstep, a, b, amp, jjj, kkk;
+
+    /* Establish which input values bracket 'thisfrq' */
+
+    while(x[khi] <= thisfrq) {
+        khi++;
+        if(khi >= arraycnt) {
+            *thisamp = y[arraycnt - 1];
+            return(FINISHED);
+        }
+    }
+    klo = khi - 1;
+    if(klo < 0) {
+        *thisamp = y[0];
+        return(FINISHED);
+    }
+    fullstep = x[khi] - x[klo];
+    a = (x[khi] - thisfrq)/fullstep;
+    b = (thisfrq - x[klo])/fullstep;
+    amp  = a * y[klo];
+    amp += b * y[khi];
+
+    jjj  = a * a * a;
+    jjj -= a;
+    jjj *= secondderiv[klo];
+
+    kkk  = b * b * b;
+    kkk -= b;
+    kkk *= secondderiv[khi];
+
+    jjj += kkk;
+    jjj *= fullstep * fullstep;
+    jjj /= 6.0;
+    
+    amp += jjj;
+    if(amp < 0.0)
+        amp = 0.0;
+    if(amp > 1.0) {
+        fprintf(stdout,"INFO: SMOOTHED DATA CLIPPED\n");
+        fflush(stdout);
+        amp = 1.0;
+    }
+    *thisamp = amp;
+    *hi = khi;
+    return(FINISHED);
 }
 
 /************************** SMOOTH **********************************/
 
 int smooth(double *x,double *y,double *secondderiv,double *outarray,int *outcnt,double chwidth,double halfchwidth,double nyquist,int arraycnt)
 {
-	int exit_status;
-	int k = 0, hi = 0;
-	double lastlofrq, lofrq = halfchwidth, thisamp;
-	outarray[k] = 0.0;
-	outarray[k+1] = 0.0;
-	k = 2;
-	while(lofrq < nyquist) {
-		k += 2;
-		if(k > *outcnt) {
-			fprintf(stdout,"OUT OF MEMORY IN OUTPUT ARRAY.\n");
-			fflush(stdout);
-			return(MEMORY_ERROR);
-		}
-		if((exit_status = splint(lofrq,&thisamp,&hi,arraycnt,secondderiv,x,y))<0)
-			return(FAILED);
-		outarray[k] = lofrq;
-		outarray[k+1] = thisamp;
-		lastlofrq = lofrq;	
-		lofrq *= PSEUDOCENT;
-		if(lofrq - lastlofrq >= chwidth)	//	Once chan separation is < PSEUDOCENT
-			lofrq = lastlofrq + chwidth;	//	Just set 1 value per channel
-	}
-	k += 2;
-	outarray[k++] = nyquist;
-	outarray[k++] = 0.0;
-	*outcnt = k;
-	if(outarray[0] == 0.0 && outarray[2] == 0.0) {		// Eliminate any duplication of zero start frq
-		k = 0;
-		hi = 2;
-		while(hi < *outcnt) {
-			outarray[k] = outarray[hi];
-			k++;
-			hi++;
-		}
-		*outcnt = k;
-	}	
-	return(FINISHED);
+    int exit_status;
+    int k = 0, hi = 0;
+    double lastlofrq, lofrq = halfchwidth, thisamp;
+    outarray[k] = 0.0;
+    outarray[k+1] = 0.0;
+    k = 2;
+    while(lofrq < nyquist) {
+        k += 2;
+        if(k > *outcnt) {
+            fprintf(stdout,"OUT OF MEMORY IN OUTPUT ARRAY.\n");
+            fflush(stdout);
+            return(MEMORY_ERROR);
+        }
+        if((exit_status = splint(lofrq,&thisamp,&hi,arraycnt,secondderiv,x,y))<0)
+            return(FAILED);
+        outarray[k] = lofrq;
+        outarray[k+1] = thisamp;
+        lastlofrq = lofrq;  
+        lofrq *= PSEUDOCENT;
+        if(lofrq - lastlofrq >= chwidth)    //  Once chan separation is < PSEUDOCENT
+            lofrq = lastlofrq + chwidth;    //  Just set 1 value per channel
+    }
+    k += 2;
+    outarray[k++] = nyquist;
+    outarray[k++] = 0.0;
+    *outcnt = k;
+    if(outarray[0] == 0.0 && outarray[2] == 0.0) {      // Eliminate any duplication of zero start frq
+        k = 0;
+        hi = 2;
+        while(hi < *outcnt) {
+            outarray[k] = outarray[hi];
+            k++;
+            hi++;
+        }
+        *outcnt = k;
+    }   
+    return(FINISHED);
 }
 
 /************************** DOVE **********************************/
 
 int dove(double *parray,int itemcnt,double *outarray,int outcnt)
 {
-	double *amp, *frq, *inarrayend = parray + itemcnt, *outarrayend = outarray + outcnt, tailstartfrq;
-	amp = inarrayend - 1;
-	if(!flteq(*amp,0.0))		// Input spectrum never falls to zero
-		return(FINISHED);
-
-	while(amp > parray) {		//	Search back from end of (orig) spectrum, until spectral vals are >0
-		if(!flteq(*amp,0.0))
-			break;
-		amp -= 2;
-	}
-	if(amp <= parray)			//	(original) spectrum is everywhere zero
-		return(FINISHED);
-	frq = amp - 1;
-	tailstartfrq = *frq;		//	Note frq at which (original) spectrum finally falls to zero
-
-	frq = outarray;				//	Parse frq vals in output array
-	while(frq < outarrayend) {
-		if(*frq >= tailstartfrq) {
-			amp = frq - 1;		//	Note where outfrq exceeds tailstartfrq of input, and step to amp BEFORE it
-			break;
-		}
-		frq += 2;
-	}
-	if(frq >= outarrayend) {	//	Output frq never exceeds input frq: should be impossible
-		fprintf(stdout,"DOVETAILING FAILED.\n");
-		fflush(stdout);
-		return(PROGRAM_ERROR);
-	}
-	while(amp < outarrayend) {	//	Search for point where output first touches zero
-		if(flteq(*amp,0.0))
-			break;
-		amp += 2;
-	}
-	if(amp >= outarrayend) {
-		fprintf(stdout,"NO DOVETAILING OCCURED.\n");
-		fflush(stdout);
-	}
-	while(amp < outarrayend) {	//	Set tail to zero
-		*amp = 0.0;
-		amp += 2;
-	}
-	return(FINISHED);
+    double *amp, *frq, *inarrayend = parray + itemcnt, *outarrayend = outarray + outcnt, tailstartfrq;
+    amp = inarrayend - 1;
+    if(!flteq(*amp,0.0))        // Input spectrum never falls to zero
+        return(FINISHED);
+
+    while(amp > parray) {       //  Search back from end of (orig) spectrum, until spectral vals are >0
+        if(!flteq(*amp,0.0))
+            break;
+        amp -= 2;
+    }
+    if(amp <= parray)           //  (original) spectrum is everywhere zero
+        return(FINISHED);
+    frq = amp - 1;
+    tailstartfrq = *frq;        //  Note frq at which (original) spectrum finally falls to zero
+
+    frq = outarray;             //  Parse frq vals in output array
+    while(frq < outarrayend) {
+        if(*frq >= tailstartfrq) {
+            amp = frq - 1;      //  Note where outfrq exceeds tailstartfrq of input, and step to amp BEFORE it
+            break;
+        }
+        frq += 2;
+    }
+    if(frq >= outarrayend) {    //  Output frq never exceeds input frq: should be impossible
+        fprintf(stdout,"DOVETAILING FAILED.\n");
+        fflush(stdout);
+        return(PROGRAM_ERROR);
+    }
+    while(amp < outarrayend) {  //  Search for point where output first touches zero
+        if(flteq(*amp,0.0))
+            break;
+        amp += 2;
+    }
+    if(amp >= outarrayend) {
+        fprintf(stdout,"NO DOVETAILING OCCURED.\n");
+        fflush(stdout);
+    }
+    while(amp < outarrayend) {  //  Set tail to zero
+        *amp = 0.0;
+        amp += 2;
+    }
+    return(FINISHED);
 }
 
 /************************** GET_FLOAT_WITH_E_FROM_WITHIN_STRING **************************
@@ -510,44 +536,44 @@ int dove(double *parray,int itemcnt,double *outarray,int outcnt)
 
 int  get_float_with_e_from_within_string(char **str,double *val)
 {
-	char   *p, *valstart;
-	int    decimal_point_cnt = 0, has_digits = 0, has_e = 0, lastchar = 0;
-	p = *str;
-	while(isspace(*p))
-		p++;
-	valstart = p;	
-	switch(*p) {
-	case('-'):						break;
-	case('.'): decimal_point_cnt=1;	break;
-	default:
-		if(!isdigit(*p))
-			return(FALSE);
-		has_digits = TRUE;
-		break;
-	}
-	p++;
-	while(!isspace(*p) && *p!=NEWLINE && *p!=ENDOFSTR) {
-		if(isdigit(*p))
-			has_digits = TRUE;
-		else if(*p == 'e') {
-			if(has_e || !has_digits)
-				return(FALSE);
-			has_e = 1;
-		} else if(*p == '-') {
-			if(!has_e || (lastchar != 'e'))
-				return(FALSE);
-		} else if(*p == '.') {
-			if(has_e || (++decimal_point_cnt>1))
-				return(FALSE);
-		} else
-			return(FALSE);
-		lastchar = *p;
-		p++;
-	}
-	if(!has_digits || sscanf(valstart,"%lf",val)!=1)
-		return(FALSE);
-	*str = p;
-	return(TRUE);
+    char   *p, *valstart;
+    int    decimal_point_cnt = 0, has_digits = 0, has_e = 0, lastchar = 0;
+    p = *str;
+    while(isspace(*p))
+        p++;
+    valstart = p;   
+    switch(*p) {
+    case('-'):                      break;
+    case('.'): decimal_point_cnt=1; break;
+    default:
+        if(!isdigit(*p))
+            return(FALSE);
+        has_digits = TRUE;
+        break;
+    }
+    p++;
+    while(!isspace(*p) && *p!=NEWLINE && *p!=ENDOFSTR) {
+        if(isdigit(*p))
+            has_digits = TRUE;
+        else if(*p == 'e') {
+            if(has_e || !has_digits)
+                return(FALSE);
+            has_e = 1;
+        } else if(*p == '-') {
+            if(!has_e || (lastchar != 'e'))
+                return(FALSE);
+        } else if(*p == '.') {
+            if(has_e || (++decimal_point_cnt>1))
+                return(FALSE);
+        } else
+            return(FALSE);
+        lastchar = *p;
+        p++;
+    }
+    if(!has_digits || sscanf(valstart,"%lf",val)!=1)
+        return(FALSE);
+    *str = p;
+    return(TRUE);
 }
 
 

File diff suppressed because it is too large
+ 740 - 716
dev/science/dvdwind.c


+ 662 - 638
dev/science/newscales.c

@@ -1,25 +1,49 @@
 /*
- *	Generating melodic (etc) output using tones of defined spectrum, in non-tempered tunings.
- *	
- *	Get list of notes, times, amplitudes, durs from textlisting or MIDI device: LOOM INTERFACE
- *	
- *	Map to a different temperament if required : LOOM INTERFACE
- *	
- *	Generate list of frequencies, amplitudes, durations required
- *	Find the MAXIMUM duration at each frequency
- *	
- *	Define the spectrum of the synthesized tones, 
- *		from a listing of harmonics and their relative amplitudes:	LOOM INTERFACE
+ * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
+ * http://www.trevorwishart.co.uk
+ * http://www.composersdesktop.com
  *
- *	Synthesis the max-duration(+safety note) required at each frequency
+ This file is part of the CDP System.
+ 
+ The CDP System is free software; you can redistribute it
+ and/or modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+ 
+ The CDP System is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU Lesser General Public License for more details.
+ 
+ You should have received a copy of the GNU Lesser General Public
+ License along with the CDP System; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA
  *
- *	Cut shorter notes to size by editing the maxlength notes
- *		Here must associate each output file with appropriate output time/amp info (for mix)
+ */
+
+/*
+ *  Generating melodic (etc) output using tones of defined spectrum, in non-tempered tunings.
+ *  
+ *  Get list of notes, times, amplitudes, durs from textlisting or MIDI device: LOOM INTERFACE
+ *  
+ *  Map to a different temperament if required : LOOM INTERFACE
+ *  
+ *  Generate list of frequencies, amplitudes, durations required
+ *  Find the MAXIMUM duration at each frequency
+ *  
+ *  Define the spectrum of the synthesized tones, 
+ *      from a listing of harmonics and their relative amplitudes:  LOOM INTERFACE
+ *
+ *  Synthesis the max-duration(+safety note) required at each frequency
+ *
+ *  Cut shorter notes to size by editing the maxlength notes
+ *      Here must associate each output file with appropriate output time/amp info (for mix)
  *
- *	Employ any envelope-shaping, vib, trem, jitter required
- *	Create a mixfile to mix the resulting events
- *	Check output level, reset mixamplitude
- *	Run mix
+ *  Employ any envelope-shaping, vib, trem, jitter required
+ *  Create a mixfile to mix the resulting events
+ *  Check output level, reset mixamplitude
+ *  Run mix
  */
 
 
@@ -64,7 +88,7 @@
 char errstr[2400];
 
 int anal_infiles = 1;
-int	sloom = 0;
+int sloom = 0;
 int sloombatch = 0;
 
 const char* cdp_version = "6.1.0";
@@ -78,7 +102,7 @@ static int  gentable(double *tab,int tabsize,dataptr dz);
 static int gen_sound(double frq, double *tab,int sampdur,double sr,double *harm,double *amp, int harmcnt,dataptr dz);
 static double getval(double *tab,int i,double fracstep,double amp);
 static void advance_in_table(double frq,int *i,double convertor,double *step,double *fracstep,double dtabsize);
-static read_srate(char *str,dataptr dz);
+static int read_srate(char *str,dataptr dz);
 
 static int setup_newscales_application(dataptr dz);
 static int handle_the_outfile(int *cmdlinecnt,char ***cmdline,dataptr dz);
@@ -87,11 +111,11 @@ static int read_newscales_data(char **cmdline,double **frq,int **duration,double
 static int establish_application(dataptr dz);
 
 /*
- *	Params must be a special data file containing
- *	(1) A list of frequencies to synthesize (each required frq synthd only ONCE
- *	(2) A list of their durations (these are > maximum duration used by any frequency in the original input melody)
- *	(3) A list of harmonics
- *	(4)	A list of harmonic amplitudes
+ *  Params must be a special data file containing
+ *  (1) A list of frequencies to synthesize (each required frq synthd only ONCE
+ *  (2) A list of their durations (these are > maximum duration used by any frequency in the original input melody)
+ *  (3) A list of harmonics
+ *  (4) A list of harmonic amplitudes
  */
 
 
@@ -99,728 +123,728 @@ static int establish_application(dataptr dz);
 
 int main(int argc,char *argv[])
 {
-	int exit_status;
-	dataptr dz = NULL;
-	char **cmdline;
-	int  cmdlinecnt;
-	int n;
-	int is_launched = FALSE;
-
-	double *frq, **harm, **amp, maxfrq;
-	int *duration;
-	
-	if(argc==2 && (strcmp(argv[1],"--version") == 0)) {
-		fprintf(stdout,"%s\n",cdp_version);
-		fflush(stdout);
-		return 0;
-	}
-						/* CHECK FOR SOUNDLOOM */
-//	if((sloom = sound_loom_in_use(&argc,&argv)) > 1) {
-//		sloom = 0;
-//		sloombatch = 1;
-//	}
-	if(sflinit("cdp")){
-		sfperror("cdp: initialisation\n");
-		return(FAILED);
-	}
-						  /* SET UP THE PRINCIPLE DATASTRUCTURE */
-	if((exit_status = establish_datastructure(&dz))<0) {					// CDP LIB
-		print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-		return(FAILED);
-	}
-	if(argc < 4 || argc > 5) {
-		usage2("dummy");	
-		return(FAILED);
-	}
-	if(argc == 5){
-		if((exit_status = read_srate(argv[4],dz))<0) {
-			print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-			return(FAILED);
-		}
-	} else
-		dz->infile->srate = 44100;
-	dz->nyquist = dz->infile->srate/2.0;
-	cmdline    = argv;
-	cmdlinecnt = argc;
-	if((exit_status = setup_newscales_application(dz))<0) {
-		print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-		return(FAILED);
-	}
-	cmdline++;
-	cmdlinecnt--;
-	if((exit_status = handle_the_outfile(&cmdlinecnt,&cmdline,dz))<0) {
-		print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-		return(FAILED);
-	}
-	if((exit_status = read_newscales_data(cmdline,&frq,&duration,&maxfrq,dz))<0) {
-		print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-		return(FAILED);
-	}
-	cmdline++;
-	cmdlinecnt--;
-	if((exit_status = read_spectrum_data(cmdline,&harm,&amp,maxfrq,dz))<0) {
-		print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-		return(FAILED);
-	}
-	dz->infile->channels = 1;
-	is_launched = TRUE;
-	dz->bufcnt = 1;
-	if((dz->sampbuf = (float **)malloc(sizeof(float *) * (dz->bufcnt+1)))==NULL) {
-		sprintf(errstr,"INSUFFICIENT MEMORY establishing sample buffers.\n");
-		return(MEMORY_ERROR);
-	}
-	if((dz->sbufptr = (float **)malloc(sizeof(float *) * dz->bufcnt))==NULL) {
-		sprintf(errstr,"INSUFFICIENT MEMORY establishing sample buffer pointers.\n");
-		return(MEMORY_ERROR);
-	}
-	for(n = 0;n <dz->bufcnt; n++)
-		dz->sampbuf[n] = dz->sbufptr[n] = (float *)0;
-	dz->sampbuf[n] = (float *)0;
-
-	if((exit_status = create_sndbufs(dz))<0) {							// CDP LIB
-		print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-		return(FAILED);
-	}
-	if((exit_status = generate_all_tones(frq,dz->itemcnt,duration,harm,amp,dz))<0) {
-		print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-		return(FAILED);
-	}
-	if((exit_status = complete_output(dz))<0) {										// CDP LIB
-		print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-		return(FAILED);
-	}
-	exit_status = print_messages_and_close_sndfiles(FINISHED,is_launched,dz);		// CDP LIB
-	free(dz);
-	return(SUCCEEDED);
+    int exit_status;
+    dataptr dz = NULL;
+    char **cmdline;
+    int  cmdlinecnt;
+    int n;
+    int is_launched = FALSE;
+
+    double *frq, **harm, **amp, maxfrq;
+    int *duration;
+    
+    if(argc==2 && (strcmp(argv[1],"--version") == 0)) {
+        fprintf(stdout,"%s\n",cdp_version);
+        fflush(stdout);
+        return 0;
+    }
+                        /* CHECK FOR SOUNDLOOM */
+//  if((sloom = sound_loom_in_use(&argc,&argv)) > 1) {
+//      sloom = 0;
+//      sloombatch = 1;
+//  }
+    if(sflinit("cdp")){
+        sfperror("cdp: initialisation\n");
+        return(FAILED);
+    }
+                          /* SET UP THE PRINCIPLE DATASTRUCTURE */
+    if((exit_status = establish_datastructure(&dz))<0) {                    // CDP LIB
+        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
+        return(FAILED);
+    }
+    if(argc < 4 || argc > 5) {
+        usage2("dummy");    
+        return(FAILED);
+    }
+    if(argc == 5){
+        if((exit_status = read_srate(argv[4],dz))<0) {
+            print_messages_and_close_sndfiles(exit_status,is_launched,dz);
+            return(FAILED);
+        }
+    } else
+        dz->infile->srate = 44100;
+    dz->nyquist = dz->infile->srate/2.0;
+    cmdline    = argv;
+    cmdlinecnt = argc;
+    if((exit_status = setup_newscales_application(dz))<0) {
+        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
+        return(FAILED);
+    }
+    cmdline++;
+    cmdlinecnt--;
+    if((exit_status = handle_the_outfile(&cmdlinecnt,&cmdline,dz))<0) {
+        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
+        return(FAILED);
+    }
+    if((exit_status = read_newscales_data(cmdline,&frq,&duration,&maxfrq,dz))<0) {
+        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
+        return(FAILED);
+    }
+    cmdline++;
+    cmdlinecnt--;
+    if((exit_status = read_spectrum_data(cmdline,&harm,&amp,maxfrq,dz))<0) {
+        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
+        return(FAILED);
+    }
+    dz->infile->channels = 1;
+    is_launched = TRUE;
+    dz->bufcnt = 1;
+    if((dz->sampbuf = (float **)malloc(sizeof(float *) * (dz->bufcnt+1)))==NULL) {
+        sprintf(errstr,"INSUFFICIENT MEMORY establishing sample buffers.\n");
+        return(MEMORY_ERROR);
+    }
+    if((dz->sbufptr = (float **)malloc(sizeof(float *) * dz->bufcnt))==NULL) {
+        sprintf(errstr,"INSUFFICIENT MEMORY establishing sample buffer pointers.\n");
+        return(MEMORY_ERROR);
+    }
+    for(n = 0;n <dz->bufcnt; n++)
+        dz->sampbuf[n] = dz->sbufptr[n] = (float *)0;
+    dz->sampbuf[n] = (float *)0;
+
+    if((exit_status = create_sndbufs(dz))<0) {                          // CDP LIB
+        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
+        return(FAILED);
+    }
+    if((exit_status = generate_all_tones(frq,dz->itemcnt,duration,harm,amp,dz))<0) {
+        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
+        return(FAILED);
+    }
+    if((exit_status = complete_output(dz))<0) {                                     // CDP LIB
+        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
+        return(FAILED);
+    }
+    exit_status = print_messages_and_close_sndfiles(FINISHED,is_launched,dz);       // CDP LIB
+    free(dz);
+    return(SUCCEEDED);
 }
 
 
 int generate_all_tones(double *frq,int frqcnt,int *duration,double **harm,double **amp,dataptr dz)
 {
-	int exit_status;
-	double *tab;
-	int n, sampdur;
-	double sr = (double)dz->infile->srate;
-	char outfilename[200], temp[4];
-	if((dz->insams = (int *)malloc(1 * sizeof(int)))==NULL) {
-		sprintf(errstr,"Insufficient memory for insams arrays.\n");
-		return(MEMORY_ERROR);
-	}
-	if((tab = (double *)malloc((SC_SYN_TABSIZE+1) * sizeof(double)))==NULL) {
-		sprintf(errstr,"Insufficient memory for wave table.\n");
-		return(MEMORY_ERROR);
-	}
-	if((exit_status = gentable(tab,SC_SYN_TABSIZE,dz))<0)
-		return(exit_status);
-	n = 0;
-	while(n < frqcnt) {
-		strcpy(outfilename,dz->outfilename);
-		sprintf(temp,"%d",n);
-		strcat(outfilename,temp);
-		strcat(outfilename,".wav");
-		sampdur = duration[n];
-		dz->insams[0] = duration[n]; 	
-		dz->process_type = EQUAL_SNDFILE;	/* allow sndfile to be created */
-		if((exit_status = create_sized_outfile(outfilename,dz))<0) {
-			sprintf(errstr, "Failed to open file %s\n",outfilename);
-			/*free(outfilename);*/
-			dz->ofd = -1;
-			dz->process_type = OTHER_PROCESS;
-			return(GOAL_FAILED);
-		}
-		reset_filedata_counters(dz);
+    int exit_status;
+    double *tab;
+    int n, sampdur;
+    double sr = (double)dz->infile->srate;
+    char outfilename[200], temp[4];
+    if((dz->insams = (int *)malloc(1 * sizeof(int)))==NULL) {
+        sprintf(errstr,"Insufficient memory for insams arrays.\n");
+        return(MEMORY_ERROR);
+    }
+    if((tab = (double *)malloc((SC_SYN_TABSIZE+1) * sizeof(double)))==NULL) {
+        sprintf(errstr,"Insufficient memory for wave table.\n");
+        return(MEMORY_ERROR);
+    }
+    if((exit_status = gentable(tab,SC_SYN_TABSIZE,dz))<0)
+        return(exit_status);
+    n = 0;
+    while(n < frqcnt) {
+        strcpy(outfilename,dz->outfilename);
+        sprintf(temp,"%d",n);
+        strcat(outfilename,temp);
+        strcat(outfilename,".wav");
+        sampdur = duration[n];
+        dz->insams[0] = duration[n];    
+        dz->process_type = EQUAL_SNDFILE;   /* allow sndfile to be created */
+        if((exit_status = create_sized_outfile(outfilename,dz))<0) {
+            sprintf(errstr, "Failed to open file %s\n",outfilename);
+            /*free(outfilename);*/
+            dz->ofd = -1;
+            dz->process_type = OTHER_PROCESS;
+            return(GOAL_FAILED);
+        }
+        reset_filedata_counters(dz);
 //HEREH, DEPENDING ON WHICH NOTE IT IS, WE GET THE HARMONIC COUNT FROM wordcnt[n],
-		
-		if((exit_status = gen_sound(frq[n],tab,sampdur,sr,harm[n],amp[n],dz->wordcnt[n],dz))<0) {
-			fprintf(stdout,"Synthesis %d failed.\n",n+1);
-			fflush(stdout);
-			return(GOAL_FAILED);
-		}
-		if((exit_status = headwrite(dz->ofd,dz))<0) {
-			fprintf(stdout,"Failed to write header to synthed output %d.\n",n+1);
-			fflush(stdout);
-			return(exit_status);
-		}
-		n++;
-		if((exit_status = reset_peak_finder(dz))<0) {
-			if(n < frqcnt) {
-				fprintf(stdout,"Failed to reset peakfinder for synthesis %d.\n",n+1);
-				fflush(stdout);
-				return(exit_status);
-			}
-		}
-		if(sndcloseEx(dz->ofd)<0) {
-			sprintf(errstr,"Failed to close output soundfile for synthesis %d.\n",n);
-			return(SYSTEM_ERROR);
-		}
-		dz->ofd = -1;
-	}
-	return(FINISHED);
-}	
+        
+        if((exit_status = gen_sound(frq[n],tab,sampdur,sr,harm[n],amp[n],dz->wordcnt[n],dz))<0) {
+            fprintf(stdout,"Synthesis %d failed.\n",n+1);
+            fflush(stdout);
+            return(GOAL_FAILED);
+        }
+        if((exit_status = headwrite(dz->ofd,dz))<0) {
+            fprintf(stdout,"Failed to write header to synthed output %d.\n",n+1);
+            fflush(stdout);
+            return(exit_status);
+        }
+        n++;
+        if((exit_status = reset_peak_finder(dz))<0) {
+            if(n < frqcnt) {
+                fprintf(stdout,"Failed to reset peakfinder for synthesis %d.\n",n+1);
+                fflush(stdout);
+                return(exit_status);
+            }
+        }
+        if(sndcloseEx(dz->ofd)<0) {
+            sprintf(errstr,"Failed to close output soundfile for synthesis %d.\n",n);
+            return(SYSTEM_ERROR);
+        }
+        dz->ofd = -1;
+    }
+    return(FINISHED);
+}   
 
 /******************************* GENTABLE ******************************/
 
 int gentable(double *tab,int tabsize,dataptr dz)
 {   
-	int n;
-	double step;
-	step = (2.0 * PI)/(double)tabsize;
-	for(n=0;n<tabsize;n++)
-		tab[n] = sin(step * (double)n) * F_MAXSAMP;
-	tab[tabsize] = 0.0;
-	return(FINISHED);
+    int n;
+    double step;
+    step = (2.0 * PI)/(double)tabsize;
+    for(n=0;n<tabsize;n++)
+        tab[n] = sin(step * (double)n) * F_MAXSAMP;
+    tab[tabsize] = 0.0;
+    return(FINISHED);
 }
 
 /****************************** GEN_SOUND *************************/
 
 int gen_sound(double frq, double *tab,int sampdur,double sr,double *harm,double *amp, int harmcnt,dataptr dz)
 {
-	int exit_status;
-	double inverse_sr = 1.0/sr;
-	double *step;
-	double dtabsize = (double)SC_SYN_TABSIZE;
-	double convertor = dtabsize * inverse_sr, maxsamp, normaliser;
-	int n, m, *i;
-	int chans = dz->infile->channels;
-	double harmfrq, harmamp;
-	double *fracstep, val;
-	int do_start = 1;
-	int synth_splicelen = SYNTH_SPLICELEN * chans;
-	int total_samps = 0;
-	int startj = 0, endj = SYNTH_SPLICELEN;
-	int total_samps_left = sampdur;
-	int endsplicestart = sampdur - synth_splicelen;
-	int todo;
-	if((step = (double *)malloc(harmcnt * sizeof(double)))==NULL) {
-		sprintf(errstr,"Insufficient memory all harmonic wave table step counters.\n");
-		return(MEMORY_ERROR);
-	}
-	if((fracstep = (double *)malloc(harmcnt * sizeof(double)))==NULL) {
-		sprintf(errstr,"Insufficient memory all harmonic wave table step counters.\n");
-		return(MEMORY_ERROR);
-	}
-	if((i = (int *)malloc(harmcnt * sizeof(int)))==NULL) {
-		sprintf(errstr,"Insufficient memory all harmonic wave table position indicators.\n");
-		return(MEMORY_ERROR);
-	}
-	for(n = 0;n < harmcnt;n++) {
-		step[n] = 0.0;
-		fracstep[n] = 0.0;
-		i[n] = 0;
-	}
-
-	if(sampdur < (synth_splicelen * 2) + chans) {
-		fprintf(stdout,"ERROR: Specified output duration is less then available splicing length.\n");
-		return(DATA_ERROR);
-	}
-	maxsamp = 0.0;
-
-	/* FIRST PASS: ADD UP ALL HARMONICS, AND GET MAX OUTPUT LEVEL */
-	
-	while(total_samps_left > 0) {
-		memset((char *)dz->bigbuf,0,dz->buflen * sizeof(float));
-		if(total_samps_left/dz->buflen <= 0)
-			todo = total_samps_left;
-		else
-			todo = dz->buflen;
-		for(n = 0;n < harmcnt;n++) {
-			harmfrq = frq * harm[n];
-			harmamp = amp[n];
-			m = 0;
-			while(m < todo) {
-				val = getval(tab,i[n],fracstep[n],harmamp);
-				dz->bigbuf[m] = (float)(dz->bigbuf[m] + val);
-				m++;
-				advance_in_table(harmfrq,&(i[n]),convertor,&(step[n]),&(fracstep[n]),dtabsize);
-			}
-		}
-		m = 0;
-		while(m < todo) {
-			if(fabs(dz->bigbuf[m]) > maxsamp)
-				maxsamp = fabs(dz->bigbuf[m]);
-			m++;
-		}	
-		total_samps_left -= dz->buflen;
-	}
-	normaliser = 1.0;
-	if(maxsamp > MAXLEVEL)
-		normaliser = MAXLEVEL/maxsamp;
-	total_samps_left = sampdur;
-	while(total_samps_left > 0) {
-		memset((char *)dz->bigbuf,0,dz->buflen * sizeof(float));
-		if(total_samps_left/dz->buflen <= 0)
-			todo = total_samps_left;
-		else
-			todo = dz->buflen;
-		for(n = 0;n < harmcnt;n++) {
-			harmfrq = frq * harm[n];
-			harmamp = amp[n];
-			m = 0;
-			while(m < todo) {
-				val = getval(tab,i[n],fracstep[n],harmamp);
-				dz->bigbuf[m] = dz->bigbuf[m] + (float)val;
-				m++;
-				advance_in_table(harmfrq,&(i[n]),convertor,&(step[n]),&(fracstep[n]),dtabsize);
-			}
-		}
-		m = 0;
-		while(m < todo) {
-			dz->bigbuf[m] = (float)(dz->bigbuf[m] * normaliser);
-			if(do_start) {
-				dz->bigbuf[m] = (float)(dz->bigbuf[m] * (startj++/(double)SYNTH_SPLICELEN));
-				if(startj >= SYNTH_SPLICELEN)
-					do_start = 0;
-			}
-			if(total_samps >= endsplicestart)
-				dz->bigbuf[m] = (float)(dz->bigbuf[m] * (endj--/(double)SYNTH_SPLICELEN));
-			total_samps++;
-			m++;
-		}
-		if(todo) {
-			if((exit_status = write_samps(dz->bigbuf,todo,dz))<0)
-				return(exit_status);
-		}
-		total_samps_left -= dz->buflen;
-	}
-	return(FINISHED);
+    int exit_status;
+    double inverse_sr = 1.0/sr;
+    double *step;
+    double dtabsize = (double)SC_SYN_TABSIZE;
+    double convertor = dtabsize * inverse_sr, maxsamp, normaliser;
+    int n, m, *i;
+    int chans = dz->infile->channels;
+    double harmfrq, harmamp;
+    double *fracstep, val;
+    int do_start = 1;
+    int synth_splicelen = SYNTH_SPLICELEN * chans;
+    int total_samps = 0;
+    int startj = 0, endj = SYNTH_SPLICELEN;
+    int total_samps_left = sampdur;
+    int endsplicestart = sampdur - synth_splicelen;
+    int todo;
+    if((step = (double *)malloc(harmcnt * sizeof(double)))==NULL) {
+        sprintf(errstr,"Insufficient memory all harmonic wave table step counters.\n");
+        return(MEMORY_ERROR);
+    }
+    if((fracstep = (double *)malloc(harmcnt * sizeof(double)))==NULL) {
+        sprintf(errstr,"Insufficient memory all harmonic wave table step counters.\n");
+        return(MEMORY_ERROR);
+    }
+    if((i = (int *)malloc(harmcnt * sizeof(int)))==NULL) {
+        sprintf(errstr,"Insufficient memory all harmonic wave table position indicators.\n");
+        return(MEMORY_ERROR);
+    }
+    for(n = 0;n < harmcnt;n++) {
+        step[n] = 0.0;
+        fracstep[n] = 0.0;
+        i[n] = 0;
+    }
+
+    if(sampdur < (synth_splicelen * 2) + chans) {
+        fprintf(stdout,"ERROR: Specified output duration is less then available splicing length.\n");
+        return(DATA_ERROR);
+    }
+    maxsamp = 0.0;
+
+    /* FIRST PASS: ADD UP ALL HARMONICS, AND GET MAX OUTPUT LEVEL */
+    
+    while(total_samps_left > 0) {
+        memset((char *)dz->bigbuf,0,dz->buflen * sizeof(float));
+        if(total_samps_left/dz->buflen <= 0)
+            todo = total_samps_left;
+        else
+            todo = dz->buflen;
+        for(n = 0;n < harmcnt;n++) {
+            harmfrq = frq * harm[n];
+            harmamp = amp[n];
+            m = 0;
+            while(m < todo) {
+                val = getval(tab,i[n],fracstep[n],harmamp);
+                dz->bigbuf[m] = (float)(dz->bigbuf[m] + val);
+                m++;
+                advance_in_table(harmfrq,&(i[n]),convertor,&(step[n]),&(fracstep[n]),dtabsize);
+            }
+        }
+        m = 0;
+        while(m < todo) {
+            if(fabs(dz->bigbuf[m]) > maxsamp)
+                maxsamp = fabs(dz->bigbuf[m]);
+            m++;
+        }   
+        total_samps_left -= dz->buflen;
+    }
+    normaliser = 1.0;
+    if(maxsamp > MAXLEVEL)
+        normaliser = MAXLEVEL/maxsamp;
+    total_samps_left = sampdur;
+    while(total_samps_left > 0) {
+        memset((char *)dz->bigbuf,0,dz->buflen * sizeof(float));
+        if(total_samps_left/dz->buflen <= 0)
+            todo = total_samps_left;
+        else
+            todo = dz->buflen;
+        for(n = 0;n < harmcnt;n++) {
+            harmfrq = frq * harm[n];
+            harmamp = amp[n];
+            m = 0;
+            while(m < todo) {
+                val = getval(tab,i[n],fracstep[n],harmamp);
+                dz->bigbuf[m] = dz->bigbuf[m] + (float)val;
+                m++;
+                advance_in_table(harmfrq,&(i[n]),convertor,&(step[n]),&(fracstep[n]),dtabsize);
+            }
+        }
+        m = 0;
+        while(m < todo) {
+            dz->bigbuf[m] = (float)(dz->bigbuf[m] * normaliser);
+            if(do_start) {
+                dz->bigbuf[m] = (float)(dz->bigbuf[m] * (startj++/(double)SYNTH_SPLICELEN));
+                if(startj >= SYNTH_SPLICELEN)
+                    do_start = 0;
+            }
+            if(total_samps >= endsplicestart)
+                dz->bigbuf[m] = (float)(dz->bigbuf[m] * (endj--/(double)SYNTH_SPLICELEN));
+            total_samps++;
+            m++;
+        }
+        if(todo) {
+            if((exit_status = write_samps(dz->bigbuf,todo,dz))<0)
+                return(exit_status);
+        }
+        total_samps_left -= dz->buflen;
+    }
+    return(FINISHED);
 }
   
 /****************************** GETVAL *************************/
 
 double getval(double *tab,int i,double fracstep,double amp)
 {
-	double diff, val  = tab[i];
-	
-	diff = tab[i+1] - val;
-	val += diff * fracstep;
-	val *= amp;
-	return(val);
+    double diff, val  = tab[i];
+    
+    diff = tab[i+1] - val;
+    val += diff * fracstep;
+    val *= amp;
+    return(val);
 }
 
 /****************************** ADVANCE_IN_TABLE *************************/
 
 static void advance_in_table(double frq,int *i,double convertor,double *step,double *fracstep,double dtabsize)
 {
-	*step += frq * convertor;
-	while(*step >= dtabsize)
-		*step -= dtabsize;
-	*i = (int)(*step); /* TRUNCATE */
-	*fracstep = *step - (double)(*i);
+    *step += frq * convertor;
+    while(*step >= dtabsize)
+        *step -= dtabsize;
+    *i = (int)(*step); /* TRUNCATE */
+    *fracstep = *step - (double)(*i);
 }
 
 /************************ HANDLE_THE_OUTFILE *********************/
 
 int handle_the_outfile(int *cmdlinecnt,char ***cmdline,dataptr dz)
 {
-	int len;
-	char *filename = (*cmdline)[0], *p, *q, *full_filename;
-	if(filename[0]=='-' && filename[1]=='f') {
-		dz->floatsam_output = 1;
-		dz->true_outfile_stype = SAMP_FLOAT;
-		filename+= 2;
-	}
-	full_filename = filename;
-	len = strlen(filename);
-	q = filename;
-	p = filename + len;
-	p--;
-	while(p >= q) {		/* Sesparate off path */
-		if(*p == '/' || *p == '\\') {
-			filename = p+1;
-			break;
-		}
-		p--;
-	}
-	if((len = strlen(filename)) <= 0) {
-		sprintf(errstr,"Invalid outfilename (path only).\n");
-		return(MEMORY_ERROR);
-	}
-	q = filename;
-	len = strlen(filename);
-	p = filename + len;
-	p--;
-	while(p >= q) {
-		if(*p == '.') {		/* Snip off file extension */
-			*p = ENDOFSTR;
-			break;
-		}
-		p--;
-	}
-	if((len = strlen(filename)) <= 0) {
-		sprintf(errstr,"Invalid outfilename.\n");
-		return(MEMORY_ERROR);
-	}
-	p = filename + len;
-	p--;
-	if(isdigit(*p)) {
-		sprintf(errstr,"Invalid outfilename (ends in number).\n");
-		return(MEMORY_ERROR);
-	}
-	filename = full_filename;
-	len = strlen(filename);
-	len++;
-	if((dz->outfilename = (char *)malloc(len * sizeof(char)))==NULL) {
-		sprintf(errstr,"INSUFFICIENT MEMORY to store output filename.\n");
-		return(MEMORY_ERROR);
-	}
-	strcpy(dz->outfilename,filename);	   
-	(*cmdline)++;
-	(*cmdlinecnt)--;
-	return(FINISHED);
+    int len;
+    char *filename = (*cmdline)[0], *p, *q, *full_filename;
+    if(filename[0]=='-' && filename[1]=='f') {
+        dz->floatsam_output = 1;
+        dz->true_outfile_stype = SAMP_FLOAT;
+        filename+= 2;
+    }
+    full_filename = filename;
+    len = strlen(filename);
+    q = filename;
+    p = filename + len;
+    p--;
+    while(p >= q) {     /* Sesparate off path */
+        if(*p == '/' || *p == '\\') {
+            filename = p+1;
+            break;
+        }
+        p--;
+    }
+    if((len = strlen(filename)) <= 0) {
+        sprintf(errstr,"Invalid outfilename (path only).\n");
+        return(MEMORY_ERROR);
+    }
+    q = filename;
+    len = strlen(filename);
+    p = filename + len;
+    p--;
+    while(p >= q) {
+        if(*p == '.') {     /* Snip off file extension */
+            *p = ENDOFSTR;
+            break;
+        }
+        p--;
+    }
+    if((len = strlen(filename)) <= 0) {
+        sprintf(errstr,"Invalid outfilename.\n");
+        return(MEMORY_ERROR);
+    }
+    p = filename + len;
+    p--;
+    if(isdigit(*p)) {
+        sprintf(errstr,"Invalid outfilename (ends in number).\n");
+        return(MEMORY_ERROR);
+    }
+    filename = full_filename;
+    len = strlen(filename);
+    len++;
+    if((dz->outfilename = (char *)malloc(len * sizeof(char)))==NULL) {
+        sprintf(errstr,"INSUFFICIENT MEMORY to store output filename.\n");
+        return(MEMORY_ERROR);
+    }
+    strcpy(dz->outfilename,filename);      
+    (*cmdline)++;
+    (*cmdlinecnt)--;
+    return(FINISHED);
 }
 
 /************************* SETUP_NEWSCALES_APPLICATION *******************/
 
 int setup_newscales_application(dataptr dz)
 {
-	int exit_status;
-	aplptr ap;
-	if((exit_status = establish_application(dz))<0)		// GLOBAL
-		return(FAILED);
-	ap = dz->application;
-	// set_legal_infile_structure -->
-	dz->has_otherfile = FALSE;
-	// assign_process_logic -->
-	dz->input_data_type = NO_FILE_AT_ALL;
-	dz->process_type	= UNEQUAL_SNDFILE;	
-	dz->outfiletype  	= SNDFILE_OUT;
-	return(FINISHED);
+    int exit_status;
+    aplptr ap;
+    if((exit_status = establish_application(dz))<0)     // GLOBAL
+        return(FAILED);
+    ap = dz->application;
+    // set_legal_infile_structure -->
+    dz->has_otherfile = FALSE;
+    // assign_process_logic -->
+    dz->input_data_type = NO_FILE_AT_ALL;
+    dz->process_type    = UNEQUAL_SNDFILE;  
+    dz->outfiletype     = SNDFILE_OUT;
+    return(FINISHED);
 }
 
 /************************* READ_SRATE *******************/
 
 int read_srate(char *str,dataptr dz)
 {
-	int dummy;
-	if(sscanf(str,"%d",&dummy) != 1) {
-		sprintf(errstr,"Failed to read output sample rate.\n");
-		return(DATA_ERROR);
-	}
-	if(BAD_SR(dummy)) {
-		sprintf(errstr,"Invalid sample rate.\n");
-		return(DATA_ERROR);
-	}
-	dz->infile->srate = dummy;
-	return(FINISHED);
+    int dummy;
+    if(sscanf(str,"%d",&dummy) != 1) {
+        sprintf(errstr,"Failed to read output sample rate.\n");
+        return(DATA_ERROR);
+    }
+    if(BAD_SR(dummy)) {
+        sprintf(errstr,"Invalid sample rate.\n");
+        return(DATA_ERROR);
+    }
+    dz->infile->srate = dummy;
+    return(FINISHED);
 }
 
 /************************* READ_NEWSCALES_DATA *******************/
 
 int read_newscales_data(char **cmdline,double **frq,int **duration,double *maxfrq,dataptr dz)
 {
-	double *f, dummy;
-	int n = 0, dur, *d;
-	char temp[200], *q;
-	int isfrq;
-	FILE *fp;
-	if((fp = fopen(cmdline[0],"r"))==NULL) {
-		sprintf(errstr,	"Can't open datafile %s to read data.\n",cmdline[0]);
-		return(DATA_ERROR);
-	}
-	n = 0;
-	while(fgets(temp,200,fp)==temp) {	 /* READ AND TEST VALS */
-		q = temp;
-		if(*q == ';')	//	Allow comments in file
-			continue;
-		while(get_float_from_within_string(&q,&dummy)) {
-			n++;
-		}
-	}	    
-	if(n <= 0) {
-		sprintf(errstr,"NO DATA Found in datafile.\n");
-		return(DATA_ERROR);
-	}
-	if(ODD(n)) {
-		sprintf(errstr,"DATA INCORRECTLY PAIRED in datafile %s.\n",cmdline[0]);
-		return(DATA_ERROR);
-	}
-	n = n/2;
-	dz->itemcnt = n;
-	if((*frq = (double *)malloc(n * sizeof(double)))==NULL) {
-		sprintf(errstr,"INSUFFICIENT MEMORY to store note frequencies.\n");
-		return(MEMORY_ERROR);
-	}
-	if((*duration = (int *)malloc(n * sizeof(int)))==NULL) {
-		sprintf(errstr,"INSUFFICIENT MEMORY to store note max-durations.\n");
-		return(MEMORY_ERROR);
-	}
-	fseek(fp,0,0);
-	f = *frq;
-	d = *duration;
-	n = 0;
-	isfrq = 1;
-	*maxfrq = 0.0;
-	while(fgets(temp,200,fp)==temp) {	 /* READ AND STORE VALS */
-		q = temp;
-		if(*q == ';')	//	Allow comments in file
-			continue;
-		while(get_float_from_within_string(&q,&dummy)) {
-			if(isfrq) {
-				if(dummy <= 5) {
-					sprintf(errstr,"Frq <= 5: too low for this application.\n");
-					return(DATA_ERROR);
-				}
-				if(dummy > *maxfrq)
-					*maxfrq = dummy;
-				*f = dummy;
-				f++;
-			} else {
-				if(dummy > 3600) {
-					sprintf(errstr,"Duration greater than an hour: too long for this application.\n");
-					return(DATA_ERROR);
-				} else if (dummy <= 0.03) {
-					sprintf(errstr,"Duration less than30 mS: too short for this application.\n");
-					return(DATA_ERROR);
-				}
-				dur = (int)(round(dummy * dz->infile->srate));
-				*d = dur;
-				d++;
-			}
-			isfrq = !isfrq;
-		}
-	}
-	return(FINISHED);
+    double *f, dummy;
+    int n = 0, dur, *d;
+    char temp[200], *q;
+    int isfrq;
+    FILE *fp;
+    if((fp = fopen(cmdline[0],"r"))==NULL) {
+        sprintf(errstr, "Can't open datafile %s to read data.\n",cmdline[0]);
+        return(DATA_ERROR);
+    }
+    n = 0;
+    while(fgets(temp,200,fp)==temp) {    /* READ AND TEST VALS */
+        q = temp;
+        if(*q == ';')   //  Allow comments in file
+            continue;
+        while(get_float_from_within_string(&q,&dummy)) {
+            n++;
+        }
+    }       
+    if(n <= 0) {
+        sprintf(errstr,"NO DATA Found in datafile.\n");
+        return(DATA_ERROR);
+    }
+    if(ODD(n)) {
+        sprintf(errstr,"DATA INCORRECTLY PAIRED in datafile %s.\n",cmdline[0]);
+        return(DATA_ERROR);
+    }
+    n = n/2;
+    dz->itemcnt = n;
+    if((*frq = (double *)malloc(n * sizeof(double)))==NULL) {
+        sprintf(errstr,"INSUFFICIENT MEMORY to store note frequencies.\n");
+        return(MEMORY_ERROR);
+    }
+    if((*duration = (int *)malloc(n * sizeof(int)))==NULL) {
+        sprintf(errstr,"INSUFFICIENT MEMORY to store note max-durations.\n");
+        return(MEMORY_ERROR);
+    }
+    fseek(fp,0,0);
+    f = *frq;
+    d = *duration;
+    n = 0;
+    isfrq = 1;
+    *maxfrq = 0.0;
+    while(fgets(temp,200,fp)==temp) {    /* READ AND STORE VALS */
+        q = temp;
+        if(*q == ';')   //  Allow comments in file
+            continue;
+        while(get_float_from_within_string(&q,&dummy)) {
+            if(isfrq) {
+                if(dummy <= 5) {
+                    sprintf(errstr,"Frq <= 5: too low for this application.\n");
+                    return(DATA_ERROR);
+                }
+                if(dummy > *maxfrq)
+                    *maxfrq = dummy;
+                *f = dummy;
+                f++;
+            } else {
+                if(dummy > 3600) {
+                    sprintf(errstr,"Duration greater than an hour: too long for this application.\n");
+                    return(DATA_ERROR);
+                } else if (dummy <= 0.03) {
+                    sprintf(errstr,"Duration less than30 mS: too short for this application.\n");
+                    return(DATA_ERROR);
+                }
+                dur = (int)(round(dummy * dz->infile->srate));
+                *d = dur;
+                d++;
+            }
+            isfrq = !isfrq;
+        }
+    }
+    return(FINISHED);
 }
 
 /************************* READ_SPECTRUM_DATA *******************/
 
 int read_spectrum_data(char **cmdline,double ***harm,double ***amp,double maxfrq,dataptr dz)
 {
-	double *h, *a, dummy;
-	int harmcnt, linecnt, k;
-	char temp[200], *q;
-	int isharm;
-	FILE *fp;
-	if((fp = fopen(cmdline[0],"r"))==NULL) {
-		sprintf(errstr,	"Can't open datafile %s to read data.\n",cmdline[0]);
-		return(DATA_ERROR);
-	}
-	harmcnt = 0;
-	linecnt = 0;
-	while(fgets(temp,200,fp)==temp) {	 /* READ AND TEST VALS */
-		q = temp;
-		if(*q == ';')	//	Allow comments in file
-			continue;
-		k = 0;
-		while(get_float_from_within_string(&q,&dummy)) {
-			k++;
-		}
-		if(k == 0) {
-			continue;
-		}
-		linecnt++;
-	}
-	if(linecnt != 1 && linecnt != dz->itemcnt) {
-		sprintf(errstr,"No. of lines of spectral data (%d) does NOT = no. of notes entered (%d).\n",linecnt,dz->itemcnt);
-		return(DATA_ERROR);
-	}
-	if((*harm = (double **)malloc(dz->itemcnt * sizeof(double *)))==NULL) {
-		sprintf(errstr,"INSUFFICIENT MEMORY to store harmonics info.\n");
-		return(MEMORY_ERROR);
-	}
-	if((*amp = (double **)malloc(dz->itemcnt * sizeof(double *)))==NULL) {
-		sprintf(errstr,"INSUFFICIENT MEMORY to store amplitudes of harmonics.\n");
-		return(MEMORY_ERROR);
-	}
-	if((dz->wordcnt = (int *)malloc(dz->itemcnt * sizeof(int)))==NULL) {
-		sprintf(errstr,"INSUFFICIENT MEMORY to store count of harmonics for each note.\n");
-		return(MEMORY_ERROR);
-	}
-	linecnt = 0;
-	fseek(fp,0,0);
-	while(fgets(temp,200,fp)==temp) {	 /* READ AND TEST VALS */
-		q = temp;
-		if(*q == ';')	//	Allow comments in file
-			continue;
-		k = 0;
-		while(get_float_from_within_string(&q,&dummy)) {
-			k++;
-		}
-		if(k == 0) {
-			continue;
-		}
-		if(k == 0 || ODD(k)) {
-			sprintf(errstr,"SPECTRAL DATA INCORRECTLY PAIRED in datafile %s line %d\n",cmdline[0],linecnt+1);
-			return(DATA_ERROR);
-		}
-		k /= 2;
-		if(((*harm)[linecnt] = (double *)malloc(k * sizeof(double)))==NULL) {
-			sprintf(errstr,"INSUFFICIENT MEMORY to store harmonics info for note %d.\n",linecnt+1);
-			return(MEMORY_ERROR);
-		}
-		if(((*amp)[linecnt] = (double *)malloc(k * sizeof(double)))==NULL) {
-			sprintf(errstr,"INSUFFICIENT MEMORY to store amplitudes of harmonics for note %d.\n",linecnt+1);
-			return(MEMORY_ERROR);
-		}
-		dz->wordcnt[linecnt] = k;
-		linecnt++;
-	}						/* IF ONLY ONE SPECTRAL DATA LINE, ASSIGN SAME SPECTRUM TO ALL INPUT NOTES */
-	fseek(fp,0,0);
-	isharm = 1;
-	linecnt = 0;
-	while(fgets(temp,200,fp)==temp) {	 /* READ AND STORE VALS */
-		h = (*harm)[linecnt];
-		a = (*amp)[linecnt];
-		q = temp;
-		if(*q == ';')	//	Allow comments in file
-			continue;
-		k = 0;
-		while(get_float_from_within_string(&q,&dummy)) {
-			if(isharm) {
-				if(dummy < 1) {
-					sprintf(errstr,"Invalid harmonic value (< 1).\n");
-					return(DATA_ERROR);
-				} else if(dummy * maxfrq > dz->nyquist) {
-					sprintf(errstr,"Harmonic value (%lf) too high for max frequency (%lf) being used\n",dummy,maxfrq);
-					return(DATA_ERROR);
-				}
-				*h = dummy;
-				h++;
-			} else {
-				if(dummy > 1 || dummy <= 0) {
-					sprintf(errstr,"Harmonic amplitude out of range (>0 - 1).\n");
-					return(DATA_ERROR);
-				}
-				*a = dummy;
-				a++;
-			}
-			isharm = !isharm;
-		}
-		linecnt++;
-	}	    
-	if(linecnt == 1) {
-		while(linecnt < dz->itemcnt) {
-			(*harm)[linecnt] = (*harm)[0];
-			(*amp)[linecnt]  = (*amp)[0];
-			dz->wordcnt[linecnt] = dz->wordcnt[0];
-			linecnt++;
-		}
-	}	
-	return(FINISHED);
+    double *h, *a, dummy;
+    int harmcnt, linecnt, k;
+    char temp[200], *q;
+    int isharm;
+    FILE *fp;
+    if((fp = fopen(cmdline[0],"r"))==NULL) {
+        sprintf(errstr, "Can't open datafile %s to read data.\n",cmdline[0]);
+        return(DATA_ERROR);
+    }
+    harmcnt = 0;
+    linecnt = 0;
+    while(fgets(temp,200,fp)==temp) {    /* READ AND TEST VALS */
+        q = temp;
+        if(*q == ';')   //  Allow comments in file
+            continue;
+        k = 0;
+        while(get_float_from_within_string(&q,&dummy)) {
+            k++;
+        }
+        if(k == 0) {
+            continue;
+        }
+        linecnt++;
+    }
+    if(linecnt != 1 && linecnt != dz->itemcnt) {
+        sprintf(errstr,"No. of lines of spectral data (%d) does NOT = no. of notes entered (%d).\n",linecnt,dz->itemcnt);
+        return(DATA_ERROR);
+    }
+    if((*harm = (double **)malloc(dz->itemcnt * sizeof(double *)))==NULL) {
+        sprintf(errstr,"INSUFFICIENT MEMORY to store harmonics info.\n");
+        return(MEMORY_ERROR);
+    }
+    if((*amp = (double **)malloc(dz->itemcnt * sizeof(double *)))==NULL) {
+        sprintf(errstr,"INSUFFICIENT MEMORY to store amplitudes of harmonics.\n");
+        return(MEMORY_ERROR);
+    }
+    if((dz->wordcnt = (int *)malloc(dz->itemcnt * sizeof(int)))==NULL) {
+        sprintf(errstr,"INSUFFICIENT MEMORY to store count of harmonics for each note.\n");
+        return(MEMORY_ERROR);
+    }
+    linecnt = 0;
+    fseek(fp,0,0);
+    while(fgets(temp,200,fp)==temp) {    /* READ AND TEST VALS */
+        q = temp;
+        if(*q == ';')   //  Allow comments in file
+            continue;
+        k = 0;
+        while(get_float_from_within_string(&q,&dummy)) {
+            k++;
+        }
+        if(k == 0) {
+            continue;
+        }
+        if(k == 0 || ODD(k)) {
+            sprintf(errstr,"SPECTRAL DATA INCORRECTLY PAIRED in datafile %s line %d\n",cmdline[0],linecnt+1);
+            return(DATA_ERROR);
+        }
+        k /= 2;
+        if(((*harm)[linecnt] = (double *)malloc(k * sizeof(double)))==NULL) {
+            sprintf(errstr,"INSUFFICIENT MEMORY to store harmonics info for note %d.\n",linecnt+1);
+            return(MEMORY_ERROR);
+        }
+        if(((*amp)[linecnt] = (double *)malloc(k * sizeof(double)))==NULL) {
+            sprintf(errstr,"INSUFFICIENT MEMORY to store amplitudes of harmonics for note %d.\n",linecnt+1);
+            return(MEMORY_ERROR);
+        }
+        dz->wordcnt[linecnt] = k;
+        linecnt++;
+    }                       /* IF ONLY ONE SPECTRAL DATA LINE, ASSIGN SAME SPECTRUM TO ALL INPUT NOTES */
+    fseek(fp,0,0);
+    isharm = 1;
+    linecnt = 0;
+    while(fgets(temp,200,fp)==temp) {    /* READ AND STORE VALS */
+        h = (*harm)[linecnt];
+        a = (*amp)[linecnt];
+        q = temp;
+        if(*q == ';')   //  Allow comments in file
+            continue;
+        k = 0;
+        while(get_float_from_within_string(&q,&dummy)) {
+            if(isharm) {
+                if(dummy < 1) {
+                    sprintf(errstr,"Invalid harmonic value (< 1).\n");
+                    return(DATA_ERROR);
+                } else if(dummy * maxfrq > dz->nyquist) {
+                    sprintf(errstr,"Harmonic value (%lf) too high for max frequency (%lf) being used\n",dummy,maxfrq);
+                    return(DATA_ERROR);
+                }
+                *h = dummy;
+                h++;
+            } else {
+                if(dummy > 1 || dummy <= 0) {
+                    sprintf(errstr,"Harmonic amplitude out of range (>0 - 1).\n");
+                    return(DATA_ERROR);
+                }
+                *a = dummy;
+                a++;
+            }
+            isharm = !isharm;
+        }
+        linecnt++;
+    }       
+    if(linecnt == 1) {
+        while(linecnt < dz->itemcnt) {
+            (*harm)[linecnt] = (*harm)[0];
+            (*amp)[linecnt]  = (*amp)[0];
+            dz->wordcnt[linecnt] = dz->wordcnt[0];
+            linecnt++;
+        }
+    }   
+    return(FINISHED);
 }
 
 int usage2(char *dummy)
 {
-	fprintf(stderr,"USAGE: newscales outfile datafile spectrumfile [srate]\n");
-	fprintf(stderr,"outfile      Generic name for output soundfiles (must not end with a number)\n");
-	fprintf(stderr,"datafile     Frq-amp pairs defining note-events in output\n");
-	fprintf(stderr,"spectrumfile Harmonicnumber-amplitude pairs, define spectrum of note.\n");
-	fprintf(stderr,"             One line for all notes\n");
-	fprintf(stderr,"             OR\n");
-	fprintf(stderr,"             One line for each note in the frq-list.\n");
-	fprintf(stderr,"            (First line corresponds to lowest note, etc.)\n");
-	return(FAILED);
+    fprintf(stderr,"USAGE: newscales outfile datafile spectrumfile [srate]\n");
+    fprintf(stderr,"outfile      Generic name for output soundfiles (must not end with a number)\n");
+    fprintf(stderr,"datafile     Frq-amp pairs defining note-events in output\n");
+    fprintf(stderr,"spectrumfile Harmonicnumber-amplitude pairs, define spectrum of note.\n");
+    fprintf(stderr,"             One line for all notes\n");
+    fprintf(stderr,"             OR\n");
+    fprintf(stderr,"             One line for each note in the frq-list.\n");
+    fprintf(stderr,"            (First line corresponds to lowest note, etc.)\n");
+    return(FAILED);
 }
 
 /****************************** ESTABLISH_APPLICATION *******************************/
 
 int establish_application(dataptr dz)
 {
-	aplptr ap;
-	if((dz->application = (aplptr)malloc(sizeof (struct applic)))==NULL) {
-		sprintf(errstr,"establish_application()\n");
-		return(MEMORY_ERROR);
-	}
-	ap = dz->application;
-	memset((char *)ap,0,sizeof(struct applic));
-	return(FINISHED);
+    aplptr ap;
+    if((dz->application = (aplptr)malloc(sizeof (struct applic)))==NULL) {
+        sprintf(errstr,"establish_application()\n");
+        return(MEMORY_ERROR);
+    }
+    ap = dz->application;
+    memset((char *)ap,0,sizeof(struct applic));
+    return(FINISHED);
 }
 
 int assign_process_logic(dataptr dz)
 {
-	return(FINISHED);
+    return(FINISHED);
 }
 void set_legal_infile_structure(dataptr dz)
 {
 }
 int set_legal_internalparam_structure(int process,int mode,aplptr ap)
 {
-	return(FINISHED);
+    return(FINISHED);
 }
 int setup_internal_arrays_and_array_pointers(dataptr dz)
 {
-	return(FINISHED);
+    return(FINISHED);
 }
 int establish_bufptrs_and_extra_buffers(dataptr dz)
 {
-	return(FINISHED);
+    return(FINISHED);
 }
 int inner_loop(int *peakscore,int *descnt,int *in_start_portion,int *least,int *pitchcnt,int windows_in_buf,dataptr dz)
 {
-	return(FINISHED);
+    return(FINISHED);
 }
 int get_process_no(char *str,dataptr dz)
 {
-	return(FINISHED);
+    return(FINISHED);
 }
 int usage3(char *str1,char *str2)
 {
-	return(FINISHED);
+    return(FINISHED);
 }
 int usage1()
 {
-	return(FINISHED);
+    return(FINISHED);
 }
 int read_special_data(char *str,dataptr dz)
 {
-	return(FINISHED);
+    return(FINISHED);
 }
 
 //***************************** APPLICATION_INIT **************************/
 //
 //int application_init(dataptr dz)
 //{
-//	int exit_status;
-//	int storage_cnt;
-//	int tipc, brkcnt;
-//	aplptr ap = dz->application;
-//	if(ap->vflag_cnt>0)
-//		initialise_vflags(dz);	  
-//	tipc  = ap->max_param_cnt + ap->option_cnt + ap->variant_param_cnt;
-//	ap->total_input_param_cnt = (char)tipc;
-//	if(tipc>0) {
-//		if((exit_status = setup_input_param_range_stores(tipc,ap))<0)			  
-//			return(exit_status);
-//		if((exit_status = setup_input_param_defaultval_stores(tipc,ap))<0)		  
-//			return(exit_status);
-//		if((exit_status = setup_and_init_input_param_activity(dz,tipc))<0)	  
-//			return(exit_status);
-//	}
-//	brkcnt = tipc;
+//  int exit_status;
+//  int storage_cnt;
+//  int tipc, brkcnt;
+//  aplptr ap = dz->application;
+//  if(ap->vflag_cnt>0)
+//      initialise_vflags(dz);    
+//  tipc  = ap->max_param_cnt + ap->option_cnt + ap->variant_param_cnt;
+//  ap->total_input_param_cnt = (char)tipc;
+//  if(tipc>0) {
+//      if((exit_status = setup_input_param_range_stores(tipc,ap))<0)             
+//          return(exit_status);
+//      if((exit_status = setup_input_param_defaultval_stores(tipc,ap))<0)        
+//          return(exit_status);
+//      if((exit_status = setup_and_init_input_param_activity(dz,tipc))<0)    
+//          return(exit_status);
+//  }
+//  brkcnt = tipc;
 //
-//	if(dz->input_data_type==BRKFILES_ONLY 					   
-//	|| dz->input_data_type==UNRANGED_BRKFILE_ONLY 
-//	|| dz->input_data_type==DB_BRKFILES_ONLY 
-//	|| dz->input_data_type==SNDFILE_AND_BRKFILE 
-//	|| dz->input_data_type==SNDFILE_AND_UNRANGED_BRKFILE 
-//	|| dz->input_data_type==SNDFILE_AND_DB_BRKFILE 
-//	|| dz->input_data_type==ALL_FILES
-//	|| dz->input_data_type==ANY_NUMBER_OF_ANY_FILES
-//	|| dz->outfiletype==BRKFILE_OUT) {
-//		dz->extrabrkno = brkcnt;			  
-//		brkcnt++;		/* extra brktable for input or output brkpntfile data */
-//	}
-//	if(brkcnt>0) {
-//		if((exit_status = setup_and_init_input_brktable_constants(dz,brkcnt))<0)			  
-//			return(exit_status);
-//	}
+//  if(dz->input_data_type==BRKFILES_ONLY                      
+//  || dz->input_data_type==UNRANGED_BRKFILE_ONLY 
+//  || dz->input_data_type==DB_BRKFILES_ONLY 
+//  || dz->input_data_type==SNDFILE_AND_BRKFILE 
+//  || dz->input_data_type==SNDFILE_AND_UNRANGED_BRKFILE 
+//  || dz->input_data_type==SNDFILE_AND_DB_BRKFILE 
+//  || dz->input_data_type==ALL_FILES
+//  || dz->input_data_type==ANY_NUMBER_OF_ANY_FILES
+//  || dz->outfiletype==BRKFILE_OUT) {
+//      dz->extrabrkno = brkcnt;              
+//      brkcnt++;       /* extra brktable for input or output brkpntfile data */
+//  }
+//  if(brkcnt>0) {
+//      if((exit_status = setup_and_init_input_brktable_constants(dz,brkcnt))<0)              
+//          return(exit_status);
+//  }
 //
-//	if((storage_cnt = tipc + ap->internal_param_cnt)>0) {		  
-//		if((exit_status = setup_parameter_storage_and_constants(storage_cnt,dz))<0)	  
-//			return(exit_status);
-//		if((exit_status = initialise_is_int_and_no_brk_constants(storage_cnt,dz))<0)	  
-//			return(exit_status);
-//	}													   
-// 	if((exit_status = mark_parameter_types(dz,ap))<0)	  
-//			return(exit_status);
+//  if((storage_cnt = tipc + ap->internal_param_cnt)>0) {         
+//      if((exit_status = setup_parameter_storage_and_constants(storage_cnt,dz))<0)   
+//          return(exit_status);
+//      if((exit_status = initialise_is_int_and_no_brk_constants(storage_cnt,dz))<0)      
+//          return(exit_status);
+//  }                                                      
+//  if((exit_status = mark_parameter_types(dz,ap))<0)     
+//          return(exit_status);
 //
-//	if((exit_status = establish_infile_constants(dz))<0)
-//		return(exit_status);
-//	if((exit_status = establish_bufptrs_and_extra_buffers(dz))<0)	
-//		return(exit_status);
-//	if((exit_status = setup_internal_arrays_and_array_pointers(dz))<0)	 
-//		return(exit_status);
-//	return(FINISHED);
+//  if((exit_status = establish_infile_constants(dz))<0)
+//      return(exit_status);
+//  if((exit_status = establish_bufptrs_and_extra_buffers(dz))<0)   
+//      return(exit_status);
+//  if((exit_status = setup_internal_arrays_and_array_pointers(dz))<0)   
+//      return(exit_status);
+//  return(FINISHED);
 //}
 
 

File diff suppressed because it is too large
+ 770 - 746
dev/science/repeater.c


File diff suppressed because it is too large
+ 781 - 757
dev/science/sorter.c


File diff suppressed because it is too large
+ 750 - 726
dev/science/verges.c


File diff suppressed because it is too large
+ 759 - 736
dev/science/waveform.c


Some files were not shown because too many files changed in this diff