📄 mcplay.buffs
字号:
/* 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 temporary file -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. 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 = "%W% %G% EPI";#endif#define MAX_VALUE 2047 /* max value of this D/A (12 bit) */#define NUM_BUFS 5#define DABUF 8000 /* size of large data buffer */#define SIZ DABUF/NUM_BUFS /* size of each smaller buffer */#define TIMEOUT 1000 /* timeout for D/A (400 msec.) */#define DUTY 50 /* duty cycle of clock */#define DADEV "/dev/dacp0/daf0"#define CLKDEV "/dev/dacp0/efclk0"#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)fprintfint debug_level = 0;main (argc, argv)int argc;char **argv;{ int c, i, n; extern optind; 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, nsec, rem, np, fwidth = 100, gflag = 0; int first = 1, first_sf, nptot = 0, clk = 0; int npleft, max = 0, clip = 0, iflag = 0; double gain=1, atof(); short buffs[DABUF], *data; float dataf[SIZ]; int stat=1, devpn = -1, clkpn = -1, byteslocked; double retwidth, retfreq, clk_width; int started=0,mropen(), mrbufwt(), mrbufget(), mrclktrig(); void dac_error(), mrlock(), nice(); while ((c = getopt (argc, argv, "p:s:r:c:k:w:f:g:x:ih:")) != 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; default: SYNTAX; } } if (optind >= argc) SYNTAX; if ((hfile = fopen(hist,"w")) == NULL) { Fprintf(stderr,"%s: warning can't open hist file.\n",argv[0]); hfile = stderr; } while (optind < argc) { if ((istrm = fopen (argv[optind], "r")) == NULL) CANTOPEN ("mcplay", argv[optind]); ih = read_header (istrm); if (ih -> common.type != FT_SD) { Fprintf (stderr, "mcplay: %s is not speech data\n", argv[optind]); exit (1); } end_p = ih -> common.ndrec - 1; 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 (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; } 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", argv[optind]); Fprintf (stderr, "end_p = %d, last point = %d\n", end_p, ih -> common.ndrec); exit (1); } skiprec (istrm, start_p, size_rec (ih)); if (first) { 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(); data = buffs; first_sf = isf; (void) mrlock(0,0,&byteslocked); (void) nice(-15); if(mrbufall(devpn,buffs,NUM_BUFS,2*SIZ) != 0) dac_error(); if(mrxoutq(devpn,SIZ,0,NULL) != 0) dac_error(); } else if (isf != first_sf) { Fprintf (stderr, "mcplay: all files must have same sample freq: %s\n", argv[optind]); exit (1); } np = end_p - start_p + 1; if ((ih->hd.sd->max_value == 0) && iflag) { clip++; Fprintf(hfile,"Samples greater than %d will be clipped to this value\n",MAX_VALUE); Fprintf(hfile,"Sample\toriginal value\n"); } if (!gflag && (ih->hd.sd->max_value > MAX_VALUE)) { gflag++; 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); } npleft = np; n = SIZ; while (npleft > 0) { if (npleft < n) n = npleft; if (get_sd_recf(dataf,n,ih,istrm) == EOF) Fprintf(stderr,"mcplay: EOF on %s\n",argv[optind]); if(mrbufwt(devpn,TIMEOUT) != 0) dac_error(); if(mrbufget(devpn,0,&data) != 0) dac_error(); if (clip) for (i=0; i<n; i++) { int j = abs(dataf[i]); if (j > MAX_VALUE) { Fprintf(hfile, "%d\t%d\n", np-npleft+i+2,j); if(j > max) max = dataf[i]; if(j < 0) dataf[i] = -MAX_VALUE; else dataf[i] = MAX_VALUE; } } for (i=0; i<n; i++) data[i] = dataf[i]*gain; if (n < SIZ) for (i=n; i<SIZ; i++) data[i] = 0; if(mrbufrel(devpn,data) != 0) dac_error(); npleft -= n; } nptot += np; first = 0; optind++; } 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)); if (debug_level) Fprintf (stderr, "Speech transfer complete\n"); while(stat == 1) {(void) sleep(1); (void) mrevck(devpn,&stat);} if(mrclosall() != 0) dac_error(); exit (0);}void dac_error(){ Fprintf(stderr,"Error on dacp call.\n"); exit(1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -