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

📄 demux.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * This material contains unpublished, proprietary software of  * Entropic Research Laboratory, Inc. Any reproduction, distribution,  * or publication of this work must be authorized in writing by Entropic  * Research Laboratory, Inc., and must bear the notice:  * *    "Copyright (c) 1986-1990  Entropic Speech, Inc.  *    "Copyright (c) 1990-1991  Entropic Research Laboratory, Inc.  *                   All rights reserved" * * The copyright notice above does not evidence any actual or intended  * publication of this source code.      * * Written by:  Alan Parker * Checked by: * Revised by: * * Brief description: * */#include <stdio.h>#include <esps/esps.h>#include <esps/fea.h>#include <esps/feasd.h>#include <esps/unix.h>char	*Version = "1.7";char	*Date = "8/31/95";#define ERROR_EXIT(text) {(void) fprintf(stderr, "%s: %s - exiting\n", \                ProgName, text); exit(1);}#define Fprintf (void)fprintf#define SYNTAX \USAGE("demux [-e grange] [-o prototype] [-{prs} range] [-x debug] [-S]\n [-P param_file] input.fsd [output1.fsd [output2.fsd] ...]")/* * global variables */char	*ProgName = "demux";int	debug_level = 0;                /* debug level */long	get_chans();char	*get_cmd_line();void	lrange_switch();long	*grange_switch();int	symsize();char	*eopen();int	symsize();int	typesiz();	main(argc, argv)int	argc;char	**argv;{	char	*param_file = NULL;  /*parameter file name*/	FILE    **out_fd;	 	/* output stream */	char	**ofile;	struct header **oh;	extern int	optind;	extern char	*optarg;	int	ch;	int	num_out_files=0;	char	*r_range=NULL;	char	*s_range=NULL;	long	start_point=1, nan=0;	long	end_point=LONG_MAX;	struct feasd *in_feasd;	struct feasd **out_feasd;		FILE * in_fd;	struct header *ih;	long	*channels=NULL;	long	num_channels=0;	char	*prototype=NULL;	int	Sflag=0;	char	*input_file=NULL;	char	*cptr;	int	i;	int	input_type;	double	*in_start_time;	int	start_type,out_type;	int	start_size;	long	num_channels_file;	double	input_sf;	int	nread=0;	int	done=0;	int	max_channels;	int	use_stdin=0;			while ((ch = getopt(argc, argv, "p:r:s:x:e:o:SP:")) != EOF)		switch (ch)  {		case 'e':			channels=grange_switch(optarg,&num_channels);			break;		case 'o':			prototype = optarg;			break;		case 'r':		case 'p':			r_range = optarg;			break;		case 's':			s_range = optarg;			break;		case 'x':			debug_level = atoi(optarg);			break;		case 'S':			Sflag=1;			break;		case 'P':			param_file = optarg;			break;		default:			SYNTAX;		}						if (s_range) {		ERROR_EXIT("s option not implemented in this version");	}	if (argc - optind < 1) {                Fprintf(stderr, "demux: no files specified.\n");                SYNTAX;        }	input_file = eopen(ProgName,argv[optind++],"r",FT_FEA,FEA_SD,		&ih,&in_fd);	if ((input_type = get_fea_type("samples", ih)) == UNDEF){		ERROR_EXIT("Input file has no field named samples!");	}	input_sf = get_genhd_val("record_freq",ih,(double)1);	if(debug_level)		Fprintf(stderr,"record_freq: %g\n",input_sf);	(void)read_params(param_file,SC_CHECK_FILE,input_file);	if(!Sflag && (symtype("make_real") != ST_UNDEF)) {		cptr = getsym_s("make_real");		if(strcmp(cptr,"yes") || strcmp(cptr,"YES"))			Sflag=1;	}	if(Sflag && !is_field_complex(ih,"samples")){		ERROR_EXIT("S option used, but input is not complex");	}		if (!channels && (symtype("channels") != ST_UNDEF)) {		num_channels = symsize("channels");		channels = (long *)calloc((unsigned)num_channels,sizeof(long));		spsassert(channels,"calloc failed");		(void)getsym_ia("channels",(int *)channels,symsize("channels"));	}	if(!prototype && (symtype("prototype") != ST_UNDEF)) 		prototype = getsym_s("prototype");	if (ih->common.ndrec == -1) ih->common.ndrec = LONG_MAX;	end_point = ih->common.ndrec;	if(r_range)		lrange_switch(r_range,&start_point,&end_point,1);	else {		if(symtype("start") != ST_UNDEF)			start_point = getsym_i("start");		if (symtype("nan") != ST_UNDEF) {			nan = getsym_i("nan");			if(nan == 0) nan=end_point;			end_point=start_point+nan-1;		}	}	if(start_point>end_point)		ERROR_EXIT("demux: start point > end_point");	if(end_point > ih->common.ndrec) {		Fprintf(stderr,"demux: end_point > number of records.\n");		Fprintf(stderr,"demux: end_point reset to %d.\n",			ih->common.ndrec);		end_point = ih->common.ndrec;	}	if (!channels) {		num_channels = get_chans(ih);		if(Sflag) num_channels *= 2;		channels = (long *)calloc((unsigned)num_channels,sizeof(long));		spsassert(channels,"calloc failed");		for(i=0;i<num_channels;i++)			channels[i]=i;	}	max_channels = get_chans(ih);	if(Sflag) max_channels *= 2;	for(i=0;i<num_channels; i++)			if(channels[i]<0 || channels[i]>max_channels-1){			ERROR_EXIT("Channel number out of bounds.");		}		if((optind == argc) && !prototype) {	    ERROR_EXIT("Either an output file or a prototype must be given.");	}		ofile = (char **)calloc((unsigned)num_channels,sizeof(char *));	spsassert(ofile,"calloc failed");	i=0;	while(optind < argc) {		ofile[i]=argv[optind++];		if(strcmp(ofile[i++],"-")==0) use_stdin++;	}	if(use_stdin>1)		ERROR_EXIT("Only one output file can be standard output.");	num_out_files=i;	if(num_out_files == 0) {		for(i=0;i<num_channels;i++) {			ofile[i]=malloc((unsigned)strlen(prototype)+10);			spsassert(ofile[i],"calloc failed");			(void)sprintf(ofile[i],"%s%03d",prototype,channels[i]);		}		num_out_files = num_channels;	}	if(num_out_files != 1 && num_out_files != num_channels) {		ERROR_EXIT(              "Number of output files must be 1 or number of output channels");	}	if(num_out_files == 1)		num_channels_file = num_channels;	else		num_channels_file = 1;	start_type = genhd_type("start_time",&start_size,ih);	if(start_type != DOUBLE) {		start_size=0;		Fprintf(stderr,		 "demux: Warning, start_time in input file not double.\n");		Fprintf(stderr,		 "demux: start_time in input file being ignored.\n");	}	if(start_size == 0) {		in_start_time = (double *)calloc((unsigned)num_channels,sizeof (double));		for(i=0;i<num_channels;i++)			in_start_time[i]=0;	} else if (start_size != get_chans(ih) && start_size != 1) {		Fprintf(stderr,		 "demux: input start size array is wrong size, just using the first value\n");		start_size = 1;		} else if (start_size == 1) {		double tmp = get_genhd_val("start_time",ih,(double)0);		in_start_time = (double *)calloc((unsigned)num_channels,sizeof (double));		for(i=0;i<num_channels;i++)			in_start_time[i]=tmp;	} else if(start_size == get_chans(ih)) {		double *ptr=get_genhd_d("start_time",ih);		in_start_time = (double *)calloc((unsigned)num_channels,sizeof (double));		spsassert(ptr,"get_genhd_d failed");		for(i=0;i<num_channels;i++)			in_start_time[i] = ptr[channels[i]];	} 	if(debug_level) {		Fprintf(stderr,"Input start_time: ");		for(i=0; i<num_channels;i++)			Fprintf(stderr,"%g ",in_start_time[i]);		Fprintf(stderr,"\n");	}	for(i=0;i<num_channels;i++) 		in_start_time[i] = in_start_time[i]+(start_point-1)/

⌨️ 快捷键说明

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