📄 mcplay.c
字号:
/* Joseph T. Buck, Entropic Processing, Inc. Modified by Alan Parker to use DACP on Masscomp at WRL 2/13/86 Modified for SPS by Alan Parker This program is used to play a SD file on the Masscomp D/A. Syntax: mcplay [options] file Options: -x debug_level -g gain gain is a floating value. The file is multiplied by this value to form the output data. -p range range is a range of points. Only those points are played the first point is 1 -f range range is a range of frames (default frame size = 100) the first frame is 1 -w width changes the frame size -s range range is a range of seconds. For LISTEN compatibility, the first second is zero -r repeats number of repetitions -c chan channel number -k clock D/A clock number -i Clip samples -h hist-file Specify alternate history file. -b bits to shift input data to form output data postive means right shift, negative means left shift This material contains proprietary software of Entropic Processing, Inc. Any reproduction, distribution, or publication without the the prior written permission of Entropic Processing, Inc. is strictly prohibited. Any public distribution of copies of this work authorized in writing by Entropic Processing, Inc. must bear the notice "Copyright 1986 Entropic Processing, Inc." */#ifndef lint static char *sccs_id = "@(#)mcplay.c 1.17 7/2/87 ESI";#endif/* **************** check these defaults ********************** */#ifndef DADEV#define DADEV "/dev/dacp0/daf%d" /* default d to a device */#endif#ifndef CLKDEV#define CLKDEV "/dev/dacp0/efclk%d" /* default clock device */#endif#define CLKDEFAULT 0 /* default clock number *//* ************************************************************ */#define MAX_VALUE 2047 /* max value of this D/A (12 bit) */#define NUM_BUFS 1#define DUTY 50 /* duty cycle of clock */#include <stdio.h>#include <sps/sps.h>#include <sps/sd.h>#define SYNTAX USAGE \("mcplay [-[spf] range] [-w fsiz] [-c chan] [-k clock] [-r nrpt] [-g gain] [-i] [-h hist-file] [-x debug-level] file ...");#define Fprintf (void)fprintfchar *calloc();int debug_level = 0;main (argc, argv)int argc;char **argv;{ int c, i; extern int optind, sym_quiet; extern char *optarg; int nrep = 1, channel = 0; char *p_switch = NULL, *s_switch = NULL, *f_switch = NULL; FILE *istrm, *hfile; char *hist = "mcplay.his"; struct header *ih; int start_p = 1, end_p, start_s, end_s, start_f, end_f; int isf, np=0, fwidth = 100, gflag = 0; int bflag=0, bits, left, right; int nptot = 0, clk = CLKDEFAULT, nofile=0; int max = 0, clip = 0, iflag = 0; double gain=1, atof(); float *dataf; short *data; int argind, devpn = -1, clkpn = -1, write_hfile=0; double retwidth, retfreq, clk_width; int mropen(), mrbufwt(), mrbufget(), mrclktrig(); char dadev[30], clkdev[30], *filename=NULL, *firstfile; char *getsym_s(); void dac_error(); sprintf(dadev,DADEV,channel); sprintf(clkdev,CLKDEV,clk); while ((c = getopt (argc, argv, "p:s:r:c:k:w:f:g:x:ih:b:C:D:")) != EOF) { switch (c) { case 'x': debug_level = atoi (optarg); break; case 'g': gflag++; gain = atof (optarg); break; case 'c': channel = atoi (optarg); break; case 'r': nrep = atoi (optarg); break; case 'p': p_switch = optarg; break; case 'f': f_switch = optarg; break; case 'w': fwidth = atoi (optarg); break; case 's': s_switch = optarg; break; case 'k': clk = atoi (optarg); break; case 'i': iflag++; break; case 'h': hist = optarg; break; case 'b': bflag++; bits = atoi(optarg); break; case 'C': strncpy(clkdev,optarg,sizeof clkdev); break; case 'D': strncpy(dadev,optarg,sizeof dadev); break; default: SYNTAX; } } if (bflag && gflag) { Fprintf(stderr,"mcplay: can't use both -b and -g\n"); exit(1); } if (bflag) if (bits < 0) left = bits*-1; else right = bits; if (optind >= argc) nofile = 1; else filename = argv[optind]; read_params(NULL,SC_CHECK_FILE,filename); if (nofile) { if(symtype("filename") == ST_UNDEF) { fprintf(stderr,"mcplay: no input file\n"); exit(1); } filename = getsym_s("filename"); } firstfile = filename; if ((hfile = fopen(hist,"w")) == NULL) { Fprintf(stderr,"mcplay: warning can't open hist file.\n"); hfile = stderr; } if(debug_level) Fprintf(stderr,"mcplay: clk: %s, d/a: %s\n",clkdev,dadev); argind = optind; while (nrep > 0) { optind = argind; while (optind < argc || nofile) { if (!nofile) filename = argv[optind]; if (strcmp(filename,"-") == 0) istrm = stdin; else if ((istrm = fopen (filename, "r")) == NULL) CANTOPEN ("mcplay", filename); ih = read_header (istrm); if (ih -> common.type != FT_SD) { Fprintf (stderr, "mcplay: %s is not speech data\n", filename); exit (1); } end_p = ih -> common.ndrec; isf = ih -> hd.sd->sf; start_s = (start_p - 1) / isf; end_s = (end_p + isf - 1) / isf; start_f = (start_p - 1) / fwidth + 1; end_f = (end_p + fwidth - 1) / fwidth; if(symtype("start") != ST_UNDEF) start_p = getsym_i("start"); if(symtype("nan") != ST_UNDEF) end_p = start_p + getsym_i("nan") - 1; if (p_switch) range_switch (p_switch, &start_p, &end_p, 1); else if (s_switch) { range_switch (s_switch, &start_s, &end_s, 1); start_p = start_s * isf + 1; end_p = end_s * isf; if (end_p <= start_p) end_p += isf; } else if (f_switch) { range_switch (f_switch, &start_f, &end_f, 1); start_p = (start_f - 1) * fwidth + 1; end_p = end_f * fwidth; } np = end_p - start_p + 1; Fprintf(stderr,"mcplay: start_p: %d, nan: %d, filename: %s\n", start_p,np,filename); if (start_p > end_p) { Fprintf (stderr, "mcplay: start > end\n"); exit (1); } else if (end_p > ih -> common.ndrec) { Fprintf (stderr, "mcplay: %s is not long enough\n", filename); Fprintf (stderr, "end_p = %d, last point = %d, end_p reset.\n", end_p, ih -> common.ndrec); end_p = ih->common.ndrec; } if(start_p > ih->common.ndrec) { Fprintf (stderr, "mcplay: start_p > than ndrec (%d)\n", ih -> common.ndrec); exit(1); } skiprec (istrm, start_p, size_rec (ih)); clk_width = (double)((1.06e6/isf)*(DUTY/100.0)); if(mropen(&devpn,dadev,0) == -1) { Fprintf(stderr,"Can't open D/A %s\n",dadev); exit(1); } if(mropen(&clkpn,clkdev,0) == -1) { Fprintf(stderr,"Can't open clock %s\n",clkdev); exit(1); } if(mrclk1(clkpn,0,(double)isf,&retfreq,0,clk_width,&retwidth,0) != 0) dac_error(); if(mrclktrig(devpn,1,clkpn) != 0) dac_error(); if(debug_level) Fprintf(stderr,"mcplay: np: %d\n",np); if((dataf = (float *)calloc((unsigned)np,sizeof FLOAT)) == NULL) { Fprintf(stderr,"Cannot alloc %d floats\n",np); exit(1); } if((data = (short *)calloc((unsigned)np,sizeof SHORT)) == NULL) { Fprintf(stderr,"Cannot alloc %d shorts\n",np); exit(1); } if ((ih->hd.sd->max_value == 0) && iflag) { clip++; write_hfile=1; Fprintf(hfile, "Samples greater than %d will be clipped to this value\n", MAX_VALUE); Fprintf(hfile,"Sample\toriginal value\n"); } if (!gflag && !bflag && (ih->hd.sd->max_value > MAX_VALUE)) { gflag++; write_hfile=1; gain = MAX_VALUE/ih->hd.sd->max_value; Fprintf(hfile,"hd.sd->max_value: %g\n",ih->hd.sd->max_value); Fprintf(hfile,"This D/A MAX_VALUE is %g\n",MAX_VALUE); Fprintf(hfile,"Data scaled by %g\n",gain); Fprintf(stderr,"mcplay: Data scaled by %g\n",gain); } if (get_sd_recf(dataf,np,ih,istrm) == EOF) Fprintf(stderr,"mcplay: EOF on %s\n",filename); if (clip) for (i=0; i<np; i++) { int j = abs((int)dataf[i]); if (j > MAX_VALUE) { Fprintf(hfile, "%d\t%d\n", i+2,j); if(j > max) max = j; if(dataf[i] < 0) dataf[i] = -MAX_VALUE; else dataf[i] = MAX_VALUE; } }/* either, 1) multiply sample by gain factor (slow), 2) shift sample bits to right (faster), or 3) just copy sample (fastest) */ if (gflag) for (i=0; i<np; i++) data[i] = dataf[i]*gain; else if (bflag && left) for (i=0; i<np; i++) data[i] = (int)dataf[i] << left; else if (bflag && right) for (i=0; i<np; i++) data[i] = (int)dataf[i] >> right; else for (i=0; i<np; i++) data[i] = dataf[i];/* old way if(mrbufall(devpn,data,NUM_BUFS,np*sizeof SHORT) != 0) dac_error(); if(mrxoutq(devpn,np,2*np,NULL) != 0) dac_error();*/ (void)mrdaxout(devpn,clkpn,clkpn,0,1,1,np,data,0); Fprintf(stderr,"mcplay: Transfer in progress..."); (void) free((char *)dataf); (void) mrevwt(devpn,0,(np/isf)*2000); Fprintf(stderr,"done\n"); (void) free((char *)data); if(mrclosall() != 0) dac_error(); nptot += np; if(nofile) break; optind++; } nrep--; } (void) putsym_i("start",start_p); (void) putsym_i("nan",np); (void) putsym_s("filename",firstfile); (void) putsym_s("prog","mcplay"); if(debug_level) Fprintf(stderr,"mcplay: Total points output: %d\n",nptot); if(clip && max) Fprintf(hfile,"To avoid clipping use a gain of %g.\n", (float)MAX_VALUE/(float)abs(max)); if(clip && max && (hfile != stderr)) Fprintf(stderr,"mcplay: To avoid clipping use a gain of %g.\n", (float)MAX_VALUE/(float)abs(max)); (void) fclose(hfile); if(!write_hfile && (hfile != stderr)) unlink(hist); exit (0);}void dac_error(){ Fprintf(stderr,"Error on dacp call.\n"); exit(1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -