⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wrecord.c

📁 speech signal process tools
💻 C
字号:
/* mcrecord - sample data from Masscomp A/D converted and store in ESPS SD file * * This material contains proprietary software of Entropic Speech, Inc. * Any reproduction, distribution, or publication without the prior * written permission of Entropic Speech, Inc. is strictly prohibited. * Any public distribution of copies of this work authorized in writing by * Entropic Speech, Inc. must bear the notice * *    "Copyright (c) 1987 Entropic Speech, Inc.; All rights reserved" * * Syntax: record [options] file *   Options: *	-g gain *		gain is a number between from 0 to 3.  *		This is a magic cookie; the gain factor used depends *		on the particular A/D converter being used. *		(See below.) *	-p range *		range is a number of points to capture. *	-f range *		range is a number of frames to capture (default frame size *                = 100) *	-w width *		changes the frame size *	-s range *		range is the number of seconds of data to capture. *	-r sampling rate *		number of samples per second *	-c a2d channel *		input channel number *	-k clock# *		the number of the clock unit that drives the conversion *	-x debug_level *		0 => no debug; 1 => print debug messages *	-t comment *		comment text to add to header *	-d adtype *		this overrides the compiled in default.  This doesn't *		affect processing; it just goes into the header. *	-C *		alternate clock device *	-D *		alternate A/D device * * Written by: David Burton * Checked by: Alan Parker * Modified for ESPS by Alan Parker * Additional modifications by Ajaipal S. Virdy * * Purpose: Digitize analog data using Masscomp A/D converter * * *       --------------------------------------------------- *       |Gain settings for different Masscomp A/D devices:| *       |						   | *       |Factor	AD12F	AD12FA	AD12FA*	EF12M	   | *       |  0	 	x1	  x1	  x1	 x1 	   | *       |  1	 	x4	  x2	  x4	 x2	   | *       |  2	 	x16	  x4	  x16	 x4	   | *       |  3	 	x64	  x8	  x64	 x8	   | *       --------------------------------------------------- * * NOTE: default clock for record is 1.  Default clock for play is 0. */#ifndef lint       static char *sccsid = "@(#)wrecord.c	1.7 11/8/91 ESI";#define DATE "11/8/91"#define VERSION "1.7"#endif#ifndef DATE#define DATE ""#endif#ifndef VERSION#define VERSION "nosccs"#endif#include <stdio.h>/* ESPS includes */#include <esps/unix.h>#include <esps/esps.h>#include <esps/sd.h>#include <Objects.h>#define BPS		sizeof (short)	/* number of bytes per short int */#define OFLAGS		(O_WRONLY | O_TRUNC | O_CREAT)/* ************************************************************************ *//*	CHECK THESE DEFAULTS.  Normally these values come from the 			       install script.*/#ifndef MAXAD#define MAXAD 2047#endif#ifndef MINAD#define MINAD -2048#endif#ifndef ADTYPE#define ADTYPE  "LOCALad1"#endif/* ************************************************************************ */#define DEF_SAMPLE_RATE 8000		/* default sample rate / sec */#define PROGRAM "record"		/* name of this program */#define SOURCE "analog data digitized by ESPS record\n"#define fperror (void)perror#define SYNTAX USAGE \("record [-x debug] [-[spf] range] [-w frame size] [-c a2d channel] [-r sampling rate] [-k clock#] [-g gain] [-t \"comment\"] [-C clock] [-D a/d device] file");/* Externals */int debug_level = 0;extern int   optind;extern char *optarg;char *get_cmd_line();int P8574_type=1;	/* 1 = P8574, 0 = P8574A */int ARIEL_16=0;		/* 16 Mhz crystal on Ariel/surf card, else 24Mhz */int vox_do = 0,vox_sec = 0,vox_thr = 0;extern int channel;main (argc, argv)int argc;char **argv;{    int     c, i,            num_samps = 0,            status[2];    short *data;    char   *comment = NULL,		/* for comment from command line */	   *adtype = ADTYPE;    char    answer[80];			/* For getting answer */    long sam_rate;    double dsam_rate;    int    amin=0, amax=0;    double start_time;        FILE *ostrm;    int s_switch = NO, p_switch = NO, f_switch = NO;    int    p_value = 0,  f_value = 0;    double s_value = 0.0;    struct header  *oh;    int  fwidth = 100;    int  gain = 0;    int  stat;		/* return status from adc */    int  dsp_type;    char   *ProgName="wrecord";    int  Iflag=0;    if (dsp32c_is_available())       dsp_type = DSP32C_VME;    else if (dsp32_is_available())       dsp_type = DSP32_FAB2;    else {       Fprintf(stderr,"%s: No DSP board available.\n",ProgName);       exit(1);       }    channel=1;			/* 1,2,0 sets left, right or stereo */    if (dsp_type == DSP32_FAB2)  	/* set default sample rate */	sam_rate = 8000;    else	sam_rate = 12000;	    while ((c = getopt (argc, argv, "Ip:s:k:r:c:w:f:g:x:t:d:C:D:")) != EOF) {	switch (c) {	    case 'x':		debug_level = atoi (optarg);		break;	    case 'g':		fprintf(stderr,"g option not in Sun/Waves record\n");		break;	    case 'c': 		if(dsp_type == DSP32C_VME) {		  if(((channel = atoi(optarg)) == 1) || (channel == 2))		    break;		  else {		    fprintf(stderr,"Channel spec. must be 1 or 2\n");		    exit(-1);		  }		} else		  fprintf(stderr,"c option not in Sun/Waves record\n");		break;	    case 'k': 		fprintf(stderr,"k option not in Sun/Waves record\n");		break;	    case 'r': 		sam_rate = atoi (optarg);		break;	    case 'p': 		p_value = atoi(optarg);		p_switch = yes;		break;	    case 'f':		f_value = atoi(optarg);		f_switch = yes;		break;	    case 'w':		fwidth = atoi (optarg);		break;	    case 's': 		s_value = atof(optarg);		s_switch = yes;		break;	    case 't':		comment = optarg;		break;	    case 'd':		adtype = optarg;		break;	    case 'C':		fprintf(stderr,"C option not in Sun/Waves record\n");		break;	    case 'D':		fprintf(stderr,"C option not in Sun/Waves record\n");		break;	    case 'I':		Iflag=1;		break;	    default: 		SYNTAX;	}    }    if (optind >= argc)	SYNTAX;/* * convert range argument to number of sample points */     if (p_switch == YES) {	num_samps = p_value;     }     else if (f_switch == YES) {             num_samps = f_value * fwidth;	  }          else if (s_switch == YES) {                  num_samps = (int) ( ( (float) sam_rate * s_value ) + 0.5 );               }	       else {                  Fprintf(stderr,		  "record: amount of data to record has not beeen specified\n");		  exit(1);	       }     if (debug_level)	Fprintf (stderr, "record: num_samps is %d, p is %d, f is %d, s is %f\n",                 num_samps, p_value, f_value, s_value);     if (num_samps == 0) {	Fprintf (stderr, "record: number of samples must be specified.\n");	exit(1);     }/* check if sampling rate is > 0 */   if ( sam_rate <= 0 ) {        Fprintf(stderr, "record: sampling rate (%d) must be > 0\n", sam_rate);        exit(1);   }/* First open designated data file - if error occurs stop program */     if(strcmp(argv[optind],"-") == 0)	ostrm = stdout;    else     	TRYOPEN ( PROGRAM, argv[optind], "w", ostrm );/* get a new SD header */    oh = new_header (FT_FEA);    start_time = 0;    (void) init_feasd_hd(oh, SHORT, (int) 1, &start_time, (int) 0, 	(double)sam_rate);/* Allocate memory for data */    if ((data = (short *) malloc (num_samps * BPS)) == NULL) {	Fprintf (stderr,	"%s: could not allocate memory for data.\n",	argv[0]);	exit (1);    }/* Prompt user for initiation of data collection */        if (!Iflag) {    	Fprintf (stderr, "record: when ready to record data, hit RETURN: ");/* Wait for carriage return */    	while( (c = getchar()) != '\n')	/* wait for carriage return */	;    }/* lock this process's image into memory */    Fprintf (stderr, "Start recording now ... ");/* Start the Analog to Digital transfer */    dsam_rate = sam_rate;    if (dsp_type == DSP32_FAB2)    	stat = adc_32(NULL, data, (int)num_samps, &dsam_rate, &amax, &amin, 0);    else if (dsp_type == DSP32C_VME)    	stat = adc_32C(-1, data, (int)num_samps, &dsam_rate, &amax, &amin, 0,0);    else	spsassert(0,"dsp_type invalid");/* Wait until completion of transfer */    if (stat == -1)      Fprintf (stderr, "adc returned with error code (-1)\n.");    else      Fprintf (stderr, "Done\n(min: %d, max: %d, true samp_rate: %lg)\n",	amin,amax,dsam_rate);/* Then copy binary data into file */     *add_genhd_f("max_value", (double *)NULL, 1, oh) = MAX(abs(amin),      abs(amax));     (void)strcpy(oh->common.prog, PROGRAM);     (void)strcpy(oh->common.vers, VERSION);     (void)strcpy(oh->common.progdate, DATE);     add_comment (oh, get_cmd_line(argc,argv));     add_comment (oh, SOURCE);     if (comment) {     	add_comment (oh, comment);	add_comment (oh, "\n");     }     write_header(oh, ostrm);    (void) put_sd_recs (data, num_samps, oh, ostrm);    /* Clean up */    (void)fclose(ostrm);    (void)putsym_s("filename",argv[optind]);    (void)putsym_s("prog","record");    (void)putsym_i("start",1);    (void)putsym_i("nan",num_samps);    exit(0);    /* NOTREACHED */}dsp32c_is_available(){  int dc2;  int dc = open("/dev/dc00",O_RDWR,0);  if(dc > 0) {    close(dc);    dc2 = dcopen("/dev/dc00");    if(dc2 > 0) {      close(dc2);      return(1);    }  }  return(0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -