sdsupport.c

来自「speech signal process tools」· C语言 代码 · 共 704 行 · 第 1/2 页

C
704
字号
    int			edr_flag;    char    	    	*data;    static struct feasd	rec = {FLOAT, 0, 1L, NULL, NULL};    spsassert(hd != NULL, "put_sd_recf: hd is NULL");    spsassert(hd->common.type == FT_SD	      || (hd->common.type == FT_FEA && hd->hd.fea->fea_type == FEA_SD		  && 1 == get_fea_siz("samples", hd,				      (short *) NULL, (long **) NULL)),	      "put_sd_recf: file not SD or single_channel FEA_SD");    spsassert(fbuf != NULL, "put_sd_recf: fbuf is NULL");    spsassert(nsmpls > 0, "put_sd_recf: nsmpls <= 0");    spsassert(stream != NULL, "put_sd_recf: stream is NULL");    switch (hd->common.type)    {    case FT_SD:	if ((type = get_sd_type(hd)) == NONE) {		Fprintf(stderr, "put_sd_recf: type not set yet.\n");		exit(1);	}	if (nsmpls == 0)		return;	edr_flag = hd->common.edr;	switch (type) {	case CHAR:	case BYTE:	case SHORT:	case LONG:	case DOUBLE:	    data = calloc((unsigned) nsmpls, (unsigned) typesiz(type));	    spsassert(data, "calloc failed!");	    (void) type_convert((long) nsmpls, (char *) fbuf, FLOAT,				data, type, (void (*)()) NULL);	    n = miio_put(type, data, nsmpls, edr_flag, stream);	    if (n != nsmpls) goto bomb;	    free(data);	    break;	case FLOAT:		/* No conversion is needed. */	    n = miio_put_float(fbuf, nsmpls, edr_flag, stream);	    if (n != nsmpls) goto bomb;	    break;	default:	    Fprintf(stderr, "put_sd_recf: unknown type code '%d'\n", type);	    exit(1);	}	break;    case FT_FEA:	rec.num_records = nsmpls;	rec.data = (char *) fbuf;	if (put_feasd_recs(&rec, 0L, (long) nsmpls, hd, stream))	    goto bomb;	break;    }	return;bomb:	perror("put_sd_recf: write error");	exit(1);}/* * writes records into a sampled data file.  The header is checked for the * type of the data in the file.  The data is taken in double format.  */voidput_sd_recd(dbuf, nsmpls, hd, stream)    double		*dbuf;    int			nsmpls;    struct header	*hd;    FILE		*stream;{    int			n, type;    int			edr_flag;    char    	    	*data;    static struct feasd	rec = {DOUBLE, 0, 1L, NULL, NULL};    spsassert(hd != NULL, "put_sd_recd: hd is NULL");    spsassert(hd->common.type == FT_SD	      || (hd->common.type == FT_FEA && hd->hd.fea->fea_type == FEA_SD		  && 1 == get_fea_siz("samples", hd,				      (short *) NULL, (long **) NULL)),	      "put_sd_recd: file not SD or single_channel FEA_SD");    spsassert(dbuf != NULL, "put_sd_recd: dbuf is NULL");    spsassert(nsmpls > 0, "put_sd_recd: nsmpls <= 0");    spsassert(stream != NULL, "put_sd_recd: stream is NULL");    switch (hd->common.type)    {    case FT_SD:	if ((type = get_sd_type(hd)) == NONE) {		Fprintf(stderr, "put_sd_recd: type not set yet.\n");		exit(1);	}	if (nsmpls == 0)		return;	edr_flag = hd->common.edr;	switch (type) {	case CHAR:	case BYTE:	case SHORT:	case LONG:	case FLOAT:	    data = calloc((unsigned) nsmpls, (unsigned) typesiz(type));	    spsassert(data, "calloc failed!");	    (void) type_convert((long) nsmpls, (char *) dbuf, DOUBLE,				data, type, (void (*)()) NULL);	    n = miio_put(type, data, nsmpls, edr_flag, stream);	    if (n != nsmpls) goto bomb;	    free(data);	    break;	case DOUBLE:		/* No conversion is needed. */	    n = miio_put_double(dbuf, nsmpls, edr_flag, stream);	    if (n != nsmpls) goto bomb;	    break;	default:	    Fprintf(stderr, "put_sd_recd: unknown type code '%d'\n", type);	    exit(1);	}	break;    case FT_FEA:	rec.num_records = nsmpls;	rec.data = (char *) dbuf;	if (put_feasd_recs(&rec, 0L, (long) nsmpls, hd, stream))	    goto bomb;	break;    }	return;bomb:	perror("put_sd_recd: write error");	exit(1);}/* * writes records into a sampled data file.  The header is checked for the * type of the data in the file.  The data is taken in short format.  */voidput_sd_recs(sbuf, nsmpls, hd, stream)    short		*sbuf;    int			nsmpls;    struct header	*hd;    FILE		*stream;{    int			n, type;    int			edr_flag;    char    	    	data[BUFSIZ];    static struct feasd	rec = {SHORT, 0, 1L, NULL, NULL};    spsassert(hd != NULL, "put_sd_recs: hd is NULL");    spsassert(hd->common.type == FT_SD	      || (hd->common.type == FT_FEA && hd->hd.fea->fea_type == FEA_SD		  && 1 == get_fea_siz("samples", hd,				      (short *) NULL, (long **) NULL)),	      "put_sd_recs: file not SD or single_channel FEA_SD");    spsassert(sbuf != NULL, "put_sd_recs: sbuf is NULL");    spsassert(nsmpls > 0, "put_sd_recs: nsmpls <= 0");    spsassert(stream != NULL, "put_sd_recs: stream is NULL");    switch (hd->common.type)    {    case FT_SD:	if ((type = get_sd_type(hd)) == NONE) {		Fprintf(stderr, "put_sd_recs: type not set yet.\n");		exit(1);	}	edr_flag = hd->common.edr;	n = BUFSIZ / typesiz(type);	/*	 * Write the next block of n samples. If fewer than n remain to be	 * written, write the smaller number 	 */	while (nsmpls > 0)	{	    if (nsmpls < n)		n = nsmpls;	    switch (type) {	    case CHAR:	    case BYTE:	    case LONG:	    case DOUBLE:	    case FLOAT:		(void) type_convert((long) n, (char *) sbuf, SHORT,				    data, type, (void (*)()) NULL);		if (miio_put(type, data, n, edr_flag, stream) != n)		    goto bomb;		break;	    case SHORT:		if (miio_put_short(sbuf, n, edr_flag, stream) != n)		    goto bomb;		break;	    default:		Fprintf(stderr, 			"put_sd_recs: called with unknown type %d\n" ,type);		exit(1);	    }	    sbuf += n;	    nsmpls -= n;	}	break;    case FT_FEA:	rec.num_records = nsmpls;	rec.data = (char *) sbuf;	if (put_feasd_recs(&rec, 0L, (long) nsmpls, hd, stream))	    goto bomb;	break;    }    return;bomb:	perror("put_sd_recs: write error");	exit(1);}intget_sd_orecd(dbuf, framelen, nmove, first, hd, file)double         *dbuf;int             framelen;int             nmove;int             first;struct header  *hd;FILE           *file;{	int             i;	int             num_read;	spsassert(hd != NULL, "get_sd_orecd: hd is NULL");	spsassert(hd->common.type == FT_SD		 || (hd->common.type == FT_FEA		     && hd->hd.fea->fea_type == FEA_SD		     && 1 == get_fea_siz("samples", hd,					 (short *) NULL, (long **) NULL)),		 "get_sd_orecd: file not SD or single_channel FEA_SD");	spsassert(dbuf != NULL, "get_sd_orecd: dbuf is NULL");	spsassert(framelen >= 0, "get_sd_orecd: framelen < 0");	spsassert(nmove >= 0, "get_sd_orecd: nmove < 0");	spsassert(file != NULL, "get_sd_orecd: file is NULL");	/*	 * first case is with first == 0, just read framelen number of points 	 */	if (first == 1)		return (get_sd_recd(dbuf, framelen, hd, file));	if (nmove == 0)		return (framelen);	if (nmove >= framelen) {		fea_skiprec(file, (long) (nmove - framelen), hd);		return (get_sd_recd(dbuf, framelen, hd, file));	}	for (i = 0; i <= framelen - nmove; i++)		dbuf[i] = dbuf[i + nmove];	num_read = get_sd_recd(dbuf + (framelen - nmove), nmove, hd, file);	return (num_read + framelen - nmove);}intget_sd_orecf(fbuf, framelen, nmove, first, hd, file)float          *fbuf;int             framelen;int             nmove;int             first;struct header  *hd;FILE           *file;{	int             i;	int             num_read;	spsassert(hd != NULL, "get_sd_orecf: hd is NULL");	spsassert(hd->common.type == FT_SD		 || (hd->common.type == FT_FEA		     && hd->hd.fea->fea_type == FEA_SD		     && 1 == get_fea_siz("samples", hd,					 (short *) NULL, (long **) NULL)),		 "get_sd_orecf: file not SD or single_channel FEA_SD");	spsassert(fbuf != NULL, "get_sd_orecf: fbuf is NULL");	spsassert(framelen >= 0, "get_sd_orecf: framelen < 0");	spsassert(nmove >= 0, "get_sd_orecf: nmove < 0");	spsassert(file != NULL, "get_sd_orecf: file is NULL");	/*	 * first case is with first == 0, just read framelen number of points 	 */	if (first == 1)		return (get_sd_recf(fbuf, framelen, hd, file));	if (nmove == 0)		return (framelen);	if (nmove >= framelen) {		fea_skiprec(file, (long) (nmove - framelen), hd);		return (get_sd_recf(fbuf, framelen, hd, file));	}	for (i = 0; i <= framelen - nmove; i++)		fbuf[i] = fbuf[i + nmove];	num_read = get_sd_recf(fbuf + (framelen - nmove), nmove, hd, file);	return (num_read + framelen - nmove);}intget_sd_orecs(sbuf, framelen, nmove, first, hd, file)short          *sbuf;int             framelen;int             nmove;int             first;struct header  *hd;FILE           *file;{	int             i;	int             num_read;	spsassert(hd != NULL, "get_sd_orecs: hd is NULL");	spsassert(hd->common.type == FT_SD		 || (hd->common.type == FT_FEA		     && hd->hd.fea->fea_type == FEA_SD		     && 1 == get_fea_siz("samples", hd,					 (short *) NULL, (long **) NULL)),		 "get_sd_orecs: file not SD or single_channel FEA_SD");	spsassert(sbuf != NULL, "get_sd_orecs: sbuf is NULL");	spsassert(framelen >= 0, "get_sd_orecs: framelen < 0");	spsassert(nmove >= 0, "get_sd_orecs: nmove < 0");	spsassert(file != NULL, "get_sd_orecs: file is NULL");	/*	 * first case is with first == 0, just read framelen number of points 	 */	if (first == 1)		return (get_sd_recs(sbuf, framelen, hd, file));	if (nmove == 0)		return (framelen);	if (nmove >= framelen) {		fea_skiprec(file, (long) (nmove - framelen), hd);		return (get_sd_recs(sbuf, framelen, hd, file));	}	for (i = 0; i <= framelen - nmove; i++)		sbuf[i] = sbuf[i + nmove];	num_read = get_sd_recs(sbuf + (framelen - nmove), nmove, hd, file);	return (num_read + framelen - nmove);}

⌨️ 快捷键说明

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