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

📄 image.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 3 页
字号:
	    src_sf_def ? LONG_MAX/src_sf		: start_time + LONG_MAX/record_freq;	frange_switch(srange, &starttim, &endtim);	REQUIRE(starttim >= start_time, "starting time before start of file");	REQUIRE(starttim < endtim,		  "starting time not less than ending time");	if (src_sf_def)	{	    starttag = 1 + LROUND(starttim * src_sf);	    endtag =		(1.5 + endtim * src_sf >= LONG_MAX)		? LONG_MAX		: 1 + LROUND(endtim * src_sf);	}	else	{	    startrec = 1 + LROUND((starttim - start_time) * record_freq);	    endrec =		(1.5 + (endtim - start_time) * record_freq >= LONG_MAX)		? LONG_MAX		: 1 + LROUND((endtim - start_time) * record_freq);	}	if (debug_level > 1)	{	    Fprintf(stderr,		    "initial and final times from -s: %f, %f\n",		    starttim, endtim);	    if (src_sf_def)		Fprintf(stderr,			"initial and final tags from times: %d, %d\n",			starttag, endtag);	    else		Fprintf(stderr,			"initial and final records from times: %d, %d\n",			startrec, endrec);	}    }    else    {	rflag = YES;	startrec =	    (symtype("startrec") != ST_UNDEF)	    ? getsym_i("startrec")	    : 1;	REQUIRE(startrec >= 1, "starting record number not positive");	endrec =	    (symtype("nrecs") != ST_UNDEF && getsym_i("nrecs") != 0)	    ? startrec - 1 + getsym_i("nrecs")	    : LONG_MAX;	if (debug_level > 1)	    Fprintf(stderr,		"initial and final records from param or default: %d, %d\n",		startrec, endrec);    }    if (!tflag)	h_ttl_text =	    (symtype("x_text") != ST_UNDEF)	    ? getsym_s("x_text")	    : "";    if (!Vflag)	v_ttl_text =	    (symtype("y_text") != ST_UNDEF)	    ? getsym_s("y_text")	    : "";    if (!Tflag)	dev =	    (symtype("device") != ST_UNDEF)	    ? lin_search2(devices, getsym_s("device"))	    : DEV_DEFAULT;    if (dev == DEV_TYPE) oflag = YES;    if (!oflag && symtype("orientation") != ST_UNDEF)    {	char	*or = getsym_s("orientation");	if (strcmp(or, "rotated") == 0) oflag = YES;	else REQUIRE(strcmp(or, "default") == 0,		"unrecognized value for \"orientation\" parameter");    }    if (!Aflag)	alg =	    (symtype("algorithm") != ST_UNDEF)	    ? lin_search2(algorithms, getsym_s("algorithm"))	    : (ihd->common.type == FT_FEA		    && ihd->hd.fea->fea_type == FEA_SPEC)	    ? ( (depth() < 4)		? HT_FS2		: HT_16OD1_2 )	    : (depth() < 4)	    ? HT_FS	    : HT_16OD1;    switch (alg)    {    case HT_16LVL:    case HT_16OD1:    case HT_16OD1_2:    case HT_16OD1_3:	gray_bits = 4;	break;    case HT_OD1:    case HT_OD2:    case HT_OD3:    case HT_OD4:    case HT_FS:    case HT_FS2:    default:	gray_bits = 1;	break;    }    cmap_len = ROUND(pow(2.0, (double) gray_bits));    if (!Cflag)	cmap_filename =	    (symtype("colormap_file") == ST_UNDEF) ? NULL	    : getsym_s("colormap_file");    cmap = read_cmap(cmap_filename, cmap_len);    if (!Mflag)    {	if (symtype("magnification") != ST_UNDEF)	    mag = getsym_i("magnification");	else	    mag = 1;    }    if (mag < 1)    {	Fprintf(stderr, "%s: magnification must be positive.\n",		ProgName);	exit(1);    }    if (!Bflag)    {	if (symtype("b_scale") != ST_UNDEF)	{	    scale = getsym_i("b_scale");	    Bflag = YES;	}	else	    scale = 0;    }    get_scale(&scale);    set_margins(Bflag, scale, &lmarg, &rmarg, &tmarg, &bmarg);    get_default_size(&width, &height);    if (Sflag)	lrange_switch(Srange, &width, &height, 0);    else    {	if (symtype("width") != ST_UNDEF)	    width = getsym_i("width");	if (symtype("height") != ST_UNDEF)	    height = getsym_i("height");    }    if (oflag)    {	nrows = height;	ncols = width;    }    else    {	nrows = width;	ncols = height;    }    data_dim[0] = data_size = DATA_CHUNK;    data_dim[1] = nelem;    data = (float **) arr_alloc(2, data_dim, FLOAT, 0);    x = (double *) arr_alloc(1, &data_dim[0], DOUBLE, 0);    y = (double *) arr_alloc(1, &nelem, DOUBLE, 0);        if (pwr_flag)    {	int 	freq_format;	double  sf;		/* sampling frequency -- used in determining				 * band limits & scale on freq. axis				 */	float   *freqs;		/* frequencies from header for case ARB_FIXED				 */	REQUIRE(genhd_type("freq_format", (int *) NULL, ihd) == CODED,		"header item \"freq_format\" undefined or not CODED");	freq_format = *get_genhd_s("freq_format", ihd);	switch (freq_format)	{	case SPFMT_SYM_CTR:	case SPFMT_SYM_EDGE:	case SPFMT_ASYM_CTR:	case SPFMT_ASYM_EDGE:	    REQUIRE(genhd_type("sf", (int *) NULL, ihd) == FLOAT,		    "header item \"sf\" undefined or not FLOAT");	    sf = *get_genhd_f("sf", ihd);	    break;	case SPFMT_ARB_VAR:	    Fprintf(stderr, "%s: freq format ARB_VAR not yet supported.\n",		ProgName);	    exit(1);	    break;	case SPFMT_ARB_FIXED:	    REQUIRE(genhd_type("freqs", (int *) NULL, ihd) == FLOAT,		    "header item \"freqs\" undefined or not FLOAT");	    freqs = get_genhd_f("freqs", ihd);	    break;	default:	    Fprintf(stderr, "%s: unrecognized freq format %d.\n",		ProgName, (int) freq_format);	    exit(1);	    break;	}	switch (freq_format)	{	case SPFMT_SYM_CTR:	    for (j = 0; j < nelem; j++)		y[j] = (j + 0.5) * sf / (2 * nelem);	    break;	case SPFMT_SYM_EDGE:	    for (j = 0; j < nelem; j++)		y[j] = j * sf / (2 * (nelem - 1));	    break;	case SPFMT_ASYM_CTR:	    for (j = 0; j < nelem; j++)		y[j] = -0.5 * sf + (j + 0.5) * sf / nelem;	    break;	case SPFMT_ASYM_EDGE:	    for (j = 0; j < nelem; j++)		y[j] = -0.5 * sf + j * sf / (nelem - 1);	    break;	case SPFMT_ARB_FIXED:	    for (j = 0; j < nelem; j++)		y[j] = freqs[j];	}    }    else    {	for (j = 0; j < nelem; j++)	    y[j] = j;    }    nrecs = read_and_count(ifile, ihd, rflag || sflag && rec_fr_def,			    &startrec, &endrec, &starttag, &endtag);    if (debug_level > 1)	Fprintf(stderr, "%ld %s\n%s: %ld, %ld\n%s %ld, %ld\n",		nrecs, "returned from read_and_count",		"initial and final records", startrec, endrec,		"initial and final tags", starttag, endtag);    REQUIRE(nrecs > 1,	"span of records in file doesn't overlap given range");    switch (lbl_units)    {    case 'p':	xmin = (pflag || sflag && src_sf_def) ? starttag : x[0];	xmax = (pflag || sflag && src_sf_def) ? endtag : x[nrecs - 1];	break;    case 'r':	xmin = x[0];	xmax = x[nrecs - 1];	break;    case 's':	xmin = (pflag || sflag && src_sf_def) ? (starttag - 1)/src_sf : x[0];	xmax = (pflag || sflag && src_sf_def) ? (endtag - 1) / src_sf : x[nrecs - 1];    }    if (debug_level > 1)	Fprintf(stderr, "xmin and xmax %g, %g\n", xmin, xmax);    datamin = FLT_MAX;    datamax = -FLT_MAX;    for (i = 0; i < nrecs; i++)	for (j = 0; j < nelem; j++)	{	    if (data[i][j] < datamin) datamin = data[i][j];	    if (data[i][j] > datamax) datamax = data[i][j];	}    if (pwr_flag)    {	switch (fun)	{	case NONE:	    zmax = datamax*0.199526;	    zmin = zmax/10000;	    break;	case FN_LOG:	    zmax = datamax - 7.0;	    zmin = zmax - 40.0;	    break;	case FN_EXP:	    zmax = pow(datamax, 0.199526);	    zmin = pow(zmax, 1.0e-4);	    break;	case FN_SQ:	    zmax = datamax*0.0398107;	    zmin = zmax/10.e8;	    break;	case FN_SQRT:	    zmax = datamax*0.446684;	    zmin = zmax/100.0;	    break;	}	if (debug_level)	    Fprintf(stderr, "Limits computed from max data value: %g, %g.\n",		zmin, zmax);    }    else    {	zmin = datamin;	zmax = datamax;	if (debug_level)	    Fprintf(stderr, "Extreme data values: %g, %g.\n", zmin, zmax);    }    if (lflag)	frange_switch(lrange, &zmin, &zmax);    else    {	if (symtype("minlevel") != ST_UNDEF) zmin = getsym_d("minlevel");	if (symtype("maxlevel") != ST_UNDEF) zmax = getsym_d("maxlevel");    }    if (!Gflag)    {	if (symtype("gain_low_lim") != ST_UNDEF		|| symtype("gain_high_lim") != ST_UNDEF)	{	    REQUIRE(symtype("gain_low_lim") != ST_UNDEF			&& symtype("gain_high_lim") != ST_UNDEF,		"just one of \"gain_low_lim\" and \"gain_high_lim\" defined")	    Gflag = YES;	    gainlolim = getsym_d("gain_low_lim");	    gainhilim = getsym_d("gain_high_lim");	    	}    }    dev_init();    exit(0);    /*NOTREACHED*/}long *fea_range(fields, hd, n_ele)    char	    **fields;    struct header   *hd;    long	    *n_ele;{    int	    i, j;    char    *field_name;	/* string to hold field name */    long    *item_array;	/* array of items given in gen_range */    long    n_item;		/* number of items given in gen_range */    long    *evec;		/* vector of element numbers */    long    total_len = 0;	/* total length of fields */    long    indx = 0;		/* index into evec */    evec = malloc_l((unsigned) 1);    for (i = 0; fields[i] != NULL; i++)    {	item_array = fld_range_switch(fields[i], &field_name, &n_item, hd);	if (!item_array)	{	    Fprintf(stderr,		    "%s: field \"%s\" not defined in feature file header\n",		    ProgName, field_name);	    exit(1);	}	REQUIRE(!is_field_complex(hd, field_name),		"complex fields not yet supported");	total_len += n_item;	evec = (long *) realloc((char *) evec,				(unsigned) total_len * sizeof (long));	spsassert(evec,		"can't reallocate space for vector of element numbers");	for (j = 0; j < n_item; j++)	{	    evec[indx] = get_fea_element(field_name, hd) + item_array[j];	    indx++;	}	free((char *) item_array);    }	/* end for (i ...) */    *n_ele = total_len;    return evec;}longread_and_count(file, hd, rfl, startrec, endrec, starttag, endtag)    FILE	    *file;    struct header   *hd;    int		    rfl;    long	    *startrec, *endrec, *starttag, *endtag;{    long    	nrec;    char	*buf0 = allo_buf(hd),    	    	*buf1 = allo_buf(hd);    spsassert(buf0 && buf1,	      "can't allocate space for buffers to make temp file");    if (debug_level > 1)	Fprintf(stderr, "%s\n%s: %ld, %ld\n%s %ld, %ld\n",		"Beginning of read_and_count",		"initial and final records", *startrec, *endrec,		"initial and final tags", *starttag, *endtag);    if (rfl)    {	long	tag0;	fea_skiprec(file, *startrec - 1, hd);	for (nrec = 0;	     nrec < *endrec - *startrec + 1	     && (tag0 = read_with_tag(buf0, hd, file)) != LONG_MAX;	     (void) put_with_tag(tag0, buf0, nrec++)	     ) { }	*endrec = nrec + *startrec - 1;    }    else    {	long    tag0, tag1;	tag0 = read_with_tag(buf0, hd, file);	nrec = 1;		/* record num in tag0, buf0 */	if (tag0 > *starttag)	{	    REQUIRE(tag0 < *endtag, 		    "first record doesn't precede end of range");	    *starttag = tag0;	}	tag1 = read_with_tag(buf1, hd, file);	while (tag1 <= *starttag)	{	    char	*tmp = buf0;	    buf0 = buf1;	tag0 = tag1;	    nrec++;	    buf1 = tmp;	    tag1 = read_with_tag(buf1, hd, file);	}	*startrec = nrec;	nrec = 0;		/* num of records in data array */	put_with_tag(tag0, buf0, nrec++);	while (tag1 < *endtag)	{	    put_with_tag(tag1, buf1, nrec++);	    tag0 = tag1;	    tag1 = read_with_tag(buf1, hd, file);	}	if (tag1 == LONG_MAX)	{	    REQUIRE(tag0 > *starttag,		    "last record doesn't follow beginning of range");	    *endtag = tag0;	}	else	    put_with_tag(tag1, buf1, nrec++);	*endrec = *startrec - 1 + nrec;    }    return nrec;}char *allo_buf(hd)    struct header   *hd;{    char    *buf;    if (pwr_flag)    {	buf = (char *) allo_feaspec_rec(hd, FLOAT);	spsassert(buf, "can't allocate space for input FEA_SPEC record");    }    else    {	buf = (char *) malloc_d((unsigned) get_rec_len(hd));	spsassert(buf, "can't allocate space for input data vector");    }    return buf;}longread_with_tag(buf, hd, strm)    char	    *buf;    struct header   *hd;    FILE	    *strm;{    int	    nread;    long    tag;    if (pwr_flag)    {	struct feaspec	*specrec = (struct feaspec *) buf;	nread = get_feaspec_rec(specrec, hd, strm);	if (nread != EOF) tag = (specrec->tag) ? *specrec->tag : 0;    }    else    {	double	*genrec = (double *) buf;	nread = get_gen_recd(genrec, &tag, hd, strm);    }    if (nread == EOF) tag = LONG_MAX;    return tag;}voidput_with_tag(tag, buf, i)    long    tag;    char    *buf;    long    i;{    long    j;    if (i >= data_size) reallo_data();    if (pwr_flag)    {	struct feaspec	*specrec = (struct feaspec *) buf;	for (j = 0; j < nelem; j++)

⌨️ 快捷键说明

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