
#include <stdio.h>
#define FLOAT 4

main()
{
        int pchfd, newpchfd,pval,j;
	int firstframe,lastframe,nbframe;
	long skipbytes;
#define ARRSIZ 200
	float vals[ARRSIZ]; /* enough for 46 poles + 4 data values */
	char  input[32]; /* orig file containing pitches & amps */
	char  output[32]; /* new file containing pitches & amps */
	char	answer[10];
	float mult;

	fprintf(stderr," Enter name of pitch data input file\t");
	scanf("%s",input);
	if((pchfd = open(input,2)) < 0) {
		fprintf(stderr," Can't open pitch analysis file\n");
		exit(1);
		}
	nbframe = 2*FLOAT; 
again:	fprintf(stderr," Enter first and last frames,and multiplier\t");
	scanf("%d %d %f",&firstframe,&lastframe,&mult);
	if(lastframe < firstframe) {
		printf("pedit: error: last frame less than first.\n");
		exit(1);
		}
	skipbytes = (firstframe) * nbframe;
	if(lseek(pchfd, skipbytes, 0) < 0) {
		printf("error on lseek\n");
		exit(1);
		}
	for(j = firstframe; j <= lastframe; j++) {
		if(read(pchfd, (char *)vals, nbframe) != nbframe) {
			printf(" bad read\n");
			exit(1);
			}	
		fprintf(stderr,
		"%d %6.2f %f\n", 
		j,vals[0],vals[1]);
		
		if(mult) {
			vals[0] *= mult;
			if(lseek(pchfd,(long)-nbframe,1) < 0) {
				printf("Error in lseek\n");
				exit(1);
				}
			if(write(pchfd,(char *)vals,nbframe) != nbframe) {
				printf("bad write\n");
				exit(1);
				}
		fprintf(stderr,
		"%d %6.2f %f\n", 
		j,vals[0],vals[1]);
			}
		}
	goto again;

}

